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-setting.php

    r20232 r20248  
    99
    1010class WP_Customize_Setting {
     11        public $manager;
    1112        public $id;
    1213        public $priority          = 10;
     
    3637         * @param array $args Setting arguments.
    3738         */
    38         function __construct( $id, $args = array() ) {
     39        function __construct( $manager, $id, $args = array() ) {
    3940                $keys = array_keys( get_class_vars( __CLASS__ ) );
    4041                foreach ( $keys as $key ) {
     
    4344                }
    4445
     46                $this->manager = $manager;
    4547                $this->id = $id;
    4648
     
    266268         */
    267269        public final function check_capabilities() {
    268                 global $customize;
    269 
    270270                if ( $this->capability && ! call_user_func_array( 'current_user_can', (array) $this->capability ) )
    271271                        return false;
     
    274274                        return false;
    275275
    276                 $section = $customize->get_section( $this->section );
     276                $section = $this->manager->get_section( $this->section );
    277277                if ( isset( $section ) && ! $section->check_capabilities() )
    278278                        return false;
     
    282282
    283283        /**
    284          * Render the control.
    285          *
    286          * @since 3.4.0
    287          */
    288         public final function _render() {
     284         * Check capabiliites and render the control.
     285         *
     286         * @since 3.4.0
     287         */
     288        public final function maybe_render() {
    289289                if ( ! $this->check_capabilities() )
    290290                        return;
    291291
    292                 do_action( 'customize_render_' . $this->id );
     292                do_action( 'customize_render_setting', $this );
     293                do_action( 'customize_render_setting_' . $this->id, $this );
    293294
    294295                $this->render();
     
    301302         */
    302303        protected function render() {
    303                 $this->_render_type();
    304         }
    305 
    306         /**
    307          * Retrieve the name attribute for an input.
    308          *
    309          * @since 3.4.0
    310          *
    311          * @return string The name.
    312          */
    313         public final function get_name() {
    314                 return self::name_prefix . esc_attr( $this->id );
    315         }
    316 
    317         /**
    318          * Echo the HTML name attribute for an input.
    319          *
    320          * @since 3.4.0
    321          *
    322          * @return string The HTML name attribute.
    323          */
    324         public final function name() {
    325                 echo 'name="' . $this->get_name() . '"';
    326         }
    327 
    328         /**
    329          * Render the control type.
    330          *
    331          * @todo Improve value and checked attributes.
    332          *
    333          * @since 3.4.0
    334          */
    335         public final function _render_type() {
    336304                switch( $this->control ) {
    337305                        case 'text':
     
    415383                                <?php
    416384                                break;
    417                         default:
    418                                 do_action( 'customize_render_control-' . $this->control, $this );
    419 
    420                 }
     385                }
     386        }
     387
     388        /**
     389         * Retrieve the name attribute for an input.
     390         *
     391         * @since 3.4.0
     392         *
     393         * @return string The name.
     394         */
     395        public final function get_name() {
     396                return self::name_prefix . esc_attr( $this->id );
     397        }
     398
     399        /**
     400         * Echo the HTML name attribute for an input.
     401         *
     402         * @since 3.4.0
     403         *
     404         * @return string The HTML name attribute.
     405         */
     406        public final function name() {
     407                echo 'name="' . $this->get_name() . '"';
    421408        }
    422409
Note: See TracChangeset for help on using the changeset viewer.