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
This commit is contained in:
ryan 2007-11-13 05:07:44 +00:00
parent 6bed155f5d
commit e531ad04c4
2 changed files with 16 additions and 14 deletions

View File

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

View File

@ -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 '<link rel="stylesheet" href="' . $stylesheet . '" type="text/css" media="screen" />';
}
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;
}