diff --git a/lib/block-supports/elements.php b/lib/block-supports/elements.php index 711631a63b6612..1c8b507c494955 100644 --- a/lib/block-supports/elements.php +++ b/lib/block-supports/elements.php @@ -65,7 +65,7 @@ function gutenberg_render_elements_support( $block_content, $block ) { $content = substr_replace( $block_content, ' class="' . $class_name . '"', $first_element_offset + strlen( $first_element ) - 1, 0 ); } - gutenberg_enqueue_block_support( $style ); + gutenberg_enqueue_block_support_styles( $style ); return $content; } diff --git a/lib/block-supports/layout.php b/lib/block-supports/layout.php index 93c530f5814ff5..8413627207996c 100644 --- a/lib/block-supports/layout.php +++ b/lib/block-supports/layout.php @@ -166,7 +166,7 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) { 1 ); - gutenberg_enqueue_block_support( $style ); + gutenberg_enqueue_block_support_styles( $style ); return $content; } diff --git a/lib/blocks.php b/lib/blocks.php index a9289f1cd9616a..8a61b1ff8a4a48 100644 --- a/lib/blocks.php +++ b/lib/blocks.php @@ -590,29 +590,3 @@ function gutenberg_multiple_block_styles( $metadata ) { return $metadata; } add_filter( 'block_type_metadata', 'gutenberg_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 gutenberg_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/lib/compat/wordpress-5.9/script-loader.php b/lib/compat/wordpress-5.9/script-loader.php index aea22756725988..36f44f41c4a921 100644 --- a/lib/compat/wordpress-5.9/script-loader.php +++ b/lib/compat/wordpress-5.9/script-loader.php @@ -46,3 +46,29 @@ function gutenberg_enqueue_global_styles_assets() { } add_action( 'wp_enqueue_scripts', 'gutenberg_enqueue_global_styles_assets' ); add_action( 'wp_footer', 'gutenberg_enqueue_global_styles_assets' ); + +/** + * 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. + * + * @link https://core.trac.wordpress.org/ticket/53494. + * + * @param string $style String containing the CSS styles to be added. + */ +function gutenberg_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"; + } + ); +}