Allow switch_theme() to take a single $stylesheet argument.

It now effectively has two function definitions:
function switch_theme( $stylesheet )
function switch_theme( $template, $stylesheet )

fixes #21075.



git-svn-id: https://develop.svn.wordpress.org/trunk@21131 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Nacin 2012-06-26 05:21:04 +00:00
parent cf2b99340f
commit f3e45be558
4 changed files with 23 additions and 15 deletions

View File

@ -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

View File

@ -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'] ) {

View File

@ -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();
}

View File

@ -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;
}