[wp-trac] [WordPress Trac] #59412: Blocks: Add post-block callback arg to `traverse_and_serialize_block(s)`, change signature
WordPress Trac
noreply at wordpress.org
Wed Sep 20 16:31:05 UTC 2023
#59412: Blocks: Add post-block callback arg to `traverse_and_serialize_block(s)`,
change signature
-----------------------------+-----------------------------
Reporter: Bernhard Reiter | Owner: Bernhard Reiter
Type: enhancement | Status: assigned
Priority: normal | Milestone: 6.4
Component: General | Version:
Severity: normal | Keywords:
Focuses: |
-----------------------------+-----------------------------
While working on #59399, I [https://github.com/WordPress/wordpress-
develop/pull/5247#discussion_r1331151853 discovered] that sibling block
insertion wasn't likely going to work the way I had planned. As a
consequence, I had to come up with a new way to make it work. This
requires some changes to `traverse_and_serialize_block(s)`.
Basically, we need to:
- Change the signature of the existing callback such that:
- the function arguments are a ''reference'' to the current block (so it
can be modified inline, which is important e.g. for `theme` attribute
insertion), the parent block, and the previous block (instead of the block
index and chunk index);
- the return value is a string that will be prepended to the result of
the inner block traversal and serialization.
- Add a second callback argument to `traverse_and_serialize_block`, which
is called _after_ the current inner block is traversed and serialized.
- Its function arguments are a reference to the current block, the
parent block, and the next block.
Its usage is demonstrated in [https://github.com/WordPress/wordpress-
develop/pull/5261 PR 5261]: The callback arguments are now sufficient to
insert the serialized hooked blocks as strings, rather than via
`insert_inner_block`, `prepend_inner block`, or `append_inner_block`. (The
latter -- which have been introduced only recently, in [56618] -- are
thus going to be obsolete.)
--
Ticket URL: <https://core.trac.wordpress.org/ticket/59412>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list