<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[20260] trunk/wp-includes: Theme Customizer: Add a WP_Customize_Setting-&gt;visibility parameter to show/hide a control based upon the value of another control.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg > ul, #logmsg > ol { margin-left: 0; margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/20260">20260</a></dd>
<dt>Author</dt> <dd>koopersmith</dd>
<dt>Date</dt> <dd>2012-03-22 07:17:26 +0000 (Thu, 22 Mar 2012)</dd>
</dl>

<h3>Log Message</h3>
<pre>Theme Customizer: Add a WP_Customize_Setting-&gt;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-&gt;render() and adds WP_Customize_Setting-&gt;render_content(). see <a href="http://core.trac.wordpress.org/ticket/19910">#19910</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpincludesclasswpcustomizesectionphp">trunk/wp-includes/class-wp-customize-section.php</a></li>
<li><a href="#trunkwpincludesclasswpcustomizesettingphp">trunk/wp-includes/class-wp-customize-setting.php</a></li>
<li><a href="#trunkwpincludesclasswpcustomizephp">trunk/wp-includes/class-wp-customize.php</a></li>
<li><a href="#trunkwpincludescustomizecontrolsphp">trunk/wp-includes/customize-controls.php</a></li>
<li><a href="#trunkwpincludesjscustomizecontrolsdevjs">trunk/wp-includes/js/customize-controls.dev.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpincludesclasswpcustomizesectionphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/class-wp-customize-section.php (20259 => 20260)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/class-wp-customize-section.php        2012-03-22 07:03:44 UTC (rev 20259)
+++ trunk/wp-includes/class-wp-customize-section.php        2012-03-22 07:17:26 UTC (rev 20260)
</span><span class="lines">@@ -83,11 +83,10 @@
</span><span class="cx">                 &lt;li id=&quot;customize-section-&lt;?php echo esc_attr( $this-&gt;id ); ?&gt;&quot; class=&quot;control-section customize-section&quot;&gt;
</span><span class="cx">                         &lt;h3 class=&quot;customize-section-title&quot; title=&quot;&lt;?php echo esc_attr( $this-&gt;description ); ?&gt;&quot;&gt;&lt;?php echo esc_html( $this-&gt;title ); ?&gt;&lt;/h3&gt;
</span><span class="cx">                         &lt;ul class=&quot;customize-section-content&quot;&gt;
</span><del>-                                &lt;?php foreach ( $this-&gt;settings as $setting ) : ?&gt;
-                                &lt;li id=&quot;customize-control-&lt;?php echo esc_attr( $setting-&gt;id ); ?&gt;&quot; class=&quot;customize-control customize-control-&lt;?php echo esc_attr( $setting-&gt;control ); ?&gt;&quot;&gt;
-                                        &lt;?php $setting-&gt;maybe_render(); ?&gt;
-                                &lt;/li&gt;
-                                &lt;?php endforeach; ?&gt;
</del><ins>+                                &lt;?php
+                                foreach ( $this-&gt;settings as $setting )
+                                        $setting-&gt;maybe_render();
+                                ?&gt;
</ins><span class="cx">                         &lt;/ul&gt;
</span><span class="cx">                 &lt;/li&gt;
</span><span class="cx">                 &lt;?php
</span></span></pre></div>
<a id="trunkwpincludesclasswpcustomizesettingphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/class-wp-customize-setting.php (20259 => 20260)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/class-wp-customize-setting.php        2012-03-22 07:03:44 UTC (rev 20259)
+++ trunk/wp-includes/class-wp-customize-setting.php        2012-03-22 07:17:26 UTC (rev 20260)
</span><span class="lines">@@ -20,6 +20,7 @@
</span><span class="cx">         public $theme_supports    = '';
</span><span class="cx">         public $default           = '';
</span><span class="cx">         public $sanitize_callback = '';
</span><ins>+        public $visibility;
</ins><span class="cx"> 
</span><span class="cx">         protected $id_data = array();
</span><span class="cx">         private $_post_value; // Cached, sanitized $_POST value.
</span><span class="lines">@@ -296,11 +297,37 @@
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         /**
</span><del>-         * Render the control.
</del><ins>+         * Render the control. Renders the control wrapper, then calls $this-&gt;render_content().
</ins><span class="cx">          *
</span><span class="cx">          * @since 3.4.0
</span><span class="cx">          */
</span><span class="cx">         protected function render() {
</span><ins>+
+                $id    = 'customize-control-' . $this-&gt;id;
+                $class = 'customize-control customize-control-' . $this-&gt;control;
+
+                $style = '';
+                if ( $this-&gt;visibility ) {
+                        $visibility_setting = $this-&gt;manager-&gt;get_setting( $this-&gt;visibility[0] );
+                        $visibility_value   = isset( $this-&gt;visibility[1] ) ? $this-&gt;visibility[1] : true;
+
+                        if ( $visibility_setting &amp;&amp; $visibility_value != $visibility_setting-&gt;value() )
+                                $style = 'style=&quot;display:none;&quot;';
+                }
+
+                ?&gt;&lt;li id=&quot;&lt;?php echo esc_attr( $id ); ?&gt;&quot; class=&quot;&lt;?php echo esc_attr( $class ); ?&gt;&quot; &lt;?php echo $style; ?&gt;&gt;
+                        &lt;?php $this-&gt;render_content(); ?&gt;
+                &lt;/li&gt;&lt;?php
+        }
+
+        /**
+         * Render the control's content.
+         *
+         * Allows the content to be overriden without having to rewrite the wrapper.
+         *
+         * @since 3.4.0
+         */
+        protected function render_content() {
</ins><span class="cx">                 switch( $this-&gt;control ) {
</span><span class="cx">                         case 'text':
</span><span class="cx">                                 ?&gt;
</span></span></pre></div>
<a id="trunkwpincludesclasswpcustomizephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/class-wp-customize.php (20259 => 20260)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/class-wp-customize.php        2012-03-22 07:03:44 UTC (rev 20259)
+++ trunk/wp-includes/class-wp-customize.php        2012-03-22 07:17:26 UTC (rev 20260)
</span><span class="lines">@@ -618,7 +618,7 @@
</span><span class="cx">                         'choices'        =&gt; $choices,
</span><span class="cx">                         'default'        =&gt; get_option( 'show_on_front' ),
</span><span class="cx">                         'type'           =&gt; 'option',
</span><del>-                        'capability'     =&gt; 'manage_options'
</del><ins>+                        'capability'     =&gt; 'manage_options',
</ins><span class="cx">                 ) );
</span><span class="cx"> 
</span><span class="cx">                 $this-&gt;add_setting( 'page_on_front', array(
</span><span class="lines">@@ -627,7 +627,8 @@
</span><span class="cx">                         'section'        =&gt; 'static_front_page',
</span><span class="cx">                         'control'        =&gt; 'dropdown-pages',
</span><span class="cx">                         'type'           =&gt; 'option',
</span><del>-                        'capability'     =&gt; 'manage_options'
</del><ins>+                        'capability'     =&gt; 'manage_options',
+                        'visibility'     =&gt; array( 'show_on_front', 'page' ),
</ins><span class="cx">                 ) );
</span><span class="cx"> 
</span><span class="cx">                 $this-&gt;add_setting( 'page_for_posts', array(
</span><span class="lines">@@ -636,7 +637,8 @@
</span><span class="cx">                         'section'        =&gt; 'static_front_page',
</span><span class="cx">                         'control'        =&gt; 'dropdown-pages',
</span><span class="cx">                         'type'           =&gt; 'option',
</span><del>-                        'capability'     =&gt; 'manage_options'
</del><ins>+                        'capability'     =&gt; 'manage_options',
+                        'visibility'     =&gt; array( 'show_on_front', 'page' ),
</ins><span class="cx">                 ) );
</span><span class="cx"> 
</span><span class="cx">                 /* Site Title &amp; Tagline */
</span><span class="lines">@@ -650,7 +652,7 @@
</span><span class="cx">                         'section'        =&gt; 'strings',
</span><span class="cx">                         'default'        =&gt; get_option( 'blogname' ),
</span><span class="cx">                         'type'           =&gt; 'option',
</span><del>-                        'capability'     =&gt; 'manage_options'
</del><ins>+                        'capability'     =&gt; 'manage_options',
</ins><span class="cx">                 ) );
</span><span class="cx"> 
</span><span class="cx">                 $this-&gt;add_setting( 'blogdescription', array(
</span><span class="lines">@@ -658,7 +660,7 @@
</span><span class="cx">                         'section'        =&gt; 'strings',
</span><span class="cx">                         'default'        =&gt; get_option( 'blogdescription' ),
</span><span class="cx">                         'type'           =&gt; 'option',
</span><del>-                        'capability'     =&gt; 'manage_options'
</del><ins>+                        'capability'     =&gt; 'manage_options',
</ins><span class="cx">                 ) );
</span><span class="cx">         }
</span><span class="cx"> };
</span></span></pre></div>
<a id="trunkwpincludescustomizecontrolsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/customize-controls.php (20259 => 20260)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/customize-controls.php        2012-03-22 07:03:44 UTC (rev 20259)
+++ trunk/wp-includes/customize-controls.php        2012-03-22 07:17:26 UTC (rev 20260)
</span><span class="lines">@@ -104,6 +104,13 @@
</span><span class="cx">                         'value'   =&gt; $setting-&gt;value(),
</span><span class="cx">                         'control' =&gt; $setting-&gt;control,
</span><span class="cx">                 );
</span><ins>+
+                if ( $setting-&gt;visibility ) {
+                        $settings['controls'][ $id ]['visibility'] = array(
+                                'id'    =&gt; $setting-&gt;visibility[0],
+                                'value' =&gt; isset( $setting-&gt;visibility[1] ) ? $setting-&gt;visibility[1] : true,
+                        );
+                }
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         ?&gt;
</span></span></pre></div>
<a id="trunkwpincludesjscustomizecontrolsdevjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/js/customize-controls.dev.js (20259 => 20260)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/js/customize-controls.dev.js        2012-03-22 07:03:44 UTC (rev 20259)
+++ trunk/wp-includes/js/customize-controls.dev.js        2012-03-22 07:17:26 UTC (rev 20260)
</span><span class="lines">@@ -230,10 +230,20 @@
</span><span class="cx">                 });
</span><span class="cx"> 
</span><span class="cx">                 $.each( api.settings.controls, function( id, data ) {
</span><del>-                        var constructor = api.controls[ data.control ] || api.Control;
-                        api.add( id, new constructor( id, data.value, {
</del><ins>+                        var constructor = api.controls[ data.control ] || api.Control,
+                                control;
+
+                        control = api.add( id, new constructor( id, data.value, {
</ins><span class="cx">                                 previewer: previewer
</span><span class="cx">                         } ) );
</span><ins>+
+                        if ( data.visibility ) {
+                                api( data.visibility.id, function( other ) {
+                                        other.bind( function( to ) {
+                                                control.container.toggle( to == data.visibility.value );
+                                        });
+                                });
+                        }
</ins><span class="cx">                 });
</span><span class="cx"> 
</span><span class="cx">                 // Temporary accordion code.
</span></span></pre>
</div>
</div>

</body>
</html>