-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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: Allow passing block definitions to hooked_block_types
filter (and thus, hooking patterns)
#5837
Block Hooks: Allow passing block definitions to hooked_block_types
filter (and thus, hooking patterns)
#5837
Conversation
hooked_block_types
filterhooked_block_types
filter (and thus, hooking patterns)
FYI @andrewserong @tellthemachines @yansern @TimBroddin |
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. |
* @param string $anchor_block_type The anchor block type. | ||
* @param WP_Block_Template|array $context The block template, template part, or pattern that the anchor block belongs to. | ||
*/ | ||
$hooked_block_types = apply_filters( 'hooked_block_types', $hooked_block_types, $relative_position, $anchor_block_type, $context ); |
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.
@gziolo had another suggestion:
$hooked_block_types = apply_filters( 'hooked_block_types', $hooked_block_types, $relative_position, $anchor_block_type, $context ); | |
$hooked_block_types = apply_filters( "hooked_blocks_{$anchor_block_type}", $hooked_blocks, $relative_position, $anchor_block, $context ); |
or even
$hooked_block_types = apply_filters( 'hooked_block_types', $hooked_block_types, $relative_position, $anchor_block_type, $context ); | |
$hooked_block_types = apply_filters( "hooked_blocks_{$relative_position}_{$anchor_block_type}", $hooked_blocks, $anchor_block, $context ); |
which would allow a syntax like
add_filter( 'hooked_blocks_before_ockham/like-button', ... );
Advantages of this approach
Downsides of this approach
|
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
I just reported the spam comments above to GH, not sure if I should delete them now or leave them here as evidence 🤔 |
I just did the same 😄 |
Great idea @andrewserong! Done. |
Thanks, folks! I wonder what keeps attracting spambots to this PR; I already reported another one about a week ago 😕 |
Closing this in favor of #5835. Per discussion on #5811, #5835 (comment), and #5837 (comment), I believe that #5835 is the better design and has fewer drawbacks. |
Another alternative to #5811 and #5835. Uses some code from #5609.
Implements an idea originally conceived of in https://core.trac.wordpress.org/ticket/59572:
In addition, this PR seeks to also explore a possible solution for https://core.trac.wordpress.org/ticket/60126: With the ability to pass attributes for hooked blocks, we can now hook patterns (by giving
core/pattern
as the block type, and setting theslug
attribute to the desired pattern).To demonstrate the latter, apply the following patch to the Like Button block code:
TODO:
block.json
after all?Trac ticket: https://core.trac.wordpress.org/ticket/59572
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.