Skip to content
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

Backport from core: Global styles duotone not rendering in post editor #38897

Merged
merged 2 commits into from
Feb 21, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 38 additions & 16 deletions lib/compat/wordpress-5.9/render-svg-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,44 @@
* @package gutenberg
*/

/**
* Render the SVG filters supplied by theme.json.
*
* Note that this doesn't render the per-block user-defined
* filters which are handled by duotone.php, but it should
* be rendered in the same location as those to satisfy
* Safari's rendering quirks.
/*
* If wp_global_styles_render_svg_filters is defined, it means the plugin
* is running on WordPress 5.9.1, so don't need to render the global styles
* SVG filters as it was already done by WordPress core.
*/
function gutenberg_experimental_global_styles_render_svg_filters() {
$filters = wp_get_global_styles_svg_filters();
if ( ! empty( $filters ) ) {
echo $filters;
if ( ! function_exists( 'wp_global_styles_render_svg_filters' ) ) {
/**
* Render 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.
*/
function gutenberg_experimental_global_styles_render_svg_filters() {
ajlende marked this conversation as resolved.
Show resolved Hide resolved
/*
* 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()
ajlende marked this conversation as resolved.
Show resolved Hide resolved
) {
return;
}

$filters = wp_get_global_styles_svg_filters();
if ( ! empty( $filters ) ) {
echo $filters;
}
}
}

add_action(
'wp_body_open',
'gutenberg_experimental_global_styles_render_svg_filters'
);
add_action(
'wp_body_open',
'gutenberg_experimental_global_styles_render_svg_filters'
);
add_action(
'in_admin_header',
'gutenberg_experimental_global_styles_render_svg_filters'
);
}