Change the Return URL from the Customizer

I want to change the return URL after someone cancels or closes out of their changes when using the Apperance -> Customize option within WordPress. In the wp-admin/customize.php file here is the code to control the return URL:

wp_reset_vars( array( 'url', 'return' ) );
$url = wp_unslash( $url );
$url = wp_validate_redirect( $url, home_url( '/' ) );
if ( $return ) {
    $return = wp_unslash( $return );
    $return = wp_validate_redirect( $return );
}
if ( ! $return ) {
    if ( $url ) {
        $return = $url;
    } elseif ( current_user_can( 'edit_theme_options' ) || current_user_can( 'switch_themes' ) ) {
        $return = admin_url( 'themes.php' );
    } else {
        $return = admin_url();
    }
}

The URL is output to the screen with the following code:

<a class="customize-controls-close" href="<?php echo esc_url( $return ); ?>">
    <span class="screen-reader-text"><?php _e( 'Cancel' ); ?></span>
</a> 

Is there a way to control the return URL wihtout modifying the core wp-admin/customize.php file?

Solutions Collecting From Web of "Change the Return URL from the Customizer"

Yes, this is possible. On the link, there you create for the customizing view can you add a return parameter with the url, for this option.

I mean, you must change the the link for the Customize Link in the Admin Menu. The follow demonstrate this. I create at fist a link inside the “Appearance” Menu and parse this slug to change the url to custom url, include two parameters.

  1. url – defined for load a specific page in the customizer
  2. return – defined the url for close the customizer, the return url

The important part is the function add_query_arg() to add this parameters to the url.

$login_url = wp_login_url();
$url       = add_query_arg(
    array(
        'url'    => urlencode( $login_url ),
        'return' => admin_url( 'themes.php' ),
    ),
    admin_url( 'customize.php' )
);

The follow source and doing the completely job, include add menu item and change his link. You must load, include this in your theme, plugin.

    <?php # -*- coding: utf-8 -*-

    namespace CustomizeLogin\Admin;

    \add_action( 'admin_menu', '\CustomizeLogin\Admin\add_menu' );
    function add_menu() {

        if ( ! current_user_can( 'customize' ) ) {
            return NULL;
        }

        add_theme_page(
            esc_attr__( 'Customize the Login screen', 'customize-login' ),
            esc_attr__( 'Customize Login', 'customize-login' ),
            'manage_options',
            'customize-login',
            '__return_null()'
        );
    }

    \add_action( 'admin_menu', '\CustomizeLogin\Admin\change_menu_url', 99 );
    function change_menu_url() {

        global $submenu;

        $parent = 'themes.php';
        $page   = 'customize-login';

        // Create specific url for login view
        $login_url = wp_login_url();
        $url       = add_query_arg(
            array(
                'url'    => urlencode( $login_url ),
                'return' => admin_url( 'themes.php' ),
            ),
            admin_url( 'customize.php' )
        );

        // If is Not Design Menu, return
        if ( ! isset( $submenu[ $parent ] ) ) {
            return NULL;
        }

        foreach ( $submenu[ $parent ] as $key => $value ) {
            // Set new URL for menu item
            if ( $page === $value[ 2 ] ) {
                $submenu[ $parent ][ $key ][ 2 ] = $url;
                break;
            }
        }
    }