WordPress.org

Make WordPress Core

Changeset 20260


Ignore:
Timestamp:
03/22/2012 07:17:26 AM (8 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.

Location:
trunk/wp-includes
Files:
5 edited

Legend:

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

    r20248 r20260  
    8484            <h3 class="customize-section-title" title="<?php echo esc_attr( $this->description ); ?>"><?php echo esc_html( $this->title ); ?></h3>
    8585            <ul class="customize-section-content">
    86                 <?php foreach ( $this->settings as $setting ) : ?>
    87                 <li id="customize-control-<?php echo esc_attr( $setting->id ); ?>" class="customize-control customize-control-<?php echo esc_attr( $setting->control ); ?>">
    88                     <?php $setting->maybe_render(); ?>
    89                 </li>
    90                 <?php endforeach; ?>
     86                <?php
     87                foreach ( $this->settings as $setting )
     88                    $setting->maybe_render();
     89                ?>
    9190            </ul>
    9291        </li>
  • 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':
  • trunk/wp-includes/class-wp-customize.php

    r20254 r20260  
    619619            'default'        => get_option( 'show_on_front' ),
    620620            'type'           => 'option',
    621             'capability'     => 'manage_options'
     621            'capability'     => 'manage_options',
    622622        ) );
    623623
     
    628628            'control'        => 'dropdown-pages',
    629629            'type'           => 'option',
    630             'capability'     => 'manage_options'
     630            'capability'     => 'manage_options',
     631            'visibility'     => array( 'show_on_front', 'page' ),
    631632        ) );
    632633
     
    637638            'control'        => 'dropdown-pages',
    638639            'type'           => 'option',
    639             'capability'     => 'manage_options'
     640            'capability'     => 'manage_options',
     641            'visibility'     => array( 'show_on_front', 'page' ),
    640642        ) );
    641643
     
    651653            'default'        => get_option( 'blogname' ),
    652654            'type'           => 'option',
    653             'capability'     => 'manage_options'
     655            'capability'     => 'manage_options',
    654656        ) );
    655657
     
    659661            'default'        => get_option( 'blogdescription' ),
    660662            'type'           => 'option',
    661             'capability'     => 'manage_options'
     663            'capability'     => 'manage_options',
    662664        ) );
    663665    }
  • trunk/wp-includes/customize-controls.php

    r20248 r20260  
    105105            'control' => $setting->control,
    106106        );
     107
     108        if ( $setting->visibility ) {
     109            $settings['controls'][ $id ]['visibility'] = array(
     110                'id'    => $setting->visibility[0],
     111                'value' => isset( $setting->visibility[1] ) ? $setting->visibility[1] : true,
     112            );
     113        }
    107114    }
    108115
  • trunk/wp-includes/js/customize-controls.dev.js

    r20259 r20260  
    231231
    232232        $.each( api.settings.controls, function( id, data ) {
    233             var constructor = api.controls[ data.control ] || api.Control;
    234             api.add( id, new constructor( id, data.value, {
     233            var constructor = api.controls[ data.control ] || api.Control,
     234                control;
     235
     236            control = api.add( id, new constructor( id, data.value, {
    235237                previewer: previewer
    236238            } ) );
     239
     240            if ( data.visibility ) {
     241                api( data.visibility.id, function( other ) {
     242                    other.bind( function( to ) {
     243                        control.container.toggle( to == data.visibility.value );
     244                    });
     245                });
     246            }
    237247        });
    238248
Note: See TracChangeset for help on using the changeset viewer.