-
Notifications
You must be signed in to change notification settings - Fork 165
Sync customizer color settings to Gutenberg and frontend #373
Changes from 24 commits
f1cce8f
418e655
f254535
924f4df
3fb0305
30a323f
ed41d5e
f5834d2
2fd0c30
8f2f569
a800aef
ee3040b
a1a06f4
816ea9e
629438c
2962e9f
4e18c94
69d6ee0
7b1cefd
99ad81e
aff372b
410eb6f
effdcbc
fd84047
9e45cb1
8fe4e67
d470e64
09cc925
3c5a128
2112c57
22636e6
86a0abf
fbca675
9d5e057
cd896fc
ce784c1
cd4891e
78a870a
3935cff
d36b6aa
a6ea555
8ccd08f
f3b83d3
338751e
c134e19
6a1ca76
4368a52
04f8036
2b84034
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,52 @@ function twentynineteen_customize_register( $wp_customize ) { | |
) | ||
); | ||
} | ||
|
||
// Add page primary color setting and control. | ||
$wp_customize->add_setting( 'primary-color', array( | ||
'default' => '#0073aa', | ||
'sanitize_callback' => 'sanitize_hex_color', | ||
'transport' => 'postMessage', | ||
) ); | ||
|
||
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'primary-color', array( | ||
'label' => __( 'Primary Color' ), | ||
'description' => __( 'Changes the Color of the Featured Image, Buttons, Links etc.' ), | ||
'section' => 'colors', | ||
) ) ); | ||
|
||
// Add page primary color hover setting and control. | ||
$wp_customize->add_setting( 'primary-hover-color', array( | ||
'default' => '#005177', | ||
'sanitize_callback' => 'sanitize_hex_color', | ||
'transport' => 'postMessage', | ||
) ); | ||
|
||
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'primary-hover-color', array( | ||
'label' => __( 'Primary Color Hover' ), | ||
'description' => __( 'Changes the Hover State color of Buttons, Links etc.' ), | ||
'section' => 'colors', | ||
) ) ); | ||
|
||
$wp_customize->add_setting( | ||
'image_filter', | ||
array( | ||
'default' => 'active', | ||
'sanitize_callback' => 'twentynineteen_sanitize_image_filter', | ||
'transport' => 'postMessage', | ||
) ); | ||
|
||
$wp_customize->add_control( | ||
'image_filter', | ||
array( | ||
'label' => __( 'Featured Image Color Filter', 'twentynineteen' ), | ||
'section' => 'colors', | ||
'type' => 'radio', | ||
'description' => __( "Twenty Nineteen adds a color filter to featured images using your site's primary color. If you disable this effect, the theme will use a black filter in individual posts to keep text readable when it appears on top of the featured image.", 'twentynineteen' ) . '<br/><span style="font-style: normal; display: block; margin-top: 16px;">' . __( 'On Featured Images, apply', 'twentynineteen' ) . '</span>', | ||
'choices' => array( | ||
'active' => __( 'A color filter', 'twentynineteen' ), | ||
'inactive' => __( 'A black filter', 'twentynineteen' ), | ||
) ) ); | ||
} | ||
add_action( 'customize_register', 'twentynineteen_customize_register' ); | ||
|
||
|
@@ -61,3 +107,173 @@ function twentynineteen_customize_preview_js() { | |
wp_enqueue_script( 'twentynineteen-customizer', get_template_directory_uri() . '/js/customizer.js', array( 'customize-preview' ), '20151215', true ); | ||
} | ||
add_action( 'customize_preview_init', 'twentynineteen_customize_preview_js' ); | ||
|
||
|
||
/** | ||
* Enqueues front-end CSS for colors. | ||
* | ||
* @since Twenty Sixteen 1.0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not Twenty Sixteen. |
||
* | ||
* @see wp_add_inline_style() | ||
*/ | ||
function twentynineteen_primary_color_css() { | ||
$default_color = '#0073aa'; | ||
$primary_color = get_theme_mod( 'primary-color', $default_color ); | ||
|
||
// Don't do anything if the current color is the default. | ||
if ( $primary_color === $default_color ) { | ||
return; | ||
} | ||
|
||
$css = ' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I recommend defining the color CSS in a separate file to make it easier to locate and adjust. It would be great to match the patter established with Twenty Seventeen by creating a |
||
|
||
/* Set background for: | ||
* - featured image :before | ||
* - featured image :before | ||
* - post thumbmail :before | ||
* - post thumbmail :before | ||
* - wp block button | ||
* - other buttons | ||
* - Submenu | ||
* - Sticky Post | ||
* - WP Block Button | ||
* - Blocks | ||
*/ | ||
.image-filters-enabled .site-header.featured-image .site-featured-image:before, | ||
.image-filters-enabled .site-header.featured-image .site-featured-image:after, | ||
.image-filters-enabled .entry .post-thumbnail:before, | ||
.image-filters-enabled .entry .post-thumbnail:after, | ||
.entry-content .wp-block-button .wp-block-button__link, | ||
.button, button, input[type="button"], input[type="reset"], input[type="submit"], | ||
.main-navigation .sub-menu, | ||
.sticky-post, | ||
.entry-content > *[class^="wp-block-"].has-primary-background-color, | ||
.entry-content > *[class^="wp-block-"] .has-primary-background-color, | ||
.entry-content > *[class^="wp-block-"].is-style-solid-color .has-primary-background-color { | ||
background-color: %1$s; | ||
} | ||
|
||
/* Set Color for: | ||
* - all links | ||
* - main navigation links | ||
* - Post navigation links | ||
* - Post entry meta hover | ||
* - Post entry header more-link hover | ||
* - main navigation svg | ||
* - comment navigation | ||
* - Comment edit link hover | ||
* - Site Footer Link hover | ||
*/ | ||
a, | ||
a:visited, | ||
.main-navigation ul.main-menu > li > a, | ||
.post-navigation .post-title, | ||
.entry .entry-meta a:hover, | ||
.entry .entry-footer a:hover, | ||
.entry .entry-content .more-link:hover, | ||
.main-navigation .main-menu > li > a + svg, | ||
.comment-navigation .nav-previous a:hover, | ||
.comment-navigation .nav-next a:hover, | ||
.comment .comment-metadata .comment-edit-link:hover, | ||
.site-footer a:hover, | ||
.entry-content .wp-block-button.is-style-outline .wp-block-button__link:not(.has-text-color), | ||
.entry-content .wp-block-button.is-style-outline .wp-block-button__link:focus:not(.has-text-color), | ||
.entry-content .wp-block-button.is-style-outline .wp-block-button__link:active:not(.has-text-color), | ||
.entry-content > *[class^="wp-block-"] .has-primary-color, | ||
.entry-content > *[class^="wp-block-"].is-style-solid-color .has-primary-color { | ||
color: %1$s; | ||
} | ||
|
||
/* Set left border color for: | ||
* wp block quote | ||
*/ | ||
.entry-content .wp-block-quote:not(.is-large), .entry-content .wp-block-quote:not(.is-style-large) { | ||
border-left-color: %1$s; | ||
} | ||
|
||
/* Set border color for: | ||
* :focus | ||
*/ | ||
input[type="text"]:focus, | ||
input[type="email"]:focus, | ||
input[type="url"]:focus, | ||
input[type="password"]:focus, | ||
input[type="search"]:focus, | ||
input[type="number"]:focus, | ||
input[type="tel"]:focus, | ||
input[type="range"]:focus, | ||
input[type="date"]:focus, | ||
input[type="month"]:focus, | ||
input[type="week"]:focus, | ||
input[type="time"]:focus, | ||
input[type="datetime"]:focus, | ||
input[type="datetime-local"]:focus, | ||
input[type="color"]:focus, | ||
textarea:focus { | ||
border-color: %1$s | ||
} | ||
|
||
.gallery-item > div > a:focus { | ||
box-shadow: 0 0 0 2px %1$s; | ||
} | ||
'; | ||
|
||
wp_add_inline_style( 'twentynineteen-style', sprintf( $css, $primary_color ) ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to Twenty Seventeen and other themes that use instant custom color previews, we need to expose a data attribute with a the color in the customize preview here. This allows us to avoid duplicating the CSS rules in JS. Instead of
|
||
} | ||
add_action( 'wp_enqueue_scripts', 'twentynineteen_primary_color_css', 11 ); | ||
|
||
|
||
/** | ||
* Enqueues front-end CSS for the page background color. | ||
* | ||
* @since Twenty Sixteen 1.0 | ||
* | ||
* @see wp_add_inline_style() | ||
*/ | ||
function twentynineteen_primary_hover_color_css() { | ||
$default_color = '#005177'; | ||
$primary_hover_color = get_theme_mod( 'primary-hover-color', $default_color ); | ||
|
||
// Don't do anything if the current color is the default. | ||
if ( $primary_hover_color === $default_color ) { | ||
return; | ||
} | ||
|
||
$css = ' | ||
a:hover, a:active, | ||
.main-navigation .main-menu > li > a:hover, | ||
.main-navigation .main-menu > li > a:hover + svg, | ||
.post-navigation .nav-links a:hover, | ||
.comment .comment-author .fn a:hover, | ||
.comment-reply-link:hover, | ||
#cancel-comment-reply-link:hover { | ||
color: %1$s; | ||
} | ||
|
||
.main-navigation .sub-menu > li > a:hover, .main-navigation .sub-menu > li > a:focus, | ||
.main-navigation .sub-menu > li > a:hover:after, .main-navigation .sub-menu > li > a:focus:after { | ||
background: %1$s; | ||
} | ||
'; | ||
|
||
wp_add_inline_style( 'twentynineteen-style', sprintf( $css, $primary_hover_color ) ); | ||
} | ||
add_action( 'wp_enqueue_scripts', 'twentynineteen_primary_hover_color_css', 11 ); | ||
|
||
/** | ||
* Sanitize image filter choice. | ||
* | ||
* @param string $choice Whether image filter is active. | ||
* | ||
* @return string | ||
*/ | ||
function twentynineteen_sanitize_image_filter( $choice ) { | ||
$valid = array( | ||
'active', | ||
'inactive', | ||
); | ||
if ( in_array( $choice, $valid, true ) ) { | ||
return $choice; | ||
} | ||
return 'active'; | ||
} |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As was noted in the colors issue, it would be more appropriate to use a hue picker than the full color picker for this theme, similar to Twenty Seventeen. This is enabled, here, by adding the line:
'mode' => 'hue',
The sanitize callback and default values should be updated to
absint
and the integer equivalent accordingly. All of the CSSS would then be revised to use HSL equivalent colors for the custom color options. While this requires a minor tenchical effort (should take less than an hour), it eliminates the concerns regarding color contrast and makes accessibility much more achievable for end users.