Skip to content

Commit

Permalink
Template Part block: Fall back to current theme if no theme attribute…
Browse files Browse the repository at this point in the history
… is given. (#55217)

* Template Part block: Fall back to current theme if no theme attribute is given.
* Remove now unnecessary _inject_theme_attribute_in_template_part_block() call from pattern block.

---------

Co-authored-by: Greg Ziółkowski <[email protected]>
Co-authored-by: Felix Arntz <[email protected]>
Co-authored-by: Felix Arntz <[email protected]>
  • Loading branch information
4 people authored Oct 12, 2023
1 parent 1e58f72 commit 1e0c9c6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
1 change: 0 additions & 1 deletion packages/block-library/src/pattern/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down
11 changes: 4 additions & 7 deletions packages/block-library/src/template-part/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,10 @@ function render_block_core_template_part( $attributes ) {
$template_part_id = null;
$content = null;
$area = WP_TEMPLATE_PART_AREA_UNCATEGORIZED;
$theme = isset( $attributes['theme'] ) ? $attributes['theme'] : get_stylesheet();

if (
isset( $attributes['slug'] ) &&
isset( $attributes['theme'] ) &&
get_stylesheet() === $attributes['theme']
) {
$template_part_id = $attributes['theme'] . '//' . $attributes['slug'];
if ( isset( $attributes['slug'] ) && get_stylesheet() === $theme ) {
$template_part_id = $theme . '//' . $attributes['slug'];
$template_part_query = new WP_Query(
array(
'post_type' => 'wp_template_part',
Expand All @@ -34,7 +31,7 @@ function render_block_core_template_part( $attributes ) {
array(
'taxonomy' => 'wp_theme',
'field' => 'name',
'terms' => $attributes['theme'],
'terms' => $theme,
),
),
'posts_per_page' => 1,
Expand Down

1 comment on commit 1e0c9c6

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 1e0c9c6.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/6493743827
📝 Reported issues:

Please sign in to comment.