<!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->control_params with WP_Customize_Control->json and WP_Customize_Control->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->$key = $args[ $key ];
</span><span class="lines">@@ -90,18 +90,33 @@
</span><span class="cx">                         return $this->settings[ $setting_key ]->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->json['settings'] = array();
</ins><span class="cx">                 foreach ( $this->settings as $key => $setting ) {
</span><del>-                        $settings[ $key ] = $setting->id;
</del><ins>+                        $this->json['settings'][ $key ] = $setting->id;
</ins><span class="cx">                 }
</span><span class="cx">
</span><del>-                return array(
-                        'type' => $this->type,
-                        'params' => wp_parse_args( wp_parse_args( $args, array(
-                                'settings' => $settings,
-                        ) ), $this->control_params ),
-                );
</del><ins>+                $this->json['type'] = $this->type;
+
+                if ( $this->visibility ) {
+                        if ( is_string( $this->visibility ) ) {
+                                $this->json['visibility'] = array(
+                                        'id' => $this->visibility,
+                                        'value' => true,
+                                );
+                        } else {
+                                $this->json['visibility'] = array(
+                                        'id' => $this->visibility[0],
+                                        'value' => $this->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">                                 </label>
</span><span class="cx">                                 <?php
</span><span class="cx">                                 break;
</span><del>-                        case 'upload':
-                                ?>
-                                <label>
-                                        <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
-                                        <div>
-                                                <input type="hidden" value="<?php echo esc_attr( $this->value() ); ?>" <?php $this->link(); ?> />
-                                                <a href="#" class="button-secondary upload"><?php _e( 'Upload' ); ?></a>
-                                                <a href="#" class="remove"><?php _e( 'Remove' ); ?></a>
-                                        </div>
-                                </label>
-                                <?php
-                                break;
-                        case 'image':
-                                $value = $this->value();
-
-                                $image = $value;
-                                if ( isset( $this->control_params['get_url'] ) )
-                                        $image = call_user_func( $this->control_params['get_url'], $image );
-
-                                ?>
-                                <label>
-                                        <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
-                                        <input type="hidden" value="<?php echo esc_attr( $this->value() ); ?>" <?php $this->link(); ?> />
-                                        <div class="customize-image-picker">
-                                                <div class="thumbnail">
-                                                        <?php if ( empty( $image ) ): ?>
-                                                                <img style="display:none;" />
-                                                        <?php else: ?>
-                                                                <img src="<?php echo esc_url( $image ); ?>" />
-                                                        <?php endif; ?>
-                                                </div>
-                                                <div class="actions">
-                                                        <a href="#" class="upload"><?php _e( 'Upload New' ); ?></a>
-                                                        <a href="#" class="change"><?php _e( 'Change Image' ); ?></a>
-                                                        <a href="#" class="remove"><?php _e( 'Remove Image' ); ?></a>
-                                                </div>
-                                                <div class="library">
-                                                        <ul>
-                                                                <?php foreach ( $this->control_params['tabs'] as $tab ): ?>
-                                                                        <li data-customize-tab='<?php echo esc_attr( $tab[0] ); ?>'>
-                                                                                <?php echo esc_html( $tab[1] ); ?>
-                                                                        </li>
-                                                                <?php endforeach; ?>
-                                                        </ul>
-                                                        <?php foreach ( $this->control_params['tabs'] as $tab ): ?>
-                                                                <div class="library-content" data-customize-tab='<?php echo esc_attr( $tab[0] ); ?>'>
-                                                                        <?php call_user_func( $tab[2] ); ?>
-                                                                </div>
-                                                        <?php endforeach; ?>
-                                                </div>
-                                        </div>
-                                </label>
-                                <?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->json['removed'] = $this->removed;
+
+                if ( $this->context )
+                        $this->json['context'] = $this->context;
+        }
+
+        public function render_content() {
+                ?>
+                <label>
+                        <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
+                        <div>
+                                <a href="#" class="button-secondary upload"><?php _e( 'Upload' ); ?></a>
+                                <a href="#" class="remove"><?php _e( 'Remove' ); ?></a>
+                        </div>
+                </label>
+                <?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->value();
+                if ( isset( $this->get_url ) )
+                        $src = call_user_func( $this->get_url, $src );
+
+                ?>
+                <label>
+                        <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
+                        <div class="customize-image-picker">
+                                <div class="thumbnail">
+                                        <?php if ( empty( $src ) ): ?>
+                                                <img style="display:none;" />
+                                        <?php else: ?>
+                                                <img src="<?php echo esc_url( $src ); ?>" />
+                                        <?php endif; ?>
+                                </div>
+                                <div class="actions">
+                                        <a href="#" class="upload"><?php _e( 'Upload New' ); ?></a>
+                                        <a href="#" class="change"><?php _e( 'Change Image' ); ?></a>
+                                        <a href="#" class="remove"><?php _e( 'Remove Image' ); ?></a>
+                                </div>
+                                <div class="library">
+                                        <ul>
+                                                <?php foreach ( $this->tabs as $tab ): ?>
+                                                        <li data-customize-tab='<?php echo esc_attr( $tab[0] ); ?>'>
+                                                                <?php echo esc_html( $tab[1] ); ?>
+                                                        </li>
+                                                <?php endforeach; ?>
+                                        </ul>
+                                        <?php foreach ( $this->tabs as $tab ): ?>
+                                                <div class="library-content" data-customize-tab='<?php echo esc_attr( $tab[0] ); ?>'>
+                                                        <?php call_user_func( $tab[2] ); ?>
+                                                </div>
+                                        <?php endforeach; ?>
+                                </div>
+                        </div>
+                </label>
+                <?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' => 'custom-header',
</span><span class="cx">                 ) );
</span><span class="cx">
</span><del>-                $this->add_control( 'header_image', array(
</del><ins>+                $this->add_control( new WP_Customize_Image_Control( $this, 'header_image', array(
</ins><span class="cx">                         'label' => 'Header Image',
</span><span class="cx">                         'section' => 'header',
</span><del>-                        'type' => 'image',
-                        'control_params' => array(
-                                'context' => 'custom-header',
-                                'removed' => 'remove-header',
-                                'get_url' => 'get_header_image',
-                                'tabs' => array(
-                                        array( 'uploaded', __('Uploaded'), 'wp_customize_print_uploaded_headers' ),
-                                        array( 'included', __('Included'), 'wp_customize_print_included_headers' ),
-                                ),
</del><ins>+                        'context' => 'custom-header',
+                        'removed' => 'remove-header',
+                        'get_url' => 'get_header_image',
+                        'tabs' => 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' => 'custom-background',
</span><span class="cx">                 ) );
</span><span class="cx">
</span><del>-                $this->add_control( 'background_image', array(
</del><ins>+                $this->add_control( new WP_Customize_Upload_Control( $this, 'background_image', array(
</ins><span class="cx">                         'label' => __( 'Background Image' ),
</span><span class="cx">                         'section' => 'background',
</span><span class="cx">                         'type' => 'upload',
</span><del>-                        'control_params' => array(
-                                'context' => 'custom-background',
-                        ),
-                ) );
</del><ins>+                        'context' => 'custom-background',
+                ) ) );
</ins><span class="cx">
</span><span class="cx">                 $this->add_setting( 'background_repeat', array(
</span><span class="cx">                         'default' => '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->controls as $id => $control ) {
</span><del>-                $settings['controls'][ $id ] = $control->json();
-
-                if ( $control->visibility ) {
-                        if ( is_string( $control->visibility ) ) {
-                                $settings['controls'][ $id ]['visibility'] = array(
-                                        'id' => $control->visibility,
-                                        'value' => true,
-                                );
-                        } else {
-                                $settings['controls'][ $id ]['visibility'] = array(
-                                        'id' => $control->visibility[0],
-                                        'value' => $control->visibility[1],
-                                );
-                        }
-
-                }
</del><ins>+                $control->to_json();
+                $settings['controls'][ $id ] = $control->json;
</ins><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         ?>
</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>