From 82b7269f9abdb91b22847dc0739dffe62f2836eb Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Tue, 26 Sep 2023 18:32:22 +0200 Subject: [PATCH] Templates: Move old theme attr injection function to deprecated.php --- src/wp-includes/block-template-utils.php | 44 ------------------------ src/wp-includes/deprecated.php | 44 ++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 44 deletions(-) diff --git a/src/wp-includes/block-template-utils.php b/src/wp-includes/block-template-utils.php index bc69c153d736d..065cfcc037fb0 100644 --- a/src/wp-includes/block-template-utils.php +++ b/src/wp-includes/block-template-utils.php @@ -470,50 +470,6 @@ function _flatten_blocks( &$blocks ) { return $all_blocks; } -/** - * Parses wp_template content and injects the active theme's - * stylesheet as a theme attribute into each wp_template_part - * - * @since 5.9.0 - * @deprecated 6.4.0 Use traverse_and_serialize_blocks( parse_blocks( $template_content ), '_inject_theme_attribute_in_template_part_block' ) instead. - * @access private - * - * @param string $template_content serialized wp_template content. - * @return string Updated 'wp_template' content. - */ -function _inject_theme_attribute_in_block_template_content( $template_content ) { - _deprecated_function( - __FUNCTION__, - '6.4.0', - 'traverse_and_serialize_blocks( parse_blocks( $template_content ), "_inject_theme_attribute_in_template_part_block" )' - ); - - $has_updated_content = false; - $new_content = ''; - $template_blocks = parse_blocks( $template_content ); - - $blocks = _flatten_blocks( $template_blocks ); - foreach ( $blocks as &$block ) { - if ( - 'core/template-part' === $block['blockName'] && - ! isset( $block['attrs']['theme'] ) - ) { - $block['attrs']['theme'] = get_stylesheet(); - $has_updated_content = true; - } - } - - if ( $has_updated_content ) { - foreach ( $template_blocks as &$block ) { - $new_content .= serialize_block( $block ); - } - - return $new_content; - } - - return $template_content; -} - /** * Injects the active theme's stylesheet as a `theme` attribute * into a given template part block. diff --git a/src/wp-includes/deprecated.php b/src/wp-includes/deprecated.php index 4cde85f42ab57..0375d69b4f863 100644 --- a/src/wp-includes/deprecated.php +++ b/src/wp-includes/deprecated.php @@ -6040,3 +6040,47 @@ function wp_img_tag_add_decoding_attr( $image, $context ) { return $image; } + +/** + * Parses wp_template content and injects the active theme's + * stylesheet as a theme attribute into each wp_template_part + * + * @since 5.9.0 + * @deprecated 6.4.0 Use traverse_and_serialize_blocks( parse_blocks( $template_content ), '_inject_theme_attribute_in_template_part_block' ) instead. + * @access private + * + * @param string $template_content serialized wp_template content. + * @return string Updated 'wp_template' content. + */ +function _inject_theme_attribute_in_block_template_content( $template_content ) { + _deprecated_function( + __FUNCTION__, + '6.4.0', + 'traverse_and_serialize_blocks( parse_blocks( $template_content ), "_inject_theme_attribute_in_template_part_block" )' + ); + + $has_updated_content = false; + $new_content = ''; + $template_blocks = parse_blocks( $template_content ); + + $blocks = _flatten_blocks( $template_blocks ); + foreach ( $blocks as &$block ) { + if ( + 'core/template-part' === $block['blockName'] && + ! isset( $block['attrs']['theme'] ) + ) { + $block['attrs']['theme'] = get_stylesheet(); + $has_updated_content = true; + } + } + + if ( $has_updated_content ) { + foreach ( $template_blocks as &$block ) { + $new_content .= serialize_block( $block ); + } + + return $new_content; + } + + return $template_content; +}