WordPress.org

Make WordPress Core


Ignore:
Timestamp:
04/17/2012 09:43:47 PM (8 years ago)
Author:
nacin
Message:

Move to admin.php?customize=on&theme=$stylesheet, rather than juggling both template and stylesheet values. see #19910.

Combine the setup_theme() and customize_previewing() methods. Remove the set_template() and set_stylesheet() methods. Add set_theme() method to WP_Customize to store the working WP_Theme object. We will use this for the stylesheet and template.

Use the WP_Theme display() method when preparing headers for display, not get() or the deprecate properties.

File:
1 edited

Legend:

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

    r20495 r20496  
    99
    1010final class WP_Customize {
    11     protected $template;
    12     protected $stylesheet;
    13     protected $original_template;
     11    protected $theme;
    1412    protected $original_stylesheet;
    1513
     
    3028        require( ABSPATH . WPINC . '/class-wp-customize-control.php' );
    3129
    32         add_action( 'setup_theme',  array( $this, 'setup_theme' ) );
     30        add_action( 'setup_theme',  array( $this, 'customize_previewing' ) );
    3331        add_action( 'admin_init',   array( $this, 'admin_init' ) );
    3432        add_action( 'wp_loaded',    array( $this, 'wp_loaded' ) );
    3533
    36         add_action( 'customize_previewing',               array( $this, 'customize_previewing' ) );
    3734        add_action( 'customize_register',                 array( $this, 'register_controls' ) );
    3835        add_action( 'customize_controls_init',            array( $this, 'prepare_controls' ) );
     
    6057    /**
    6158     * Start preview and customize theme.
    62      * Check if customize query variable exist.
    63      *
    64      * @since 3.4.0
    65      */
    66     public function setup_theme() {
     59     *
     60     * Check if customize query variable exist. Init filters to filter the current theme.
     61     *
     62     * @since 3.4.0
     63     */
     64    public function customize_previewing() {
    6765        if ( ! isset( $_REQUEST['customize'] ) || 'on' != $_REQUEST['customize'] )
    6866            return;
    6967
    70         if ( ! $this->set_stylesheet() || isset( $_REQUEST['save_customize_controls'] ) )
     68        if ( ! $this->set_theme() || isset( $_REQUEST['save_customize_controls'] ) )
    7169            return;
    7270
    7371        $this->previewing = true;
    74         do_action( 'customize_previewing' );
    75     }
    76 
    77     /**
    78      * Init filters to filter theme options.
    79      *
    80      * @since 3.4.0
    81      */
    82     public function customize_previewing() {
    83         global $wp_theme_directories;
    8472
    8573        show_admin_bar( false );
    8674
    87         $this->original_template   = get_template();
    8875        $this->original_stylesheet = get_stylesheet();
    8976
     
    9784
    9885        // Handle custom theme roots.
    99         if ( count( $wp_theme_directories ) > 1 ) {
    100             add_filter( 'pre_option_stylesheet_root', array( $this, 'get_stylesheet_root' ) );
    101             add_filter( 'pre_option_template_root', array( $this, 'get_template_root' ) );
    102         }
     86        add_filter( 'pre_option_stylesheet_root', array( $this, 'get_stylesheet_root' ) );
     87        add_filter( 'pre_option_template_root', array( $this, 'get_template_root' ) );
     88
     89        do_action( 'customize_previewing' );
    10390    }
    10491
     
    174161
    175162    /**
    176      * Set the template name of the previewed theme.
    177      *
    178      * @since 3.4.0
    179      *
    180      * @return bool|string Template name.
    181      */
    182     public function set_template() {
    183         if ( ! empty( $this->template ) )
    184             return $this->template;
    185 
    186         $template = preg_replace('|[^a-z0-9_./-]|i', '', $_REQUEST['template'] );
    187         if ( validate_file( $template ) )
    188             return false;
    189 
    190         return $this->template = $template;
    191     }
    192 
    193     /**
    194163     * Set the stylesheet name of the previewed theme.
    195164     *
     
    198167     * @return bool|string Stylesheet name.
    199168     */
    200     public function set_stylesheet() {
    201         if ( ! empty( $this->stylesheet ) )
    202             return $this->stylesheet;
    203 
    204         $this->set_template();
    205         if ( empty( $this->template ) )
    206             return false;
    207 
    208         if ( empty( $_REQUEST['stylesheet'] ) ) {
    209             $stylesheet = $this->template;
    210         } else {
    211             $stylesheet = preg_replace( '|[^a-z0-9_./-]|i', '', $_REQUEST['stylesheet'] );
    212             if ( $stylesheet != $this->template && validate_file( $stylesheet ) )
    213                 return false;
    214         }
    215         return $this->stylesheet = $stylesheet;
    216 
     169    public function set_theme() {
     170        if ( isset( $this->theme ) )
     171            return $this->theme;
     172
     173        $this->theme = wp_get_theme( $_REQUEST['theme'] );
     174        if ( ! $this->theme->exists() )
     175            $this->theme = false;
     176
     177        return $this->theme;
    217178    }
    218179
     
    225186     */
    226187    public function get_template() {
    227         return $this->template;
     188        return $this->theme->get_template();
    228189    }
    229190
     
    236197     */
    237198    public function get_stylesheet() {
    238         return $this->stylesheet;
     199        return $this->theme->get_stylesheet();
    239200    }
    240201
     
    247208     */
    248209    public function get_template_root() {
    249         return get_raw_theme_root( $this->template, true );
     210        return get_raw_theme_root( $this->get_template(), true );
    250211    }
    251212
     
    258219     */
    259220    public function get_stylesheet_root() {
    260         return get_raw_theme_root( $this->stylesheet, true );
     221        return get_raw_theme_root( $this->get_stylesheet(), true );
    261222    }
    262223
     
    269230     */
    270231    public function current_theme( $current_theme ) {
    271         return wp_get_theme( $this->stylesheet )->get('Name');
     232        return $this->theme->display('Name');
    272233    }
    273234
     
    287248            return;
    288249
     250        if ( empty( $_GET['theme'] ) )
     251            return;
     252
    289253        if ( ! $this->is_preview() )
    290254            return;
     
    309273        check_admin_referer( 'customize_controls' );
    310274
    311         if ( ! $this->set_stylesheet() )
     275        if ( ! $this->set_theme() )
    312276            return;
    313277
Note: See TracChangeset for help on using the changeset viewer.