From 5443bec597744f464674eab18f8717bc8c97ef94 Mon Sep 17 00:00:00 2001 From: koopersmith Date: Thu, 22 Mar 2012 07:17:26 +0000 Subject: [PATCH] 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. git-svn-id: http://svn.automattic.com/wordpress/trunk@20260 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-customize-section.php | 9 +++---- wp-includes/class-wp-customize-setting.php | 29 +++++++++++++++++++++- wp-includes/class-wp-customize.php | 12 +++++---- wp-includes/customize-controls.php | 7 ++++++ wp-includes/js/customize-controls.dev.js | 14 +++++++++-- 5 files changed, 58 insertions(+), 13 deletions(-) diff --git a/wp-includes/class-wp-customize-section.php b/wp-includes/class-wp-customize-section.php index 78b3de9fde..21f751a49f 100644 --- a/wp-includes/class-wp-customize-section.php +++ b/wp-includes/class-wp-customize-section.php @@ -83,11 +83,10 @@ class WP_Customize_Section {
  • title ); ?>

  • render_content(). * * @since 3.4.0 */ protected function render() { + + $id = 'customize-control-' . $this->id; + $class = 'customize-control customize-control-' . $this->control; + + $style = ''; + if ( $this->visibility ) { + $visibility_setting = $this->manager->get_setting( $this->visibility[0] ); + $visibility_value = isset( $this->visibility[1] ) ? $this->visibility[1] : true; + + if ( $visibility_setting && $visibility_value != $visibility_setting->value() ) + $style = 'style="display:none;"'; + } + + ?>
  • > + render_content(); ?> +
  • control ) { case 'text': ?> diff --git a/wp-includes/class-wp-customize.php b/wp-includes/class-wp-customize.php index 5b64d76444..2bba95663e 100644 --- a/wp-includes/class-wp-customize.php +++ b/wp-includes/class-wp-customize.php @@ -618,7 +618,7 @@ final class WP_Customize { 'choices' => $choices, 'default' => get_option( 'show_on_front' ), 'type' => 'option', - 'capability' => 'manage_options' + 'capability' => 'manage_options', ) ); $this->add_setting( 'page_on_front', array( @@ -627,7 +627,8 @@ final class WP_Customize { 'section' => 'static_front_page', 'control' => 'dropdown-pages', 'type' => 'option', - 'capability' => 'manage_options' + 'capability' => 'manage_options', + 'visibility' => array( 'show_on_front', 'page' ), ) ); $this->add_setting( 'page_for_posts', array( @@ -636,7 +637,8 @@ final class WP_Customize { 'section' => 'static_front_page', 'control' => 'dropdown-pages', 'type' => 'option', - 'capability' => 'manage_options' + 'capability' => 'manage_options', + 'visibility' => array( 'show_on_front', 'page' ), ) ); /* Site Title & Tagline */ @@ -650,7 +652,7 @@ final class WP_Customize { 'section' => 'strings', 'default' => get_option( 'blogname' ), 'type' => 'option', - 'capability' => 'manage_options' + 'capability' => 'manage_options', ) ); $this->add_setting( 'blogdescription', array( @@ -658,7 +660,7 @@ final class WP_Customize { 'section' => 'strings', 'default' => get_option( 'blogdescription' ), 'type' => 'option', - 'capability' => 'manage_options' + 'capability' => 'manage_options', ) ); } }; diff --git a/wp-includes/customize-controls.php b/wp-includes/customize-controls.php index 13f6b6e1ab..8de52be33f 100644 --- a/wp-includes/customize-controls.php +++ b/wp-includes/customize-controls.php @@ -104,6 +104,13 @@ do_action( 'customize_controls_print_scripts' ); 'value' => $setting->value(), 'control' => $setting->control, ); + + if ( $setting->visibility ) { + $settings['controls'][ $id ]['visibility'] = array( + 'id' => $setting->visibility[0], + 'value' => isset( $setting->visibility[1] ) ? $setting->visibility[1] : true, + ); + } } ?> diff --git a/wp-includes/js/customize-controls.dev.js b/wp-includes/js/customize-controls.dev.js index c0c9e6974d..6688d1f48b 100644 --- a/wp-includes/js/customize-controls.dev.js +++ b/wp-includes/js/customize-controls.dev.js @@ -230,10 +230,20 @@ }); $.each( api.settings.controls, function( id, data ) { - var constructor = api.controls[ data.control ] || api.Control; - api.add( id, new constructor( id, data.value, { + var constructor = api.controls[ data.control ] || api.Control, + control; + + control = api.add( id, new constructor( id, data.value, { previewer: previewer } ) ); + + if ( data.visibility ) { + api( data.visibility.id, function( other ) { + other.bind( function( to ) { + control.container.toggle( to == data.visibility.value ); + }); + }); + } }); // Temporary accordion code.