Make WordPress Core

Ticket #29758: 29758.php.diff

File 29758.php.diff, 4.6 KB (added by celloexpressions, 9 years ago)

PHP side of the API only, not yet functional. Once JS API is in place, we can build out contextuality there as well.

  • src/wp-includes/class-wp-customize-panel.php

     
    8383        public $sections;
    8484
    8585        /**
     86         * Callback.
     87         *
     88         * @since 4.1.0
     89         * @access public
     90         *
     91         * @see WP_Customize_Panel::active()
     92         *
     93         * @var callable Callback is called with one argument, the instance of
     94         *               WP_Customize_Panel, and returns bool to indicate whether
     95         *               the panel is active (such as it relates to the URL
     96         *               currently being previewed).
     97         */
     98        public $active_callback = '';
     99
     100        /**
    86101         * Constructor.
    87102         *
    88103         * Any supplied $args override class property defaults.
     
    103118
    104119                $this->manager = $manager;
    105120                $this->id = $id;
     121                if ( empty( $this->active_callback ) ) {
     122                        $this->active_callback = array( $this, 'active_callback' );
     123                }
    106124
    107125                $this->sections = array(); // Users cannot customize the $sections array.
    108126
     
    110128        }
    111129
    112130        /**
     131         * Check whether panel is active to current customizer preview.
     132         *
     133         * @since 4.1.0
     134         * @access public
     135         *
     136         * @return bool Whether the panel is active to the current preview.
     137         */
     138        public final function active() {
     139                $panel = $this;
     140                $active = call_user_func( $this->active_callback, $this );
     141
     142                /**
     143                 * Filter response of WP_Customize_Panel::active().
     144                 *
     145                 * @since 4.1.0
     146                 *
     147                 * @param bool               $active Whether the Customizer panel is active.
     148                 * @param WP_Customize_Panel $panel  WP_Customize_Panel instance.
     149                 */
     150                $active = apply_filters( 'customize_panel_active', $active, $panel );
     151
     152                return $active;
     153        }
     154
     155        /**
     156         * Default callback used when invoking WP_Customize_Panel::active().
     157         *
     158         * Subclasses can override this with their specific logic, or they may
     159         * provide an 'active_callback' argument to the constructor.
     160         *
     161         * @since 4.1.0
     162         * @access public
     163         *
     164         * @return bool Always true.
     165         */
     166        public function active_callback() {
     167                return true;
     168        }
     169
     170        // @todo once JS API is in place: $this->json['active'] = $this->active();
     171
     172        /**
    113173         * Checks required user capabilities and whether the theme has the
    114174         * feature support required by the panel.
    115175         *
  • src/wp-includes/class-wp-customize-section.php

     
    9292        public $controls;
    9393
    9494        /**
     95         * Callback.
     96         *
     97         * @since 4.1.0
     98         * @access public
     99         *
     100         * @see WP_Customize_Section::active()
     101         *
     102         * @var callable Callback is called with one argument, the instance of
     103         *               WP_Customize_Section, and returns bool to indicate whether
     104         *               the secyion is active (such as it relates to the URL
     105         *               currently being previewed).
     106         */
     107        public $active_callback = '';
     108
     109        /**
    95110         * Constructor.
    96111         *
    97112         * Any supplied $args override class property defaults.
     
    112127                $this->manager = $manager;
    113128                $this->id = $id;
    114129
     130                if ( empty( $this->active_callback ) ) {
     131                        $this->active_callback = array( $this, 'active_callback' );
     132                }
     133
    115134                $this->controls = array(); // Users cannot customize the $controls array.
    116135
    117136                return $this;
     
    118137        }
    119138
    120139        /**
     140         * Check whether section is active to current customizer preview.
     141         *
     142         * @since 4.1.0
     143         * @access public
     144         *
     145         * @return bool Whether the section is active to the current preview.
     146         */
     147        public final function active() {
     148                $section = $this;
     149                $active = call_user_func( $this->active_callback, $this );
     150
     151                /**
     152                 * Filter response of WP_Customize_Section::active().
     153                 *
     154                 * @since 4.1.0
     155                 *
     156                 * @param bool                 $active  Whether the Customizer section is active.
     157                 * @param WP_Customize_Section $section WP_Customize_Section instance.
     158                 */
     159                $active = apply_filters( 'customize_section_active', $active, $section );
     160
     161                return $active;
     162        }
     163
     164        /**
     165         * Default callback used when invoking WP_Customize_Section::active().
     166         *
     167         * Subclasses can override this with their specific logic, or they may
     168         * provide an 'active_callback' argument to the constructor.
     169         *
     170         * @since 4.1.0
     171         * @access public
     172         *
     173         * @return bool Always true.
     174         */
     175        public function active_callback() {
     176                return true;
     177        }
     178
     179        // @todo once JS API is in place: $this->json['active'] = $this->active();
     180
     181        /**
    121182         * Checks required user capabilities and whether the theme has the
    122183         * feature support required by the section.
    123184         *