From e531ad04c481d3a21fe1f01a24523becad72c6f7 Mon Sep 17 00:00:00 2001 From: ryan Date: Tue, 13 Nov 2007 05:07:44 +0000 Subject: [PATCH] Add switch_theme(). Cache current theme in options to avoid calling get_themes(). fixes #5346 git-svn-id: http://svn.automattic.com/wordpress/trunk@6334 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/themes.php | 9 +-------- wp-includes/theme.php | 21 +++++++++++++++------ 2 files changed, 16 insertions(+), 14 deletions(-) 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; }