[wp-trac] [WordPress Trac] #60769: Block Hooks: Consolidate approach to get the list of hooked blocks.

WordPress Trac noreply at wordpress.org
Wed Apr 24 16:41:35 UTC 2024


#60769: Block Hooks: Consolidate approach to get the list of hooked blocks.
---------------------------+------------------------------
 Reporter:  tomjcafferkey  |       Owner:  (none)
     Type:  enhancement    |      Status:  new
 Priority:  normal         |   Milestone:  Awaiting Review
Component:  General        |     Version:
 Severity:  normal         |  Resolution:
 Keywords:                 |     Focuses:
---------------------------+------------------------------

Comment (by Bernhard Reiter):

 Agree, this is an architectural flaw/oversight on my part.

 > How this to work we would also need to know the current context so we
 can pass that data to the filter callbacks.

 I think we'll have to add not only `$context` but also
 `$anchor_block_type` and `$relative_position` as arguments to
 `get_hooked_blocks()`, since we need all of them to apply the filters (see
 [https://developer.wordpress.org/reference/hooks/hooked_block_types/
 `hooked_block_types`] and
 [https://developer.wordpress.org/reference/hooks/hooked_block/
 `hooked_block`].

 We'd likely want the arguments in a different order though, probably
 `get_hooked_blocks( $anchor_block_type, $relative_position, $context )`.
 We'd then apply the filters inside of the function if those arguments are
 non-null.

 This means that the return value should also look a bit different, since
 we no longer need to return a [https://github.com/WordPress/wordpress-
 develop/blob/d898a25d1a37f493b7050b263cb9c5b29565792a/src/wp-
 includes/blocks.php#L848 nested array] (by anchor block and relative
 position) like we do now.

 Makes me wonder if we should introduce a separate helper function for this
 (since it seems like it would be different enough from
 `get_hooked_blocks()`). `get_hooked_blocks_for_block_hook()` or so maybe.
 (If we assume that a block hook is defined by an anchor block and a
 relative position.)

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


More information about the wp-trac mailing list