diff --git a/wp-admin/themes.php b/wp-admin/themes.php index 8aa783aa8..f91a69bbb 100644 --- a/wp-admin/themes.php +++ b/wp-admin/themes.php @@ -5,14 +5,7 @@ if ( isset($_GET['action']) ) { check_admin_referer('switch-theme_' . $_GET['template']); if ('activate' == $_GET['action']) { - if ( isset($_GET['template']) ) - update_option('template', $_GET['template']); - - if ( isset($_GET['stylesheet']) ) - update_option('stylesheet', $_GET['stylesheet']); - - do_action('switch_theme', get_current_theme()); - + switch_theme($_GET['template'], $_GET['stylesheet']); wp_redirect('themes.php?activated=true'); exit; } diff --git a/wp-includes/theme.php b/wp-includes/theme.php index 3362c1d4b..e14ea6788 100644 --- a/wp-includes/theme.php +++ b/wp-includes/theme.php @@ -294,6 +294,9 @@ function get_theme($theme) { } function get_current_theme() { + if ( $theme = get_option('current_theme') ) + return $theme; + $themes = get_themes(); $theme_names = array_keys($themes); $current_template = get_option('template'); @@ -310,6 +313,8 @@ function get_current_theme() { } } + update_option('current_theme', $current_theme); + return $current_theme; } @@ -447,22 +452,26 @@ function locale_stylesheet() { echo ''; } +function switch_theme($template, $stylesheet) { + update_option('template', $template); + update_option('stylesheet', $stylesheet); + delete_option('current_theme'); + $theme = get_current_theme(); + do_action('switch_theme', $theme); +} + function validate_current_theme() { // Don't validate during an install/upgrade. if ( defined('WP_INSTALLING') ) return true; if ( get_template() != 'default' && !file_exists(get_template_directory() . '/index.php') ) { - update_option('template', 'default'); - update_option('stylesheet', 'default'); - do_action('switch_theme', 'Default'); + switch_theme('default', 'default'); return false; } if ( get_stylesheet() != 'default' && !file_exists(get_template_directory() . '/style.css') ) { - update_option('template', 'default'); - update_option('stylesheet', 'default'); - do_action('switch_theme', 'Default'); + switch_theme('default', 'default'); return false; }