[wp-trac] [WordPress Trac] #59313: Implement Block Hooks

WordPress Trac noreply at wordpress.org
Tue Sep 12 13:00:47 UTC 2023


#59313: Implement Block Hooks
-------------------------------------------------+-------------------------
 Reporter:  Bernhard Reiter                      |       Owner:  Bernhard
                                                 |  Reiter
     Type:  enhancement                          |      Status:  assigned
 Priority:  high                                 |   Milestone:  6.4
Component:  Editor                               |     Version:
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch gutenberg-merge has-unit-  |     Focuses:
  tests                                          |
-------------------------------------------------+-------------------------

Comment (by Bernhard Reiter):

 In [changeset:"56557" 56557]:
 {{{
 #!CommitTicketReference repository="" revision="56557"
 General: Add optional callback argument to serialize_block(s).

 Allow passing a function callback to serialize_block(s) that is invoked on
 each node in the tree of parsed blocks as it is traversed for
 serialization.

 A function argument was chosen for passing the callback function as it
 reflects a pattern familiar from other algorithms that apply a given
 callback function while traversing a data structure -- most notably PHP's
 own `array_map()`.

 Introducing a filter was considered as an alternative but ultimately
 dismissed. For a fairly low-level and general-purpose function such as
 `serialize_block()`, using a filter to pass the callback seemed risky, as
 it also requires ''removing'' that filter after usage in order to prevent
 the callback from being accidentally applied when `serialize_block()` is
 called in an entirely different context.

 Introducing a separate function for applying a given operation during tree
 traversal (i.e. independently of serialization) was also considered but
 dismissed, as it would unnecessarily duplicate tree traversal.

 Props dlh, gziolo.
 Fixes #59327. See #59313.
 }}}

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


More information about the wp-trac mailing list