From 8fa1ff8b8e8f827044770c9c6fb3c52ad06f3269 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Tue, 10 Oct 2023 20:34:04 +0200 Subject: [PATCH 1/4] Template Part block: Fall back to current theme if no theme attribute is given. --- .../block-library/src/template-part/index.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/block-library/src/template-part/index.php b/packages/block-library/src/template-part/index.php index a7bd4033affc34..21a904ab8a691b 100644 --- a/packages/block-library/src/template-part/index.php +++ b/packages/block-library/src/template-part/index.php @@ -19,12 +19,14 @@ function render_block_core_template_part( $attributes ) { $content = null; $area = WP_TEMPLATE_PART_AREA_UNCATEGORIZED; - if ( - isset( $attributes['slug'] ) && - isset( $attributes['theme'] ) && - get_stylesheet() === $attributes['theme'] - ) { - $template_part_id = $attributes['theme'] . '//' . $attributes['slug']; + if ( isset( $attribues['theme'] ) ) { + $theme = $attributes['theme']; + } else { + $theme = get_stylesheet(); + } + + if ( isset( $attributes['slug'] ) ) { + $template_part_id = $theme . '//' . $attributes['slug']; $template_part_query = new WP_Query( array( 'post_type' => 'wp_template_part', @@ -34,7 +36,7 @@ function render_block_core_template_part( $attributes ) { array( 'taxonomy' => 'wp_theme', 'field' => 'name', - 'terms' => $attributes['theme'], + 'terms' => $theme, ), ), 'posts_per_page' => 1, From f9d9d35dde56778b0b710e2c51eb89dd69960b64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Zi=C3=B3=C5=82kowski?= Date: Wed, 11 Oct 2023 08:37:32 +0200 Subject: [PATCH 2/4] Update packages/block-library/src/template-part/index.php Co-authored-by: Felix Arntz --- packages/block-library/src/template-part/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-library/src/template-part/index.php b/packages/block-library/src/template-part/index.php index 21a904ab8a691b..e398e196a7c5dd 100644 --- a/packages/block-library/src/template-part/index.php +++ b/packages/block-library/src/template-part/index.php @@ -25,7 +25,7 @@ function render_block_core_template_part( $attributes ) { $theme = get_stylesheet(); } - if ( isset( $attributes['slug'] ) ) { + if ( isset( $attributes['slug'] ) && get_stylesheet() === $theme ) { $template_part_id = $theme . '//' . $attributes['slug']; $template_part_query = new WP_Query( array( From 06af1954236e2a8e918dde411b69fe7c7281e47a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Zi=C3=B3=C5=82kowski?= Date: Wed, 11 Oct 2023 08:40:39 +0200 Subject: [PATCH 3/4] Fix the type in the variable name --- packages/block-library/src/template-part/index.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/packages/block-library/src/template-part/index.php b/packages/block-library/src/template-part/index.php index e398e196a7c5dd..3ad400906945b8 100644 --- a/packages/block-library/src/template-part/index.php +++ b/packages/block-library/src/template-part/index.php @@ -18,12 +18,7 @@ function render_block_core_template_part( $attributes ) { $template_part_id = null; $content = null; $area = WP_TEMPLATE_PART_AREA_UNCATEGORIZED; - - if ( isset( $attribues['theme'] ) ) { - $theme = $attributes['theme']; - } else { - $theme = get_stylesheet(); - } + $theme = isset( $attributes['theme'] ) ? $attributes['theme'] : get_stylesheet(); if ( isset( $attributes['slug'] ) && get_stylesheet() === $theme ) { $template_part_id = $theme . '//' . $attributes['slug']; From 47608ff7a68aa60d3ed878314a0d57e8d93e8a27 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Wed, 11 Oct 2023 10:36:50 -0500 Subject: [PATCH 4/4] Remove now unnecessary _inject_theme_attribute_in_template_part_block() call from pattern block. --- packages/block-library/src/pattern/index.php | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/block-library/src/pattern/index.php b/packages/block-library/src/pattern/index.php index 1f5477968b92d1..f05bb333bd186d 100644 --- a/packages/block-library/src/pattern/index.php +++ b/packages/block-library/src/pattern/index.php @@ -44,7 +44,6 @@ function render_block_core_pattern( $attributes ) { // Backward compatibility for handling Block Hooks and injecting the theme attribute in the Gutenberg plugin. // This can be removed when the minimum supported WordPress is >= 6.4. if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN && ! function_exists( 'traverse_and_serialize_blocks' ) ) { - $content = _inject_theme_attribute_in_block_template_content( $content ); $blocks = parse_blocks( $content ); $content = gutenberg_serialize_blocks( $blocks ); }