From 1a410b01badbd383a2a455ef9238cc491d3a3a20 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Wed, 11 Oct 2023 10:45:54 -0500 Subject: [PATCH] Remove _inject_theme_attribute_in_template_part_block() and all its usage. --- src/wp-includes/block-template-utils.php | 21 +---- src/wp-includes/blocks.php | 2 - .../class-wp-block-patterns-registry.php | 2 +- src/wp-includes/deprecated.php | 4 +- tests/phpunit/tests/block-template-utils.php | 92 ------------------- 5 files changed, 4 insertions(+), 117 deletions(-) diff --git a/src/wp-includes/block-template-utils.php b/src/wp-includes/block-template-utils.php index c5953e1d4ce2c..c4d78a0b174fe 100644 --- a/src/wp-includes/block-template-utils.php +++ b/src/wp-includes/block-template-utils.php @@ -470,25 +470,6 @@ function _flatten_blocks( &$blocks ) { return $all_blocks; } -/** - * Injects the active theme's stylesheet as a `theme` attribute - * into a given template part block. - * - * @since 6.4.0 - * @access private - * - * @param array $block a parsed block. - * @return void - */ -function _inject_theme_attribute_in_template_part_block( &$block ) { - if ( - 'core/template-part' === $block['blockName'] && - ! isset( $block['attrs']['theme'] ) - ) { - $block['attrs']['theme'] = get_stylesheet(); - } -} - /** * Removes the `theme` attribute from a given template part block. * @@ -549,7 +530,7 @@ function _build_block_template_result_from_file( $template_file, $template_type $template->area = $template_file['area']; } - $before_block_visitor = '_inject_theme_attribute_in_template_part_block'; + $before_block_visitor = null; $after_block_visitor = null; $hooked_blocks = get_hooked_blocks(); if ( ! empty( $hooked_blocks ) || has_filter( 'hooked_block_types' ) ) { diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index 00d9fdae3e26e..26c3e8685c4ee 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -779,8 +779,6 @@ function make_before_block_visitor( $hooked_blocks, $context ) { * @return string The serialized markup for the given block, with the markup for any hooked blocks prepended to it. */ return function ( &$block, $parent_block = null, $prev = null ) use ( $hooked_blocks, $context ) { - _inject_theme_attribute_in_template_part_block( $block ); - $markup = ''; if ( $parent_block && ! $prev ) { diff --git a/src/wp-includes/class-wp-block-patterns-registry.php b/src/wp-includes/class-wp-block-patterns-registry.php index 6be81e1e2cd34..cf2d7ce16dd08 100644 --- a/src/wp-includes/class-wp-block-patterns-registry.php +++ b/src/wp-includes/class-wp-block-patterns-registry.php @@ -165,7 +165,7 @@ public function unregister( $pattern_name ) { private function prepare_content( $pattern, $hooked_blocks ) { $content = $pattern['content']; - $before_block_visitor = '_inject_theme_attribute_in_template_part_block'; + $before_block_visitor = null; $after_block_visitor = null; if ( ! empty( $hooked_blocks ) || has_filter( 'hooked_block_types' ) ) { $before_block_visitor = make_before_block_visitor( $hooked_blocks, $pattern ); diff --git a/src/wp-includes/deprecated.php b/src/wp-includes/deprecated.php index 51d7490c87c25..a9fb2e852f5b4 100644 --- a/src/wp-includes/deprecated.php +++ b/src/wp-includes/deprecated.php @@ -6046,7 +6046,7 @@ function wp_img_tag_add_decoding_attr( $image, $context ) { * 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. + * @deprecated 6.4.0 Use traverse_and_serialize_blocks( parse_blocks( $template_content ) ) instead. * @access private * * @param string $template_content serialized wp_template content. @@ -6056,7 +6056,7 @@ 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" )' + 'traverse_and_serialize_blocks( parse_blocks( $template_content ) )' ); $has_updated_content = false; diff --git a/tests/phpunit/tests/block-template-utils.php b/tests/phpunit/tests/block-template-utils.php index b06e931529f1e..1b85296fc2924 100644 --- a/tests/phpunit/tests/block-template-utils.php +++ b/tests/phpunit/tests/block-template-utils.php @@ -219,98 +219,6 @@ public function data_build_block_template_result_from_file_injects_theme_attribu ); } - /** - * @ticket 59338 - * - * @covers ::_inject_theme_attribute_in_template_part_block - */ - public function test_inject_theme_attribute_in_template_part_block() { - $template_part_block = array( - 'blockName' => 'core/template-part', - 'attrs' => array( - 'slug' => 'header', - 'align' => 'full', - 'tagName' => 'header', - 'className' => 'site-header', - ), - 'innerHTML' => '', - 'innerContent' => array(), - 'innerBlocks' => array(), - ); - - _inject_theme_attribute_in_template_part_block( $template_part_block ); - $expected = array( - 'blockName' => 'core/template-part', - 'attrs' => array( - 'slug' => 'header', - 'align' => 'full', - 'tagName' => 'header', - 'className' => 'site-header', - 'theme' => get_stylesheet(), - ), - 'innerHTML' => '', - 'innerContent' => array(), - 'innerBlocks' => array(), - ); - $this->assertSame( - $expected, - $template_part_block, - '`theme` attribute was not correctly injected in template part block.' - ); - } - - /** - * @ticket 59338 - * - * @covers ::_inject_theme_attribute_in_template_part_block - */ - public function test_not_inject_theme_attribute_in_template_part_block_theme_attribute_exists() { - $template_part_block = array( - 'blockName' => 'core/template-part', - 'attrs' => array( - 'slug' => 'header', - 'align' => 'full', - 'tagName' => 'header', - 'className' => 'site-header', - 'theme' => 'fake-theme', - ), - 'innerHTML' => '', - 'innerContent' => array(), - 'innerBlocks' => array(), - ); - - $expected = $template_part_block; - _inject_theme_attribute_in_template_part_block( $template_part_block ); - $this->assertSame( - $expected, - $template_part_block, - 'Existing `theme` attribute in template part block was not respected by attribute injection.' - ); - } - - /** - * @ticket 59338 - * - * @covers ::_inject_theme_attribute_in_template_part_block - */ - public function test_not_inject_theme_attribute_non_template_part_block() { - $non_template_part_block = array( - 'blockName' => 'core/post-content', - 'attrs' => array(), - 'innerHTML' => '', - 'innerContent' => array(), - 'innerBlocks' => array(), - ); - - $expected = $non_template_part_block; - _inject_theme_attribute_in_template_part_block( $non_template_part_block ); - $this->assertSame( - $expected, - $non_template_part_block, - '`theme` attribute injection modified non-template-part block.' - ); - } - /** * @ticket 59452 *