[wp-trac] [WordPress Trac] #59327: Add optional callback argument to serialize_block(s)
WordPress Trac
noreply at wordpress.org
Tue Sep 12 13:00:47 UTC 2023
#59327: Add optional callback argument to serialize_block(s)
-----------------------------+------------------------------
Reporter: Bernhard Reiter | Owner: Bernhard Reiter
Type: enhancement | Status: closed
Priority: normal | Milestone: 6.4
Component: General | Version:
Severity: normal | Resolution: fixed
Keywords: | Focuses:
-----------------------------+------------------------------
Changes (by Bernhard Reiter):
* status: assigned => closed
* resolution: => fixed
Comment:
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/59327#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list