Ticket #5346: current_theme.diff

File current_theme.diff, 2.2 KB (added by ryan, 5 years ago)

Adds switch_theme() and caches current theme in options

  • wp-includes/theme.php

     
    294294} 
    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); 
    299302        $current_template = get_option('template'); 
     
    310313                } 
    311314        } 
    312315 
     316        update_option('current_theme', $current_theme); 
     317 
    313318        return $current_theme; 
    314319} 
    315320 
     
    447452        echo '<link rel="stylesheet" href="' . $stylesheet . '" type="text/css" media="screen" />'; 
    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. 
    452465        if ( defined('WP_INSTALLING') ) 
    453466                return true; 
    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        } 
    468477 
  • wp-admin/themes.php

     
    55        check_admin_referer('switch-theme_' . $_GET['template']); 
    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; 
    1811        }