Changeset 6334

Show
Ignore:
Timestamp:
11/13/07 05:07:44 (1 year ago)
Author:
ryan
Message:

Add switch_theme(). Cache current theme in options to avoid calling get_themes(). fixes #5346

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/wp-admin/themes.php

    r6033 r6334  
    66 
    77    if ('activate' == $_GET['action']) { 
    8         if ( isset($_GET['template']) ) 
    9             update_option('template', $_GET['template']); 
    10  
    11         if ( isset($_GET['stylesheet']) ) 
    12             update_option('stylesheet', $_GET['stylesheet']); 
    13  
    14         do_action('switch_theme', get_current_theme()); 
    15  
     8        switch_theme($_GET['template'], $_GET['stylesheet']); 
    169        wp_redirect('themes.php?activated=true'); 
    1710        exit; 
  • trunk/wp-includes/theme.php

    r6099 r6334  
    295295 
    296296function get_current_theme() { 
     297    if ( $theme = get_option('current_theme') ) 
     298        return $theme; 
     299 
    297300    $themes = get_themes(); 
    298301    $theme_names = array_keys($themes); 
     
    310313        } 
    311314    } 
     315 
     316    update_option('current_theme', $current_theme); 
    312317 
    313318    return $current_theme; 
     
    448453} 
    449454 
     455function switch_theme($template, $stylesheet) { 
     456    update_option('template', $template); 
     457    update_option('stylesheet', $stylesheet); 
     458    delete_option('current_theme'); 
     459    $theme = get_current_theme(); 
     460    do_action('switch_theme', $theme); 
     461} 
     462 
    450463function validate_current_theme() { 
    451464    // Don't validate during an install/upgrade. 
     
    454467 
    455468    if ( get_template() != 'default' && !file_exists(get_template_directory() . '/index.php') ) { 
    456         update_option('template', 'default'); 
    457         update_option('stylesheet', 'default'); 
    458         do_action('switch_theme', 'Default'); 
     469        switch_theme('default', 'default'); 
    459470        return false; 
    460471    } 
    461472 
    462473    if ( get_stylesheet() != 'default' && !file_exists(get_template_directory() . '/style.css') ) { 
    463         update_option('template', 'default'); 
    464         update_option('stylesheet', 'default'); 
    465         do_action('switch_theme', 'Default'); 
     474        switch_theme('default', 'default'); 
    466475        return false; 
    467476    }