From 2efeaca76c6da5f05b7295f1f02860291dad5791 Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Wed, 16 Feb 2022 16:34:15 -0600 Subject: [PATCH 1/5] Move where duotone rendering happens --- src/wp-includes/block-supports/duotone.php | 18 ------------------ src/wp-includes/default-filters.php | 4 ++++ src/wp-includes/script-loader.php | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/wp-includes/block-supports/duotone.php b/src/wp-includes/block-supports/duotone.php index 992e014dfc366..6589f4d1506e9 100644 --- a/src/wp-includes/block-supports/duotone.php +++ b/src/wp-includes/block-supports/duotone.php @@ -584,21 +584,3 @@ static function () use ( $filter_svg, $selector ) { ) ); add_filter( 'render_block', 'wp_render_duotone_support', 10, 2 ); - -/** - * 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 in the same location as those to satisfy - * Safari's rendering quirks. - * - * @since 5.9.1 - */ -function wp_global_styles_render_svg_filters() { - $filters = wp_get_global_styles_svg_filters(); - if ( ! empty( $filters ) ) { - echo $filters; - } -} -add_action( 'wp_body_open', 'wp_global_styles_render_svg_filters' ); diff --git a/src/wp-includes/default-filters.php b/src/wp-includes/default-filters.php index 20559dd179f9b..182f94eddf5ed 100644 --- a/src/wp-includes/default-filters.php +++ b/src/wp-includes/default-filters.php @@ -574,6 +574,10 @@ add_action( 'wp_enqueue_scripts', 'wp_enqueue_global_styles' ); add_action( 'wp_footer', 'wp_enqueue_global_styles', 1 ); +// SVG filters like duotone have to be loaded at the beginning of the body in both admin and the front-end. +add_action( 'wp_body_open', 'wp_global_styles_render_svg_filters' ); +add_action( 'in_admin_header', 'wp_global_styles_render_svg_filters' ); + add_action( 'wp_default_styles', 'wp_default_styles' ); add_filter( 'style_loader_src', 'wp_style_loader_src', 10, 2 ); diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php index 0957dce2d703d..374873d31629d 100644 --- a/src/wp-includes/script-loader.php +++ b/src/wp-includes/script-loader.php @@ -2336,6 +2336,23 @@ function wp_enqueue_global_styles() { wp_enqueue_style( 'global-styles' ); } +/** + * 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. + * + * @since 5.9.1 + */ +function wp_global_styles_render_svg_filters() { + $filters = wp_get_global_styles_svg_filters(); + if ( ! empty( $filters ) ) { + echo $filters; + } +} + /** * Checks if the editor scripts and styles for all registered block types * should be enqueued on the current screen. From 6ca54ed35de4d3a01c364d28bdf57b263227830a Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Thu, 17 Feb 2022 08:45:38 -0600 Subject: [PATCH 2/5] Only render SVGs on edit-post in admin --- src/wp-includes/script-loader.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php index 374873d31629d..9cfff6af3936a 100644 --- a/src/wp-includes/script-loader.php +++ b/src/wp-includes/script-loader.php @@ -2347,6 +2347,18 @@ function wp_enqueue_global_styles() { * @since 5.9.1 */ function wp_global_styles_render_svg_filters() { + /* + * When calling via the in_admin_header action, we only want to render the + * SVGs on the post editor page. + */ + global $pagenow; + if ( + is_admin() && + ( 'post.php' !== $pagenow || 'edit' !== $_GET['action'] ) + ) { + return; + } + $filters = wp_get_global_styles_svg_filters(); if ( ! empty( $filters ) ) { echo $filters; From 99b9af7881efec729e3d25e272cae92691ecc954 Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Thu, 17 Feb 2022 09:15:05 -0600 Subject: [PATCH 3/5] Check block editor differently --- src/wp-includes/script-loader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php index 9cfff6af3936a..ea5d4dad76637 100644 --- a/src/wp-includes/script-loader.php +++ b/src/wp-includes/script-loader.php @@ -2354,7 +2354,7 @@ function wp_global_styles_render_svg_filters() { global $pagenow; if ( is_admin() && - ( 'post.php' !== $pagenow || 'edit' !== $_GET['action'] ) + get_current_screen()->is_block_editor() ) { return; } From a0788a54729eb01a90aa3fe36aa4ca76e8736012 Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Thu, 17 Feb 2022 10:12:21 -0600 Subject: [PATCH 4/5] Fix comment for wp_global_styles_render_svg_filters --- src/wp-includes/script-loader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php index ea5d4dad76637..8755066901b6c 100644 --- a/src/wp-includes/script-loader.php +++ b/src/wp-includes/script-loader.php @@ -2349,7 +2349,7 @@ function wp_enqueue_global_styles() { function wp_global_styles_render_svg_filters() { /* * When calling via the in_admin_header action, we only want to render the - * SVGs on the post editor page. + * SVGs on block editor pages. */ global $pagenow; if ( From 0048119bb6dbeeb5bcd5ba120f8293dd0016e7b6 Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Thu, 17 Feb 2022 12:09:28 -0600 Subject: [PATCH 5/5] Fix checking for editor --- src/wp-includes/script-loader.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php index 8755066901b6c..25615b77a9290 100644 --- a/src/wp-includes/script-loader.php +++ b/src/wp-includes/script-loader.php @@ -2351,10 +2351,9 @@ function wp_global_styles_render_svg_filters() { * When calling via the in_admin_header action, we only want to render the * SVGs on block editor pages. */ - global $pagenow; if ( is_admin() && - get_current_screen()->is_block_editor() + ! get_current_screen()->is_block_editor() ) { return; }