Skip to content

Commit 1a410b0

Browse files
author
Felix Arntz
committed
Remove _inject_theme_attribute_in_template_part_block() and all its usage.
1 parent 0d6a8ca commit 1a410b0

File tree

5 files changed

+4
-117
lines changed

5 files changed

+4
-117
lines changed

src/wp-includes/block-template-utils.php

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -470,25 +470,6 @@ function _flatten_blocks( &$blocks ) {
470470
return $all_blocks;
471471
}
472472

473-
/**
474-
* Injects the active theme's stylesheet as a `theme` attribute
475-
* into a given template part block.
476-
*
477-
* @since 6.4.0
478-
* @access private
479-
*
480-
* @param array $block a parsed block.
481-
* @return void
482-
*/
483-
function _inject_theme_attribute_in_template_part_block( &$block ) {
484-
if (
485-
'core/template-part' === $block['blockName'] &&
486-
! isset( $block['attrs']['theme'] )
487-
) {
488-
$block['attrs']['theme'] = get_stylesheet();
489-
}
490-
}
491-
492473
/**
493474
* Removes the `theme` attribute from a given template part block.
494475
*
@@ -549,7 +530,7 @@ function _build_block_template_result_from_file( $template_file, $template_type
549530
$template->area = $template_file['area'];
550531
}
551532

552-
$before_block_visitor = '_inject_theme_attribute_in_template_part_block';
533+
$before_block_visitor = null;
553534
$after_block_visitor = null;
554535
$hooked_blocks = get_hooked_blocks();
555536
if ( ! empty( $hooked_blocks ) || has_filter( 'hooked_block_types' ) ) {

src/wp-includes/blocks.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -779,8 +779,6 @@ function make_before_block_visitor( $hooked_blocks, $context ) {
779779
* @return string The serialized markup for the given block, with the markup for any hooked blocks prepended to it.
780780
*/
781781
return function ( &$block, $parent_block = null, $prev = null ) use ( $hooked_blocks, $context ) {
782-
_inject_theme_attribute_in_template_part_block( $block );
783-
784782
$markup = '';
785783

786784
if ( $parent_block && ! $prev ) {

src/wp-includes/class-wp-block-patterns-registry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public function unregister( $pattern_name ) {
165165
private function prepare_content( $pattern, $hooked_blocks ) {
166166
$content = $pattern['content'];
167167

168-
$before_block_visitor = '_inject_theme_attribute_in_template_part_block';
168+
$before_block_visitor = null;
169169
$after_block_visitor = null;
170170
if ( ! empty( $hooked_blocks ) || has_filter( 'hooked_block_types' ) ) {
171171
$before_block_visitor = make_before_block_visitor( $hooked_blocks, $pattern );

src/wp-includes/deprecated.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6046,7 +6046,7 @@ function wp_img_tag_add_decoding_attr( $image, $context ) {
60466046
* stylesheet as a theme attribute into each wp_template_part
60476047
*
60486048
* @since 5.9.0
6049-
* @deprecated 6.4.0 Use traverse_and_serialize_blocks( parse_blocks( $template_content ), '_inject_theme_attribute_in_template_part_block' ) instead.
6049+
* @deprecated 6.4.0 Use traverse_and_serialize_blocks( parse_blocks( $template_content ) ) instead.
60506050
* @access private
60516051
*
60526052
* @param string $template_content serialized wp_template content.
@@ -6056,7 +6056,7 @@ function _inject_theme_attribute_in_block_template_content( $template_content )
60566056
_deprecated_function(
60576057
__FUNCTION__,
60586058
'6.4.0',
6059-
'traverse_and_serialize_blocks( parse_blocks( $template_content ), "_inject_theme_attribute_in_template_part_block" )'
6059+
'traverse_and_serialize_blocks( parse_blocks( $template_content ) )'
60606060
);
60616061

60626062
$has_updated_content = false;

tests/phpunit/tests/block-template-utils.php

Lines changed: 0 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -219,98 +219,6 @@ public function data_build_block_template_result_from_file_injects_theme_attribu
219219
);
220220
}
221221

222-
/**
223-
* @ticket 59338
224-
*
225-
* @covers ::_inject_theme_attribute_in_template_part_block
226-
*/
227-
public function test_inject_theme_attribute_in_template_part_block() {
228-
$template_part_block = array(
229-
'blockName' => 'core/template-part',
230-
'attrs' => array(
231-
'slug' => 'header',
232-
'align' => 'full',
233-
'tagName' => 'header',
234-
'className' => 'site-header',
235-
),
236-
'innerHTML' => '',
237-
'innerContent' => array(),
238-
'innerBlocks' => array(),
239-
);
240-
241-
_inject_theme_attribute_in_template_part_block( $template_part_block );
242-
$expected = array(
243-
'blockName' => 'core/template-part',
244-
'attrs' => array(
245-
'slug' => 'header',
246-
'align' => 'full',
247-
'tagName' => 'header',
248-
'className' => 'site-header',
249-
'theme' => get_stylesheet(),
250-
),
251-
'innerHTML' => '',
252-
'innerContent' => array(),
253-
'innerBlocks' => array(),
254-
);
255-
$this->assertSame(
256-
$expected,
257-
$template_part_block,
258-
'`theme` attribute was not correctly injected in template part block.'
259-
);
260-
}
261-
262-
/**
263-
* @ticket 59338
264-
*
265-
* @covers ::_inject_theme_attribute_in_template_part_block
266-
*/
267-
public function test_not_inject_theme_attribute_in_template_part_block_theme_attribute_exists() {
268-
$template_part_block = array(
269-
'blockName' => 'core/template-part',
270-
'attrs' => array(
271-
'slug' => 'header',
272-
'align' => 'full',
273-
'tagName' => 'header',
274-
'className' => 'site-header',
275-
'theme' => 'fake-theme',
276-
),
277-
'innerHTML' => '',
278-
'innerContent' => array(),
279-
'innerBlocks' => array(),
280-
);
281-
282-
$expected = $template_part_block;
283-
_inject_theme_attribute_in_template_part_block( $template_part_block );
284-
$this->assertSame(
285-
$expected,
286-
$template_part_block,
287-
'Existing `theme` attribute in template part block was not respected by attribute injection.'
288-
);
289-
}
290-
291-
/**
292-
* @ticket 59338
293-
*
294-
* @covers ::_inject_theme_attribute_in_template_part_block
295-
*/
296-
public function test_not_inject_theme_attribute_non_template_part_block() {
297-
$non_template_part_block = array(
298-
'blockName' => 'core/post-content',
299-
'attrs' => array(),
300-
'innerHTML' => '',
301-
'innerContent' => array(),
302-
'innerBlocks' => array(),
303-
);
304-
305-
$expected = $non_template_part_block;
306-
_inject_theme_attribute_in_template_part_block( $non_template_part_block );
307-
$this->assertSame(
308-
$expected,
309-
$non_template_part_block,
310-
'`theme` attribute injection modified non-template-part block.'
311-
);
312-
}
313-
314222
/**
315223
* @ticket 59452
316224
*

0 commit comments

Comments
 (0)