[wp-trac] [WordPress Trac] #60580: Block Hooks: Allow hooked_block filter(s) to return null

WordPress Trac noreply at wordpress.org
Tue Feb 20 11:16:51 UTC 2024


#60580: Block Hooks: Allow hooked_block filter(s) to return null
-----------------------------+------------------------------
 Reporter:  Bernhard Reiter  |       Owner:  (none)
     Type:  enhancement      |      Status:  new
 Priority:  normal           |   Milestone:  Awaiting Review
Component:  General          |     Version:
 Severity:  normal           |  Resolution:
 Keywords:                   |     Focuses:
-----------------------------+------------------------------
Description changed by Bernhard Reiter:

Old description:

> The [https://developer.wordpress.org/reference/hooks/hooked_block_types/
> `hooked_block_types` filter] allows extenders to conditionally insert a
> block, based on the anchor block's ''type''.
>
> However, it's currently not possible to base the criterion for insertion
> on the value of an attribute of the anchor block.
>
> One fairly straight-forward way to implement this would be to allow the
> `hooked_block` (and `hooked_block_{$hooked_block_type}` filter -- which
> has access to the entire parsed anchor block, i.e. including attributes
> -- to return `null`, which Block Hooks could then interpret as "do not
> render hooked block". (This would avoid changing the `hooked_block_types`
> filter's signature in an awkward way.)

New description:

 The [https://developer.wordpress.org/reference/hooks/hooked_block_types/
 `hooked_block_types` filter] allows extenders to conditionally insert a
 block, based on the anchor block's ''type''.

 However, it's currently not possible to base the criterion for insertion
 on the value of an attribute of the anchor block.

 One fairly straight-forward way to implement this would be to allow the
 `hooked_block` (and `hooked_block_{$hooked_block_type}`) filter -- which
 has access to the entire parsed anchor block, i.e. including attributes --
 to return `null`, which Block Hooks could then interpret as "do not render
 hooked block". (This would avoid changing the `hooked_block_types`
 filter's signature in an awkward way.)

--

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/60580#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list