Make WordPress Core

Changeset 20852


Ignore:
Timestamp:
05/23/2012 05:56:42 PM (14 years ago)
Author:
nacin
Message:

Customize API shuffling.

  • Rename WP_Customize to WP_Customize_Manager.
  • Move customize-controls.php to wp-admin/customize.php.
  • Make customize.php the formal entry point, rather than admin.php?customize=on.
  • Rename is_current_theme_active() to is_theme_active().
  • Add getters for the theme, settings, controls, and sections properties.
  • Allow customize.php (no ?theme=) to load the active theme. Not used yet.

see #20736.

Location:
trunk
Files:
2 edited
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/customize.php

    r20847 r20852  
    88 */
    99
    10 if ( ! defined( 'ABSPATH' ) )
    11         die;
     10require_once( './admin.php' );
     11if ( ! current_user_can( 'edit_theme_options' ) )
     12        die( 'Cap check failed' );
    1213
    13 global $wp_scripts;
     14global $wp_scripts, $wp_customize;
     15
     16if ( ! $wp_customize->is_preview() )
     17        die( 'is_preview() failed' );
     18
     19wp_reset_vars( array( 'theme' ) );
     20
     21if ( ! $theme )
     22        $theme = get_stylesheet();
    1423
    1524$registered = $wp_scripts->registered;
    … …  
    3443_wp_admin_html_begin();
    3544
    36 $admin_title = sprintf( __( '%1$s — WordPress' ), strip_tags( sprintf( __( 'Customize %s' ), $this->theme->display('Name') ) ) );
     45$admin_title = sprintf( __( '%1$s — WordPress' ), strip_tags( sprintf( __( 'Customize %s' ), $wp_customize->theme()->display('Name') ) ) );
    3746?><title><?php echo $admin_title; ?></title><?php
    3847
    … …  
    5463                                <div class="customize-section-title">
    5564                                        <span class="preview-notice"><?php _e('You are previewing'); ?></span>
    56                                         <strong class="theme-name"><?php echo $this->theme->display('Name'); ?></strong>
     65                                        <strong class="theme-name"><?php echo $wp_customize->theme()->display('Name'); ?></strong>
    5766                                </div>
    5867                                <div class="customize-section-content">
    59                                         <?php if ( $screenshot = $this->theme->get_screenshot() ) : ?>
     68                                        <?php if ( $screenshot = $wp_customize->theme()->get_screenshot() ) : ?>
    6069                                                <img class="theme-screenshot" src="<?php echo esc_url( $screenshot ); ?>" />
    6170                                        <?php endif; ?>
    6271
    63                                         <?php if ( $this->theme->get('Description') ): ?>
    64                                                 <div class="theme-description"><?php echo $this->theme->display('Description'); ?></div>
     72                                        <?php if ( $wp_customize->theme()->get('Description') ): ?>
     73                                                <div class="theme-description"><?php echo $wp_customize->theme()->display('Description'); ?></div>
    6574                                        <?php endif; ?>
    6675                                </div>
    … …  
    6978                        <div id="customize-theme-controls"><ul>
    7079                                <?php
    71                                 foreach ( $this->sections as $section )
     80                                foreach ( $wp_customize->sections() as $section )
    7281                                        $section->maybe_render();
    7382                                ?>
    … …  
    7786                <div id="customize-footer-actions" class="wp-full-overlay-footer">
    7887                        <?php
    79                         $save_text = $this->is_current_theme_active() ? __('Save') : __('Save and Activate');
     88                        $save_text = $wp_customize->is_theme_active() ? __('Save') : __('Save and Activate');
    8089                        submit_button( $save_text, 'primary', 'save', false );
    8190                        ?>
    … …  
    109118        $settings = array(
    110119                'theme'    => array(
    111                         'stylesheet' => $this->get_stylesheet(),
    112                         'active'     => $this->is_current_theme_active(),
     120                        'stylesheet' => $wp_customize->get_stylesheet(),
     121                        'active'     => $wp_customize->is_theme_active(),
    113122                ),
    114123                'url'      => array(
    … …  
    121130        );
    122131
    123         foreach ( $this->settings as $id => $setting ) {
     132        foreach ( $wp_customize->settings() as $id => $setting ) {
    124133                $settings['settings'][ $id ] = array(
    125134                        'value'     => $setting->js_value(),
    … …  
    128137        }
    129138
    130         foreach ( $this->controls as $id => $control ) {
     139        foreach ( $wp_customize->controls() as $id => $control ) {
    131140                $control->to_json();
    132141                $settings['controls'][ $id ] = $control->json;
  • trunk/wp-admin/includes/class-wp-plugins-list-table.php

    r20525 r20852  
    7070                                foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) {
    7171                                        if ( isset( $current->response[ $plugin_file ] ) ) {
     72                                                ob_start();
     73                                                var_dump( $current->response[ $plugin_file ] );
     74                                                error_log( $plugin_file . ': ' . ob_get_clean() );
     75                                        }
     76                                        if ( ! empty( $current->response[ $plugin_file ] ) ) {
    7277                                                $plugins['all'][ $plugin_file ]['update'] = true;
    7378                                                $plugins['upgrade'][ $plugin_file ] = $plugins['all'][ $plugin_file ];
  • trunk/wp-includes/class-wp-customize-manager.php

    r20847 r20852  
    88 */
    99
    10 final class WP_Customize {
     10final class WP_Customize_Manager {
    1111        protected $theme;
    1212        protected $original_stylesheet;
    … …  
    3333
    3434                add_action( 'setup_theme',  array( $this, 'setup_theme' ) );
    35                 add_action( 'admin_init',   array( $this, 'admin_init' ) );
    3635                add_action( 'wp_loaded',    array( $this, 'wp_loaded' ) );
    3736
    … …  
    6968         */
    7069        public function setup_theme() {
    71                 if ( ! isset( $_REQUEST['customize'] ) || 'on' != $_REQUEST['customize'] )
     70                if ( ! ( isset( $_REQUEST['customize'] ) && 'on' == $_REQUEST['customize'] ) && ! basename( $_SERVER['PHP_SELF'] ) == 'customize.php' )
    7271                        return;
    7372
    … …  
    9190                // Initialize $theme and $original_stylesheet if they do not yet exist.
    9291                if ( ! isset( $this->theme ) ) {
    93                         $this->theme = wp_get_theme( $_REQUEST['theme'] );
     92                        $this->theme = wp_get_theme( isset( $_REQUEST['theme'] ) ? $_REQUEST['theme'] : null );
    9493                        if ( ! $this->theme->exists() ) {
    9594                                $this->theme = false;
    … …  
    146145
    147146        /**
     147         * Generic getter.
     148         *
     149         * @since 3.4.0
     150         *
     151         * @return WP_Theme
     152         */
     153        public function __call( $callee, $args ) {
     154                if ( in_array( $callee, array( 'theme', 'settings', 'controls', 'sections' ) ) )
     155                        return $this->$callee;
     156        }
     157
     158        /**
    148159         * Checks if the current theme is active.
    149160         *
    150161         * @since 3.4.0
    151          */
    152         public function is_current_theme_active() {
     162         *
     163         * @return bool
     164         */
     165        public function is_theme_active() {
    153166                return $this->get_stylesheet() == $this->original_stylesheet;
    154167        }
    … …  
    183196        }
    184197
    185 
    186198        /**
    187199         * Print javascript settings.
    … …  
    291303
    292304        /**
    293          * Trigger save action and load customize controls.
    294          *
    295          * @since 3.4.0
    296          */
    297         public function admin_init() {
    298                 if ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) )
    299                         return;
    300 
    301                 if ( ! isset( $_GET['customize'] ) || 'on' != $_GET['customize'] )
    302                         return;
    303 
    304                 if ( empty( $_GET['theme'] ) )
    305                         return;
    306 
    307                 if ( ! $this->is_preview() )
    308                         return;
    309 
    310                 if ( ! current_user_can( 'edit_theme_options' ) )
    311                         return;
    312 
    313                 include( ABSPATH . WPINC . '/customize-controls.php' );
    314 
    315                 die;
    316         }
    317 
    318         /**
    319305         * Switch the theme and trigger the save action of each setting.
    320306         *
    … …  
    565551
    566552                $this->add_setting( 'header_textcolor', array(
    567                         // @todo: replace with a new accept() setting method
    568                         // 'sanitize_callback' => 'sanitize_hexcolor',
     553                        'sanitize_callback' => 'sanitize_header_textcolor',
    569554                        'theme_supports' => array( 'custom-header', 'header-text' ),
    570555                        'default'        => get_theme_support( 'custom-header', 'default-text-color' ),
    … …  
    794779};
    795780
     781// Callback function for sanitizing the header textcolor setting.
     782function sanitize_header_textcolor( $color ) {
     783        if ( empty( $color ) )
     784                return get_theme_support( 'custom-header', 'default-text-color' );
     785
     786        elseif ( $color == 'blank' )
     787                return 'blank';
     788
     789        return sanitize_hexcolor( $color );
     790}
     791
    796792// Callback function for sanitizing a hex color
    797793function sanitize_hexcolor( $color ) {
  • trunk/wp-includes/theme.php

    r20802 r20852  
    15671567
    15681568/**
    1569  * Includes and instantiates the WP_Customize class.
     1569 * Includes and instantiates the WP_Customize_Manager class.
    15701570 *
    15711571 * Fires when ?customize=on.
    … …  
    15751575function _wp_customize_include() {
    15761576        // Load on themes.php or ?customize=on
    1577         if ( ! ( isset( $_REQUEST['customize'] ) && 'on' == $_REQUEST['customize'] ) )
     1577        if ( ! ( ( isset( $_REQUEST['customize'] ) && 'on' == $_REQUEST['customize'] ) || 'customize.php' == basename( $_SERVER['PHP_SELF'] ) ) )
    15781578                return;
    15791579
    1580         require( ABSPATH . WPINC . '/class-wp-customize.php' );
     1580        require( ABSPATH . WPINC . '/class-wp-customize-manager.php' );
    15811581        // Init Customize class
    1582         $GLOBALS['wp_customize'] = new WP_Customize;
     1582        $GLOBALS['wp_customize'] = new WP_Customize_Manager;
    15831583}
    15841584add_action( 'plugins_loaded', '_wp_customize_include' );
    … …  
    16051605 */
    16061606function wp_customize_url( $stylesheet ) {
    1607         return esc_url( admin_url( 'admin.php' ) . '?customize=on&theme=' . $stylesheet );
    1608 }
     1607        return esc_url( admin_url( 'customize.php' ) . '?theme=' . $stylesheet );
     1608}
Note: See TracChangeset for help on using the changeset viewer.