Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wp_template renaming when hooked_block_types filter exists #6955

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/wp-includes/block-template-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -1602,6 +1602,10 @@ function inject_ignored_hooked_blocks_metadata_attributes( $changes, $deprecated
_deprecated_argument( __FUNCTION__, '6.5.3' );
}

if ( ! isset( $changes->post_content ) ) {
return $changes;
}

$hooked_blocks = get_hooked_blocks();
if ( empty( $hooked_blocks ) && ! has_filter( 'hooked_block_types' ) ) {
return $changes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -621,4 +621,59 @@ public function test_inject_ignored_hooked_blocks_metadata_attributes_into_templ
'The template part\'s post content was modified.'
);
}

/**
* @ticket 61550
*/
public function test_inject_ignored_hooked_blocks_metadata_attributes_into_template_with_no_changes_to_post_content() {
register_block_type(
'tests/hooked-block',
array(
'block_hooks' => array(
'core/heading' => 'after',
),
)
);

$id = self::TEST_THEME . '//' . 'my_template';
$template = get_block_template( $id, 'wp_template' );

$changes = new stdClass();
$changes->ID = $template->wp_id;

// Note that we're not setting `$changes->post_content`!

$post = inject_ignored_hooked_blocks_metadata_attributes( $changes );
$this->assertFalse(
isset( $post->post_content ),
"post_content shouldn't have been set."
);
}

/**
* @ticket 61550
*/
public function test_inject_ignored_hooked_blocks_metadata_attributes_into_template_part_with_no_changes_to_post_content() {
register_block_type(
'tests/hooked-block',
array(
'block_hooks' => array(
'core/heading' => 'after',
),
)
);

$id = self::TEST_THEME . '//' . 'my_template_part';
$template = get_block_template( $id, 'wp_template_part' );

$changes = new stdClass();
$changes->ID = $template->wp_id;
// Note that we're not setting `$changes->post_content`!

$post = inject_ignored_hooked_blocks_metadata_attributes( $changes );
$this->assertFalse(
isset( $post->post_content ),
"post_content shouldn't have been set."
);
}
}
Loading