Skip to content

Commit

Permalink
Remove _inject_theme_attribute_in_template_part_block() and all its u…
Browse files Browse the repository at this point in the history
…sage.
  • Loading branch information
felixarntz committed Oct 11, 2023
1 parent 0d6a8ca commit 1a410b0
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 117 deletions.
21 changes: 1 addition & 20 deletions src/wp-includes/block-template-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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' ) ) {
Expand Down
2 changes: 0 additions & 2 deletions src/wp-includes/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
2 changes: 1 addition & 1 deletion src/wp-includes/class-wp-block-patterns-registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
4 changes: 2 additions & 2 deletions src/wp-includes/deprecated.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
Expand Down
92 changes: 0 additions & 92 deletions tests/phpunit/tests/block-template-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down

0 comments on commit 1a410b0

Please sign in to comment.