diff --git a/wp-includes/block-template-utils.php b/wp-includes/block-template-utils.php index 065cfcc037..98c151048a 100644 --- a/wp-includes/block-template-utils.php +++ b/wp-includes/block-template-utils.php @@ -490,36 +490,21 @@ function _inject_theme_attribute_in_template_part_block( &$block ) { } /** - * Parses a block template and removes the theme attribute from each template part. + * Removes the `theme` attribute from a given template part block. * - * @since 5.9.0 + * @since 6.4.0 * @access private * - * @param string $template_content Serialized block template content. - * @return string Updated block template content. + * @param array $block a parsed block. + * @return void */ -function _remove_theme_attribute_in_block_template_content( $template_content ) { - $has_updated_content = false; - $new_content = ''; - $template_blocks = parse_blocks( $template_content ); - - $blocks = _flatten_blocks( $template_blocks ); - foreach ( $blocks as $key => $block ) { - if ( 'core/template-part' === $block['blockName'] && isset( $block['attrs']['theme'] ) ) { - unset( $blocks[ $key ]['attrs']['theme'] ); - $has_updated_content = true; - } +function _remove_theme_attribute_from_template_part_block( &$block ) { + if ( + 'core/template-part' === $block['blockName'] && + isset( $block['attrs']['theme'] ) + ) { + unset( $block['attrs']['theme'] ); } - - if ( ! $has_updated_content ) { - return $template_content; - } - - foreach ( $template_blocks as $block ) { - $new_content .= serialize_block( $block ); - } - - return $new_content; } /** @@ -1278,7 +1263,10 @@ function wp_generate_block_templates_export_file() { // Load templates into the zip file. $templates = get_block_templates(); foreach ( $templates as $template ) { - $template->content = _remove_theme_attribute_in_block_template_content( $template->content ); + $template->content = traverse_and_serialize_blocks( + parse_blocks( $template->content ), + '_remove_theme_attribute_from_template_part_block' + ); $zip->addFromString( 'templates/' . $template->slug . '.html', diff --git a/wp-includes/deprecated.php b/wp-includes/deprecated.php index 0375d69b4f..9f8981d663 100644 --- a/wp-includes/deprecated.php +++ b/wp-includes/deprecated.php @@ -6084,3 +6084,43 @@ function _inject_theme_attribute_in_block_template_content( $template_content ) return $template_content; } + +/** + * Parses a block template and removes the theme attribute from each template part. + * + * @since 5.9.0 + * @deprecated 6.4.0 Use traverse_and_serialize_blocks( parse_blocks( $template_content ), '_remove_theme_attribute_from_template_part_block' ) instead. + * @access private + * + * @param string $template_content Serialized block template content. + * @return string Updated block template content. + */ +function _remove_theme_attribute_in_block_template_content( $template_content ) { + _deprecated_function( + __FUNCTION__, + '6.4.0', + 'traverse_and_serialize_blocks( parse_blocks( $template_content ), "_remove_theme_attribute_from_template_part_block" )' + ); + + $has_updated_content = false; + $new_content = ''; + $template_blocks = parse_blocks( $template_content ); + + $blocks = _flatten_blocks( $template_blocks ); + foreach ( $blocks as $key => $block ) { + if ( 'core/template-part' === $block['blockName'] && isset( $block['attrs']['theme'] ) ) { + unset( $blocks[ $key ]['attrs']['theme'] ); + $has_updated_content = true; + } + } + + if ( ! $has_updated_content ) { + return $template_content; + } + + foreach ( $template_blocks as $block ) { + $new_content .= serialize_block( $block ); + } + + return $new_content; +} diff --git a/wp-includes/version.php b/wp-includes/version.php index 50fda38303..f48a34c423 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.4-alpha-56723'; +$wp_version = '6.4-alpha-56724'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.