Make WordPress Core

Changeset 20496


Ignore:
Timestamp:
04/17/2012 09:43:47 PM (13 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.

Location:
trunk/wp-includes
Files:
3 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
  • trunk/wp-includes/customize-controls.php

    r20495 r20496  
    2828do_action( 'customize_controls_enqueue_scripts' );
    2929
    30 $theme = wp_get_theme();
    31 $screenshot = $theme->get_screenshot();
    32 
    3330// Let's roll.
    3431@header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
     
    3734_wp_admin_html_begin();
    3835
    39 $admin_title = sprintf( __( '%1$s — WordPress' ), strip_tags( sprintf( __( 'Customize %s' ), $theme['Name'] ) ) );
     36$admin_title = sprintf( __( '%1$s — WordPress' ), strip_tags( sprintf( __( 'Customize %s' ), $this->theme->display('Name') ) ) );
    4037?><title><?php echo $admin_title; ?></title><?php
    4138
     
    4845        <?php wp_nonce_field( 'customize_controls' ); ?>
    4946        <input type="hidden" name="customize" value="on" />
    50         <input type="hidden" id="customize-template" name="template" value="<?php echo esc_attr( $theme['Template'] ); ?>" />
    51         <input type="hidden" id="customize-stylesheet" name="stylesheet" value="<?php echo esc_attr( $theme['Stylesheet'] ); ?>" />
    52 
     47        <input type="hidden" name="theme" value="<?php echo esc_attr( $this->get_stylesheet() ); ?>" />
    5348        <div id="customize-header-actions" class="customize-section wp-full-overlay-header">
    5449            <a class="back" href="<?php echo esc_url( admin_url( 'themes.php' ) ); ?>">
     
    6055            <div class="customize-section-title">
    6156                <span class="preview-notice"><?php _e('You are previewing'); ?></span>
    62                 <strong class="theme-name"><?php echo $theme['Name']; ?></strong>
     57                <strong class="theme-name"><?php echo $this->theme->display('Name'); ?></strong>
    6358            </div>
    6459            <div class="customize-section-content">
    65                 <?php if ( $screenshot ) : ?>
     60                <?php if ( $screenshot = $this->theme->get_screenshot() ) : ?>
    6661                    <img class="theme-screenshot" src="<?php echo esc_url( $screenshot ); ?>" />
    6762                <?php endif; ?>
    6863
    69                 <?php if ( $theme->description ): ?>
    70                     <div class="theme-description"><?php echo $theme->description; ?></div>
     64                <?php if ( $this->theme->get('Description') ): ?>
     65                    <div class="theme-description"><?php echo $this->theme->display('Description'); ?></div>
    7166                <?php endif; ?>
    7267            </div>
  • trunk/wp-includes/theme.php

    r20488 r20496  
    16021602 */
    16031603function wp_customize_url( $stylesheet, $template ) {
    1604     return esc_url( admin_url( 'admin.php' ) . '?customize=on&template=' . $template . '&stylesheet=' . $stylesheet );
    1605 }
     1604    return esc_url( admin_url( 'admin.php' ) . '?customize=on&theme=' . $stylesheet );
     1605}
Note: See TracChangeset for help on using the changeset viewer.