WordPress.org

Make WordPress Core

Changeset 20033


Ignore:
Timestamp:
02/29/2012 05:09:29 AM (6 years ago)
Author:
nacin
Message:

Update switch_theme() to use wp_get_theme(). see #20103, #20138.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/theme.php

    r20029 r20033  
    634634
    635635    // Prevent theme mods to current theme being used on theme being previewed
    636     add_filter( 'pre_option_mods_' . get_current_theme(), '__return_empty_array' );
     636    add_filter( 'pre_option_theme_mods_' . get_option( 'stylesheet' ), '__return_empty_array' );
    637637
    638638    ob_start( 'preview_theme_ob_filter' );
     
    712712 *
    713713 * @since 2.5.0
    714  * @uses do_action() Calls 'switch_theme' action on updated theme display name.
     714 * @uses do_action() Calls 'switch_theme' action, passing the new theme.
    715715 *
    716716 * @param string $template Template name
    717717 * @param string $stylesheet Stylesheet name.
    718718 */
    719 function switch_theme($template, $stylesheet) {
     719function switch_theme( $template, $stylesheet ) {
    720720    global $wp_theme_directories, $sidebars_widgets;
    721721
     
    723723        set_theme_mod( 'sidebars_widgets', array( 'time' => time(), 'data' => $sidebars_widgets ) );
    724724
    725     $old_theme = get_current_theme();
    726 
    727     update_option('template', $template);
    728     update_option('stylesheet', $stylesheet);
    729 
    730     if ( count($wp_theme_directories) > 1 ) {
    731         update_option('template_root', get_raw_theme_root($template, true));
    732         update_option('stylesheet_root', get_raw_theme_root($stylesheet, true));
    733     }
    734 
    735     delete_option('current_theme');
    736     $theme = get_current_theme();
    737 
    738     if ( is_admin() && false === get_option( "theme_mods_$stylesheet" ) ) {
    739         $default_theme_mods = (array) get_option( "mods_$theme" );
     725    $old_theme  = wp_get_theme();
     726    $new_theme = wp_get_theme( $stylesheet );
     727    $new_name  = $new_theme->get('Name');
     728
     729    update_option( 'template', $template );
     730    update_option( 'stylesheet', $stylesheet );
     731
     732    if ( count( $wp_theme_directories ) > 1 ) {
     733        update_option( 'template_root', get_raw_theme_root( $template, true ) );
     734        update_option( 'stylesheet_root', get_raw_theme_root( $stylesheet, true ) );
     735    }
     736
     737    update_option( 'current_theme', $new_name );
     738
     739    if ( is_admin() && false === get_option( 'theme_mods_' . $stylesheet ) ) {
     740        $default_theme_mods = (array) get_option( 'mods_' . $new_name );
    740741        add_option( "theme_mods_$stylesheet", $default_theme_mods );
    741742    }
    742743
    743     update_option( 'theme_switched', $old_theme );
    744     do_action( 'switch_theme', $theme );
     744    update_option( 'theme_switched', $old_theme->get('Name') );
     745    do_action( 'switch_theme', $new_name, $new_theme );
    745746}
    746747
Note: See TracChangeset for help on using the changeset viewer.