diff --git a/wp-admin/includes/class-wp-upgrader.php b/wp-admin/includes/class-wp-upgrader.php index f2db9ef97..406032037 100644 --- a/wp-admin/includes/class-wp-upgrader.php +++ b/wp-admin/includes/class-wp-upgrader.php @@ -953,13 +953,11 @@ class Theme_Upgrader extends WP_Upgrader { if ( $theme != get_stylesheet() ) // If not current return $return; - // Ensure stylesheet name hasnt changed after the upgrade: - // @TODO: Note, This doesn't handle the Template changing, or the Template name changing. + // Ensure stylesheet name hasn't changed after the upgrade: if ( $theme == get_stylesheet() && $theme != $this->result['destination_name'] ) { - $theme_info = $this->theme_info(); + wp_clean_themes_cache(); $stylesheet = $this->result['destination_name']; - $template = $theme_info->get_template(); - switch_theme($template, $stylesheet, true); + switch_theme( $stylesheet ); } //Time to remove maintenance mode diff --git a/wp-admin/themes.php b/wp-admin/themes.php index 465626d2d..5a78fe3dd 100644 --- a/wp-admin/themes.php +++ b/wp-admin/themes.php @@ -20,7 +20,7 @@ if ( current_user_can( 'switch_themes' ) && isset($_GET['action'] ) ) { $theme = wp_get_theme( $_GET['stylesheet'] ); if ( ! $theme->exists() || ! $theme->is_allowed() ) wp_die( __( 'Cheatin’ uh?' ) ); - switch_theme($_GET['template'], $_GET['stylesheet']); + switch_theme( $theme->get_stylesheet() ); wp_redirect( admin_url('themes.php?activated=true') ); exit; } elseif ( 'delete' == $_GET['action'] ) { diff --git a/wp-includes/class-wp-customize-manager.php b/wp-includes/class-wp-customize-manager.php index c1ce0510e..b561fb24e 100644 --- a/wp-includes/class-wp-customize-manager.php +++ b/wp-includes/class-wp-customize-manager.php @@ -475,7 +475,7 @@ final class WP_Customize_Manager { // Temporarily stop previewing the theme to allow switch_themes() // to operate properly. $this->stop_previewing_theme(); - switch_theme( $this->get_template(), $this->get_stylesheet() ); + switch_theme( $this->get_stylesheet() ); $this->start_previewing_theme(); } diff --git a/wp-includes/theme.php b/wp-includes/theme.php index ba968bca8..a99f58c40 100644 --- a/wp-includes/theme.php +++ b/wp-includes/theme.php @@ -650,15 +650,17 @@ function preview_theme_ob_filter_callback( $matches ) { } /** - * Switches current theme to new template and stylesheet names. + * Switches the theme. + * + * Accepts one argument: $stylesheet of the theme. It also accepts an additional function signature + * of two arguments: $template then $stylesheet. This is for backwards compatibility. * * @since 2.5.0 * @uses do_action() Calls 'switch_theme' action, passing the new theme. * - * @param string $template Template name - * @param string $stylesheet Stylesheet name. + * @param string $stylesheet Stylesheet name */ -function switch_theme( $template, $stylesheet ) { +function switch_theme( $stylesheet ) { global $wp_theme_directories, $sidebars_widgets; if ( is_array( $sidebars_widgets ) ) @@ -666,7 +668,13 @@ function switch_theme( $template, $stylesheet ) { $old_theme = wp_get_theme(); $new_theme = wp_get_theme( $stylesheet ); - $new_name = $new_theme->get('Name'); + + if ( func_num_args() > 1 ) { + $template = $stylesheet; + $stylesheet = func_get_arg( 1 ); + } else { + $template = $new_theme->get_template(); + } update_option( 'template', $template ); update_option( 'stylesheet', $stylesheet ); @@ -676,6 +684,8 @@ function switch_theme( $template, $stylesheet ) { update_option( 'stylesheet_root', get_raw_theme_root( $stylesheet, true ) ); } + $new_name = $new_theme->get('Name'); + update_option( 'current_theme', $new_name ); if ( is_admin() && false === get_option( 'theme_mods_' . $stylesheet ) ) { @@ -706,17 +716,17 @@ function validate_current_theme() { return true; if ( get_template() != WP_DEFAULT_THEME && !file_exists(get_template_directory() . '/index.php') ) { - switch_theme( WP_DEFAULT_THEME, WP_DEFAULT_THEME ); + switch_theme( WP_DEFAULT_THEME ); return false; } if ( get_stylesheet() != WP_DEFAULT_THEME && !file_exists(get_template_directory() . '/style.css') ) { - switch_theme( WP_DEFAULT_THEME, WP_DEFAULT_THEME ); + switch_theme( WP_DEFAULT_THEME ); return false; } if ( is_child_theme() && ! file_exists( get_stylesheet_directory() . '/style.css' ) ) { - switch_theme( WP_DEFAULT_THEME, WP_DEFAULT_THEME ); + switch_theme( WP_DEFAULT_THEME ); return false; }