Customize: If the return URL for Close button is a page added to the Appearance menu by a deactivated theme, fall back to the Themes screen.

Props JarretC, Jean-David, SergeyBiryukov.
Fixes #46686.

git-svn-id: https://develop.svn.wordpress.org/trunk@46754 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2019-11-20 18:47:08 +00:00
parent 071030b793
commit 3b54ab37ed
2 changed files with 28 additions and 0 deletions

View File

@ -4622,9 +4622,13 @@ final class WP_Customize_Manager {
*
* @since 4.4.0
*
* @global array $_registered_pages
*
* @return string URL for link to close Customizer.
*/
public function get_return_url() {
global $_registered_pages;
$referer = wp_get_referer();
$excluded_referer_basenames = array( 'customize.php', 'wp-login.php' );
@ -4637,6 +4641,22 @@ final class WP_Customize_Manager {
} else {
$return_url = home_url( '/' );
}
$return_url_basename = wp_basename( parse_url( $this->return_url, PHP_URL_PATH ) );
$return_url_query = parse_url( $this->return_url, PHP_URL_QUERY );
if ( 'themes.php' === $return_url_basename && $return_url_query ) {
parse_str( $return_url_query, $query_vars );
/*
* If the return URL is a page added by a theme to the Appearance menu via add_submenu_page(),
* verify that belongs to the active theme, otherwise fall back to the Themes screen.
*/
if ( isset( $query_vars['page'] ) && ! isset( $_registered_pages[ "appearance_page_{$query_vars['page']}" ] ) ) {
$return_url = admin_url( 'themes.php' );
}
}
return $return_url;
}

View File

@ -2829,6 +2829,14 @@ class Tests_WP_Customize_Manager extends WP_UnitTestCase {
$this->assertEquals( admin_url( 'edit.php' ), $this->manager->get_return_url() );
}
/**
* @ticket 46686
*/
function test_return_url_with_deactivated_theme() {
$this->manager->set_return_url( admin_url( 'themes.php?page=mytheme_documentation' ) );
$this->assertEquals( admin_url( 'themes.php' ), $this->manager->get_return_url() );
}
/**
* Test get_autofocus()/set_autofocus() methods.
*