Skip to content

Commit

Permalink
comment for how style engine call works and match expression for filt…
Browse files Browse the repository at this point in the history
…er in css string
  • Loading branch information
draganescu committed Feb 22, 2023
1 parent 8dddbd2 commit e1ab155
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
9 changes: 7 additions & 2 deletions lib/block-supports/duotone.php
Original file line number Diff line number Diff line change
Expand Up @@ -462,13 +462,18 @@ function gutenberg_render_duotone_support( $block_content, $block ) {
}
$selector = implode( ', ', $scoped );

// !important is needed because these styles render before global styles,
// and they should be overriding the duotone filters set by global styles.
// Calling gutenberg_style_engine_get_stylesheet_from_css_rules ensures that
// the styles are rendered in an inline for block supports because we're
// useing the `context` option to instruct it so.
gutenberg_style_engine_get_stylesheet_from_css_rules(
array(
array(
'selector' => $selector,
'declarations' => array(
// !important is needed because these styles
// render before global styles,
// and they should be overriding the duotone
// filters set by global styles.
'filter' => $filter_property . ' !important',
),
),
Expand Down
5 changes: 4 additions & 1 deletion lib/experimental/kses.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ function gutenberg_override_core_kses_init_filters() {
* @param string $css_test_string The CSS to test.
*/
function allow_filter_in_styles( $allow_css, $css_test_string ) {
if ( strpos( $css_test_string, "filter: url('#wp-duotone" ) !== false ) {
if ( preg_match(
"/^filter: url\('#wp-duotone-[-a-zA-Z0-9]+'\) \!important$/",
$css_test_string
) ) {
return true;
}
return $allow_css;
Expand Down

0 comments on commit e1ab155

Please sign in to comment.