<!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>[25418] trunk/src/wp-content/themes/twentyfourteen/inc/customizer.php: Twenty Fourteen: let authors customize the green "accent" color by changing to a different hex value in the Customizer.</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/25418">25418</a></dd>
<dt>Author</dt> <dd>lancewillett</dd>
<dt>Date</dt> <dd>2013-09-12 22:05:06 +0000 (Thu, 12 Sep 2013)</dd>
</dl>
<h3>Log Message</h3>
<pre>Twenty Fourteen: let authors customize the green "accent" color by changing to a different hex value in the Customizer. Props celloexpressions.
Also add an ID attribute to all `style` elements.
See <a href="http://core.trac.wordpress.org/ticket/25220">#25220</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 (25417 => 25418)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-content/themes/twentyfourteen/inc/customizer.php 2013-09-12 21:44:49 UTC (rev 25417)
+++ trunk/src/wp-content/themes/twentyfourteen/inc/customizer.php 2013-09-12 22:05:06 UTC (rev 25418)
</span><span class="lines">@@ -10,19 +10,206 @@
</span><span class="cx"> * Add postMessage support for site title and description for the Theme Customizer.
</span><span class="cx"> *
</span><span class="cx"> * @param WP_Customize_Manager $wp_customize Theme Customizer object.
</span><del>- *
</del><span class="cx"> */
</span><span class="cx"> function twentyfourteen_customize_register( $wp_customize ) {
</span><span class="cx"> $wp_customize->get_setting( 'blogname' )->transport = 'postMessage';
</span><span class="cx"> $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage';
</span><ins>+
+ $wp_customize->add_setting( 'accent_color', array(
+ 'default' => '#24890d',
+ 'sanitize_callback' => 'twentyfourteen_generate_accent_colors',
+ ) );
+
+ $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'accent_color', array(
+ 'label' => __( 'Accent Color', 'twentyfourteen' ),
+ 'section' => 'colors',
+ 'settings' => 'accent_color',
+ ) ) );
</ins><span class="cx"> }
</span><span class="cx"> add_action( 'customize_register', 'twentyfourteen_customize_register' );
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
</span><del>- *
</del><span class="cx"> */
</span><span class="cx"> function twentyfourteen_customize_preview_js() {
</span><span class="cx"> wp_enqueue_script( 'twentyfourteen_customizer', get_template_directory_uri() . '/js/customizer.js', array( 'customize-preview' ), '20120827', true );
</span><span class="cx"> }
</span><span class="cx"> add_action( 'customize_preview_init', 'twentyfourteen_customize_preview_js' );
</span><ins>+
+/**
+ * Generates two variants of the accent color, returns the original, and saves the others as theme mods.
+ *
+ * @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, 14 ) );
+ set_theme_mod( 'accent_much_lighter', twentyfourteen_adjust_color( $color, 71 ) );
+
+ return $color;
+}
+
+/**
+ * Tweaks the brightness of a color by adjusting the RGB values by the given interval.
+ *
+ * Use positive values of $steps to brighten the color and negative values to darken the color.
+ * All three RGB values are modified by the specified steps, within the range of 0-255. The hue
+ * is generally maintained unless the number of steps causes one value to be capped at 0 or 255.
+ *
+ * @param string $color The original color, in 3- or 6-digit hexadecimal form.
+ * @param int $steps The number of steps to adjust the color by, in rgb units.
+ * @return string $color The new color, in 6-digit hexadecimal form.
+ */
+function twentyfourteen_adjust_color( $color, $steps ) {
+ // Convert shorthand to full hex.
+ if ( strlen( $color ) == 3 ) {
+ $color = str_repeat( substr( $color, 1, 1 ), 2 ) . str_repeat( substr( $color, 2, 1 ), 2 ) . str_repeat( substr( $color, 3, 1), 2 );
+ }
+
+ // Convert hex to rgb.
+ $rgb = array( hexdec( substr( $color, 1, 2 ) ), hexdec( substr( $color, 3, 2 ) ), hexdec( substr( $color, 5, 2 ) ) );
+
+ // Adjust color and switch back to hex.
+ $hex = '#';
+ 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);
+ }
+
+ return $hex;
+}
+
+/**
+ * Outputs the css for the Theme Customizer options.
+ */
+function twentyfourteen_customizer_styles() {
+ $accent_color = get_theme_mod( 'accent_color' );
+
+ // Don't do anything if the current color is the default.
+ if ( '#24890d' === $accent_color )
+ return;
+
+ $accent_lighter = get_theme_mod( 'accent_lighter' );
+ $accent_much_lighter = get_theme_mod( 'accent_much_lighter' );
+
+ $css = '<style type="text/css" id="twentyfourteen-accent-color">
+ /* Custom accent color. */
+ h1 a:hover,
+ h2 a:hover,
+ h3 a:hover,
+ h4 a:hover,
+ h5 a:hover,
+ h6 a:hover,
+ a,
+ .primary-navigation ul ul a:hover,
+ .entry-title a:hover,
+ .cat-links a:hover,
+ .site-content .post-navigation a:hover,
+ .site-content .image-navigation a:hover,
+ .comment-author a:hover,
+ .comment-metadata a:hover,
+ .comment-list .trackback a:hover,
+ .comment-list .pingback a:hover,
+ .content-sidebar a:hover,
+ .paging-navigation .page-numbers.current {
+ color: ' . $accent_color . ';
+ }
+
+ button:hover,
+ html input[type="button"]:hover,
+ input[type="reset"]:hover,
+ input[type="submit"]:hover,
+ button:focus,
+ html input[type="button"]:focus,
+ input[type="reset"]:focus,
+ input[type="submit"]:focus,
+ .header-extra,
+ .search-toggle,
+ .bypostauthor .avatar,
+ .widget-area button,
+ .widget-area html input[type="button"],
+ .widget-area input[type="reset"],
+ .widget-area input[type="submit"],
+ .widget_calendar a,
+ .content-sidebar button:hover,
+ .content-sidebar html input[type="button"]:hover,
+ .content-sidebar input[type="reset"]:hover,
+ .content-sidebar input[type="submit"]:hover,
+ .content-sidebar button:focus,
+ .content-sidebar html input[type="button"]:focus,
+ .content-sidebar input[type="reset"]:focus,
+ .content-sidebar input[type="submit"]:focus,
+ .page-links a:hover {
+ background-color: ' . $accent_color . ';
+ }
+
+ ::-moz-selection {
+ background: ' . $accent_color . ';
+ }
+
+ ::selection {
+ background: ' . $accent_color . ';
+ }
+
+ .page-links a:hover,
+ .paging-navigation .page-numbers.current {
+ border-color: ' . $accent_color . ';
+ }
+
+ /* Generated variant of custom accent color: slightly lighter. */
+ .search-toggle:hover,
+ .search-toggle.active,
+ .search-box,
+ .widget-area button:hover,
+ .widget-area html input[type="button"]:hover,
+ .widget-area input[type="reset"]:hover,
+ .widget-area input[type="submit"]:hover,
+ .widget-area button:focus,
+ .widget-area html input[type="button"]:focus,
+ .widget-area input[type="reset"]:focus,
+ .widget-area input[type="submit"]:focus,
+ .widget-area button:active,
+ .widget-area html input[type="button"]:active,
+ .widget-area input[type="reset"]:active,
+ .widget-area input[type="submit"]:active,
+ .widget_calendar a:hover {
+ background-color: ' . $accent_lighter . ';
+ }
+
+ /* Generated variant of custom accent color: much lighter. */
+ button:active,
+ html input[type="button"]:active,
+ input[type="reset"]:active,
+ input[type="submit"]:active,
+ .content-sidebar button:active,
+ .content-sidebar html input[type="button"]:active,
+ .content-sidebar input[type="reset"]:active,
+ .content-sidebar input[type="submit"]:active {
+ background-color: ' . $accent_much_lighter . ';
+ }
+
+ a:hover,
+ a:focus,
+ a:active,
+ .primary-navigation li.current_page_item > a,
+ .primary-navigation li.current-menu-item > a,
+ .secondary-navigation a:hover,
+ #secondary .current_page_item > a,
+ #secondary .current-menu-item > a,
+ #featured-content .entry-meta a:hover,
+ #featured-content .entry-title a:hover,
+ #featured-content .more-link,
+ .widget-area a:hover {
+ color: ' . $accent_much_lighter . ';
+ }
+ </style>';
+
+ wp_add_inline_style( 'twentyfourteen-style', $css );
+}
+add_action( 'wp_enqueue_scripts', 'twentyfourteen_customizer_styles' );
</ins><span class="cx">\ No newline at end of file
</span></span></pre>
</div>
</div>
</body>
</html>