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',
|
2013-11-05 18:29:08 -05:00
|
|
|
'sanitize_callback' => 'sanitize_hex_color',
|
2013-09-12 18:06:09 -04:00
|
|
|
) );
|
|
|
|
|
|
|
|
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'accent_color', array(
|
|
|
|
'label' => __( 'Accent Color', 'twentyfourteen' ),
|
|
|
|
'section' => 'colors',
|
|
|
|
'settings' => 'accent_color',
|
|
|
|
) ) );
|
2013-10-30 10:39:10 -04:00
|
|
|
|
2013-11-05 18:29:08 -05:00
|
|
|
add_filter( 'theme_mod_accent_mid', 'twentyfourteen_accent_mid' );
|
|
|
|
add_filter( 'theme_mod_accent_light', 'twentyfourteen_accent_light' );
|
|
|
|
|
2013-10-30 10:39:10 -04:00
|
|
|
// Add the featured content section.
|
|
|
|
$wp_customize->add_section( 'featured_content', array(
|
|
|
|
'title' => __( 'Featured Content', 'twentyfourteen' ),
|
|
|
|
'priority' => 120,
|
|
|
|
) );
|
|
|
|
|
|
|
|
// Add the featured content layout setting and control.
|
|
|
|
$wp_customize->add_setting( 'featured_content_layout', array(
|
|
|
|
'default' => 'grid',
|
|
|
|
'type' => 'theme_mod',
|
|
|
|
'capability' => 'edit_theme_options',
|
|
|
|
) );
|
|
|
|
|
|
|
|
$wp_customize->add_control( 'featured_content_layout', array(
|
|
|
|
'label' => __( 'Layout', 'twentyfourteen' ),
|
|
|
|
'section' => 'featured_content',
|
|
|
|
'type' => 'select',
|
|
|
|
'choices' => array(
|
|
|
|
'grid' => __( 'Grid', 'twentyfourteen' ),
|
|
|
|
'slider' => __( 'Slider', 'twentyfourteen' ),
|
|
|
|
),
|
|
|
|
) );
|
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
|
|
|
* 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 ) ) );
|
|
|
|
|
2013-11-05 18:29:08 -05:00
|
|
|
// Adjust color and switch back to 6-digit hex.
|
2013-09-12 18:06:09 -04:00
|
|
|
$hex = '#';
|
2013-11-05 18:29:08 -05:00
|
|
|
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);
|
2013-09-12 18:06:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return $hex;
|
|
|
|
}
|
|
|
|
|
2013-11-05 18:29:08 -05:00
|
|
|
/**
|
|
|
|
* 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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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' );
|
|
|
|
|
2013-09-12 18:06:09 -04:00
|
|
|
/**
|
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() {
|
2013-11-05 18:29:08 -05:00
|
|
|
$accent_color = get_theme_mod( 'accent_color', '#24890d' );
|
2013-09-12 18:06:09 -04:00
|
|
|
|
|
|
|
// Don't do anything if the current color is the default.
|
|
|
|
if ( '#24890d' === $accent_color )
|
|
|
|
return;
|
|
|
|
|
2013-11-05 18:29:08 -05:00
|
|
|
$accent_mid = get_theme_mod( 'accent_mid' );
|
|
|
|
$accent_light = get_theme_mod( 'accent_light' );
|
2013-09-12 18:06:09 -04:00
|
|
|
|
2013-10-15 13:56:10 -04:00
|
|
|
$css = '/* Custom accent color. */
|
2013-09-12 18:06:09 -04:00
|
|
|
a,
|
2013-10-31 00:28:10 -04:00
|
|
|
.content-sidebar .widget a {
|
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-11-02 00:36:12 -04:00
|
|
|
.widget button,
|
|
|
|
.widget input[type="button"],
|
|
|
|
.widget input[type="reset"],
|
|
|
|
.widget input[type="submit"],
|
2013-10-31 00:28:10 -04:00
|
|
|
.widget_calendar tbody a,
|
2013-11-04 13:08:10 -05:00
|
|
|
.content-sidebar .widget input[type="button"],
|
|
|
|
.content-sidebar .widget input[type="reset"],
|
|
|
|
.content-sidebar .widget input[type="submit"],
|
|
|
|
.slider-control-paging .slider-active:before,
|
|
|
|
.slider-control-paging .slider-active:hover:before,
|
2013-10-31 00:28:10 -04:00
|
|
|
.slider-direction-nav a:hover {
|
2013-09-12 18:06:09 -04:00
|
|
|
background-color: ' . $accent_color . ';
|
|
|
|
}
|
|
|
|
|
|
|
|
::-moz-selection {
|
|
|
|
background: ' . $accent_color . ';
|
|
|
|
}
|
|
|
|
|
|
|
|
::selection {
|
|
|
|
background: ' . $accent_color . ';
|
|
|
|
}
|
|
|
|
|
|
|
|
.paging-navigation .page-numbers.current {
|
|
|
|
border-color: ' . $accent_color . ';
|
|
|
|
}
|
|
|
|
|
2013-10-31 00:28:10 -04:00
|
|
|
@media screen and (min-width: 782px) {
|
2013-11-04 13:08:10 -05:00
|
|
|
.primary-navigation li:hover > a,
|
|
|
|
.primary-navigation li.focus > a,
|
|
|
|
.primary-navigation ul ul {
|
2013-10-31 00:28:10 -04:00
|
|
|
background-color: ' . $accent_color . ';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@media screen and (min-width: 1008px) {
|
|
|
|
.secondary-navigation li:hover > a,
|
2013-11-04 13:08:10 -05:00
|
|
|
.secondary-navigation li.focus > a,
|
2013-10-31 00:28:10 -04:00
|
|
|
.secondary-navigation ul ul {
|
|
|
|
background-color: ' . $accent_color . ';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-05 18:29:08 -05:00
|
|
|
/* Generated "mid" variant of custom accent color. */
|
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-11-04 13:08:10 -05:00
|
|
|
.entry-meta .tag-links a:hover,
|
|
|
|
.widget input[type="button"]:hover,
|
|
|
|
.widget input[type="button"]:focus,
|
|
|
|
.widget input[type="reset"]:hover,
|
|
|
|
.widget input[type="reset"]:focus,
|
|
|
|
.widget input[type="submit"]:hover,
|
|
|
|
.widget input[type="submit"]:focus,
|
2013-10-31 00:28:10 -04:00
|
|
|
.widget_calendar tbody a:hover,
|
2013-11-04 13:08:10 -05:00
|
|
|
.content-sidebar .widget input[type="button"]:hover,
|
|
|
|
.content-sidebar .widget input[type="button"]:focus,
|
|
|
|
.content-sidebar .widget input[type="reset"]:hover,
|
|
|
|
.content-sidebar .widget input[type="reset"]:focus,
|
|
|
|
.content-sidebar .widget input[type="submit"]:hover,
|
|
|
|
.content-sidebar .widget input[type="submit"]:focus,
|
|
|
|
.slider-control-paging a:hover:before {
|
2013-11-05 18:29:08 -05:00
|
|
|
background-color: ' . $accent_mid . ';
|
2013-09-12 18:06:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
a:active,
|
2013-11-04 13:08:10 -05:00
|
|
|
a:hover,
|
|
|
|
.site-navigation a:hover,
|
2013-10-24 18:57:42 -04:00
|
|
|
.entry-title a:hover,
|
2013-10-31 00:28:10 -04:00
|
|
|
.entry-meta a:hover,
|
2013-10-24 18:57:42 -04:00
|
|
|
.cat-links a:hover,
|
2013-11-02 00:36:12 -04:00
|
|
|
.entry-content .edit-link a:hover,
|
2013-11-04 13:08:10 -05:00
|
|
|
.page-links a:hover,
|
2013-10-24 18:57:42 -04:00
|
|
|
.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,
|
2013-11-02 00:36:12 -04:00
|
|
|
.comment-reply-title small a:hover,
|
2013-10-31 00:28:10 -04:00
|
|
|
.widget a:hover,
|
2013-11-04 13:08:10 -05:00
|
|
|
.widget-title a:hover,
|
2013-10-31 00:28:10 -04:00
|
|
|
.content-sidebar .widget a:hover,
|
2013-11-02 00:36:12 -04:00
|
|
|
.content-sidebar .widget .widget-title a:hover,
|
2013-10-31 00:28:10 -04:00
|
|
|
.content-sidebar .widget_twentyfourteen_ephemera .entry-meta a:hover,
|
2013-11-04 13:08:10 -05:00
|
|
|
.site-info a:hover,
|
2013-10-24 18:57:42 -04:00
|
|
|
.featured-content a:hover {
|
2013-11-05 18:29:08 -05:00
|
|
|
color: ' . $accent_mid . ';
|
2013-10-24 18:57:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
.page-links a:hover,
|
|
|
|
.paging-navigation a:hover {
|
2013-11-05 18:29:08 -05:00
|
|
|
border-color: ' . $accent_mid . ';
|
2013-11-04 13:08:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
.tag-links a:hover:before {
|
2013-11-05 18:29:08 -05:00
|
|
|
border-right-color: ' . $accent_mid . ';
|
2013-11-04 13:08:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@media screen and (min-width: 782px) {
|
|
|
|
.primary-navigation ul ul a:hover,
|
|
|
|
.primary-navigation ul ul li.focus > a {
|
2013-11-05 18:29:08 -05:00
|
|
|
background-color: ' . $accent_mid . ';
|
2013-11-04 13:08:10 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@media screen and (min-width: 1008px) {
|
|
|
|
.secondary-navigation ul ul a:hover,
|
|
|
|
.secondary-navigation ul ul li.focus > a {
|
2013-11-05 18:29:08 -05:00
|
|
|
background-color: ' . $accent_mid . ';
|
2013-11-04 13:08:10 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-05 18:29:08 -05:00
|
|
|
/* Generated "light" variant of custom accent color. */
|
2013-11-04 13:08:10 -05:00
|
|
|
button:active,
|
|
|
|
.contributor-posts-link:active,
|
|
|
|
input[type="button"]:active,
|
|
|
|
input[type="reset"]:active,
|
|
|
|
input[type="submit"]:active,
|
|
|
|
.widget input[type="button"]:active,
|
|
|
|
.widget input[type="reset"]:active,
|
|
|
|
.widget input[type="submit"]:active,
|
|
|
|
.content-sidebar .widget input[type="button"]:active,
|
|
|
|
.content-sidebar .widget input[type="reset"]:active,
|
|
|
|
.content-sidebar .widget input[type="submit"]:active {
|
2013-11-05 18:29:08 -05:00
|
|
|
background-color: ' . $accent_light . ';
|
2013-11-04 13:08:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
.site-navigation .current_page_item > a,
|
|
|
|
.site-navigation .current_page_ancestor > a,
|
|
|
|
.site-navigation .current-menu-item > a,
|
|
|
|
.site-navigation .current-menu-ancestor > a {
|
2013-11-05 18:29:08 -05:00
|
|
|
color: ' . $accent_light . ';
|
2013-10-15 13:56:10 -04:00
|
|
|
}';
|
2013-09-12 18:06:09 -04:00
|
|
|
|
2013-11-04 13:08:10 -05: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' );
|