<!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>[20319] trunk: Theme Customizer: Move upload and image controls to subclasses.</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/20319">20319</a></dd>
<dt>Author</dt> <dd>koopersmith</dd>
<dt>Date</dt> <dd>2012-03-29 06:35:54 +0000 (Thu, 29 Mar 2012)</dd>
</dl>

<h3>Log Message</h3>
<pre>Theme Customizer: Move upload and image controls to subclasses. see <a href="http://core.trac.wordpress.org/ticket/19910">#19910</a>.

Instead of grouping together every control parameter into a single  array and passing them all to the JS, use subclasses with custom parameters to implement additional PHP functionality and the  parameter to send only the necessary variables to the JavaScript control.

Replaces WP_Customize_Control-&gt;control_params with WP_Customize_Control-&gt;json and WP_Customize_Control-&gt;to_json(). The to_json() method refreshes the json array passed to the JavaScript control (set to control.param by default).

Creates WP_Customize_Upload_Control and WP_Customize_Image_Control.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludesajaxactionsphp">trunk/wp-admin/includes/ajax-actions.php</a></li>
<li><a href="#trunkwpincludesclasswpcustomizecontrolphp">trunk/wp-includes/class-wp-customize-control.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="trunkwpadminincludesajaxactionsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/ajax-actions.php (20318 => 20319)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/ajax-actions.php        2012-03-29 05:39:26 UTC (rev 20318)
+++ trunk/wp-admin/includes/ajax-actions.php        2012-03-29 06:35:54 UTC (rev 20319)
</span><span class="lines">@@ -1615,7 +1615,7 @@
</span><span class="cx">                 $post_id = null;
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        $post_data = is_array( $_REQUEST['post_data'] ) ? $_REQUEST['post_data'] : array();
</del><ins>+        $post_data = isset( $_REQUEST['post_data'] ) ? $_REQUEST['post_data'] : array();
</ins><span class="cx"> 
</span><span class="cx">         $attachment_id = media_handle_upload( 'async-upload', $post_id, $post_data );
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkwpincludesclasswpcustomizecontrolphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/class-wp-customize-control.php (20318 => 20319)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/class-wp-customize-control.php        2012-03-29 05:39:26 UTC (rev 20318)
+++ trunk/wp-includes/class-wp-customize-control.php        2012-03-29 06:35:54 UTC (rev 20319)
</span><span class="lines">@@ -17,11 +17,11 @@
</span><span class="cx">         public $priority          = 10;
</span><span class="cx">         public $section           = '';
</span><span class="cx">         public $label             = '';
</span><del>-        // @todo: remove control_params
-        public $control_params    = array();
</del><span class="cx">         // @todo: remove choices
</span><span class="cx">         public $choices           = array();
</span><span class="cx"> 
</span><ins>+        public $json = array();
+
</ins><span class="cx">         public $visibility;
</span><span class="cx"> 
</span><span class="cx">         public $type = 'text';
</span><span class="lines">@@ -35,7 +35,7 @@
</span><span class="cx">          * @since 3.4.0
</span><span class="cx">          */
</span><span class="cx">         function __construct( $manager, $id, $args = array() ) {
</span><del>-                $keys = array_keys( get_class_vars( __CLASS__ ) );
</del><ins>+                $keys = array_keys( get_object_vars( $this ) );
</ins><span class="cx">                 foreach ( $keys as $key ) {
</span><span class="cx">                         if ( isset( $args[ $key ] ) )
</span><span class="cx">                                 $this-&gt;$key = $args[ $key ];
</span><span class="lines">@@ -90,18 +90,33 @@
</span><span class="cx">                         return $this-&gt;settings[ $setting_key ]-&gt;value();
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        public function json( $args = array() ) {
-                $settings = array();
</del><ins>+        /**
+         * Refresh the parameters passed to the JavaScript via JSON.
+         *
+         * @since 3.4.0
+         */
+        public function to_json() {
+                $this-&gt;json['settings'] = array();
</ins><span class="cx">                 foreach ( $this-&gt;settings as $key =&gt; $setting ) {
</span><del>-                        $settings[ $key ] = $setting-&gt;id;
</del><ins>+                        $this-&gt;json['settings'][ $key ] = $setting-&gt;id;
</ins><span class="cx">                 }
</span><span class="cx"> 
</span><del>-                return array(
-                        'type'   =&gt; $this-&gt;type,
-                        'params' =&gt; wp_parse_args( wp_parse_args( $args, array(
-                                'settings' =&gt; $settings,
-                        ) ), $this-&gt;control_params ),
-                );
</del><ins>+                $this-&gt;json['type'] = $this-&gt;type;
+
+                if ( $this-&gt;visibility ) {
+                        if ( is_string( $this-&gt;visibility ) ) {
+                                $this-&gt;json['visibility'] = array(
+                                        'id'    =&gt; $this-&gt;visibility,
+                                        'value' =&gt; true,
+                                );
+                        } else {
+                                $this-&gt;json['visibility'] = array(
+                                        'id'    =&gt; $this-&gt;visibility[0],
+                                        'value' =&gt; $this-&gt;visibility[1],
+                                );
+                        }
+
+                }
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         /**
</span><span class="lines">@@ -258,60 +273,6 @@
</span><span class="cx">                                 &lt;/label&gt;
</span><span class="cx">                                 &lt;?php
</span><span class="cx">                                 break;
</span><del>-                        case 'upload':
-                                ?&gt;
-                                &lt;label&gt;
-                                        &lt;span class=&quot;customize-control-title&quot;&gt;&lt;?php echo esc_html( $this-&gt;label ); ?&gt;&lt;/span&gt;
-                                        &lt;div&gt;
-                                                &lt;input type=&quot;hidden&quot; value=&quot;&lt;?php echo esc_attr( $this-&gt;value() ); ?&gt;&quot; &lt;?php $this-&gt;link(); ?&gt; /&gt;
-                                                &lt;a href=&quot;#&quot; class=&quot;button-secondary upload&quot;&gt;&lt;?php _e( 'Upload' ); ?&gt;&lt;/a&gt;
-                                                &lt;a href=&quot;#&quot; class=&quot;remove&quot;&gt;&lt;?php _e( 'Remove' ); ?&gt;&lt;/a&gt;
-                                        &lt;/div&gt;
-                                &lt;/label&gt;
-                                &lt;?php
-                                break;
-                        case 'image':
-                                $value = $this-&gt;value();
-
-                                $image = $value;
-                                if ( isset( $this-&gt;control_params['get_url'] ) )
-                                        $image = call_user_func( $this-&gt;control_params['get_url'], $image );
-
-                                ?&gt;
-                                &lt;label&gt;
-                                        &lt;span class=&quot;customize-control-title&quot;&gt;&lt;?php echo esc_html( $this-&gt;label ); ?&gt;&lt;/span&gt;
-                                        &lt;input type=&quot;hidden&quot; value=&quot;&lt;?php echo esc_attr( $this-&gt;value() ); ?&gt;&quot; &lt;?php $this-&gt;link(); ?&gt; /&gt;
-                                        &lt;div class=&quot;customize-image-picker&quot;&gt;
-                                                &lt;div class=&quot;thumbnail&quot;&gt;
-                                                        &lt;?php if ( empty( $image ) ): ?&gt;
-                                                                &lt;img style=&quot;display:none;&quot; /&gt;
-                                                        &lt;?php else: ?&gt;
-                                                                &lt;img src=&quot;&lt;?php echo esc_url( $image ); ?&gt;&quot; /&gt;
-                                                        &lt;?php endif; ?&gt;
-                                                &lt;/div&gt;
-                                                &lt;div class=&quot;actions&quot;&gt;
-                                                        &lt;a href=&quot;#&quot; class=&quot;upload&quot;&gt;&lt;?php _e( 'Upload New' ); ?&gt;&lt;/a&gt;
-                                                        &lt;a href=&quot;#&quot; class=&quot;change&quot;&gt;&lt;?php _e( 'Change Image' ); ?&gt;&lt;/a&gt;
-                                                        &lt;a href=&quot;#&quot; class=&quot;remove&quot;&gt;&lt;?php _e( 'Remove Image' ); ?&gt;&lt;/a&gt;
-                                                &lt;/div&gt;
-                                                &lt;div class=&quot;library&quot;&gt;
-                                                        &lt;ul&gt;
-                                                                &lt;?php foreach ( $this-&gt;control_params['tabs'] as $tab ): ?&gt;
-                                                                        &lt;li data-customize-tab='&lt;?php echo esc_attr( $tab[0] ); ?&gt;'&gt;
-                                                                                &lt;?php echo esc_html( $tab[1] ); ?&gt;
-                                                                        &lt;/li&gt;
-                                                                &lt;?php endforeach; ?&gt;
-                                                        &lt;/ul&gt;
-                                                        &lt;?php foreach ( $this-&gt;control_params['tabs'] as $tab ): ?&gt;
-                                                                &lt;div class=&quot;library-content&quot; data-customize-tab='&lt;?php echo esc_attr( $tab[0] ); ?&gt;'&gt;
-                                                                        &lt;?php call_user_func( $tab[2] ); ?&gt;
-                                                                &lt;/div&gt;
-                                                        &lt;?php endforeach; ?&gt;
-                                                &lt;/div&gt;
-                                        &lt;/div&gt;
-                                &lt;/label&gt;
-                                &lt;?php
-                                break;
</del><span class="cx">                         case 'dropdown-pages':
</span><span class="cx">                                 $dropdown = wp_dropdown_pages(
</span><span class="cx">                                         array(
</span><span class="lines">@@ -334,4 +295,81 @@
</span><span class="cx">                                 break;
</span><span class="cx">                 }
</span><span class="cx">         }
</span><ins>+}
+
+class WP_Customize_Upload_Control extends WP_Customize_Control {
+        public $type    = 'upload';
+        public $removed = '';
+        public $context;
+
+        public function enqueue() {
+                wp_enqueue_script( 'wp-plupload' );
+        }
+
+        public function to_json() {
+                parent::to_json();
+
+                $this-&gt;json['removed'] = $this-&gt;removed;
+
+                if ( $this-&gt;context )
+                        $this-&gt;json['context'] = $this-&gt;context;
+        }
+
+        public function render_content() {
+                ?&gt;
+                &lt;label&gt;
+                        &lt;span class=&quot;customize-control-title&quot;&gt;&lt;?php echo esc_html( $this-&gt;label ); ?&gt;&lt;/span&gt;
+                        &lt;div&gt;
+                                &lt;a href=&quot;#&quot; class=&quot;button-secondary upload&quot;&gt;&lt;?php _e( 'Upload' ); ?&gt;&lt;/a&gt;
+                                &lt;a href=&quot;#&quot; class=&quot;remove&quot;&gt;&lt;?php _e( 'Remove' ); ?&gt;&lt;/a&gt;
+                        &lt;/div&gt;
+                &lt;/label&gt;
+                &lt;?php
+        }
+}
+
+class WP_Customize_Image_Control extends WP_Customize_Upload_Control {
+        public $type = 'image';
+        public $tabs = array();
+        public $get_url;
+
+        public function render_content() {
+                $src = $this-&gt;value();
+                if ( isset( $this-&gt;get_url ) )
+                        $src = call_user_func( $this-&gt;get_url, $src );
+
+                ?&gt;
+                &lt;label&gt;
+                        &lt;span class=&quot;customize-control-title&quot;&gt;&lt;?php echo esc_html( $this-&gt;label ); ?&gt;&lt;/span&gt;
+                        &lt;div class=&quot;customize-image-picker&quot;&gt;
+                                &lt;div class=&quot;thumbnail&quot;&gt;
+                                        &lt;?php if ( empty( $src ) ): ?&gt;
+                                                &lt;img style=&quot;display:none;&quot; /&gt;
+                                        &lt;?php else: ?&gt;
+                                                &lt;img src=&quot;&lt;?php echo esc_url( $src ); ?&gt;&quot; /&gt;
+                                        &lt;?php endif; ?&gt;
+                                &lt;/div&gt;
+                                &lt;div class=&quot;actions&quot;&gt;
+                                        &lt;a href=&quot;#&quot; class=&quot;upload&quot;&gt;&lt;?php _e( 'Upload New' ); ?&gt;&lt;/a&gt;
+                                        &lt;a href=&quot;#&quot; class=&quot;change&quot;&gt;&lt;?php _e( 'Change Image' ); ?&gt;&lt;/a&gt;
+                                        &lt;a href=&quot;#&quot; class=&quot;remove&quot;&gt;&lt;?php _e( 'Remove Image' ); ?&gt;&lt;/a&gt;
+                                &lt;/div&gt;
+                                &lt;div class=&quot;library&quot;&gt;
+                                        &lt;ul&gt;
+                                                &lt;?php foreach ( $this-&gt;tabs as $tab ): ?&gt;
+                                                        &lt;li data-customize-tab='&lt;?php echo esc_attr( $tab[0] ); ?&gt;'&gt;
+                                                                &lt;?php echo esc_html( $tab[1] ); ?&gt;
+                                                        &lt;/li&gt;
+                                                &lt;?php endforeach; ?&gt;
+                                        &lt;/ul&gt;
+                                        &lt;?php foreach ( $this-&gt;tabs as $tab ): ?&gt;
+                                                &lt;div class=&quot;library-content&quot; data-customize-tab='&lt;?php echo esc_attr( $tab[0] ); ?&gt;'&gt;
+                                                        &lt;?php call_user_func( $tab[2] ); ?&gt;
+                                                &lt;/div&gt;
+                                        &lt;?php endforeach; ?&gt;
+                                &lt;/div&gt;
+                        &lt;/div&gt;
+                &lt;/label&gt;
+                &lt;?php
+        }
</ins><span class="cx"> }
</span><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkwpincludesclasswpcustomizephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/class-wp-customize.php (20318 => 20319)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/class-wp-customize.php        2012-03-29 05:39:26 UTC (rev 20318)
+++ trunk/wp-includes/class-wp-customize.php        2012-03-29 06:35:54 UTC (rev 20319)
</span><span class="lines">@@ -585,20 +585,17 @@
</span><span class="cx">                         'theme_supports' =&gt; 'custom-header',
</span><span class="cx">                 ) );
</span><span class="cx"> 
</span><del>-                $this-&gt;add_control( 'header_image', array(
</del><ins>+                $this-&gt;add_control( new WP_Customize_Image_Control( $this, 'header_image', array(
</ins><span class="cx">                         'label'          =&gt; 'Header Image',
</span><span class="cx">                         'section'        =&gt; 'header',
</span><del>-                        'type'           =&gt; 'image',
-                        'control_params' =&gt; array(
-                                'context'        =&gt; 'custom-header',
-                                'removed'        =&gt; 'remove-header',
-                                'get_url'        =&gt; 'get_header_image',
-                                'tabs'           =&gt; array(
-                                        array( 'uploaded', __('Uploaded'), 'wp_customize_print_uploaded_headers' ),
-                                        array( 'included', __('Included'), 'wp_customize_print_included_headers' ),
-                                ),
</del><ins>+                        'context'        =&gt; 'custom-header',
+                        'removed'        =&gt; 'remove-header',
+                        'get_url'        =&gt; 'get_header_image',
+                        'tabs'           =&gt; array(
+                                array( 'uploaded', __('Uploaded'), 'wp_customize_print_uploaded_headers' ),
+                                array( 'included', __('Included'), 'wp_customize_print_included_headers' ),
</ins><span class="cx">                         ),
</span><del>-                ) );
</del><ins>+                ) ) );
</ins><span class="cx"> 
</span><span class="cx">                 /* Custom Background */
</span><span class="cx"> 
</span><span class="lines">@@ -627,14 +624,12 @@
</span><span class="cx">                         'theme_supports' =&gt; 'custom-background',
</span><span class="cx">                 ) );
</span><span class="cx"> 
</span><del>-                $this-&gt;add_control( 'background_image', array(
</del><ins>+                $this-&gt;add_control( new WP_Customize_Upload_Control( $this, 'background_image', array(
</ins><span class="cx">                         'label'          =&gt; __( 'Background Image' ),
</span><span class="cx">                         'section'        =&gt; 'background',
</span><span class="cx">                         'type'           =&gt; 'upload',
</span><del>-                        'control_params' =&gt; array(
-                                'context'        =&gt; 'custom-background',
-                        ),
-                ) );
</del><ins>+                        'context'        =&gt; 'custom-background',
+                ) ) );
</ins><span class="cx"> 
</span><span class="cx">                 $this-&gt;add_setting( 'background_repeat', array(
</span><span class="cx">                         'default'        =&gt; 'repeat',
</span></span></pre></div>
<a id="trunkwpincludescustomizecontrolsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/customize-controls.php (20318 => 20319)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/customize-controls.php        2012-03-29 05:39:26 UTC (rev 20318)
+++ trunk/wp-includes/customize-controls.php        2012-03-29 06:35:54 UTC (rev 20319)
</span><span class="lines">@@ -107,22 +107,8 @@
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         foreach ( $this-&gt;controls as $id =&gt; $control ) {
</span><del>-                $settings['controls'][ $id ] = $control-&gt;json();
-
-                if ( $control-&gt;visibility ) {
-                        if ( is_string( $control-&gt;visibility ) ) {
-                                $settings['controls'][ $id ]['visibility'] = array(
-                                        'id'    =&gt; $control-&gt;visibility,
-                                        'value' =&gt; true,
-                                );
-                        } else {
-                                $settings['controls'][ $id ]['visibility'] = array(
-                                        'id'    =&gt; $control-&gt;visibility[0],
-                                        'value' =&gt; $control-&gt;visibility[1],
-                                );
-                        }
-
-                }
</del><ins>+                $control-&gt;to_json();
+                $settings['controls'][ $id ] = $control-&gt;json;
</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 (20318 => 20319)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/js/customize-controls.dev.js        2012-03-29 05:39:26 UTC (rev 20318)
+++ trunk/wp-includes/js/customize-controls.dev.js        2012-03-29 06:35:54 UTC (rev 20319)
</span><span class="lines">@@ -361,7 +361,7 @@
</span><span class="cx">                                 control;
</span><span class="cx"> 
</span><span class="cx">                         control = api.control.add( id, new constructor( id, {
</span><del>-                                params: data.params,
</del><ins>+                                params: data,
</ins><span class="cx">                                 previewer: previewer
</span><span class="cx">                         } ) );
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>