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

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

<h3>Log Message</h3>
<pre>Twenty Eleven:
 * Use add_option(), rather than get_option() with defaults, to prevent notoption queries.
 * Add twentyeleven_theme_options_validate filter, that way one doesn't need to add a filter to sanitize_option_\$option to allow more options in.
 * Some inline doc modifications and additions.
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 (17733 => 17734)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-content/themes/twentyeleven/inc/theme-options/theme-options.php        2011-04-28 08:06:57 UTC (rev 17733)
+++ trunk/wp-content/themes/twentyeleven/inc/theme-options/theme-options.php        2011-04-28 08:52:37 UTC (rev 17734)
</span><span class="lines">@@ -37,10 +37,21 @@
</span><span class="cx">  * which is used when the option is saved, to ensure that our option values are complete, properly
</span><span class="cx">  * formatted, and safe.
</span><span class="cx">  *
</span><ins>+ * We also use this function to add our theme option if it doesn't already exist.
+ *
</ins><span class="cx">  * @since Twenty Eleven 1.0
</span><span class="cx">  */
</span><span class="cx"> function twentyeleven_theme_options_init() {
</span><del>-        register_setting( 'twentyeleven_options', 'twentyeleven_theme_options', 'twentyeleven_theme_options_validate' );
</del><ins>+
+        // If we have no options in the database, let's add them now.
+        if ( false === twentyeleven_get_theme_options() )
+                add_option( 'twentyeleven_theme_options', twentyeleven_get_default_theme_options() );
+
+        register_setting(
+                'twentyeleven_options',       // Options group, see settings_fields() call in theme_options_render_page()
+                'twentyeleven_theme_options', // Database option, see twentyeleven_get_theme_options()
+                'twentyeleven_theme_options_validate' // The sanitization callback, see twentyeleven_theme_options_validate()
+        );
</ins><span class="cx"> }
</span><span class="cx"> add_action( 'admin_init', 'twentyeleven_theme_options_init' );
</span><span class="cx"> 
</span><span class="lines">@@ -119,7 +130,7 @@
</span><span class="cx"> function twentyeleven_get_default_theme_options() {
</span><span class="cx">         $default_theme_options = array(
</span><span class="cx">                 'color_scheme' =&gt; 'light',
</span><del>-                'link_color' =&gt; '#1b8be0',
</del><ins>+                'link_color'   =&gt; '#1b8be0',
</ins><span class="cx">                 'theme_layout' =&gt; 'content-sidebar',
</span><span class="cx">         );
</span><span class="cx"> 
</span><span class="lines">@@ -132,10 +143,7 @@
</span><span class="cx">  * @since Twenty Eleven 1.0
</span><span class="cx">  */
</span><span class="cx"> function twentyeleven_get_theme_options() {
</span><del>-        $defaults = twentyeleven_get_default_theme_options();
-        $options = get_option( 'twentyeleven_theme_options', $defaults );
-
-        return $options;
</del><ins>+        return get_option( 'twentyeleven_theme_options' );
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><span class="lines">@@ -228,10 +236,10 @@
</span><span class="cx">  * @see twentyeleven_theme_options_init()
</span><span class="cx">  * @todo set up Reset Options action
</span><span class="cx">  *
</span><del>- * @since Twenty Ten 1.0
</del><ins>+ * @since Twenty Eleven 1.0
</ins><span class="cx">  */
</span><span class="cx"> function twentyeleven_theme_options_validate( $input ) {
</span><del>-        $output = twentyeleven_get_default_theme_options();
</del><ins>+        $output = $defaults = 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><span class="cx">         if ( isset( $input['color_scheme'] ) &amp;&amp; array_key_exists( $input['color_scheme'], twentyeleven_color_schemes() ) )
</span><span class="lines">@@ -245,11 +253,13 @@
</span><span class="cx">         if ( isset( $input['theme_layout'] ) &amp;&amp; array_key_exists( $input['theme_layout'], twentyeleven_layouts() ) )
</span><span class="cx">                 $output['theme_layout'] = $input['theme_layout'];
</span><span class="cx"> 
</span><del>-        return $output;
</del><ins>+        return apply_filters( 'twentyeleven_theme_options_validate', $output, $input, $defaults );
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><del>- * Register our color schemes and add them to the queue
</del><ins>+ * Enqueue the styles for the current color scheme.
+ *
+ * @since Twenty Eleven 1.0
</ins><span class="cx">  */
</span><span class="cx"> function twentyeleven_color_styles() {
</span><span class="cx">         $options = twentyeleven_get_theme_options();
</span><span class="lines">@@ -291,7 +301,7 @@
</span><span class="cx"> add_action( 'wp_head', 'twentyeleven_link_color' );
</span><span class="cx"> 
</span><span class="cx"> /**
</span><del>- *  Adds Twenty Ten layout classes to the array of body classes
</del><ins>+ * Adds Twenty Eleven 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></span></pre>
</div>
</div>

</body>
</html>