From cb3e78b0c3a49905d87f2d173740daad9f93452d Mon Sep 17 00:00:00 2001 From: jorgefilipecosta Date: Wed, 16 Feb 2022 22:20:01 +0000 Subject: [PATCH] Script Loader: Improvements to the load block support styles mechanism. This commit applies feedback given to commit 52741. It changes the new function name, the file where it is located, and improves its documentation and marks. Follow-up to [52741]. Props hellofromtonya, swissspidy, oandregal. See #55148. Built from https://develop.svn.wordpress.org/trunk@52743 git-svn-id: http://core.svn.wordpress.org/trunk@52332 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/block-supports/elements.php | 2 +- wp-includes/block-supports/layout.php | 2 +- wp-includes/blocks.php | 26 ----------------------- wp-includes/script-loader.php | 28 +++++++++++++++++++++++++ wp-includes/version.php | 2 +- 5 files changed, 31 insertions(+), 29 deletions(-) diff --git a/wp-includes/block-supports/elements.php b/wp-includes/block-supports/elements.php index 4f09591227..44a22424ae 100644 --- a/wp-includes/block-supports/elements.php +++ b/wp-includes/block-supports/elements.php @@ -68,7 +68,7 @@ function wp_render_elements_support( $block_content, $block ) { $content = substr_replace( $block_content, ' class="' . $class_name . '"', $first_element_offset + strlen( $first_element ) - 1, 0 ); } - wp_enqueue_block_support( $style ); + wp_enqueue_block_support_styles( $style ); return $content; } diff --git a/wp-includes/block-supports/layout.php b/wp-includes/block-supports/layout.php index e225a637ce..65e5910dec 100644 --- a/wp-includes/block-supports/layout.php +++ b/wp-includes/block-supports/layout.php @@ -175,7 +175,7 @@ function wp_render_layout_support_flag( $block_content, $block ) { 1 ); - wp_enqueue_block_support( $style ); + wp_enqueue_block_support_styles( $style ); return $content; } diff --git a/wp-includes/blocks.php b/wp-includes/blocks.php index ae1fc9bffe..cec2f36925 100644 --- a/wp-includes/blocks.php +++ b/wp-includes/blocks.php @@ -1332,29 +1332,3 @@ function _wp_multiple_block_styles( $metadata ) { return $metadata; } add_filter( 'block_type_metadata', '_wp_multiple_block_styles' ); - -/** - * This function takes care of adding inline styles - * in the proper place, depending on the theme in use. - * - * For block themes, it's loaded in the head. - * For classic ones, it's loaded in the body - * because the wp_head action (and wp_enqueue_scripts) - * happens before the render_block. - * - * See https://core.trac.wordpress.org/ticket/53494. - * - * @param string $style String containing the CSS styles to be added. - */ -function wp_enqueue_block_support( $style ) { - $action_hook_name = 'wp_footer'; - if ( wp_is_block_theme() ) { - $action_hook_name = 'wp_enqueue_scripts'; - } - add_action( - $action_hook_name, - function () use ( $style ) { - echo "\n"; - } - ); -} diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index a18cc78e2c..824748b17b 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -2883,3 +2883,31 @@ function wp_enqueue_global_styles_css_custom_properties() { wp_add_inline_style( 'global-styles-css-custom-properties', wp_get_global_stylesheet( array( 'variables' ) ) ); wp_enqueue_style( 'global-styles-css-custom-properties' ); } + +/** + * This function takes care of adding inline styles + * in the proper place, depending on the theme in use. + * + * @since 5.9.1 + * + * For block themes, it's loaded in the head. + * For classic ones, it's loaded in the body + * because the wp_head action (and wp_enqueue_scripts) + * happens before the render_block. + * + * @link https://core.trac.wordpress.org/ticket/53494. + * + * @param string $style String containing the CSS styles to be added. + */ +function wp_enqueue_block_support_styles( $style ) { + $action_hook_name = 'wp_footer'; + if ( wp_is_block_theme() ) { + $action_hook_name = 'wp_enqueue_scripts'; + } + add_action( + $action_hook_name, + static function () use ( $style ) { + echo "\n"; + } + ); +} diff --git a/wp-includes/version.php b/wp-includes/version.php index 6261680483..23d0b2f587 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.0-alpha-52742'; +$wp_version = '6.0-alpha-52743'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.