Patterns: Inject `theme` attribute into Template Part blocks.

[56805] introduced a regression: The `theme` attribute was no longer injected into Template Part blocks inside of patterns. This caused errors on the frontend, where instead of a given template part, an error message such as `Template part has been deleted or is unavailable: header` was seen.

This changeset rectifies that problem, and adds unit test coverage to guard against future regressions.

Follow-up to [56805].
Props scruffian, gziolo.
Fixes #59583.
Built from https://develop.svn.wordpress.org/trunk@56818


git-svn-id: http://core.svn.wordpress.org/trunk@56330 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Bernhard Reiter 2023-10-10 13:21:22 +00:00
parent eb9aaa5f9e
commit b44637c00c
2 changed files with 6 additions and 3 deletions

View File

@ -164,12 +164,15 @@ final class WP_Block_Patterns_Registry {
*/
private function prepare_content( $pattern, $hooked_blocks ) {
$content = $pattern['content'];
$before_block_visitor = '_inject_theme_attribute_in_template_part_block';
$after_block_visitor = null;
if ( ! empty( $hooked_blocks ) || has_filter( 'hooked_block_types' ) ) {
$blocks = parse_blocks( $content );
$before_block_visitor = make_before_block_visitor( $hooked_blocks, $pattern );
$after_block_visitor = make_after_block_visitor( $hooked_blocks, $pattern );
$content = traverse_and_serialize_blocks( $blocks, $before_block_visitor, $after_block_visitor );
}
$blocks = parse_blocks( $content );
$content = traverse_and_serialize_blocks( $blocks, $before_block_visitor, $after_block_visitor );
return $content;
}

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.4-beta2-56817';
$wp_version = '6.4-beta2-56818';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.