<!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>[21037] trunk: * Introduce remove_header_image(), reset_header_image(), set_header_image(), and get_header_image_data() for Custom_Image_Header.</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/21037">21037</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2012-06-10 00:32:19 +0000 (Sun, 10 Jun 2012)</dd>
</dl>
<h3>Log Message</h3>
<pre>* Introduce remove_header_image(), reset_header_image(), set_header_image(), and get_header_image_data() for Custom_Image_Header.
* Handle all set/get of header theme mod through these methods.
* Use these methods in the customizer.
Props kovshenin, nacin, SergeyBiryukov, koopersmith.
fixes <a href="http://core.trac.wordpress.org/ticket/20871">#20871</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadmincustombackgroundphp">trunk/wp-admin/custom-background.php</a></li>
<li><a href="#trunkwpadmincustomheaderphp">trunk/wp-admin/custom-header.php</a></li>
<li><a href="#trunkwpadminjscustomizecontrolsdevjs">trunk/wp-admin/js/customize-controls.dev.js</a></li>
<li><a href="#trunkwpincludesclasswpcustomizecontrolphp">trunk/wp-includes/class-wp-customize-control.php</a></li>
<li><a href="#trunkwpincludesclasswpcustomizemanagerphp">trunk/wp-includes/class-wp-customize-manager.php</a></li>
<li><a href="#trunkwpincludesclasswpcustomizesettingphp">trunk/wp-includes/class-wp-customize-setting.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadmincustombackgroundphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/custom-background.php (21036 => 21037)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/custom-background.php        2012-06-09 15:58:24 UTC (rev 21036)
+++ trunk/wp-admin/custom-background.php        2012-06-10 00:32:19 UTC (rev 21037)
</span><span class="lines">@@ -383,10 +383,10 @@
</span><span class="cx">                 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
</span><span class="cx">                 update_post_meta( $id, '_wp_attachment_is_custom_background', get_option('stylesheet' ) );
</span><span class="cx">
</span><del>-                set_theme_mod('background_image', esc_url($url));
</del><ins>+                set_theme_mod('background_image', esc_url_raw($url));
</ins><span class="cx">
</span><span class="cx">                 $thumbnail = wp_get_attachment_image_src( $id, 'thumbnail' );
</span><del>-                set_theme_mod('background_image_thumb', esc_url( $thumbnail[0] ) );
</del><ins>+                set_theme_mod('background_image_thumb', esc_url_raw( $thumbnail[0] ) );
</ins><span class="cx">
</span><span class="cx">                 do_action('wp_create_file_in_uploads', $file, $id); // For replication
</span><span class="cx">                 $this->updated = true;
</span><span class="lines">@@ -425,8 +425,8 @@
</span><span class="cx">                 update_post_meta( $attachment_id, '_wp_attachment_is_custom_background', get_option('stylesheet' ) );
</span><span class="cx">                 $url = wp_get_attachment_image_src( $attachment_id, $size );
</span><span class="cx">                 $thumbnail = wp_get_attachment_image_src( $attachment_id, 'thumbnail' );
</span><del>-                set_theme_mod( 'background_image', esc_url( $url[0] ) );
-                set_theme_mod( 'background_image_thumb', esc_url( $thumbnail[0] ) );
</del><ins>+                set_theme_mod( 'background_image', esc_url_raw( $url[0] ) );
+                set_theme_mod( 'background_image_thumb', esc_url_raw( $thumbnail[0] ) );
</ins><span class="cx">                 exit;
</span><span class="cx">         }
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkwpadmincustomheaderphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/custom-header.php (21036 => 21037)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/custom-header.php        2012-06-09 15:58:24 UTC (rev 21036)
+++ trunk/wp-admin/custom-header.php        2012-06-10 00:32:19 UTC (rev 21037)
</span><span class="lines">@@ -211,21 +211,7 @@
</span><span class="cx">
</span><span class="cx">                 if ( isset( $_POST['resetheader'] ) ) {
</span><span class="cx">                         check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' );
</span><del>-                        $this->process_default_headers();
-                        $default = get_theme_support( 'custom-header', 'default-image' );
-                        $default = sprintf( $default, get_template_directory_uri(), get_stylesheet_directory_uri() );
-                        foreach ( $this->default_headers as $header => $details ) {
-                                if ( $details['url'] == $default ) {
-                                        $default_data = $details;
-                                        break;
-                                }
-                        }
-                        set_theme_mod( 'header_image', $default );
-                        if ( empty( $default_data['width'] ) )
-                                $default_data['width'] = get_theme_support( 'custom-header', 'width' );
-                        if ( empty( $default_data['height'] ) )
-                                $default_data['height'] = get_theme_support( 'custom-header', 'height' );
-                        set_theme_mod( 'header_image_data', (object) $default_data );
</del><ins>+                        $this->reset_header_image();
</ins><span class="cx">                         return;
</span><span class="cx">                 }
</span><span class="cx">
</span><span class="lines">@@ -237,7 +223,7 @@
</span><span class="cx">
</span><span class="cx">                 if ( isset( $_POST['removeheader'] ) ) {
</span><span class="cx">                         check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' );
</span><del>-                        set_theme_mod( 'header_image', 'remove-header' );
</del><ins>+                        $this->remove_header_image();
</ins><span class="cx">                         return;
</span><span class="cx">                 }
</span><span class="cx">
</span><span class="lines">@@ -256,25 +242,8 @@
</span><span class="cx">
</span><span class="cx">                 if ( isset( $_POST['default-header'] ) ) {
</span><span class="cx">                         check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' );
</span><del>-                        if ( 'random-default-image' == $_POST['default-header'] ) {
-                                set_theme_mod( 'header_image', 'random-default-image' );
-                        } elseif ( 'random-uploaded-image' == $_POST['default-header'] ) {
-                                set_theme_mod( 'header_image', 'random-uploaded-image' );
-                        } else {
-                                $this->process_default_headers();
-                                $uploaded = get_uploaded_header_images();
-                                if ( isset( $uploaded[$_POST['default-header']] ) ) {
-                                        set_theme_mod( 'header_image', esc_url( $uploaded[$_POST['default-header']]['url'] ) );
-                                        set_theme_mod( 'header_image_data', (object) $uploaded[$_POST['default-header']] );
-                                } elseif ( isset( $this->default_headers[$_POST['default-header']] ) ) {
-                                        set_theme_mod( 'header_image', esc_url( $this->default_headers[$_POST['default-header']]['url'] ) );
-                                        if ( empty( $this->default_headers[$_POST['default-header']]['width'] ) )
-                                                $this->default_headers[$_POST['default-header']]['width'] = get_theme_support( 'custom-header', 'width' );
-                                        if ( empty( $this->default_headers[$_POST['default-header']]['height'] ) )
-                                                $this->default_headers[$_POST['default-header']]['height'] = get_theme_support( 'custom-header', 'height' );
-                                        set_theme_mod( 'header_image_data', (object) $this->default_headers[$_POST['default-header']] );
-                                }
-                        }
</del><ins>+                        $this->set_header_image( $_POST['default-header'] );
+                        return;
</ins><span class="cx">                 }
</span><span class="cx">         }
</span><span class="cx">
</span><span class="lines">@@ -718,9 +687,9 @@
</span><span class="cx">                         wp_die( __( 'Cheatin&#8217; uh?' ) );
</span><span class="cx">
</span><span class="cx">                 if ( empty( $_POST ) && isset( $_GET['file'] ) ) {
</span><del>-                        $id = absint( $_GET['file'] );
-                        $file = get_attached_file( $id, true );
-                        $url = wp_get_attachment_image_src( $id, 'full');
</del><ins>+                        $attachment_id = absint( $_GET['file'] );
+                        $file = get_attached_file( $attachment_id, true );
+                        $url = wp_get_attachment_image_src( $attachment_id, 'full');
</ins><span class="cx">                         $url = $url[0];
</span><span class="cx">                 } elseif ( isset( $_POST ) ) {
</span><span class="cx">                         extract($this->step_2_manage_upload());
</span><span class="lines">@@ -729,7 +698,7 @@
</span><span class="cx">                 if ( file_exists( $file ) ) {
</span><span class="cx">                         list( $width, $height, $type, $attr ) = getimagesize( $file );
</span><span class="cx">                 } else {
</span><del>-                        $data = wp_get_attachment_metadata( $id );
</del><ins>+                        $data = wp_get_attachment_metadata( $attachment_id );
</ins><span class="cx">                         $height = $data[ 'height' ];
</span><span class="cx">                         $width = $data[ 'width' ];
</span><span class="cx">                         unset( $data );
</span><span class="lines">@@ -750,19 +719,19 @@
</span><span class="cx">                 {
</span><span class="cx">                         // Add the meta-data
</span><span class="cx">                         if ( file_exists( $file ) )
</span><del>-                                wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
-                        update_post_meta( $id, '_wp_attachment_is_custom_header', get_option('stylesheet' ) );
</del><ins>+                                wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $file ) );
</ins><span class="cx">
</span><del>-                        set_theme_mod('header_image', esc_url($url));
-                        do_action('wp_create_file_in_uploads', $file, $id); // For replication
</del><ins>+                        $this->set_header_image( compact( 'url', 'attachment_id', 'width', 'height' ) );
+
+                        do_action('wp_create_file_in_uploads', $file, $attachment_id); // For replication
</ins><span class="cx">                         return $this->finished();
</span><span class="cx">                 } elseif ( $width > $max_width ) {
</span><span class="cx">                         $oitar = $width / $max_width;
</span><del>-                        $image = wp_crop_image($id, 0, 0, $width, $height, $max_width, $height / $oitar, false, str_replace(basename($file), 'midsize-'.basename($file), $file));
</del><ins>+                        $image = wp_crop_image($attachment_id, 0, 0, $width, $height, $max_width, $height / $oitar, false, str_replace(basename($file), 'midsize-'.basename($file), $file));
</ins><span class="cx">                         if ( ! $image || is_wp_error( $image ) )
</span><span class="cx">                                 wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) );
</span><span class="cx">
</span><del>-                        $image = apply_filters('wp_create_file_in_uploads', $image, $id); // For replication
</del><ins>+                        $image = apply_filters('wp_create_file_in_uploads', $image, $attachment_id); // For replication
</ins><span class="cx">
</span><span class="cx">                         $url = str_replace(basename($url), basename($image), $url);
</span><span class="cx">                         $width = $width / $oitar;
</span><span class="lines">@@ -788,7 +757,7 @@
</span><span class="cx">         <input type="hidden" name="y1" id="y1" value="0"/>
</span><span class="cx">         <input type="hidden" name="width" id="width" value="<?php echo esc_attr( $width ); ?>"/>
</span><span class="cx">         <input type="hidden" name="height" id="height" value="<?php echo esc_attr( $height ); ?>"/>
</span><del>-        <input type="hidden" name="attachment_id" id="attachment_id" value="<?php echo esc_attr( $id ); ?>" />
</del><ins>+        <input type="hidden" name="attachment_id" id="attachment_id" value="<?php echo esc_attr( $attachment_id ); ?>" />
</ins><span class="cx">         <input type="hidden" name="oitar" id="oitar" value="<?php echo esc_attr( $oitar ); ?>" />
</span><span class="cx">         <?php if ( empty( $_POST ) && isset( $_GET['file'] ) ) { ?>
</span><span class="cx">         <input type="hidden" name="create-new-attachment" value="true" />
</span><span class="lines">@@ -835,8 +804,8 @@
</span><span class="cx">                 );
</span><span class="cx">
</span><span class="cx">                 // Save the data
</span><del>-                $id = wp_insert_attachment( $object, $file );
-                return compact( 'id', 'file', 'filename', 'url', 'type' );
</del><ins>+                $attachment_id = wp_insert_attachment( $object, $file );
+                return compact( 'attachment_id', 'file', 'filename', 'url', 'type' );
</ins><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         /**
</span><span class="lines">@@ -918,19 +887,11 @@
</span><span class="cx">                 // Update the attachment
</span><span class="cx">                 $attachment_id = wp_insert_attachment( $object, $cropped );
</span><span class="cx">                 wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $cropped ) );
</span><del>-                update_post_meta( $attachment_id, '_wp_attachment_is_custom_header', get_option( 'stylesheet' ) );
</del><span class="cx">
</span><del>-                set_theme_mod('header_image', $url);
</del><ins>+                $width = $dst_width;
+                $height = $dst_height;
+                $this->set_header_image( compact( 'url', 'attachment_id', 'width', 'height' ) );
</ins><span class="cx">
</span><del>-                $header_data = new stdClass();
-                $header_data->attachment_id = $attachment_id;
-                $header_data->url = $url;
-                $header_data->thumbnail_url = $url;
-                $header_data->width = $dst_width;
-                $header_data->height = $dst_height;
-
-                set_theme_mod( 'header_image_data', $header_data );
-
</del><span class="cx">                 // cleanup
</span><span class="cx">                 $medium = str_replace( basename( $original ), 'midsize-' . basename( $original ), $original );
</span><span class="cx">                 if ( file_exists( $medium ) )
</span><span class="lines">@@ -997,4 +958,95 @@
</span><span class="cx">                 return array( 'library' => __('Media Library') );
</span><span class="cx">         }
</span><span class="cx">
</span><ins>+        /**
+         * Choose a header image, selected from existing uploaded and default headers,
+         * or provide an array of uploaded header data (either new, or from media library).
+         *
+         * @param mixed $choice Which header image to select. Allows for values of 'random-default-image',
+         *         for randomly cycling among the default images; 'random-uploaded-image', for randomly cycling
+         *         among the uploaded images; the key of a default image registered for that theme; and
+         *         the key of an image uploaded for that theme (the basename of the URL).
+         * Or an array of arguments: attachment_id, url, width, height. All are required.
+         *
+         * @since 3.4.0
+         */
+        final public function set_header_image( $choice ) {
+                if ( is_array( $choice ) || is_object( $choice ) ) {
+                        $choice = (array) $choice;
+                        if ( ! isset( $choice['attachment_id'] ) || ! isset( $choice['url'] ) )
+                                return;
+
+                        $choice['url'] = esc_url_raw( $choice['url'] );
+
+                        $header_image_data = (object) array(
+                                'attachment_id' => $choice['attachment_id'],
+                                'url' => $choice['url'],
+                                'thumbnail_url' => $choice['url'],
+                                'height' => $choice['height'],
+                                'width' => $choice['width'],
+                        );
+
+                        update_post_meta( $choice['attachment_id'], '_wp_attachment_is_custom_header', get_stylesheet() );
+                        set_theme_mod( 'header_image', $choice['url'] );
+                        set_theme_mod( 'header_image_data', $header_image_data );
+                        return;
+                }
+
+                if ( in_array( $choice, array( 'remove-header', 'random-default-image', 'random-uploaded-image' ) ) ) {
+                        set_theme_mod( 'header_image', $choice );
+                        remove_theme_mod( 'header_image_data' );
+                        return;
+                }
+
+                $uploaded = get_uploaded_header_images();
+                if ( $uploaded && isset( $uploaded[ $choice ] ) ) {
+                        $header_image_data = $uploaded[ $choice ];
+
+                } else {
+                        $this->process_default_headers();
+                        if ( isset( $this->default_headers[ $choice ] ) )
+                                $header_image_data = $this->default_headers[ $choice ];
+                        else
+                                return;
+                }
+
+                set_theme_mod( 'header_image', esc_url_raw( $header_image_data['url'] ) );
+                set_theme_mod( 'header_image_data', $header_image_data );
+        }
+
+        /**
+         * Remove a header image.
+         *
+         * @since 3.4.0
+         */
+        final public function remove_header_image() {
+                return $this->set_header_image( 'remove-header' );
+        }
+
+        /**
+         * Reset a header image to the default image for the theme.
+         *
+         * This method does not do anything if the theme does not have a default header image.
+         *
+         * @since 3.4.0
+         */
+        final public function reset_header_image() {
+                $this->process_default_headers();
+                $default = get_theme_support( 'custom-header', 'default-image' );
+
+                if ( ! $default )
+                        return $this->remove_header_image();
+
+                $default = sprintf( $default, get_template_directory_uri(), get_stylesheet_directory_uri() );
+
+                foreach ( $this->default_headers as $header => $details ) {
+                        if ( $details['url'] == $default ) {
+                                $default_data = $details;
+                                break;
+                        }
+                }
+
+                set_theme_mod( 'header_image', $default );
+                set_theme_mod( 'header_image_data', (object) $default_data );
+        }
</ins><span class="cx"> }
</span></span></pre></div>
<a id="trunkwpadminjscustomizecontrolsdevjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/js/customize-controls.dev.js (21036 => 21037)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/js/customize-controls.dev.js        2012-06-09 15:58:24 UTC (rev 21036)
+++ trunk/wp-admin/js/customize-controls.dev.js        2012-06-10 00:32:19 UTC (rev 21037)
</span><span class="lines">@@ -239,6 +239,7 @@
</span><span class="cx">                                 control.selected.both.addClass('library-selected');
</span><span class="cx">                         });
</span><span class="cx">
</span><ins>+                        // Bind events to switch image urls.
</ins><span class="cx">                         this.library.on( 'click', 'a', function( event ) {
</span><span class="cx">                                 var value = $(this).data('customizeImageValue');
</span><span class="cx">
</span><span class="lines">@@ -263,7 +264,7 @@
</span><span class="cx">                         if ( this.tabs.uploaded && this.tabs.uploaded.target.length ) {
</span><span class="cx">                                 this.tabs.uploaded.both.removeClass('hidden');
</span><span class="cx">
</span><del>-                                $( '<a href="#" class="thumbnail"></a>' )
</del><ins>+                                attachment.element = $( '<a href="#" class="thumbnail"></a>' )
</ins><span class="cx">                                         .data( 'customizeImageValue', attachment.url )
</span><span class="cx">                                         .append( '<img src="' + attachment.url+ '" />' )
</span><span class="cx">                                         .appendTo( this.tabs.uploaded.target );
</span><span class="lines">@@ -868,6 +869,35 @@
</span><span class="cx">                         });
</span><span class="cx">                 });
</span><span class="cx">
</span><ins>+                // Handle header image data
+                api.control( 'header_image', function( control ) {
+                        control.setting.bind( function( to ) {
+                                if ( to === control.params.removed )
+                                        control.settings.data.set( false );
+                        });
+
+                        control.library.on( 'click', 'a', function( event ) {
+                                control.settings.data.set( $(this).data('customizeHeaderImageData') );
+                        });
+
+                        control.uploader.success = function( attachment ) {
+                                var data;
+
+                                api.ImageControl.prototype.success.call( control, attachment );
+
+                                data = {
+                                        attachment_id: attachment.id,
+                                        url: attachment.url,
+                                        thumbnail_url: attachment.url,
+                                        height: attachment.meta.height,
+                                        width: attachment.meta.width
+                                };
+
+                                attachment.element.data( 'customizeHeaderImageData', data );
+                                control.settings.data.set( data );
+                        }
+                });
+
</ins><span class="cx">                 api.trigger( 'ready' );
</span><span class="cx">         });
</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 (21036 => 21037)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/class-wp-customize-control.php        2012-06-09 15:58:24 UTC (rev 21036)
+++ trunk/wp-includes/class-wp-customize-control.php        2012-06-10 00:32:19 UTC (rev 21037)
</span><span class="lines">@@ -11,9 +11,12 @@
</span><span class="cx">         public $manager;
</span><span class="cx">         public $id;
</span><span class="cx">
</span><ins>+        // All settings tied to the control.
</ins><span class="cx">         public $settings;
</span><del>-        public $setting;
</del><span class="cx">
</span><ins>+        // The primary setting for the control (if there is one).
+        public $setting = 'default';
+
</ins><span class="cx">         public $priority = 10;
</span><span class="cx">         public $section = '';
</span><span class="cx">         public $label = '';
</span><span class="lines">@@ -455,6 +458,10 @@
</span><span class="cx">         public function __construct( $manager ) {
</span><span class="cx">                 parent::__construct( $manager, 'header_image', array(
</span><span class="cx">                         'label' => __( 'Header Image' ),
</span><ins>+                        'settings' => array(
+                                'default' => 'header_image',
+                                'data' => 'header_image_data',
+                        ),
</ins><span class="cx">                         'section' => 'header_image',
</span><span class="cx">                         'context' => 'custom-header',
</span><span class="cx">                         'removed' => 'remove-header',
</span><span class="lines">@@ -470,20 +477,40 @@
</span><span class="cx">                 $this->add_tab( 'default', __('Default'), array( $this, 'tab_default_headers' ) );
</span><span class="cx">         }
</span><span class="cx">
</span><ins>+        public function print_header_image( $choice, $header ) {
+                $header['url'] = set_url_scheme( $header['url'] );
+                $header['thumbnail_url'] = set_url_scheme( $header['thumbnail_url'] );
+
+                $header_image_data = array( 'choice' => $choice );
+                foreach ( array( 'attachment_id', 'width', 'height', 'url', 'thumbnail_url' ) as $key ) {
+                        if ( isset( $header[ $key ] ) )
+                                $header_image_data[ $key ] = $header[ $key ];
+                }
+
+
+                ?>
+                <a href="#" class="thumbnail"
+                        data-customize-image-value="<?php echo esc_url( $header['url'] ); ?>"
+                        data-customize-header-image-data="<?php echo esc_attr( json_encode( $header_image_data ) ); ?>">
+                        <img src="<?php echo esc_url( $header['thumbnail_url'] ); ?>" />
+                </a>
+                <?php
+        }
+
</ins><span class="cx">         public function tab_uploaded() {
</span><span class="cx">                 $headers = get_uploaded_header_images();
</span><span class="cx">
</span><span class="cx">                 ?><div class="uploaded-target"></div><?php
</span><span class="cx">
</span><del>-                foreach ( $headers as $header )
-                        $this->print_tab_image( $header['url'], $header['thumbnail_url'] );
</del><ins>+                foreach ( $headers as $choice => $header )
+                        $this->print_header_image( $choice, $header );
</ins><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         public function tab_default_headers() {
</span><span class="cx">                 global $custom_image_header;
</span><span class="cx">                 $custom_image_header->process_default_headers();
</span><span class="cx">
</span><del>-                foreach ( $custom_image_header->default_headers as $header )
-                        $this->print_tab_image( $header['url'], $header['thumbnail_url'] );
</del><ins>+                foreach ( $custom_image_header->default_headers as $choice => $header )
+                        $this->print_header_image( $choice, $header );
</ins><span class="cx">         }
</span><span class="cx"> }
</span><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkwpincludesclasswpcustomizemanagerphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/class-wp-customize-manager.php (21036 => 21037)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/class-wp-customize-manager.php        2012-06-09 15:58:24 UTC (rev 21036)
+++ trunk/wp-includes/class-wp-customize-manager.php        2012-06-10 00:32:19 UTC (rev 21037)
</span><span class="lines">@@ -756,11 +756,16 @@
</span><span class="cx">                         'priority' => 60,
</span><span class="cx">                 ) );
</span><span class="cx">
</span><del>-                $this->add_setting( 'header_image', array(
</del><ins>+                $this->add_setting( new WP_Customize_Filter_Setting( $this, 'header_image', array(
</ins><span class="cx">                         'default' => get_theme_support( 'custom-header', 'default-image' ),
</span><span class="cx">                         'theme_supports' => 'custom-header',
</span><del>-                ) );
</del><ins>+                ) ) );
</ins><span class="cx">
</span><ins>+                $this->add_setting( new WP_Customize_Header_Image_Setting( $this, 'header_image_data', array(
+                        // 'default' => get_theme_support( 'custom-header', 'default-image' ),
+                        'theme_supports' => 'custom-header',
+                ) ) );
+
</ins><span class="cx">                 $this->add_control( new WP_Customize_Header_Image_Control( $this ) );
</span><span class="cx">
</span><span class="cx">                 /* Custom Background */
</span></span></pre></div>
<a id="trunkwpincludesclasswpcustomizesettingphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/class-wp-customize-setting.php (21036 => 21037)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/class-wp-customize-setting.php        2012-06-09 15:58:24 UTC (rev 21036)
+++ trunk/wp-includes/class-wp-customize-setting.php        2012-06-10 00:32:19 UTC (rev 21037)
</span><span class="lines">@@ -367,3 +367,35 @@
</span><span class="cx">                 return isset( $result );
</span><span class="cx">         }
</span><span class="cx"> }
</span><ins>+
+/**
+ * A setting that is used to filter a value, but will not save the results.
+ *
+ * Results should be properly handled using another setting or callback.
+ */
+class WP_Customize_Filter_Setting extends WP_Customize_Setting {
+        public function update() {}
+}
+
+/**
+ * A setting that is used to filter a value, but will not save the results.
+ *
+ * Results should be properly handled using another setting or callback.
+ */
+class WP_Customize_Header_Image_Setting extends WP_Customize_Setting {
+        public $id = 'header_image_data';
+
+        public function update( $value ) {
+                global $custom_image_header;
+
+                // If the value doesn't exist (removed or random),
+                // use the header_image value.
+                if ( ! $value )
+                        $value = $this->manager->get_setting('header_image')->post_value();
+
+                if ( is_array( $value ) && isset( $value['choice'] ) )
+                        $custom_image_header->set_header_image( $value['choice'] );
+                else
+                        $custom_image_header->set_header_image( $value );
+        }
+}
</ins><span class="cx">\ No newline at end of file
</span></span></pre>
</div>
</div>
</body>
</html>