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
+18 -8
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;
}