From 6f0000205cee02cb9ab0e8f14873d07a5fb0a7ce Mon Sep 17 00:00:00 2001 From: Matias Benedetto Date: Thu, 16 Feb 2023 17:45:59 +0700 Subject: [PATCH] Fix the template parts included in patterns --- admin/class-create-block-theme-admin.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/admin/class-create-block-theme-admin.php b/admin/class-create-block-theme-admin.php index 49dc7835..dcc0e1ff 100644 --- a/admin/class-create-block-theme-admin.php +++ b/admin/class-create-block-theme-admin.php @@ -703,6 +703,16 @@ function make_mediatext_block_local ( $block ) { return $block; } + function add_theme_attr_to_template_part_block ( $block ) { + // The template parts included in the patterns need to indicate the theme they belong to + if ( 'core/template-part' === $block[ 'blockName' ] ) { + $block['attrs']['theme'] = ( $_POST['theme']['type'] === "export" || $_POST['theme']['type'] === "save" ) + ? get_stylesheet() + : $_POST['theme']['name']; + } + return $block; + } + function make_media_blocks_local ( $nested_blocks ) { $new_blocks = []; foreach ( $nested_blocks as $block ) { @@ -718,6 +728,9 @@ function make_media_blocks_local ( $nested_blocks ) { case 'core/media-text': $block = $this->make_mediatext_block_local( $block ); break; + case 'core/template-part': + $block = $this->add_theme_attr_to_template_part_block( $block ); + break; } // recursive call for inner blocks if ( !empty ( $block['innerBlocks'] ) ) {