<!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>[17733] trunk/wp-content/themes/twentyeleven/inc/theme-options/
 theme-options.php: Rewrite of Twenty Eleven theme-options.php.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/17733">17733</a></dd>
<dt>Author</dt> <dd>nacin</dd>
<dt>Date</dt> <dd>2011-04-28 08:06:57 +0000 (Thu, 28 Apr 2011)</dd>
</dl>

<h3>Log Message</h3>
<pre>Rewrite of Twenty Eleven theme-options.php. Including:
 * Full inline documentation.
 * Enqueue scripts/styles on admin_enqueue_scripts and use hook_suffix rather than GET[page]
 * Add filters to twentyeleven_color_schemes(), twentyeleven_layouts(), which necessitates adding a thumbnail URL value here, rather than generating them in the form.
 * Add a twentyeleven_default_theme_options filter.
 * Remove manual check for REQUEST[settings-updated], instead using settings_errors(), since we're using options.php.
 * Abstract out the default link color, rather than hardcoding it in certain places.
 * Use checked().
 * Rename some variables and functions for clarity.
 * Remove unnecessary functions twentyeleven_current_layout() and twentyeleven_current_color_scheme(), as we already have twentyeleven_get_theme_options().
 * Add a twentyeleven_color_schemes action to allow for enqueueing custom color schemes.
 * Add a twentyeleven_layout_classes filter, to allow filtering what gets sent back to body_class().
 * Hook into wp_enqueue_scripts rather than wp_print_styles for enqueueing the color stylesheet.
 * Rewrite the register_setting() callback to start from scratch with an empty array. Improve the link_color logic.
 * Use submit_button().
 * Use esc_attr() rather than esc_attr_e() for non-translations.

TODO:
 * Implement settings sections/fields logic to allow extension of the options page.
 * Consider re-doing this in a class. It'll be cleaner.
 * Store a DB version so we can do an add_option(), rather than calling get_option() with defaults.

