2013-07-29 00:55:10 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2013-10-12 00:02:11 +02:00
|
|
|
* Twenty Fourteen Theme Customizer support
|
2013-07-29 00:55:10 +02:00
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Twenty_Fourteen
|
2013-10-12 00:02:11 +02:00
|
|
|
* @since Twenty Fourteen 1.0
|
2013-07-29 00:55:10 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2013-10-15 20:01:09 +02:00
|
|
|
* Implement Theme Customizer additions and adjustments.
|
2013-07-29 00:55:10 +02:00
|
|
|
*
|
2013-10-12 00:02:11 +02:00
|
|
|
* @since Twenty Fourteen 1.0
|
|
|
|
*
|
2013-07-29 00:55:10 +02:00
|
|
|
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
|
|
|
*/
|
|
|
|
function twentyfourteen_customize_register( $wp_customize ) {
|
2013-10-15 20:01:09 +02:00
|
|
|
// Add postMessage support for site title and description.
|
2013-07-29 00:55:10 +02:00
|
|
|
$wp_customize->get_setting( 'blogname' )->transport = 'postMessage';
|
|
|
|
$wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage';
|
2013-10-16 01:24:10 +02:00
|
|
|
|
2013-10-15 20:01:09 +02:00
|
|
|
// Add the custom accent color setting and control.
|
2013-09-13 00:06:09 +02: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-29 00:55:10 +02:00
|
|
|
}
|
|
|
|
add_action( 'customize_register', 'twentyfourteen_customize_register' );
|
|
|
|
|
|
|
|
/**
|
2013-10-12 00:02:11 +02:00
|
|
|
* Bind JS handlers to make Theme Customizer preview reload changes asynchronously.
|
|
|
|
*
|
|
|
|
* @since Twenty Fourteen 1.0
|
2013-07-29 00:55:10 +02: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-15 05:13:29 +02:00
|
|
|
add_action( 'customize_preview_init', 'twentyfourteen_customize_preview_js' );
|
2013-09-13 00:06:09 +02:00
|
|
|
|
|
|
|
/**
|
2013-10-12 00:02:11 +02: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-13 00:06:09 +02: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-25 00:57:42 +02:00
|
|
|
set_theme_mod( 'accent_lighter', twentyfourteen_adjust_color( $color, 29 ) );
|
|
|
|
set_theme_mod( 'accent_much_lighter', twentyfourteen_adjust_color( $color, 49 ) );
|
2013-09-13 00:06:09 +02:00
|
|
|
|
|
|
|
return $color;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-10-12 00:02:11 +02:00
|
|
|
* Tweak the brightness of a color by adjusting the RGB values by the given interval.
|
2013-09-13 00:06:09 +02: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-12 00:02:11 +02:00
|
|
|
* @since Twenty Fourteen 1.0
|
|
|
|
*
|
2013-09-13 00:06:09 +02:00
|
|
|
* @param string $color The original color, in 3- or 6-digit hexadecimal form.
|
2013-10-12 00:02:11 +02:00
|
|
|
* @param int $steps The number of steps to adjust the color by, in RGB units.
|
2013-09-13 00:06:09 +02: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-12 00:02:11 +02:00
|
|
|
* Output the CSS for the Theme Customizer options.
|
|
|
|
*
|
|
|
|
* @since Twenty Fourteen 1.0
|
|
|
|
*
|
|
|
|
* @return void
|
2013-09-13 00:06:09 +02: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 19:56:10 +02:00
|
|
|
$css = '/* Custom accent color. */
|
2013-09-13 00:06:09 +02:00
|
|
|
a,
|
2013-10-11 05:17:11 +02:00
|
|
|
.paging-navigation .page-numbers.current,
|
|
|
|
.content-sidebar .widget_twentyfourteen_ephemera .post-format-archive-link {
|
2013-09-13 00:06:09 +02:00
|
|
|
color: ' . $accent_color . ';
|
|
|
|
}
|
|
|
|
|
2013-10-11 05:17:11 +02:00
|
|
|
button,
|
2013-10-25 00:57:42 +02:00
|
|
|
.contributor-posts-link,
|
|
|
|
input[type="button"],
|
2013-10-11 05:17:11 +02:00
|
|
|
input[type="reset"],
|
|
|
|
input[type="submit"],
|
2013-10-25 00:53:14 +02:00
|
|
|
.header-extra,
|
|
|
|
.search-toggle,
|
|
|
|
.primary-navigation ul ul,
|
|
|
|
.primary-navigation li:hover > a,
|
2013-10-25 00:57:42 +02:00
|
|
|
.hentry .mejs-controls .mejs-time-rail .mejs-time-current,
|
2013-10-11 05:17:11 +02:00
|
|
|
.widget_calendar tbody a {
|
2013-09-13 00:06:09 +02:00
|
|
|
background-color: ' . $accent_color . ';
|
|
|
|
}
|
|
|
|
|
|
|
|
::-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-11 05:17:11 +02:00
|
|
|
button:hover,
|
2013-10-25 00:53:14 +02:00
|
|
|
button:focus,
|
2013-10-25 00:57:42 +02:00
|
|
|
.contributor-posts-link:hover,
|
|
|
|
input[type="button"]:hover,
|
|
|
|
input[type="button"]:focus,
|
|
|
|
input[type="reset"]:hover,
|
2013-10-25 00:53:14 +02:00
|
|
|
input[type="reset"]:focus,
|
2013-10-25 00:57:42 +02:00
|
|
|
input[type="submit"]:hover,
|
2013-10-11 05:17:11 +02:00
|
|
|
input[type="submit"]:focus,
|
2013-10-25 00:57:42 +02:00
|
|
|
.search-toggle:hover,
|
|
|
|
.search-toggle.active,
|
|
|
|
.search-box,
|
2013-10-11 05:17:11 +02:00
|
|
|
.widget_calendar tbody a:hover {
|
2013-09-13 00:06:09 +02:00
|
|
|
background-color: ' . $accent_lighter . ';
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Generated variant of custom accent color: much lighter. */
|
|
|
|
button:active,
|
2013-10-25 00:57:42 +02:00
|
|
|
.contributor-posts-link:active,
|
|
|
|
input[type="button"]:active,
|
2013-09-13 00:06:09 +02:00
|
|
|
input[type="reset"]:active,
|
2013-10-25 00:57:42 +02:00
|
|
|
input[type="submit"]:active,
|
|
|
|
.page-links a:hover {
|
2013-09-13 00:06:09 +02:00
|
|
|
background-color: ' . $accent_much_lighter . ';
|
|
|
|
}
|
|
|
|
|
|
|
|
a:hover,
|
|
|
|
a:focus,
|
|
|
|
a:active,
|
2013-10-25 00:57:42 +02:00
|
|
|
.site-navigation .current_page_item > a,
|
|
|
|
.site-navigation .current-menu-item > a,
|
2013-09-13 00:06:09 +02:00
|
|
|
.secondary-navigation a:hover,
|
2013-10-25 00:57:42 +02: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-13 00:06:09 +02:00
|
|
|
color: ' . $accent_much_lighter . ';
|
2013-10-25 00:57:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
.page-links a:hover,
|
|
|
|
.paging-navigation a:hover {
|
|
|
|
border-color: ' . $accent_much_lighter . ';
|
2013-10-15 19:56:10 +02:00
|
|
|
}';
|
2013-09-13 00:06:09 +02:00
|
|
|
|
|
|
|
wp_add_inline_style( 'twentyfourteen-style', $css );
|
|
|
|
}
|
2013-10-12 00:02:11 +02:00
|
|
|
add_action( 'wp_enqueue_scripts', 'twentyfourteen_customizer_styles' );
|