Make WordPress Core


Ignore:
Timestamp:
03/22/2012 07:17:26 AM (15 years ago)
Author:
koopersmith
Message:

Theme Customizer: Add a WP_Customize_Setting->visibility parameter to show/hide a control based upon the value of another control. Also shifts rendering the setting wrapper element into WP_Customize_Setting->render() and adds WP_Customize_Setting->render_content(). see #19910.

File:
1 edited

Legend:

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

    r20254 r20260  
    2121        public $default           = '';
    2222        public $sanitize_callback = '';
     23        public $visibility;
    2324
    2425        protected $id_data = array();
    … …  
    297298
    298299        /**
    299          * Render the control.
     300         * Render the control. Renders the control wrapper, then calls $this->render_content().
    300301         *
    301302         * @since 3.4.0
    302303         */
    303304        protected function render() {
     305
     306                $id    = 'customize-control-' . $this->id;
     307                $class = 'customize-control customize-control-' . $this->control;
     308
     309                $style = '';
     310                if ( $this->visibility ) {
     311                        $visibility_setting = $this->manager->get_setting( $this->visibility[0] );
     312                        $visibility_value   = isset( $this->visibility[1] ) ? $this->visibility[1] : true;
     313
     314                        if ( $visibility_setting && $visibility_value != $visibility_setting->value() )
     315                                $style = 'style="display:none;"';
     316                }
     317
     318                ?><li id="<?php echo esc_attr( $id ); ?>" class="<?php echo esc_attr( $class ); ?>" <?php echo $style; ?>>
     319                        <?php $this->render_content(); ?>
     320                </li><?php
     321        }
     322
     323        /**
     324         * Render the control's content.
     325         *
     326         * Allows the content to be overriden without having to rewrite the wrapper.
     327         *
     328         * @since 3.4.0
     329         */
     330        protected function render_content() {
    304331                switch( $this->control ) {
    305332                        case 'text':
Note: See TracChangeset for help on using the changeset viewer.