From 76207c890b68098000be3e54385dea54229a1944 Mon Sep 17 00:00:00 2001 From: hellofromTonya Date: Thu, 17 Feb 2022 20:45:00 +0000 Subject: [PATCH] Editor: Automatically apply global styles duotone filters to render in post editor. Global styles duotone filters were not rendering in the post editor. This fixes that by adding `wp_global_styles_render_svg_filters` to the `in_admin_header` so it renders in the body before the editor. Follow-up [52757]. Props ajlende, abhanonstopnewsuk. Fixes #55190. Built from https://develop.svn.wordpress.org/trunk@52768 git-svn-id: http://core.svn.wordpress.org/trunk@52357 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/block-supports/duotone.php | 18 ----------------- wp-includes/default-filters.php | 4 ++++ wp-includes/script-loader.php | 28 ++++++++++++++++++++++++++ wp-includes/version.php | 2 +- 4 files changed, 33 insertions(+), 19 deletions(-) diff --git a/wp-includes/block-supports/duotone.php b/wp-includes/block-supports/duotone.php index 992e014dfc..6589f4d150 100644 --- a/wp-includes/block-supports/duotone.php +++ b/wp-includes/block-supports/duotone.php @@ -584,21 +584,3 @@ WP_Block_Supports::get_instance()->register( ) ); 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/wp-includes/default-filters.php b/wp-includes/default-filters.php index 20559dd179..182f94eddf 100644 --- a/wp-includes/default-filters.php +++ b/wp-includes/default-filters.php @@ -574,6 +574,10 @@ add_action( 'admin_head', 'wp_check_widget_editor_deps' ); 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/wp-includes/script-loader.php b/wp-includes/script-loader.php index 0957dce2d7..25615b77a9 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -2336,6 +2336,34 @@ 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() { + /* + * 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 = 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. diff --git a/wp-includes/version.php b/wp-includes/version.php index 40eac56cf9..2fed974688 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.0-alpha-52765'; +$wp_version = '6.0-alpha-52768'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.