-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Duotone: Only output Duotone filters that are used #48291
Changes from all commits
afb2547
0335718
cb94566
c8e659a
f6b610a
7e03c5d
117cdf3
1acc298
3b06685
7623952
4e1876d
74ae720
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 |
---|---|---|
|
@@ -255,3 +255,45 @@ function _gutenberg_add_non_persistent_theme_json_cache_group() { | |
wp_cache_add_non_persistent_groups( 'theme_json' ); | ||
} | ||
add_action( 'plugins_loaded', '_gutenberg_add_non_persistent_theme_json_cache_group' ); | ||
|
||
|
||
/** | ||
* Returns a string containing the SVGs to be referenced as filters (duotone). | ||
* | ||
* @since 5.9.1 | ||
* | ||
* @return string | ||
*/ | ||
function gutenberg_get_global_styles_svg_filters() { | ||
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 just a copy of |
||
/* | ||
* Ignore cache when `WP_DEBUG` is enabled, so it doesn't interfere with the theme | ||
* developer's workflow. | ||
* | ||
* @todo Replace `WP_DEBUG` once an "in development mode" check is available in Core. | ||
*/ | ||
$can_use_cached = ! WP_DEBUG; | ||
$cache_group = 'theme_json'; | ||
$cache_key = 'wp_get_global_styles_svg_filters'; | ||
if ( $can_use_cached ) { | ||
$cached = wp_cache_get( $cache_key, $cache_group ); | ||
if ( $cached ) { | ||
return $cached; | ||
} | ||
} | ||
|
||
$supports_theme_json = wp_theme_has_theme_json(); | ||
|
||
$origins = array( 'default', 'theme', 'custom' ); | ||
if ( ! $supports_theme_json ) { | ||
$origins = array( 'default' ); | ||
} | ||
|
||
$tree = WP_Theme_JSON_Resolver_Gutenberg::get_merged_data(); | ||
$svgs = $tree->get_svg_filters( $origins ); | ||
|
||
if ( $can_use_cached ) { | ||
wp_cache_set( $cache_key, $svgs, $cache_group ); | ||
} | ||
|
||
return $svgs; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -191,3 +191,38 @@ function gutenberg_enqueue_global_styles_custom_css() { | |
} | ||
} | ||
add_action( 'wp_enqueue_scripts', 'gutenberg_enqueue_global_styles_custom_css' ); | ||
|
||
|
||
|
||
/** | ||
* Renders the SVG filters supplied by theme.json. | ||
* | ||
* Note that this doesn't render the per-block user-defined | ||
* filters which are handled by wp_render_duotone_support, | ||
* but it should be rendered before the filtered content | ||
* in the body to satisfy Safari's rendering quirks. | ||
* | ||
* @since 5.9.1 | ||
*/ | ||
function gutenberg_global_styles_render_svg_filters() { | ||
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 just a copy of |
||
/* | ||
* When calling via the in_admin_header action, we only want to render the | ||
* SVGs on block editor pages. | ||
*/ | ||
if ( | ||
is_admin() && | ||
! get_current_screen()->is_block_editor() | ||
) { | ||
return; | ||
} | ||
|
||
$filters = gutenberg_get_global_styles_svg_filters(); | ||
if ( ! empty( $filters ) ) { | ||
echo $filters; | ||
} | ||
} | ||
|
||
remove_action( 'wp_body_open', 'wp_global_styles_render_svg_filters' ); | ||
remove_action( 'in_admin_header', 'wp_global_styles_render_svg_filters' ); | ||
add_action( 'wp_body_open', 'gutenberg_global_styles_render_svg_filters' ); | ||
add_action( 'in_admin_header', 'gutenberg_global_styles_render_svg_filters' ); |
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.
It would be nice if it could still be handled by
value_func
inWP_Theme_JSON_Gutenberg
instead of moving it here.Maybe we have to think a little more about where the filters/actions belong in that code? Could it be more useful in
gutenberg_add_global_styles_for_blocks
—modifying the$metadata
passed intoget_styles_for_block
?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.
I think @ajlende has a point. Somehow appending that preset CSS code doesn't feel it belongs in
get_filter_svg
and since it's a preset and WP Theme json gives us a way to add callback for presets then we should use that.