Twenty Fourteen: improvements to Accent Color behavior, including a case where options were published too soon. Props celloexpressions, fixes #25580.
Built from https://develop.svn.wordpress.org/trunk@26021 git-svn-id: http://core.svn.wordpress.org/trunk@25952 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
c1b0fa9039
commit
16831f259d
|
@ -22,7 +22,7 @@ function twentyfourteen_customize_register( $wp_customize ) {
|
||||||
// Add the custom accent color setting and control.
|
// Add the custom accent color setting and control.
|
||||||
$wp_customize->add_setting( 'accent_color', array(
|
$wp_customize->add_setting( 'accent_color', array(
|
||||||
'default' => '#24890d',
|
'default' => '#24890d',
|
||||||
'sanitize_callback' => 'twentyfourteen_generate_accent_colors',
|
'sanitize_callback' => 'sanitize_hex_color',
|
||||||
) );
|
) );
|
||||||
|
|
||||||
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'accent_color', array(
|
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'accent_color', array(
|
||||||
|
@ -31,6 +31,9 @@ function twentyfourteen_customize_register( $wp_customize ) {
|
||||||
'settings' => 'accent_color',
|
'settings' => 'accent_color',
|
||||||
) ) );
|
) ) );
|
||||||
|
|
||||||
|
add_filter( 'theme_mod_accent_mid', 'twentyfourteen_accent_mid' );
|
||||||
|
add_filter( 'theme_mod_accent_light', 'twentyfourteen_accent_light' );
|
||||||
|
|
||||||
// Add the featured content section.
|
// Add the featured content section.
|
||||||
$wp_customize->add_section( 'featured_content', array(
|
$wp_customize->add_section( 'featured_content', array(
|
||||||
'title' => __( 'Featured Content', 'twentyfourteen' ),
|
'title' => __( 'Featured Content', 'twentyfourteen' ),
|
||||||
|
@ -66,24 +69,6 @@ function twentyfourteen_customize_preview_js() {
|
||||||
}
|
}
|
||||||
add_action( 'customize_preview_init', 'twentyfourteen_customize_preview_js' );
|
add_action( 'customize_preview_init', 'twentyfourteen_customize_preview_js' );
|
||||||
|
|
||||||
/**
|
|
||||||
* 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tweak the brightness of a color by adjusting the RGB values by the given interval.
|
* Tweak the brightness of a color by adjusting the RGB values by the given interval.
|
||||||
*
|
*
|
||||||
|
@ -106,20 +91,56 @@ function twentyfourteen_adjust_color( $color, $steps ) {
|
||||||
// Convert hex to rgb.
|
// Convert hex to rgb.
|
||||||
$rgb = array( hexdec( substr( $color, 1, 2 ) ), hexdec( substr( $color, 3, 2 ) ), hexdec( substr( $color, 5, 2 ) ) );
|
$rgb = array( hexdec( substr( $color, 1, 2 ) ), hexdec( substr( $color, 3, 2 ) ), hexdec( substr( $color, 5, 2 ) ) );
|
||||||
|
|
||||||
// Adjust color and switch back to hex.
|
// Adjust color and switch back to 6-digit hex.
|
||||||
$hex = '#';
|
$hex = '#';
|
||||||
foreach ( $rgb as $c ) {
|
foreach ( $rgb as $value ) {
|
||||||
$c += $steps;
|
$value += $steps;
|
||||||
if ( $c > 255 )
|
if ( $value > 255 )
|
||||||
$c = 255;
|
$value = 255;
|
||||||
elseif ( $c < 0 )
|
elseif ( $value < 0 )
|
||||||
$c = 0;
|
$value = 0;
|
||||||
$hex .= str_pad( dechex( $c ), 2, '0', STR_PAD_LEFT);
|
$hex .= str_pad( dechex( $value ), 2, '0', STR_PAD_LEFT);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $hex;
|
return $hex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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' );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Output the CSS for the Theme Customizer options.
|
* Output the CSS for the Theme Customizer options.
|
||||||
*
|
*
|
||||||
|
@ -128,14 +149,14 @@ function twentyfourteen_adjust_color( $color, $steps ) {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function twentyfourteen_customizer_styles() {
|
function twentyfourteen_customizer_styles() {
|
||||||
$accent_color = get_theme_mod( 'accent_color' );
|
$accent_color = get_theme_mod( 'accent_color', '#24890d' );
|
||||||
|
|
||||||
// Don't do anything if the current color is the default.
|
// Don't do anything if the current color is the default.
|
||||||
if ( '#24890d' === $accent_color )
|
if ( '#24890d' === $accent_color )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
$accent_lighter = get_theme_mod( 'accent_lighter' );
|
$accent_mid = get_theme_mod( 'accent_mid' );
|
||||||
$accent_much_lighter = get_theme_mod( 'accent_much_lighter' );
|
$accent_light = get_theme_mod( 'accent_light' );
|
||||||
|
|
||||||
$css = '/* Custom accent color. */
|
$css = '/* Custom accent color. */
|
||||||
a,
|
a,
|
||||||
|
@ -192,7 +213,7 @@ function twentyfourteen_customizer_styles() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Generated variant of custom accent color: slightly lighter. */
|
/* Generated "mid" variant of custom accent color. */
|
||||||
button:hover,
|
button:hover,
|
||||||
button:focus,
|
button:focus,
|
||||||
.contributor-posts-link:hover,
|
.contributor-posts-link:hover,
|
||||||
|
@ -220,7 +241,7 @@ function twentyfourteen_customizer_styles() {
|
||||||
.content-sidebar .widget input[type="submit"]:hover,
|
.content-sidebar .widget input[type="submit"]:hover,
|
||||||
.content-sidebar .widget input[type="submit"]:focus,
|
.content-sidebar .widget input[type="submit"]:focus,
|
||||||
.slider-control-paging a:hover:before {
|
.slider-control-paging a:hover:before {
|
||||||
background-color: ' . $accent_lighter . ';
|
background-color: ' . $accent_mid . ';
|
||||||
}
|
}
|
||||||
|
|
||||||
a:active,
|
a:active,
|
||||||
|
@ -245,33 +266,33 @@ function twentyfourteen_customizer_styles() {
|
||||||
.content-sidebar .widget_twentyfourteen_ephemera .entry-meta a:hover,
|
.content-sidebar .widget_twentyfourteen_ephemera .entry-meta a:hover,
|
||||||
.site-info a:hover,
|
.site-info a:hover,
|
||||||
.featured-content a:hover {
|
.featured-content a:hover {
|
||||||
color: ' . $accent_lighter . ';
|
color: ' . $accent_mid . ';
|
||||||
}
|
}
|
||||||
|
|
||||||
.page-links a:hover,
|
.page-links a:hover,
|
||||||
.paging-navigation a:hover {
|
.paging-navigation a:hover {
|
||||||
border-color: ' . $accent_lighter . ';
|
border-color: ' . $accent_mid . ';
|
||||||
}
|
}
|
||||||
|
|
||||||
.tag-links a:hover:before {
|
.tag-links a:hover:before {
|
||||||
border-right-color: ' . $accent_lighter . ';
|
border-right-color: ' . $accent_mid . ';
|
||||||
}
|
}
|
||||||
|
|
||||||
@media screen and (min-width: 782px) {
|
@media screen and (min-width: 782px) {
|
||||||
.primary-navigation ul ul a:hover,
|
.primary-navigation ul ul a:hover,
|
||||||
.primary-navigation ul ul li.focus > a {
|
.primary-navigation ul ul li.focus > a {
|
||||||
background-color: ' . $accent_lighter . ';
|
background-color: ' . $accent_mid . ';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@media screen and (min-width: 1008px) {
|
@media screen and (min-width: 1008px) {
|
||||||
.secondary-navigation ul ul a:hover,
|
.secondary-navigation ul ul a:hover,
|
||||||
.secondary-navigation ul ul li.focus > a {
|
.secondary-navigation ul ul li.focus > a {
|
||||||
background-color: ' . $accent_lighter . ';
|
background-color: ' . $accent_mid . ';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Generated variant of custom accent color: much lighter. */
|
/* Generated "light" variant of custom accent color. */
|
||||||
button:active,
|
button:active,
|
||||||
.contributor-posts-link:active,
|
.contributor-posts-link:active,
|
||||||
input[type="button"]:active,
|
input[type="button"]:active,
|
||||||
|
@ -283,14 +304,14 @@ function twentyfourteen_customizer_styles() {
|
||||||
.content-sidebar .widget input[type="button"]:active,
|
.content-sidebar .widget input[type="button"]:active,
|
||||||
.content-sidebar .widget input[type="reset"]:active,
|
.content-sidebar .widget input[type="reset"]:active,
|
||||||
.content-sidebar .widget input[type="submit"]:active {
|
.content-sidebar .widget input[type="submit"]:active {
|
||||||
background-color: ' . $accent_much_lighter . ';
|
background-color: ' . $accent_light . ';
|
||||||
}
|
}
|
||||||
|
|
||||||
.site-navigation .current_page_item > a,
|
.site-navigation .current_page_item > a,
|
||||||
.site-navigation .current_page_ancestor > a,
|
.site-navigation .current_page_ancestor > a,
|
||||||
.site-navigation .current-menu-item > a,
|
.site-navigation .current-menu-item > a,
|
||||||
.site-navigation .current-menu-ancestor > a {
|
.site-navigation .current-menu-ancestor > a {
|
||||||
color: ' . $accent_much_lighter . ';
|
color: ' . $accent_light . ';
|
||||||
}';
|
}';
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue