<!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>[26021] trunk/src/wp-content/themes/twentyfourteen/inc/customizer.php: Twenty Fourteen: improvements to Accent Color behavior, including a case where options were published too soon.</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 { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { 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/26021">26021</a></dd>
<dt>Author</dt> <dd>lancewillett</dd>
<dt>Date</dt> <dd>2013-11-05 23:28:07 +0000 (Tue, 05 Nov 2013)</dd>
</dl>

<h3>Log Message</h3>
<pre>Twenty Fourteen: improvements to Accent Color behavior, including a case where options were published too soon. Props celloexpressions, fixes <a href="http://core.trac.wordpress.org/ticket/25580">#25580</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpcontentthemestwentyfourteeninccustomizerphp">trunk/src/wp-content/themes/twentyfourteen/inc/customizer.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpcontentthemestwentyfourteeninccustomizerphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-content/themes/twentyfourteen/inc/customizer.php (26020 => 26021)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-content/themes/twentyfourteen/inc/customizer.php    2013-11-05 21:51:03 UTC (rev 26020)
+++ trunk/src/wp-content/themes/twentyfourteen/inc/customizer.php       2013-11-05 23:28:07 UTC (rev 26021)
</span><span class="lines">@@ -22,7 +22,7 @@
</span><span class="cx">  // Add the custom accent color setting and control.
</span><span class="cx">  $wp_customize->add_setting( 'accent_color', array(
</span><span class="cx">          'default'           => '#24890d',
</span><del>-               'sanitize_callback' => 'twentyfourteen_generate_accent_colors',
</del><ins>+                'sanitize_callback' => 'sanitize_hex_color',
</ins><span class="cx">   ) );
</span><span class="cx"> 
</span><span class="cx">  $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'accent_color', array(
</span><span class="lines">@@ -31,6 +31,9 @@
</span><span class="cx">          'settings' => 'accent_color',
</span><span class="cx">  ) ) );
</span><span class="cx"> 
</span><ins>+       add_filter( 'theme_mod_accent_mid',  'twentyfourteen_accent_mid'  );
+       add_filter( 'theme_mod_accent_light', 'twentyfourteen_accent_light' );
+
</ins><span class="cx">   // Add the featured content section.
</span><span class="cx">  $wp_customize->add_section( 'featured_content', array(
</span><span class="cx">          'title'    => __( 'Featured Content', 'twentyfourteen' ),
</span><span class="lines">@@ -67,24 +70,6 @@
</span><span class="cx"> add_action( 'customize_preview_init', 'twentyfourteen_customize_preview_js' );
</span><span class="cx"> 
</span><span class="cx"> /**
</span><del>- * Generate two variants of the accent color, return the original, and
- * save the others as theme mods.
- *
- * @since Twenty Fourteen 1.0
- *
- * @param string $color The original color.
- * @return string $color The original color, sanitized.
- */
-function twentyfourteen_generate_accent_colors( $color ) {
-       $color = sanitize_hex_color( $color );
-
-       set_theme_mod( 'accent_lighter', twentyfourteen_adjust_color( $color, 29 ) );
-       set_theme_mod( 'accent_much_lighter', twentyfourteen_adjust_color( $color, 49 ) );
-
-       return $color;
-}
-
-/**
</del><span class="cx">  * Tweak the brightness of a color by adjusting the RGB values by the given interval.
</span><span class="cx">  *
</span><span class="cx">  * Use positive values of $steps to brighten the color and negative values to darken the color.
</span><span class="lines">@@ -106,21 +91,57 @@
</span><span class="cx">  // Convert hex to rgb.
</span><span class="cx">  $rgb = array( hexdec( substr( $color, 1, 2 ) ), hexdec( substr( $color, 3, 2 ) ), hexdec( substr( $color, 5, 2 ) ) );
</span><span class="cx"> 
</span><del>-       // Adjust color and switch back to hex.
</del><ins>+        // Adjust color and switch back to 6-digit hex.
</ins><span class="cx">   $hex = '#';
</span><del>-       foreach ( $rgb as $c ) {
-               $c += $steps;
-               if ( $c > 255 )
-                       $c = 255;
-               elseif ( $c < 0 )
-                       $c = 0;
-               $hex .= str_pad( dechex( $c ), 2, '0', STR_PAD_LEFT);
</del><ins>+        foreach ( $rgb as $value ) {
+               $value += $steps;
+               if ( $value > 255 )
+                       $value = 255;
+               elseif ( $value < 0 )
+                       $value = 0;
+               $hex .= str_pad( dechex( $value ), 2, '0', STR_PAD_LEFT);
</ins><span class="cx">   }
</span><span class="cx"> 
</span><span class="cx">  return $hex;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+ /**
+ * Returns a slightly lighter color than what is set as the theme's
+ * accent color.
+ *
+ * @since Twenty Fourteen 1.0
+ *
+ * @return string
+ */
+function twentyfourteen_accent_mid() {
+       return twentyfourteen_adjust_color( get_theme_mod( 'accent_color' ), 29 );
+}
+
</ins><span class="cx"> /**
</span><ins>+ * Returns a lighter color than what is set as the theme's accent color.
+ *
+ * @since Twenty Fourteen 1.0
+ *
+ * @return string
+ */
+function twentyfourteen_accent_light() {
+       return twentyfourteen_adjust_color( get_theme_mod( 'accent_color' ), 49 );
+}
+
+/**
+ * Caches the generated variants of the theme's accent color.
+ *
+ * @since Twenty Fourteen 1.0
+ *
+ * @return void
+ */
+function twentyfourteen_rebuild_accent_colors() {
+       set_theme_mod( 'accent_mid',  twentyfourteen_accent_mid()  );
+       set_theme_mod( 'accent_light', twentyfourteen_accent_light() );
+}
+add_action( 'update_option_theme_mods_twentyfourteen', 'twentyfourteen_rebuild_accent_colors' );
+
+/**
</ins><span class="cx">  * Output the CSS for the Theme Customizer options.
</span><span class="cx">  *
</span><span class="cx">  * @since Twenty Fourteen 1.0
</span><span class="lines">@@ -128,14 +149,14 @@
</span><span class="cx">  * @return void
</span><span class="cx">  */
</span><span class="cx"> function twentyfourteen_customizer_styles() {
</span><del>-       $accent_color = get_theme_mod( 'accent_color' );
</del><ins>+        $accent_color = get_theme_mod( 'accent_color', '#24890d' );
</ins><span class="cx"> 
</span><span class="cx">  // Don't do anything if the current color is the default.
</span><span class="cx">  if ( '#24890d' === $accent_color )
</span><span class="cx">          return;
</span><span class="cx"> 
</span><del>-       $accent_lighter = get_theme_mod( 'accent_lighter' );
-       $accent_much_lighter = get_theme_mod( 'accent_much_lighter' );
</del><ins>+        $accent_mid = get_theme_mod( 'accent_mid' );
+       $accent_light = get_theme_mod( 'accent_light' );
</ins><span class="cx"> 
</span><span class="cx">  $css = '/* Custom accent color. */
</span><span class="cx">          a,
</span><span class="lines">@@ -192,7 +213,7 @@
</span><span class="cx">                  }
</span><span class="cx">          }
</span><span class="cx"> 
</span><del>-               /* Generated variant of custom accent color: slightly lighter. */
</del><ins>+                /* Generated "mid" variant of custom accent color. */
</ins><span class="cx">           button:hover,
</span><span class="cx">          button:focus,
</span><span class="cx">          .contributor-posts-link:hover,
</span><span class="lines">@@ -220,7 +241,7 @@
</span><span class="cx">          .content-sidebar .widget input[type="submit"]:hover,
</span><span class="cx">          .content-sidebar .widget input[type="submit"]:focus,
</span><span class="cx">          .slider-control-paging a:hover:before {
</span><del>-                       background-color: ' . $accent_lighter . ';
</del><ins>+                        background-color: ' . $accent_mid . ';
</ins><span class="cx">           }
</span><span class="cx"> 
</span><span class="cx">          a:active,
</span><span class="lines">@@ -245,33 +266,33 @@
</span><span class="cx">          .content-sidebar .widget_twentyfourteen_ephemera .entry-meta a:hover,
</span><span class="cx">          .site-info a:hover,
</span><span class="cx">          .featured-content a:hover {
</span><del>-                       color: ' . $accent_lighter . ';
</del><ins>+                        color: ' . $accent_mid . ';
</ins><span class="cx">           }
</span><span class="cx"> 
</span><span class="cx">          .page-links a:hover,
</span><span class="cx">          .paging-navigation a:hover {
</span><del>-                       border-color: ' . $accent_lighter . ';
</del><ins>+                        border-color: ' . $accent_mid . ';
</ins><span class="cx">           }
</span><span class="cx"> 
</span><span class="cx">          .tag-links a:hover:before {
</span><del>-                       border-right-color: ' . $accent_lighter . ';
</del><ins>+                        border-right-color: ' . $accent_mid . ';
</ins><span class="cx">           }
</span><span class="cx"> 
</span><span class="cx">          @media screen and (min-width: 782px) {
</span><span class="cx">                  .primary-navigation ul ul a:hover,
</span><span class="cx">                  .primary-navigation ul ul li.focus > a {
</span><del>-                               background-color: ' . $accent_lighter . ';
</del><ins>+                                background-color: ' . $accent_mid . ';
</ins><span class="cx">                   }
</span><span class="cx">          }
</span><span class="cx"> 
</span><span class="cx">          @media screen and (min-width: 1008px) {
</span><span class="cx">                  .secondary-navigation ul ul a:hover,
</span><span class="cx">                  .secondary-navigation ul ul li.focus > a {
</span><del>-                               background-color: ' . $accent_lighter . ';
</del><ins>+                                background-color: ' . $accent_mid . ';
</ins><span class="cx">                   }
</span><span class="cx">          }
</span><span class="cx"> 
</span><del>-               /* Generated variant of custom accent color: much lighter. */
</del><ins>+                /* Generated "light" variant of custom accent color. */
</ins><span class="cx">           button:active,
</span><span class="cx">          .contributor-posts-link:active,
</span><span class="cx">          input[type="button"]:active,
</span><span class="lines">@@ -283,14 +304,14 @@
</span><span class="cx">          .content-sidebar .widget input[type="button"]:active,
</span><span class="cx">          .content-sidebar .widget input[type="reset"]:active,
</span><span class="cx">          .content-sidebar .widget input[type="submit"]:active {
</span><del>-                       background-color: ' . $accent_much_lighter . ';
</del><ins>+                        background-color: ' . $accent_light . ';
</ins><span class="cx">           }
</span><span class="cx"> 
</span><span class="cx">          .site-navigation .current_page_item > a,
</span><span class="cx">          .site-navigation .current_page_ancestor > a,
</span><span class="cx">          .site-navigation .current-menu-item > a,
</span><span class="cx">          .site-navigation .current-menu-ancestor > a {
</span><del>-                       color: ' . $accent_much_lighter . ';
</del><ins>+                        color: ' . $accent_light . ';
</ins><span class="cx">           }';
</span><span class="cx"> 
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>