2013-07-28 18:55:10 -04:00
|
|
|
<?php
|
|
|
|
/**
|
2013-10-11 18:02:11 -04:00
|
|
|
* Twenty Fourteen Theme Customizer support
|
2013-07-28 18:55:10 -04:00
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Twenty_Fourteen
|
2013-10-11 18:02:11 -04:00
|
|
|
* @since Twenty Fourteen 1.0
|
2013-07-28 18:55:10 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2013-10-15 14:01:09 -04:00
|
|
|
* Implement Theme Customizer additions and adjustments.
|
2013-07-28 18:55:10 -04:00
|
|
|
*
|
2013-10-11 18:02:11 -04:00
|
|
|
* @since Twenty Fourteen 1.0
|
|
|
|
*
|
2013-07-28 18:55:10 -04:00
|
|
|
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
|
|
|
*/
|
|
|
|
function twentyfourteen_customize_register( $wp_customize ) {
|
2013-10-15 14:01:09 -04:00
|
|
|
// Add postMessage support for site title and description.
|
2013-07-28 18:55:10 -04:00
|
|
|
$wp_customize->get_setting( 'blogname' )->transport = 'postMessage';
|
|
|
|
$wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage';
|
2013-10-15 19:24:10 -04:00
|
|
|
|
2013-10-15 14:01:09 -04:00
|
|
|
// Add the custom accent color setting and control.
|
2013-09-12 18:06:09 -04:00
|
|
|
$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',
|
|
|
|
) ) );
|
2013-07-28 18:55:10 -04:00
|
|
|
}
|
|
|
|
add_action( 'customize_register', 'twentyfourteen_customize_register' );
|
|
|
|
|
|
|
|
/**
|
2013-10-11 18:02:11 -04:00
|
|
|
* Bind JS handlers to make Theme Customizer preview reload changes asynchronously.
|
|
|
|
*
|
|
|
|
* @since Twenty Fourteen 1.0
|
2013-07-28 18:55:10 -04:00
|
|
|
*/
|
|
|
|
function twentyfourteen_customize_preview_js() {
|
|
|
|
wp_enqueue_script( 'twentyfourteen_customizer', get_template_directory_uri() . '/js/customizer.js', array( 'customize-preview' ), '20120827', true );
|
|
|
|
}
|
2013-08-14 23:13:29 -04:00
|
|
|
add_action( 'customize_preview_init', 'twentyfourteen_customize_preview_js' );
|
2013-09-12 18:06:09 -04:00
|
|
|
|
|
|
|
/**
|
2013-10-11 18:02:11 -04:00
|
|
|
* Generate two variants of the accent color, return the original, and
|
|
|
|
* save the others as theme mods.
|
|
|
|
*
|
|
|
|
* @since Twenty Fourteen 1.0
|
2013-09-12 18:06:09 -04:00
|
|
|
*
|
|
|
|
* @param string $color The original color.
|
|
|
|
* @return string $color The original color, sanitized.
|
|
|
|
*/
|
|
|
|
function twentyfourteen_generate_accent_colors( $color ) {
|
|
|
|
$color = sanitize_hex_color( $color );
|
|
|
|
|
2013-10-24 18:57:42 -04:00
|
|
|
set_theme_mod( 'accent_lighter', twentyfourteen_adjust_color( $color, 29 ) );
|
|
|
|
set_theme_mod( 'accent_much_lighter', twentyfourteen_adjust_color( $color, 49 ) );
|
2013-09-12 18:06:09 -04:00
|
|
|
|
|
|
|
return $color;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-10-11 18:02:11 -04:00
|
|
|
* Tweak the brightness of a color by adjusting the RGB values by the given interval.
|
2013-09-12 18:06:09 -04:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2013-10-11 18:02:11 -04:00
|
|
|
* @since Twenty Fourteen 1.0
|
|
|
|
*
|
2013-09-12 18:06:09 -04:00
|
|
|
* @param string $color The original color, in 3- or 6-digit hexadecimal form.
|
2013-10-11 18:02:11 -04:00
|
|
|
* @param int $steps The number of steps to adjust the color by, in RGB units.
|
2013-09-12 18:06:09 -04:00
|
|
|
* @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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-10-11 18:02:11 -04:00
|
|
|
* Output the CSS for the Theme Customizer options.
|
|
|
|
*
|
|
|
|
* @since Twenty Fourteen 1.0
|
|
|
|
*
|
|
|
|
* @return void
|
2013-09-12 18:06:09 -04:00
|
|
|
*/
|
|
|
|
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' );
|
|
|
|
|
2013-10-15 13:56:10 -04:00
|
|
|
$css = '/* Custom accent color. */
|
2013-09-12 18:06:09 -04:00
|
|
|
a,
|
2013-10-10 23:17:11 -04:00
|
|
|
.paging-navigation .page-numbers.current,
|
|
|
|
.content-sidebar .widget_twentyfourteen_ephemera .post-format-archive-link {
|
2013-09-12 18:06:09 -04:00
|
|
|
color: ' . $accent_color . ';
|
|
|
|
}
|
|
|
|
|
2013-10-10 23:17:11 -04:00
|
|
|
button,
|
2013-10-24 18:57:42 -04:00
|
|
|
.contributor-posts-link,
|
|
|
|
input[type="button"],
|
2013-10-10 23:17:11 -04:00
|
|
|
input[type="reset"],
|
|
|
|
input[type="submit"],
|
2013-10-24 18:53:14 -04:00
|
|
|
.search-toggle,
|
2013-10-24 18:57:42 -04:00
|
|
|
.hentry .mejs-controls .mejs-time-rail .mejs-time-current,
|
2013-10-10 23:17:11 -04:00
|
|
|
.widget_calendar tbody a {
|
2013-09-12 18:06:09 -04:00
|
|
|
background-color: ' . $accent_color . ';
|
|
|
|
}
|
|
|
|
|
2013-10-24 18:58:48 -04:00
|
|
|
@media screen and (min-width: 782px) {
|
|
|
|
.primary-navigation ul ul,
|
|
|
|
.primary-navigation li:hover > a {
|
|
|
|
background-color: ' . $accent_color . ';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-12 18:06:09 -04:00
|
|
|
::-moz-selection {
|
|
|
|
background: ' . $accent_color . ';
|
|
|
|
}
|
|
|
|
|
|
|
|
::selection {
|
|
|
|
background: ' . $accent_color . ';
|
|
|
|
}
|
|
|
|
|
|
|
|
.paging-navigation .page-numbers.current {
|
|
|
|
border-color: ' . $accent_color . ';
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Generated variant of custom accent color: slightly lighter. */
|
2013-10-10 23:17:11 -04:00
|
|
|
button:hover,
|
2013-10-24 18:53:14 -04:00
|
|
|
button:focus,
|
2013-10-24 18:57:42 -04:00
|
|
|
.contributor-posts-link:hover,
|
|
|
|
input[type="button"]:hover,
|
|
|
|
input[type="button"]:focus,
|
|
|
|
input[type="reset"]:hover,
|
2013-10-24 18:53:14 -04:00
|
|
|
input[type="reset"]:focus,
|
2013-10-24 18:57:42 -04:00
|
|
|
input[type="submit"]:hover,
|
2013-10-10 23:17:11 -04:00
|
|
|
input[type="submit"]:focus,
|
2013-10-24 18:57:42 -04:00
|
|
|
.search-toggle:hover,
|
|
|
|
.search-toggle.active,
|
|
|
|
.search-box,
|
2013-10-24 18:58:48 -04:00
|
|
|
.primary-navigation ul ul a:hover,
|
2013-10-10 23:17:11 -04:00
|
|
|
.widget_calendar tbody a:hover {
|
2013-09-12 18:06:09 -04:00
|
|
|
background-color: ' . $accent_lighter . ';
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Generated variant of custom accent color: much lighter. */
|
|
|
|
button:active,
|
2013-10-24 18:57:42 -04:00
|
|
|
.contributor-posts-link:active,
|
|
|
|
input[type="button"]:active,
|
2013-09-12 18:06:09 -04:00
|
|
|
input[type="reset"]:active,
|
2013-10-24 18:57:42 -04:00
|
|
|
input[type="submit"]:active,
|
|
|
|
.page-links a:hover {
|
2013-09-12 18:06:09 -04:00
|
|
|
background-color: ' . $accent_much_lighter . ';
|
|
|
|
}
|
|
|
|
|
|
|
|
a:hover,
|
|
|
|
a:focus,
|
|
|
|
a:active,
|
2013-10-24 18:57:42 -04:00
|
|
|
.site-navigation .current_page_item > a,
|
2013-10-24 18:58:48 -04:00
|
|
|
.site-navigation .current_page_ancestor > a,
|
2013-10-24 18:57:42 -04:00
|
|
|
.site-navigation .current-menu-item > a,
|
2013-10-24 18:58:48 -04:00
|
|
|
.site-navigation .current-menu-ancestor > a,
|
2013-09-12 18:06:09 -04:00
|
|
|
.secondary-navigation a:hover,
|
2013-10-24 18:57:42 -04:00
|
|
|
.entry-title a:hover,
|
|
|
|
.cat-links a:hover,
|
|
|
|
.post-navigation a:hover,
|
|
|
|
.image-navigation a:hover,
|
|
|
|
.comment-author a:hover,
|
|
|
|
.comment-list .pingback a:hover,
|
|
|
|
.comment-list .trackback a:hover,
|
|
|
|
.comment-metadata a:hover,
|
|
|
|
.footer-sidebar a:hover,
|
|
|
|
.primary-sidebar a:hover,
|
|
|
|
.content-sidebar .widget_twentyfourteen_ephemera .post-format-archive-link:hover,
|
|
|
|
.featured-content a:hover {
|
2013-09-12 18:06:09 -04:00
|
|
|
color: ' . $accent_much_lighter . ';
|
2013-10-24 18:57:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
.page-links a:hover,
|
|
|
|
.paging-navigation a:hover {
|
|
|
|
border-color: ' . $accent_much_lighter . ';
|
2013-10-15 13:56:10 -04:00
|
|
|
}';
|
2013-09-12 18:06:09 -04:00
|
|
|
|
|
|
|
wp_add_inline_style( 'twentyfourteen-style', $css );
|
|
|
|
}
|
2013-10-11 18:02:11 -04:00
|
|
|
add_action( 'wp_enqueue_scripts', 'twentyfourteen_customizer_styles' );
|