WordPress.org

Make WordPress Core


Ignore:
Timestamp:
05/23/2012 05:56:42 PM (8 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.

File:
1 moved

Legend:

Unmodified
Added
Removed
  • 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 ) {
Note: See TracChangeset for help on using the changeset viewer.