-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Navigation block: Use apply_block_hooks_to_content()
#65703
Navigation block: Use apply_block_hooks_to_content()
#65703
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
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.
I went through the test instructions in #57754
✅ The hooked_block_types
PHP filter works as expected, including switching positions
✅ blockHooks
in block.json also works as expected, including switching positions
The injected blocks only appear once
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.
Thanks for the PR 👍
This tests as advertised for me:
✅ Login/Logout appears as inner block of core navigation block
✅ Block is only added once
✅ Block appears when editing header template part
✅ Custom positioning of block works and is persisted
✅ Removal of block works
✅ When using blockHooks
in block.json, the same behaviour occurs
LGTM 🚢
* Navigation block: Use apply-block-hooks-to-content * WPCS Co-authored-by: ockham <[email protected]> Co-authored-by: ramonjd <[email protected]> Co-authored-by: aaronrobertshaw <[email protected]>
I just cherry-picked this PR to the wp/6.7 branch to get it included in the next release: e2f2dce |
Thank you very much, @ramonjd and @aaronrobertshaw! |
and @noisysocks 🙂 |
* Navigation block: Use apply-block-hooks-to-content * WPCS Co-authored-by: ockham <[email protected]> Co-authored-by: ramonjd <[email protected]> Co-authored-by: aaronrobertshaw <[email protected]>
…ress#65703)" This reverts commit 78dc0d4.
What?
In the Navigation block, use
apply_block_hooks_to_content
(introduced in WP 6.6), if available.Why?
This is part of a centralization effort, i.e. to make
apply_block_hooks_to_content
the canonical entrypoint for applying the Block Hooks logic to a given piece of block markup. The same change has already been applied to the relevant call sites of Block Hooks logic in Core, see WordPress/wordpress-develop#7220.This is particularly relevant for WordPress/wordpress-develop#7443, which will ensure that
apply_block_hooks_to_content
respects a hooked block's"multiple": false
setting. In other words, the present PR is required to make sure that a hooked block isn't inserted more than once into a Navigation menu if it has"multiple": false
set.How?
By checking if
apply_block_hooks_to_content
exists, and if it does, by invoking it instead of the more indirect sequence ofmake_before_block_visitor
/make_after_block_visitor
, followed bytraverse_and_serialize_block
.Testing Instructions
Verify that hooked blocks insertion into the Navigation menu works as before. For more detailed testing instructions, refer to #57754.