[wp-trac] [WordPress Trac] #60574: Block Hooks: Add new `hooked_block` filter
WordPress Trac
noreply at wordpress.org
Mon Feb 19 16:05:14 UTC 2024
#60574: Block Hooks: Add new `hooked_block` filter
-----------------------------+---------------------
Reporter: Bernhard Reiter | Owner: (none)
Type: task (blessed) | Status: new
Priority: normal | Milestone: 6.5
Component: Editor | Version: trunk
Severity: normal | Resolution:
Keywords: has-patch | Focuses:
-----------------------------+---------------------
Changes (by swissspidy):
* type: enhancement => task (blessed)
* version: => trunk
* component: General => Editor
* milestone: Awaiting Review => 6.5
Comment:
Re-sharing the gist of that Slack conversation here for improved
visibility, as Slack requires signup.
My main input was that it's common for dynamic filters in WordPress to
have a non-dynamic counterpart, see e.g. `pre_option_{$option}` and
`pre_option filters`.
The question about the signature for the dynamic version is really
independent of that.
Usually when we have a dynamic filter such as
`hooked_block_{$hooked_block_type}`, `$hooked_block_type` is often then
added as an additional argument to the filter. This makes it easier for
devs to add a filter for multiple block types and then figuring out which
block type the current invocation is for.
As for the exact signature, the argument could also come in last, e.g.
`apply_filters( "hooked_block_{$hooked_block_type}", $parsed_hooked_block,
$relative_position, $parsed_anchor_block, $context )` and `apply_filters(
"hooked_block", $parsed_hooked_block, $relative_position,
$parsed_anchor_block, $context, $hooked_block_type )`.
That seems like a reasonable change to me.
Moving to milestone for consideration as a blessed task, as it's a new
filter in 6.5 so now is the best opportunity to make bigger changes to it.
However, adding a new filter & adding a new argument at the end is a non
breaking change that could also be added later as well.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/60574#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list