Make WordPress Core

Changeset 21131


Ignore:
Timestamp:
06/26/2012 05:21:04 AM (14 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.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/class-wp-upgrader.php

    r21080 r21131  
    954954                        return $return;
    955955
    956                 // Ensure stylesheet name hasnt changed after the upgrade:
    957                 // @TODO: Note, This doesn't handle the Template changing, or the Template name changing.
     956                // Ensure stylesheet name hasn't changed after the upgrade:
    958957                if ( $theme == get_stylesheet() && $theme != $this->result['destination_name'] ) {
    959                         $theme_info = $this->theme_info();
     958                        wp_clean_themes_cache();
    960959                        $stylesheet = $this->result['destination_name'];
    961                         $template = $theme_info->get_template();
    962                         switch_theme($template, $stylesheet, true);
     960                        switch_theme( $stylesheet );
    963961                }
    964962
  • trunk/wp-admin/themes.php

    r21106 r21131  
    2121                if ( ! $theme->exists() || ! $theme->is_allowed() )
    2222                        wp_die( __( 'Cheatin’ uh?' ) );
    23                 switch_theme($_GET['template'], $_GET['stylesheet']);
     23                switch_theme( $theme->get_stylesheet() );
    2424                wp_redirect( admin_url('themes.php?activated=true') );
    2525                exit;
  • trunk/wp-includes/class-wp-customize-manager.php

    r21070 r21131  
    476476                        // to operate properly.
    477477                        $this->stop_previewing_theme();
    478                         switch_theme( $this->get_template(), $this->get_stylesheet() );
     478                        switch_theme( $this->get_stylesheet() );
    479479                        $this->start_previewing_theme();
    480480                }
  • 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.