Skip to content

Commit

Permalink
Pass through if value is a valid CSS color
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Sep 18, 2020
1 parent 98d56c2 commit 7b94a13
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions lib/global-styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -900,16 +900,24 @@ function gutenberg_experimental_global_styles_allow_css_var_name( $allowed_attr
* @return boolean Filtered result.
*/
function gutenberg_experimental_global_styles_allow_css_var_value( $allow_css, $css_test_string ) {
$parts = explode( ':', $css_test_string, 2 );
$parts = explode( ':', $css_test_string, 2 );
$property_name = trim( $parts[0] );
$property_value = trim( $parts[1] );

if ( '--wp--style--color--link' !== $parts[0] ) {
// Pass through if we're not processing the link color property.
if ( '--wp--style--color--link' !== $property_name ) {
return $allow_css;
}

// The only value the block editor attaches to link color is
// var(--wp--preset--color--<value-with-alphanumeric-chars-or-hyphen>)
// so be specific in testing for that value.
return preg_match( '/^var\(--wp--preset--color--[A-Za-z0-9-]*\)$/', $parts[1] );
// Pass through if $allow_css true. This means the link color has a valid color value
// (the user selected a custom color).
if ( $allow_css ) {
return $allow_css;
}

// We want to be specific in testing that the value for link color
// matches this: var(--wp--preset--color--<value-with-alphanumeric-chars-or-hyphen>)
return preg_match( '/^var\(--wp--preset--color--[A-Za-z0-9-]*\)$/', $property_value );
}

add_action( 'init', 'gutenberg_experimental_global_styles_register_cpt' );
Expand Down

0 comments on commit 7b94a13

Please sign in to comment.