-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN:
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thank you very much for the fix!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies, I might've spoken too soon 😅
I remembered to look at the comment for this PR that fixed the same issue for wp_navigation
post types.
Note this comment on using isset
vs empty
:
empty()
is bad, because it would miss the cases where thepost_content
is legitimately changed to an empty string.isset()
is better.
Specifically, per #6867, we could hit an edge case where a hooked block would be injected as the first or last child of an (otherwise empty) Template Part block. If we use empty()
, this isn't going to work.
We should probably add some test coverage in tests/phpunit/tests/block-templates/injectIgnoredHookedBlocksMetadataAttributes.php
to cover the case where $changes->post_content
isn't set (to make sure that https://core.trac.wordpress.org/ticket/61550 is fixed), and another test to cover the case I described in the previous paragraph.
(I can take care of those things next week if you don't have time. Unfortunately, this will mean the fix won't make it into 6.6.1 and will have to wait for 6.6.2 instead.)
Oooh great catch! How about |
So the only difference between It's also more consistent with what we're doing with |
Hi @ockham! Thanks for addressing your feedback. I was working on it at the same time and only realized because I couldn't push. Here's my take on the test in case it helps /**
* @ticket 61550
*/
public function test_hooked_block_types_filter_with_renamed_template_part() {
$action = new MockAction();
add_filter( 'hooked_block_types', array( $action, 'filter' ), 10, 4 );
$changes = new stdClass();
$changes->ID = 1;
$changes->post_type = 'wp_template_part';
$changes->post_title = 'new title';
$cloned_changes = unserialize( serialize( $changes ) );
$result = inject_ignored_hooked_blocks_metadata_attributes( $changes );
// Ensure same reference.
$this->assertSame(
$changes,
$result,
'Should leave the changes object untouched if `post_content` is not set.'
);
// Ensure same values.
$this->assertTrue(
$result == $cloned_changes, // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual -- == compares all props and their values.
'Should leave the changes object untouched if `post_content` is not set.'
);
$changes = new stdClass();
$changes->ID = 1;
$changes->post_type = 'wp_template_part';
$changes->post_title = 'new title';
$changes->post_content = 'new content';
$cloned_changes = unserialize( serialize( $changes ) );
$result = inject_ignored_hooked_blocks_metadata_attributes( $changes );
$this->assertNotSame(
$changes,
$result,
'Should process the changes object if `post_content` is set.'
);
$changes = new stdClass();
$changes->ID = 1;
$changes->post_type = 'wp_template_part';
$changes->post_title = 'new title';
$changes->post_content = '';
$cloned_changes = unserialize( serialize( $changes ) );
$result = inject_ignored_hooked_blocks_metadata_attributes( $changes );
$this->assertNotSame(
$changes,
$result,
'Should process the changes object if `post_content` is set to an empty string.'
);
} |
Oh no, I should've posted a comment to let you know! Apologies, I didn't mean to make you duplicate work. Anyway, thank you for sharing your patch! I'll have a look if there's anything to incorporate into the tests and will probably land the PR later today 😊 |
Committed to Core in https://core.trac.wordpress.org/changeset/58785. |
Backported to the 6.6 branch in https://core.trac.wordpress.org/changeset/58802. |
The ticket explains the problem.
Trac ticket: https://core.trac.wordpress.org/ticket/61550
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.