-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Block Hooks: Use apply_block_hooks_to_content
in Patterns and Templates
#7220
Block Hooks: Use apply_block_hooks_to_content
in Patterns and Templates
#7220
Conversation
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. |
apply_block_hooks_to_content
apply_block_hooks_to_content
in Patterns and Templates
f41d44a
to
b901657
Compare
b901657
to
1604b38
Compare
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. |
I have opened this for review, as it's going to be a prerequisite for #7296 (to which I'll push some commits shortly that will implement the required change inside of I haven't yet added dedicated unit test coverage for
|
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.
These changes make sense, it seems to be mostly shifting some code around so that apply_glock_hooks_to_content
is used more consistently.
I'm not especially well versed in templates or block hooks, so if there's additional testing I can do I'd be happy to.
Thank you very much for reviewing and approving!
I just did a bunch of smoke-testing and I'm confident enough to merge this, but thank you for offering! FWIW, I typically use my own Like Button block plugin to test (which has code to use Block Hooks to automatically insert it after the Post Content block), or something like the following to inject the Login/out block into the Navigation menu. I then check if hooked blocks are inserted both on the frontend and in the editor, and move them around in the editor to see if those changes are respected on the frontend. function register_logout_block_as_navigation_last_child( $hooked_blocks, $position, $anchor_block, $context ) {
if ( $anchor_block === 'core/navigation' && $position === 'last_child' ) {
$hooked_blocks[] = 'core/loginout';
}
return $hooked_blocks;
}
add_filter( 'hooked_block_types', 'register_logout_block_as_navigation_last_child', 10, 4 ); |
Committed to Core in https://core.trac.wordpress.org/changeset/59101. |
There's one more instance where we should call |
In the Patterns registry, use
apply_block_hooks_to_content
instead of theWP_Block_Patterns_Registry
class's privateget_content
method. (The latter is removed at part of this PR.)In a similar vein, use
apply_block_hooks_to_content
in the_build_block_template_result_from_file
and_build_block_template_result_from_post
functions, respectively.For that to work,
apply_block_hooks_to_content
is amended to inject thetheme
attribute into Template Part blocks, even if no hooked blocks are present.This kind of centralization is required as a preparation for https://core.trac.wordpress.org/ticket/61902.
Trac ticket: https://core.trac.wordpress.org/ticket/61902.
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.