Make WordPress Core


Ignore:
Timestamp:
03/21/2012 10:55:43 PM (14 years ago)
Author:
koopersmith
Message:

Theme Customizer: Numerous API refinements and bugfixes. Add a theme_supports check for header_textcolor. see #19910.

  • prepare_controls() now removes any settings and sections that return false for check_capabilities().
  • Added maybe_render() methods to both settings and sections that call the protected render() methods.
  • Stop firing front-end preview functionality when rendering the controls.
  • Merged the WP_Customize_Setting->_render_type() method into WP_Customize_Setting->render().
  • Removed the 'customize_render_control-' hook; use 'customize_render_setting' instead.
  • Added a property to sections and settings so they no longer rely on the global. Hooray for dependency injection.
  • Shifted calls to WP_Customize_Setting->enqueue() to the 'customize_controls_enqueue_scripts' action.
  • Added a theme_supports check for the header_textcolor setting.
File:
1 edited

Legend:

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

    r20212 r20248  
    3030                add_action( 'admin_footer', array( $this, 'admin_footer' ) );
    3131
    32                 add_action( 'customize_previewing',    array( $this, 'customize_previewing' ) );
    33                 add_action( 'customize_register',      array( $this, 'register_controls' ) );
    34                 add_action( 'customize_controls_init', array( $this, 'prepare_controls' ) );
     32                add_action( 'customize_previewing',               array( $this, 'customize_previewing' ) );
     33                add_action( 'customize_register',                 array( $this, 'register_controls' ) );
     34                add_action( 'customize_controls_init',            array( $this, 'prepare_controls' ) );
     35                add_action( 'customize_controls_enqueue_scripts', array( $this, 'enqueue_control_scripts' ) );
    3536        }
    3637
     
    103104                do_action( 'customize_register' );
    104105
    105                 if ( ! $this->is_preview() )
    106                         return;
     106                if ( $this->is_preview() )
     107                        add_action( 'template_redirect', array( $this, 'customize_preview_init' ) );
     108        }
     109
     110        /**
     111         * Print javascript settings.
     112         *
     113         * @since 3.4.0
     114         */
     115        public function customize_preview_init() {
     116                $this->prepare_controls();
    107117
    108118                wp_enqueue_script( 'customize-preview' );
     
    112122                        $setting->preview();
    113123                }
    114         }
     124
     125                do_action( 'customize_preview_init' );
     126        }
     127
    115128
    116129        /**
     
    350363         */
    351364        public function add_setting( $id, $args = array() ) {
    352                 $setting = new WP_Customize_Setting( $id, $args );
     365                $setting = new WP_Customize_Setting( $this, $id, $args );
    353366
    354367                $this->settings[ $setting->id ] = $setting;
     
    388401         */
    389402        public function add_section( $id, $args = array() ) {
    390                 $section = new WP_Customize_Section( $id, $args );
     403                $section = new WP_Customize_Section( $this, $id, $args );
    391404
    392405                $this->sections[ $section->id ] = $section;
     
    425438         * @param object $b Object B.
    426439         */
    427         protected function _cmp_priority( $a, $b ) {
     440        protected final function _cmp_priority( $a, $b ) {
    428441                $ap = $a->priority;
    429442                $bp = $b->priority;
     
    435448
    436449        /**
    437          * Prepare settings and sections. Also enqueue needed scripts/styles.
     450         * Prepare settings and sections.
    438451         *
    439452         * @since 3.4.0
    440453         */
    441454        public function prepare_controls() {
     455                // Prepare settings
    442456                // Reversing makes uasort sort by time added when conflicts occur.
    443457
     458                $this->settings = array_reverse( $this->settings );
     459                $settings = array();
     460
     461                foreach ( $this->settings as $id => $setting ) {
     462                        if ( ! isset( $this->sections[ $setting->section ] ) || ! $setting->check_capabilities() )
     463                                continue;
     464
     465                        $this->sections[ $setting->section ]->settings[] = $setting;
     466                        $settings[ $id ] = $setting;
     467                }
     468                $this->settings = $settings;
     469
     470                // Prepare sections
    444471                $this->sections = array_reverse( $this->sections );
    445472                uasort( $this->sections, array( $this, '_cmp_priority' ) );
    446 
    447                 $this->settings = array_reverse( $this->settings );
     473                $sections = array();
     474
     475                foreach ( $this->sections as $section ) {
     476                        if ( ! $section->check_capabilities() )
     477                                continue;
     478
     479                        usort( $section->settings, array( $this, '_cmp_priority' ) );
     480                        $sections[] = $section;
     481                }
     482                $this->sections = $sections;
     483        }
     484
     485        /**
     486         * Enqueue scripts for customize controls.
     487         *
     488         * @since 3.4.0
     489         */
     490        public function enqueue_control_scripts() {
    448491                foreach ( $this->settings as $setting ) {
    449                         if ( ! isset( $this->sections[ $setting->section ] ) )
    450                                 continue;
    451 
    452                         $this->sections[ $setting->section ]->settings[] = $setting;
    453 
    454                         if ( $setting->check_capabilities() )
    455                                 $setting->enqueue();
    456                 }
    457 
    458                 foreach ( $this->sections as $section ) {
    459                         usort( $section->settings, array( $this, '_cmp_priority' ) );
     492                        $setting->enqueue();
    460493                }
    461494        }
     
    480513                        'sanitize_callback' => 'sanitize_hexcolor',
    481514                        'control'           => 'color',
     515                        'theme_supports'    => array( 'custom-header', 'header-text' ),
    482516                        'default'           => get_theme_support( 'custom-header', 'default-text-color' ),
    483517                ) );
Note: See TracChangeset for help on using the changeset viewer.