Make WordPress Core


Ignore:
Timestamp:
06/26/2012 05:21:04 AM (12 years ago)
Author:
nacin
Message:

Allow switch_theme() to take a single $stylesheet argument.

It now effectively has two function definitions:
function switch_theme( $stylesheet )
function switch_theme( $template, $stylesheet )

fixes #21075.

File:
1 edited

Legend:

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

    r21126 r21131  
    651651
    652652/**
    653  * Switches current theme to new template and stylesheet names.
     653 * Switches the theme.
     654 *
     655 * Accepts one argument: $stylesheet of the theme. It also accepts an additional function signature
     656 * of two arguments: $template then $stylesheet. This is for backwards compatibility.
    654657 *
    655658 * @since 2.5.0
    656659 * @uses do_action() Calls 'switch_theme' action, passing the new theme.
    657660 *
    658  * @param string $template Template name
    659  * @param string $stylesheet Stylesheet name.
    660  */
    661 function switch_theme( $template, $stylesheet ) {
     661 * @param string $stylesheet Stylesheet name
     662 */
     663function switch_theme( $stylesheet ) {
    662664    global $wp_theme_directories, $sidebars_widgets;
    663665
     
    667669    $old_theme  = wp_get_theme();
    668670    $new_theme = wp_get_theme( $stylesheet );
    669     $new_name  = $new_theme->get('Name');
     671
     672    if ( func_num_args() > 1 ) {
     673        $template = $stylesheet;
     674        $stylesheet = func_get_arg( 1 );
     675    } else {
     676        $template = $new_theme->get_template();
     677    }
    670678
    671679    update_option( 'template', $template );
     
    676684        update_option( 'stylesheet_root', get_raw_theme_root( $stylesheet, true ) );
    677685    }
     686
     687    $new_name  = $new_theme->get('Name');
    678688
    679689    update_option( 'current_theme', $new_name );
     
    707717
    708718    if ( get_template() != WP_DEFAULT_THEME && !file_exists(get_template_directory() . '/index.php') ) {
    709         switch_theme( WP_DEFAULT_THEME, WP_DEFAULT_THEME );
     719        switch_theme( WP_DEFAULT_THEME );
    710720        return false;
    711721    }
    712722
    713723    if ( get_stylesheet() != WP_DEFAULT_THEME && !file_exists(get_template_directory() . '/style.css') ) {
    714         switch_theme( WP_DEFAULT_THEME, WP_DEFAULT_THEME );
     724        switch_theme( WP_DEFAULT_THEME );
    715725        return false;
    716726    }
    717727
    718728    if ( is_child_theme() && ! file_exists( get_stylesheet_directory() . '/style.css' ) ) {
    719         switch_theme( WP_DEFAULT_THEME, WP_DEFAULT_THEME );
     729        switch_theme( WP_DEFAULT_THEME );
    720730        return false;
    721731    }
Note: See TracChangeset for help on using the changeset viewer.