see <a href="http://trac.wordpress.org/ticket/17198">#17198</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpcontentthemestwentyelevenincthemeoptionsthemeoptionsphp">trunk/wp-content/themes/twentyeleven/inc/theme-options/theme-options.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpcontentthemestwentyelevenincthemeoptionsthemeoptionsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-content/themes/twentyeleven/inc/theme-options/theme-options.php (17732 => 17733)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-content/themes/twentyeleven/inc/theme-options/theme-options.php        2011-04-27 23:03:27 UTC (rev 17732)
+++ trunk/wp-content/themes/twentyeleven/inc/theme-options/theme-options.php        2011-04-28 08:06:57 UTC (rev 17733)
</span><span class="lines">@@ -4,90 +4,132 @@
</span><span class="cx">  *
</span><span class="cx">  * @package WordPress
</span><span class="cx">  * @subpackage Twenty Eleven
</span><ins>+ * @since Twenty Eleven 1.0
</ins><span class="cx">  */
</span><span class="cx"> 
</span><del>-add_action( 'admin_init', 'theme_options_init' );
-add_action( 'admin_menu', 'theme_options_add_page' );
-
</del><span class="cx"> /**
</span><del>- * Add theme options page styles and scripts
</del><ins>+ * Properly enqueue styles and scripts for our theme options page.
+ *
+ * This function is attached to the admin_enqueue_scripts action hook.
+ *
+ * @since Twenty Eleven 1.0
+ *
+ * @param string $hook_suffix The action passes the current page to the function. We don't
+ *         do anything if we're not on our theme options page.
</ins><span class="cx">  */
</span><del>-wp_register_style( 'twentyeleven-theme-options', get_template_directory_uri() . '/inc/theme-options/theme-options.css', '', '0.1' );
-wp_register_script( 'twentyeleven-theme-options', get_template_directory_uri() . '/inc/theme-options/theme-options.js' );
-if ( isset( $_GET['page'] ) &amp;&amp; $_GET['page'] == 'theme_options' ) {
-        wp_enqueue_style( 'twentyeleven-theme-options' );
-        wp_enqueue_script( 'twentyeleven-theme-options' );
-        wp_enqueue_script( 'farbtastic' );
</del><ins>+function twentyeleven_admin_enqueue_scripts( $hook_suffix ) {
+        if ( $hook_suffix != 'appearance_page_theme_options' )
+                return;
+
+        wp_enqueue_style(  'twentyeleven-theme-options', get_template_directory_uri() . '/inc/theme-options/theme-options.css', '', '0.1' );
+        wp_enqueue_script( 'twentyeleven-theme-options', get_template_directory_uri() . '/inc/theme-options/theme-options.js' );
</ins><span class="cx">         wp_enqueue_style( 'farbtastic' );
</span><ins>+        wp_enqueue_script( 'farbtastic' );
</ins><span class="cx"> }
</span><ins>+add_action( 'admin_enqueue_scripts', 'twentyeleven_admin_enqueue_scripts' );
</ins><span class="cx"> 
</span><span class="cx"> /**
</span><del>- * Init plugin options to white list our options
</del><ins>+ * Register the form setting for our twentyeleven_options array.
+ *
+ * This function is attached to the admin_init action hook.
+ *
+ * This call to register_setting() registers a validation callback, twentyeleven_theme_options_validate(),
+ * which is used when the option is saved, to ensure that our option values are complete, properly
+ * formatted, and safe.
+ *
+ * @since Twenty Eleven 1.0
</ins><span class="cx">  */
</span><del>-function theme_options_init(){
</del><ins>+function twentyeleven_theme_options_init() {
</ins><span class="cx">         register_setting( 'twentyeleven_options', 'twentyeleven_theme_options', 'twentyeleven_theme_options_validate' );
</span><span class="cx"> }
</span><ins>+add_action( 'admin_init', 'twentyeleven_theme_options_init' );
</ins><span class="cx"> 
</span><span class="cx"> /**
</span><del>- * Load up the menu page
</del><ins>+ * Add our theme options page to the admin menu.
+ *
+ * This function is attached to the admin_menu action hook.
+ *
+ * @since Twenty Eleven 1.0
</ins><span class="cx">  */
</span><del>-function theme_options_add_page() {
-        add_theme_page( __( 'Theme Options', 'twentyeleven' ), __( 'Theme Options', 'twentyeleven' ), 'edit_theme_options', 'theme_options', 'theme_options_do_page' );
</del><ins>+function twentyeleven_theme_options_add_page() {
+        add_theme_page(
+                __( 'Theme Options', 'twentyeleven' ), // Name of page
+                __( 'Theme Options', 'twentyeleven' ), // Label in menu
+                'edit_theme_options',                  // Capability required
+                'theme_options',                       // Menu slug, used to uniquely identify the page
+                'theme_options_render_page'            // Function that renders the options page
+        );
</ins><span class="cx"> }
</span><ins>+add_action( 'admin_menu', 'twentyeleven_theme_options_add_page' );
</ins><span class="cx"> 
</span><span class="cx"> /**
</span><del>- * Return array for our color schemes
</del><ins>+ * Returns an array of color schemes registered for Twenty Eleven.
+ *
+ * @since Twenty Eleven 1.0
</ins><span class="cx">  */
</span><span class="cx"> function twentyeleven_color_schemes() {
</span><span class="cx">         $color_scheme_options = array(
</span><span class="cx">                 'light' =&gt; array(
</span><span class="cx">                         'value' =&gt; 'light',
</span><del>-                        'label' =&gt; __( 'Light', 'twentyeleven' )
</del><ins>+                        'label' =&gt; __( 'Light', 'twentyeleven' ),
+                        'thumbnail' =&gt; get_template_directory_uri() . '/inc/theme-options/images/light.png',
</ins><span class="cx">                 ),
</span><span class="cx">                 'dark' =&gt; array(
</span><span class="cx">                         'value' =&gt; 'dark',
</span><del>-                        'label' =&gt; __( 'Dark', 'twentyeleven' )
</del><ins>+                        'label' =&gt; __( 'Dark', 'twentyeleven' ),
+                        'thumbnail' =&gt; get_template_directory_uri() . '/inc/theme-options/images/dark.png',
</ins><span class="cx">                 ),
</span><span class="cx">         );
</span><span class="cx"> 
</span><del>-        return $color_scheme_options;
</del><ins>+        return apply_filters( 'twentyeleven_color_schemes', $color_scheme_options );
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><del>- * Return array for our layout options
</del><ins>+ * Returns an array of layout options registered for Twenty Eleven.
+ *
+ * @since Twenty Eleven 1.0
</ins><span class="cx">  */
</span><span class="cx"> function twentyeleven_layouts() {
</span><span class="cx">         $layout_options = array(
</span><span class="cx">                 'content-sidebar' =&gt; array(
</span><span class="cx">                         'value' =&gt; 'content-sidebar',
</span><span class="cx">                         'label' =&gt; __( 'Content on left', 'twentyeleven' ),
</span><ins>+                        'thumbnail' =&gt; get_template_directory_uri() . '/inc/theme-options/images/content-sidebar.png',
</ins><span class="cx">                 ),
</span><span class="cx">                 'sidebar-content' =&gt; array(
</span><span class="cx">                         'value' =&gt; 'sidebar-content',
</span><del>-                        'label' =&gt; __( 'Content on right', 'twentyeleven' )
</del><ins>+                        'label' =&gt; __( 'Content on right', 'twentyeleven' ),
+                        'thumbnail' =&gt; get_template_directory_uri() . '/inc/theme-options/images/sidebar-content.png',
</ins><span class="cx">                 ),
</span><span class="cx">                 'content' =&gt; array(
</span><span class="cx">                         'value' =&gt; 'content',
</span><del>-                        'label' =&gt; __( 'One-column, no Sidebar', 'twentyeleven' )
</del><ins>+                        'label' =&gt; __( 'One-column, no Sidebar', 'twentyeleven' ),
+                        'thumbnail' =&gt; get_template_directory_uri() . '/inc/theme-options/images/content.png',
</ins><span class="cx">                 ),
</span><span class="cx">         );
</span><span class="cx"> 
</span><del>-        return $layout_options;
</del><ins>+        return apply_filters( 'twentyeleven_layouts', $layout_options );
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><del>- *  Return the default Twenty Eleven theme option values
</del><ins>+ * Returns the default options for Twenty Eleven.
+ *
+ * @since Twenty Eleven 1.0
</ins><span class="cx">  */
</span><span class="cx"> function twentyeleven_get_default_theme_options() {
</span><del>-        return array(
</del><ins>+        $default_theme_options = array(
</ins><span class="cx">                 'color_scheme' =&gt; 'light',
</span><span class="cx">                 'link_color' =&gt; '#1b8be0',
</span><span class="cx">                 'theme_layout' =&gt; 'content-sidebar',
</span><span class="cx">         );
</span><ins>+
+        return apply_filters( 'twentyeleven_default_theme_options', $default_theme_options );
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><del>- *  Return the current Twenty Eleven theme options, with default values as fallback
</del><ins>+ * Returns the options array for Twenty Eleven.
+ *
+ * @since Twenty Eleven 1.0
</ins><span class="cx">  */
</span><span class="cx"> function twentyeleven_get_theme_options() {
</span><span class="cx">         $defaults = twentyeleven_get_default_theme_options();
</span><span class="lines">@@ -97,54 +139,38 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><del>- * Create the options page
</del><ins>+ * Returns the options array for Twenty Eleven.
+ *
+ * @since Twenty Eleven 1.0
</ins><span class="cx">  */
</span><del>-function theme_options_do_page() {
-        if ( ! isset( $_REQUEST['settings-updated'] ) )
-                $_REQUEST['settings-updated'] = false;
-
</del><ins>+function theme_options_render_page() {
</ins><span class="cx">         ?&gt;
</span><span class="cx">         &lt;div class=&quot;wrap&quot;&gt;
</span><del>-                &lt;?php screen_icon(); echo &quot;&lt;h2&gt;&quot; . get_current_theme() . __( ' Theme Options', 'twentyeleven' ) . &quot;&lt;/h2&gt;&quot;; ?&gt;
</del><ins>+                &lt;?php screen_icon(); ?&gt;
+                &lt;h2&gt;&lt;?php printf( __( '%s Theme Options', 'twentyeleven' ), get_current_theme() ); ?&gt;&lt;/h2&gt;
+                &lt;?php settings_errors(); ?&gt;
</ins><span class="cx"> 
</span><del>-                &lt;?php if ( false !== $_REQUEST['settings-updated'] ) : ?&gt;
-                &lt;div class=&quot;updated fade&quot;&gt;&lt;p&gt;&lt;strong&gt;&lt;?php _e( 'Options saved', 'twentyeleven' ); ?&gt;&lt;/strong&gt;&lt;/p&gt;&lt;/div&gt;
-                &lt;?php endif; ?&gt;
-
</del><span class="cx">                 &lt;form method=&quot;post&quot; action=&quot;options.php&quot;&gt;
</span><del>-                        &lt;?php settings_fields( 'twentyeleven_options' ); ?&gt;
-                        &lt;?php $options = twentyeleven_get_theme_options(); ?&gt;
</del><ins>+                        &lt;?php
+                                settings_fields( 'twentyeleven_options' );
+                                $options = twentyeleven_get_theme_options();
+                                $default_options = twentyeleven_get_default_theme_options();
+                        ?&gt;
</ins><span class="cx"> 
</span><span class="cx">                         &lt;table class=&quot;form-table&quot;&gt;
</span><span class="cx"> 
</span><del>-                                &lt;?php
-                                /**
-                                 * Color Scheme Options
-                                 */
-                                ?&gt;
</del><span class="cx">                                 &lt;tr valign=&quot;top&quot; class=&quot;image-radio-option&quot;&gt;&lt;th scope=&quot;row&quot;&gt;&lt;?php _e( 'Color Scheme', 'twentyeleven' ); ?&gt;&lt;/th&gt;
</span><span class="cx">                                         &lt;td&gt;
</span><span class="cx">                                                 &lt;fieldset&gt;&lt;legend class=&quot;screen-reader-text&quot;&gt;&lt;span&gt;&lt;?php _e( 'Color Scheme', 'twentyeleven' ); ?&gt;&lt;/span&gt;&lt;/legend&gt;
</span><span class="cx">                                                 &lt;?php
</span><del>-                                                        if ( ! isset( $checked ) )
-                                                                $checked = '';
-                                                        foreach ( twentyeleven_color_schemes() as $option ) {
-                                                                $radio_setting = $options['color_scheme'];
-
-                                                                if ( '' != $radio_setting ) {
-                                                                        if ( $options['color_scheme'] == $option['value'] ) {
-                                                                                $checked = &quot;checked=\&quot;checked\&quot;&quot;;
-                                                                        } else {
-                                                                                $checked = '';
-                                                                        }
-                                                                }
</del><ins>+                                                        foreach ( twentyeleven_color_schemes() as $color ) {
</ins><span class="cx">                                                                 ?&gt;
</span><span class="cx">                                                                 &lt;div class=&quot;layout&quot;&gt;
</span><span class="cx">                                                                 &lt;label class=&quot;description&quot;&gt;
</span><del>-                                                                        &lt;input type=&quot;radio&quot; name=&quot;twentyeleven_theme_options[color_scheme]&quot; value=&quot;&lt;?php esc_attr_e( $option['value'] ); ?&gt;&quot; &lt;?php echo $checked; ?&gt; /&gt;
</del><ins>+                                                                        &lt;input type=&quot;radio&quot; name=&quot;twentyeleven_theme_options[color_scheme]&quot; value=&quot;&lt;?php echo esc_attr( $color['value'] ); ?&gt;&quot; &lt;?php checked( $options['color_scheme'], $color['value'] ); ?&gt; /&gt;
</ins><span class="cx">                                                                         &lt;span&gt;
</span><del>-                                                                                &lt;img src=&quot;&lt;?php echo get_template_directory_uri(); ?&gt;/inc/theme-options/images/&lt;?php echo $option['value']; ?&gt;.png&quot;/&gt;
-                                                                                &lt;?php echo $option['label']; ?&gt;
</del><ins>+                                                                                &lt;img src=&quot;&lt;?php echo esc_url( $color['thumbnail'] ); ?&gt;&quot;/&gt;
+                                                                                &lt;?php echo $color['label']; ?&gt;
</ins><span class="cx">                                                                         &lt;/span&gt;
</span><span class="cx">                                                                 &lt;/label&gt;
</span><span class="cx">                                                                 &lt;/div&gt;
</span><span class="lines">@@ -155,51 +181,30 @@
</span><span class="cx">                                         &lt;/td&gt;
</span><span class="cx">                                 &lt;/tr&gt;
</span><span class="cx"> 
</span><del>-                                &lt;?php
-                                /**
-                                 * Link Color Options
-                                 */
-                                ?&gt;
</del><span class="cx">                                 &lt;tr valign=&quot;top&quot;&gt;&lt;th scope=&quot;row&quot;&gt;&lt;?php _e( 'Link Color', 'twentyeleven' ); ?&gt;&lt;/th&gt;
</span><span class="cx">                                         &lt;td&gt;
</span><span class="cx">                                                 &lt;fieldset&gt;&lt;legend class=&quot;screen-reader-text&quot;&gt;&lt;span&gt;&lt;?php _e( 'Link Color', 'twentyeleven' ); ?&gt;&lt;/span&gt;&lt;/legend&gt;
</span><del>-                                                        &lt;input type=&quot;text&quot; name=&quot;twentyeleven_theme_options[link_color]&quot; id=&quot;link-color&quot; value=&quot;&lt;?php esc_attr_e( $options['link_color'] ); ?&gt;&quot; /&gt;
</del><ins>+                                                        &lt;input type=&quot;text&quot; name=&quot;twentyeleven_theme_options[link_color]&quot; id=&quot;link-color&quot; value=&quot;&lt;?php echo esc_attr( $options['link_color'] ); ?&gt;&quot; /&gt;
</ins><span class="cx">                                                         &lt;a class=&quot;hide-if-no-js&quot; href=&quot;#&quot; id=&quot;pickcolor&quot;&gt;&lt;?php _e( 'Select a Color', 'twentyeleven' ); ?&gt;&lt;/a&gt;
</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;br /&gt;
</span><del>-                                                        &lt;small class=&quot;description&quot;&gt;&lt;?php printf( __( 'Default color: %s', 'twentyeleven' ), '#1b8be0' ); ?&gt;&lt;/small&gt;
</del><ins>+                                                        &lt;small class=&quot;description&quot;&gt;&lt;?php printf( __( 'Default color: %s', 'twentyeleven' ), $default_options['link_color'] ); ?&gt;&lt;/small&gt;
</ins><span class="cx">                                                 &lt;/fieldset&gt;
</span><span class="cx">                                         &lt;/td&gt;
</span><span class="cx">                                 &lt;/tr&gt;
</span><span class="cx"> 
</span><del>-                                &lt;?php
-                                /**
-                                 * Layout Options
-                                 */
-                                ?&gt;
</del><span class="cx">                                 &lt;tr valign=&quot;top&quot; class=&quot;image-radio-option&quot;&gt;&lt;th scope=&quot;row&quot;&gt;&lt;?php _e( 'Layout', 'twentyeleven' ); ?&gt;&lt;/th&gt;
</span><span class="cx">                                         &lt;td&gt;
</span><span class="cx">                                                 &lt;fieldset&gt;&lt;legend class=&quot;screen-reader-text&quot;&gt;&lt;span&gt;&lt;?php _e( 'Color Scheme', 'twentyeleven' ); ?&gt;&lt;/span&gt;&lt;/legend&gt;
</span><span class="cx">                                                 &lt;?php
</span><del>-                                                        if ( ! isset( $checked ) )
-                                                                $checked = '';
-                                                        foreach ( twentyeleven_layouts() as $option ) {
-                                                                $radio_setting = $options['theme_layout'];
-
-                                                                if ( '' != $radio_setting ) {
-                                                                        if ( $options['theme_layout'] == $option['value'] ) {
-                                                                                $checked = &quot;checked=\&quot;checked\&quot;&quot;;
-                                                                        } else {
-                                                                                $checked = '';
-                                                                        }
-                                                                }
</del><ins>+                                                        foreach ( twentyeleven_layouts() as $layout ) {
</ins><span class="cx">                                                                 ?&gt;
</span><span class="cx">                                                                 &lt;div class=&quot;layout&quot;&gt;
</span><span class="cx">                                                                 &lt;label class=&quot;description&quot;&gt;
</span><del>-                                                                        &lt;input type=&quot;radio&quot; name=&quot;twentyeleven_theme_options[theme_layout]&quot; value=&quot;&lt;?php esc_attr_e( $option['value'] ); ?&gt;&quot; &lt;?php echo $checked; ?&gt; /&gt;
</del><ins>+                                                                        &lt;input type=&quot;radio&quot; name=&quot;twentyeleven_theme_options[theme_layout]&quot; value=&quot;&lt;?php echo esc_attr( $layout['value'] ); ?&gt;&quot; &lt;?php checked( $options['theme_layout'], $layout['value'] ); ?&gt; /&gt;
</ins><span class="cx">                                                                         &lt;span&gt;
</span><del>-                                                                                &lt;img src=&quot;&lt;?php echo get_template_directory_uri(); ?&gt;/inc/theme-options/images/&lt;?php echo $option['value']; ?&gt;.png&quot;/&gt;
-                                                                                &lt;?php echo $option['label']; ?&gt;
</del><ins>+                                                                                &lt;img src=&quot;&lt;?php echo esc_url( $layout['thumbnail'] ); ?&gt;&quot;/&gt;
+                                                                                &lt;?php echo $layout['label']; ?&gt;
</ins><span class="cx">                                                                         &lt;/span&gt;
</span><span class="cx">                                                                 &lt;/label&gt;
</span><span class="cx">                                                                 &lt;/div&gt;
</span><span class="lines">@@ -211,120 +216,102 @@
</span><span class="cx">                                 &lt;/tr&gt;
</span><span class="cx">                         &lt;/table&gt;
</span><span class="cx"> 
</span><del>-                        &lt;p class=&quot;submit&quot;&gt;
-                                &lt;input type=&quot;submit&quot; class=&quot;button-primary&quot; value=&quot;&lt;?php esc_attr_e( 'Save Options', 'twentyeleven' ); ?&gt;&quot; /&gt;
-                        &lt;/p&gt;
</del><ins>+                        &lt;?php submit_button(); ?&gt;
</ins><span class="cx">                 &lt;/form&gt;
</span><span class="cx">         &lt;/div&gt;
</span><span class="cx">         &lt;?php
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><del>- * Sanitize and validate input. Accepts an array, return a sanitized array.
</del><ins>+ * Sanitize and validate form input. Accepts an array, return a sanitized array.
</ins><span class="cx">  *
</span><del>- * todo set up Reset Options action
</del><ins>+ * @see twentyeleven_theme_options_init()
+ * @todo set up Reset Options action
+ *
+ * @since Twenty Ten 1.0
</ins><span class="cx">  */
</span><span class="cx"> function twentyeleven_theme_options_validate( $input ) {
</span><del>-        $defaults = twentyeleven_get_default_theme_options();
</del><ins>+        $output = twentyeleven_get_default_theme_options();
</ins><span class="cx"> 
</span><span class="cx">         // Color scheme must be in our array of color scheme options
</span><del>-        if ( ! isset( $input['color_scheme'] ) || ! array_key_exists( $input['color_scheme'], twentyeleven_color_schemes() ) )
-                $input['color_scheme'] = $defaults['color_scheme'];
</del><ins>+        if ( isset( $input['color_scheme'] ) &amp;&amp; array_key_exists( $input['color_scheme'], twentyeleven_color_schemes() ) )
+                $output['color_scheme'] = $input['color_scheme'];
</ins><span class="cx"> 
</span><span class="cx">         // Link color must be 3 or 6 hexadecimal characters
</span><del>-        if ( ! isset( $input[ 'link_color' ] ) ) {
-                $input['link_color'] = $defaults['link_color'];
-        } else {
-                if ( preg_match( '/^#?([a-f0-9]{3}){1,2}$/i', $input['link_color'] ) ) {
-                        $link_color = $input['link_color'];
-                        // If color value doesn't have a preceding hash, add it
-                        if ( false === strpos( $link_color, '#' ) )
-                                $link_color = '#' . $link_color;
-                } else {
-                        $input['link_color'] = $defaults['link_color'];
-                }
-        }
</del><ins>+        if ( isset( $input['link_color'] ) &amp;&amp; preg_match( '/^#?([a-f0-9]{3}){1,2}$/i', $input['link_color'] ) )
+                        $output['link_color'] = '#' . strtolower( ltrim( $input['link_color'], '#' ) );
</ins><span class="cx"> 
</span><span class="cx">         // Theme layout must be in our array of theme layout options
</span><del>-        if ( ! isset( $input['theme_layout'] ) || ! array_key_exists( $input['theme_layout'], twentyeleven_layouts() ) )
-                $input['theme_layout'] = $defaults['theme_layout'];
</del><ins>+        if ( isset( $input['theme_layout'] ) &amp;&amp; array_key_exists( $input['theme_layout'], twentyeleven_layouts() ) )
+                $output['theme_layout'] = $input['theme_layout'];
</ins><span class="cx"> 
</span><del>-        return $input;
</del><ins>+        return $output;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><del>- *  Returns the current Twenty Eleven color scheme as selected in the theme options
- *
- * @since Twenty Eleven 1.0
</del><ins>+ * Register our color schemes and add them to the queue
</ins><span class="cx">  */
</span><del>-function twentyeleven_current_color_scheme() {
</del><ins>+function twentyeleven_color_styles() {
</ins><span class="cx">         $options = twentyeleven_get_theme_options();
</span><del>-        return $options['color_scheme'];
-}
</del><ins>+        $color_scheme = $options['color_scheme'];
</ins><span class="cx"> 
</span><del>-/**
- * Register our color schemes and add them to the queue
- */
-function twentyeleven_color_registrar() {
-        $color_scheme = twentyeleven_current_color_scheme();
</del><ins>+        if ( 'dark' == $color_scheme )
+                wp_enqueue_style( 'dark', get_template_directory_uri() . '/colors/dark.css', null, null );
</ins><span class="cx"> 
</span><del>-        if ( 'dark' == $color_scheme ) {
-                wp_register_style( 'dark', get_template_directory_uri() . '/colors/dark.css', null, null );
-                wp_enqueue_style( 'dark' );
-        }
</del><ins>+        do_action( 'twentyeleven_color_schemes', $color_scheme );
</ins><span class="cx"> }
</span><del>-if ( ! is_admin() )
-        add_action( 'wp_print_styles', 'twentyeleven_color_registrar' );
</del><ins>+add_action( 'wp_enqueue_scripts', 'twentyeleven_color_styles' );
</ins><span class="cx"> 
</span><span class="cx"> /**
</span><del>- *  Returns the current Twenty Eleven layout as selected in the theme options
</del><ins>+ * Add a style block to the theme for the current link color.
</ins><span class="cx">  *
</span><ins>+ * This function is attached to the wp_head action hook.
+ *
</ins><span class="cx">  * @since Twenty Eleven 1.0
</span><span class="cx">  */
</span><del>-function twentyeleven_current_layout() {
-        $options = twentyeleven_get_theme_options();
-        $current_layout = $options['theme_layout'];
-
-        $two_columns = array( 'content-sidebar', 'sidebar-content' );
-
-        if ( in_array( $current_layout, $two_columns ) )
-                return 'two-column ' . $current_layout;
-        else
-                return 'one-column ' . $current_layout;
-}
-
-/**
- * Add an internal style block for the link color to wp_head()
- */
</del><span class="cx"> function twentyeleven_link_color() {
</span><span class="cx">         $options = twentyeleven_get_theme_options();
</span><del>-        $current_link_color = $options['link_color'];
</del><ins>+        $link_color = $options['link_color'];
</ins><span class="cx"> 
</span><del>-        // Is the link color just the default color?
-        if ( '#1b8be0' == $current_link_color ) :
-                return; // we don't need to do anything then
-        else :
-                ?&gt;
-                        &lt;style&gt;
-                                /* Link color */
-                                a,
-                                .entry-title a:hover {
-                                    color: &lt;?php echo $current_link_color; ?&gt;;
-                                }
-                        &lt;/style&gt;
-                &lt;?php
-        endif;
</del><ins>+        $default_options = twentyeleven_get_default_theme_options();
+        
+        // Don't do anything if the current link color is the default.
+        if ( $default_options['link_color'] == $link_color )
+                return;
+?&gt;
+        &lt;style&gt;
+                /* Link color */
+                a,
+                .entry-title a:hover {
+                        color: &lt;?php echo $link_color; ?&gt;;
+                }
+        &lt;/style&gt;
+&lt;?php
</ins><span class="cx"> }
</span><span class="cx"> add_action( 'wp_head', 'twentyeleven_link_color' );
</span><span class="cx"> 
</span><span class="cx"> /**
</span><del>- *  Adds twentyeleven_current_layout() to the array of body classes
</del><ins>+ *  Adds Twenty Ten layout classes to the array of body classes
</ins><span class="cx">  *
</span><span class="cx">  * @since Twenty Eleven 1.0
</span><span class="cx">  */
</span><del>-function twentyeleven_layout_class( $classes ) {
-        $classes[] = twentyeleven_current_layout();
</del><ins>+function twentyeleven_layout_classes( $classes ) {
+        $options = twentyeleven_get_theme_options();
+        $current_layout = $options['theme_layout'];
</ins><span class="cx"> 
</span><del>-        return $classes;
</del><ins>+        $twentyeleven_classes = array();
+
+        $two_column_layouts = array( 'content-sidebar', 'sidebar-content' );
+
+        if ( in_array( $current_layout, $two_column_layouts ) )
+                $twentyeleven_classes[] = 'two-column';
+        else
+                $twentyeleven_classes[] = 'one-column';
+
+        $twentyeleven_classes[] = $current_layout;
+
+        $twentyeleven_classes = apply_filters( 'twentyeleven_layout_classes', $twentyeleven_classes, $current_layout );
+
+        return array_merge( $classes, $twentyeleven_classes );
</ins><span class="cx"> }
</span><del>-add_filter( 'body_class', 'twentyeleven_layout_class' );
</del><span class="cx">\ No newline at end of file
</span><ins>+add_filter( 'body_class', 'twentyeleven_layout_classes' );
</ins><span class="cx">\ No newline at end of file
</span></span></pre>
</div>
</div>

</body>
</html>