From d5434d7cc72591d4f9e8afcd646c0fcf136249ba Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Wed, 20 Nov 2019 18:49:03 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@46754 git-svn-id: http://core.svn.wordpress.org/trunk@46554 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-customize-manager.php | 20 ++++++++++++++++++++ wp-includes/version.php | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/wp-includes/class-wp-customize-manager.php b/wp-includes/class-wp-customize-manager.php index 17a6fa5767..decf0b87cf 100644 --- a/wp-includes/class-wp-customize-manager.php +++ b/wp-includes/class-wp-customize-manager.php @@ -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; } diff --git a/wp-includes/version.php b/wp-includes/version.php index 1e7face89a..1bbc25bcfe 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.4-alpha-46753'; +$wp_version = '5.4-alpha-46754'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.