<!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" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { 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 #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#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>
<title>[13403] trunk: Default header selector, first pass.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/13403">13403</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2010-02-25 19:18:44 +0000 (Thu, 25 Feb 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Default header selector, first pass. see <a href="http://trac.wordpress.org/ticket/12343">#12343</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadmincustomheaderphp">trunk/wp-admin/custom-header.php</a></li>
<li><a href="#trunkwpcontentthemestwentytenfunctionsphp">trunk/wp-content/themes/twentyten/functions.php</a></li>
<li><a href="#trunkwpincludesthemephp">trunk/wp-includes/theme.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadmincustomheaderphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/custom-header.php (13402 => 13403)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/custom-header.php        2010-02-25 17:10:00 UTC (rev 13402)
+++ trunk/wp-admin/custom-header.php        2010-02-25 19:18:44 UTC (rev 13403)
</span><span class="lines">@@ -33,6 +33,8 @@
</span><span class="cx">          */
</span><span class="cx">         var $admin_image_div_callback;
</span><span class="cx"> 
</span><ins>+        var $default_headers = array();
+
</ins><span class="cx">         /**
</span><span class="cx">          * PHP4 Constructor - Register administration header callback.
</span><span class="cx">          *
</span><span class="lines">@@ -133,9 +135,77 @@
</span><span class="cx">                         check_admin_referer('custom-header');
</span><span class="cx">                         remove_theme_mods();
</span><span class="cx">                 }
</span><ins>+
+                if ( isset($_POST['default-header']) ) {
+                        $this-&gt;process_default_headers();
+                        if ( isset($this-&gt;default_headers[$_POST['default-header']]) )
+                                set_theme_mod('header_image', esc_url($this-&gt;default_headers[$_POST['default-header']]['url']));
+                }
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         /**
</span><ins>+         * Process the default headers
+         *
+         *  @since 3.0.0
+         */
+        function process_default_headers() {
+                global $_wp_default_headers;
+
+                if ( !empty($this-&gt;headers) )
+                        return;
+
+                if ( !isset($_wp_default_headers) )
+                        return;
+
+                $this-&gt;default_headers = $_wp_default_headers;
+                foreach ( array_keys($this-&gt;default_headers) as $header ) {
+                        $this-&gt;default_headers[$header]['url'] =  sprintf( $this-&gt;default_headers[$header]['url'], get_template_directory_uri(), get_stylesheet_directory_uri() );
+                        $this-&gt;default_headers[$header]['thumbnail_url'] =  sprintf( $this-&gt;default_headers[$header]['thumbnail_url'], get_template_directory_uri(), get_stylesheet_directory_uri() );
+                }
+        }
+
+        /**
+         * Display UI for selecting one of several default headers.
+         *
+         * @since 3.0.0
+         */
+        function show_default_header_selector() {
+                echo '&lt;table id=&quot;available-headers&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;&gt;';
+
+                $headers = array_keys($this-&gt;default_headers);
+                $table = array();
+                $rows = ceil(count($headers) / 3);
+                for ( $row = 1; $row &lt;= $rows; $row++ ) {
+                        for ( $col = 1; $col &lt;= 3; $col++ ) {
+                                $table[$row][$col] = array_shift($headers);
+                        }
+                }
+
+                foreach ( $table as $row =&gt; $cols ) {
+                        echo '&lt;tr&gt;';
+                        foreach ( $cols as $col =&gt; $header_key ) {
+                                if ( !$header_key )
+                                        continue;
+                                $class = array('available-theme');
+                                if ( $row == 1 ) $class[] = 'top';
+                                if ( $col == 1 ) $class[] = 'left';
+                                if ( $row == $rows ) $class[] = 'bottom';
+                                if ( $col == 3 ) $class[] = 'right';
+                                if ( !isset($this-&gt;headers[$header_key]))
+                                echo '&lt;td class=&quot;' . join(' ', $class) . '&quot;&gt;';
+                                $header_thumbnail = $this-&gt;default_headers[$header_key]['thumbnail_url'];
+                                $header_url = $this-&gt;default_headers[$header_key]['url'];
+                                $header_desc = $this-&gt;default_headers[$header_key]['description'];
+                                echo '&lt;label&gt;&lt;input name=&quot;default-header&quot; type=&quot;radio&quot; value=&quot;' . esc_attr($header_key) . '&quot; ' . checked($header_url, get_header_image(), false) . ' /&gt;';
+                                echo '&lt;img src=&quot;' . $header_thumbnail . '&quot; alt=&quot;' . esc_attr($header_desc) .'&quot; /&gt;&lt;/label&gt;';
+                                echo  '&lt;/td&gt;';
+                        }
+                        echo '&lt;/tr&gt;';
+                }
+                echo '&lt;/table&gt;';
+        }
+
+        /**
</ins><span class="cx">          * Execute Javascript depending on step.
</span><span class="cx">          *
</span><span class="cx">          * @since unknown
</span><span class="lines">@@ -284,6 +354,7 @@
</span><span class="cx">          * @since unknown
</span><span class="cx">          */
</span><span class="cx">         function step_1() {
</span><ins>+                $this-&gt;process_default_headers();
</ins><span class="cx">                 if ( isset($_GET['updated']) &amp;&amp; $_GET['updated'] ) { ?&gt;
</span><span class="cx"> &lt;div id=&quot;message&quot; class=&quot;updated&quot;&gt;
</span><span class="cx"> &lt;p&gt;&lt;?php printf(__('Header updated. &lt;a href=&quot;%s&quot;&gt;Visit your site&lt;/a&gt; to see how it looks.'), home_url()); ?&gt;&lt;/p&gt;
</span><span class="lines">@@ -293,6 +364,9 @@
</span><span class="cx"> &lt;div class=&quot;wrap&quot;&gt;
</span><span class="cx"> &lt;?php screen_icon(); ?&gt;
</span><span class="cx"> &lt;h2&gt;&lt;?php _e('Your Header Image'); ?&gt;&lt;/h2&gt;
</span><ins>+&lt;?php
+if ( get_theme_mod('header_image') || empty($this-&gt;default_headers) ) :
+?&gt;
</ins><span class="cx"> &lt;p&gt;&lt;?php _e('This is your header image. You can change the text color or upload and crop a new image.'); ?&gt;&lt;/p&gt;
</span><span class="cx"> &lt;?php
</span><span class="cx"> 
</span><span class="lines">@@ -310,12 +384,23 @@
</span><span class="cx"> &lt;form method=&quot;post&quot; action=&quot;&lt;?php echo admin_url('themes.php?page=custom-header&amp;amp;updated=true') ?&gt;&quot;&gt;
</span><span class="cx"> &lt;input type=&quot;button&quot; class=&quot;button&quot; value=&quot;&lt;?php esc_attr_e('Hide Text'); ?&gt;&quot; onclick=&quot;hide_text()&quot; id=&quot;hidetext&quot; /&gt;
</span><span class="cx"> &lt;input type=&quot;button&quot; class=&quot;button&quot; value=&quot;&lt;?php esc_attr_e('Select a Text Color'); ?&gt;&quot; id=&quot;pickcolor&quot; /&gt;&lt;input type=&quot;button&quot; class=&quot;button&quot; value=&quot;&lt;?php esc_attr_e('Use Original Color'); ?&gt;&quot; onclick=&quot;colorDefault()&quot; id=&quot;defaultcolor&quot; /&gt;
</span><del>-&lt;?php wp_nonce_field('custom-header') ?&gt;
</del><ins>+&lt;?php wp_nonce_field('custom-header'); ?&gt;
</ins><span class="cx"> &lt;input type=&quot;hidden&quot; name=&quot;textcolor&quot; id=&quot;textcolor&quot; value=&quot;#&lt;?php esc_attr(header_textcolor()) ?&gt;&quot; /&gt;&lt;input name=&quot;submit&quot; type=&quot;submit&quot; class=&quot;button&quot; value=&quot;&lt;?php esc_attr_e('Save Changes'); ?&gt;&quot; /&gt;&lt;/form&gt;
</span><span class="cx"> &lt;?php } ?&gt;
</span><span class="cx"> 
</span><span class="cx"> &lt;div id=&quot;colorPickerDiv&quot; style=&quot;z-index: 100;background:#eee;border:1px solid #ccc;position:absolute;display:none;&quot;&gt; &lt;/div&gt;
</span><span class="cx"> &lt;/div&gt;
</span><ins>+&lt;?php
+else:
+        echo '&lt;p&gt;' . __('Choose one of these cool headers, or upload your own image below.') . '&lt;/p&gt;';
+        echo '&lt;form method=&quot;post&quot; action=&quot;' . admin_url('themes.php?page=custom-header&amp;amp;updated=true') . '&quot;&gt;';
+        wp_nonce_field('custom-header');
+        $this-&gt;show_default_header_selector();
+        echo '&lt;input type=&quot;submit&quot; class=&quot;button&quot; value=&quot;' . esc_attr__('Save Your Choice') . '&quot;  /&gt;';
+        echo '&lt;/form&gt;';
+        echo '&lt;/div&gt;';
+endif;
+?&gt;
</ins><span class="cx"> &lt;div class=&quot;wrap&quot;&gt;
</span><span class="cx"> &lt;h2&gt;&lt;?php _e('Upload New Header Image'); ?&gt;&lt;/h2&gt;&lt;p&gt;&lt;?php _e('Here you can upload a custom header image to be shown at the top of your blog instead of the default one. On the next screen you will be able to crop the image.'); ?&gt;&lt;/p&gt;
</span><span class="cx"> &lt;p&gt;&lt;?php printf(__('Images of exactly &lt;strong&gt;%1$d x %2$d pixels&lt;/strong&gt; will be used as-is.'), HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT); ?&gt;&lt;/p&gt;
</span></span></pre></div>
<a id="trunkwpcontentthemestwentytenfunctionsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-content/themes/twentyten/functions.php (13402 => 13403)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-content/themes/twentyten/functions.php        2010-02-25 17:10:00 UTC (rev 13402)
+++ trunk/wp-content/themes/twentyten/functions.php        2010-02-25 19:18:44 UTC (rev 13403)
</span><span class="lines">@@ -9,7 +9,7 @@
</span><span class="cx">         // Your Changeable header business starts here
</span><span class="cx">         // No CSS, just IMG call
</span><span class="cx">         define( 'HEADER_TEXTCOLOR', '');
</span><del>-        define( 'HEADER_IMAGE', '%s/images/header-1.jpg'); // %s is theme dir uri
</del><ins>+        define( 'HEADER_IMAGE', '%s/images/headers/forestfloor.jpg'); // %s is theme dir uri
</ins><span class="cx">         define( 'HEADER_IMAGE_WIDTH', apply_filters( 'twentyten_header_image_width',  940 ) );
</span><span class="cx">         define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'twentyten_header_image_height',        198 ) );
</span><span class="cx">         define( 'NO_HEADER_TEXT', true );
</span><span class="lines">@@ -17,6 +17,15 @@
</span><span class="cx">         add_custom_image_header( '', 'twentyten_admin_header_style' );
</span><span class="cx">         // and thus ends the changeable header business
</span><span class="cx"> 
</span><ins>+        register_default_headers( array('berries' =&gt; array('url' =&gt; '%s/images/headers/berries.jpg', 'thumbnail_url' =&gt; '%s/images/headers/berries-thumbnail.jpg', 'description' =&gt; __('Berries')),
+                                                                        'cherryblossom' =&gt; array( 'url' =&gt; '%s/images/headers/cherryblossoms.jpg', 'thumbnail_url' =&gt; '%s/images/headers/cherryblossoms-thumbnail.jpg', 'description' =&gt; __('Cherry Blossoms')),
+                                                                        'concave' =&gt; array('url' =&gt; '%s/images/headers/concave.jpg', 'thumbnail_url' =&gt; '%s/images/headers/concave-thumbnail.jpg', 'description' =&gt; __('Concave')),
+                                                                        'fern' =&gt; array('url' =&gt; '%s/images/headers/fern.jpg', 'thumbnail_url' =&gt; '%s/images/headers/fern-thumbnail.jpg', 'description' =&gt; __('Fern')),
+                                                                        'forestfloor' =&gt; array('url' =&gt; '%s/images/headers/forestfloor.jpg', 'thumbnail_url' =&gt; '%s/images/headers/forestfloor-thumbnail.jpg', 'description' =&gt; __('Forest Floor')),
+                                                                        'inkwell' =&gt; array('url' =&gt; '%s/images/headers/inkwell.jpg', 'thumbnail_url' =&gt; '%s/images/headers/inkwell-thumbnail.jpg', 'description' =&gt; __('Ink Well')),
+                                                                        'path' =&gt; array('url' =&gt; '%s/images/headers/path.jpg', 'thumbnail_url' =&gt; '%s/images/headers/path-thumbnail.jpg', 'description' =&gt; __('Path')),
+                                                                        'sunset' =&gt; array('url' =&gt; '%s/images/headers/sunset.jpg', 'thumbnail_url' =&gt; '%s/images/headers/sunset-thumbnail.jpg', 'description' =&gt; __('Sunset')) ) );
+
</ins><span class="cx">         add_custom_background();
</span><span class="cx"> 
</span><span class="cx">         // This theme needs post thumbnails
</span></span></pre></div>
<a id="trunkwpincludesthemephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/theme.php (13402 => 13403)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/theme.php        2010-02-25 17:10:00 UTC (rev 13402)
+++ trunk/wp-includes/theme.php        2010-02-25 19:18:44 UTC (rev 13403)
</span><span class="lines">@@ -1335,6 +1335,19 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><ins>+ * Register a selection of default headers to be displayed by the custom header admin UI.
+ *
+ * @since 3.0.0
+ *
+ * @param array $headers Array of headers keyed by a string id.  The ids point to arrays containing 'url', 'thumbnail_url', and 'description' keys.
+ */
+function register_default_headers( $headers ) {
+        global $_wp_default_headers;
+
+        $_wp_default_headers = $headers;
+}
+
+/**
</ins><span class="cx">  * Retrieve background image for custom background.
</span><span class="cx">  *
</span><span class="cx">  * @since 3.0.0
</span></span></pre>
</div>
</div>

</body>
</html>