#59669 closed defect (bug) (fixed)
Block: Give `traverse_and_serialize_block(s)`' post-callback access to block instance
Reported by: | Bernhard Reiter | Owned by: | Bernhard Reiter |
---|---|---|---|
Milestone: | 6.4 | Priority: | normal |
Severity: | normal | Version: | 6.4 |
Component: | General | Keywords: | has-patch has-unit-tests commit dev-reviewed |
Focuses: | Cc: |
Description (last modified by )
Both the $pre_
and $post_callback
functions that are given as arguments to traverse_and_serialize_block(s)
receive a reference to the current block as their first argument. However, while any changes that the "pre" callback makes to the block are actually respected during serialization, the same isn't true for the "post" callback: Any changes that it makes are only applied after the block has already been serialized. For applications like #59646, we probably want to change that.
Change History (12)
This ticket was mentioned in PR #5525 on WordPress/wordpress-develop by @Bernhard Reiter.
12 months ago
#1
- Keywords has-patch has-unit-tests added
@Bernhard Reiter commented on PR #5525:
12 months ago
#4
Committed to Core trunk
in https://core.trac.wordpress.org/changeset/56970.
#5
@
11 months ago
- Keywords dev-feedback added
- Milestone changed from 6.5 to 6.4
- Resolution fixed deleted
- Status changed from closed to reopened
Re-opening for potential inclusion in 6.4. Requesting another committer's feedback/approval :)
I forgot to backport this to the 6.4 branch after committing to trunk
. It might not be a "huge" bug (doesn't seem to affect Block Hooks in Core), but it might pose problems for third parties that want to use traverse_and_serialize_block(s)
with a $post_callback
that modifies the current block (as that won't work, without the fix). One use case could be the Gutenberg plugin, if we want to e.g. implement something like #59646 there first.
FWIW, traverse_and_serialize_block(s)
was only introduced during the 6.4 cycle, so I believe the fix qualifies for backporting during RC.
This ticket was mentioned in Slack in #core by bernhardreiter. View the logs.
11 months ago
#7
@
11 months ago
- Type changed from enhancement to defect (bug)
Looks like the Type was set to enhancement. I've now changed that to defect (bug) because it actually is one :)
#8
@
11 months ago
- Keywords commit dev-reviewed added; dev-feedback removed
- Version set to trunk
it might pose problems for third parties that want to use
traverse_and_serialize_block(s)
with a$post_callback
that modifies the current block (as that won't work, without the fix).
Good catch @bernhard-reiter flagging this fix.
As the bug (and functions) was(were) introduced in 6.4, [56970] LGTM for backport to the 6.4 branch.
@Bernhard Reiter commented on PR #5525:
11 months ago
#10
Backported to the 6.4
branch in https://core.trac.wordpress.org/changeset/57043.
#11
@
11 months ago
Just curious, why callbacks (as function params) and not filters? The (basic) difference between callbacks as params and filters is that with filters many plugins can apply callbacks at the same time, i.e. work in sync. With separate callbacks all plugins will have to rerun the same functions again and again.
Looking ast gthe code here, these callbacks seem like an anti-pattern in WP?
#12
@
11 months ago
Looping back here. Today, there was a discussion in Make/Core slack about @azaozz (and my) concerns.
tl;dr
- The new functionality and functions are low-level and intended for internal Core-only usage.
- Architectural changes will be discussed in a separate ticket for a future release, as it's too late in the 6.4 cycle for new filters or architectural redesign to encapsulate this internal functionality.
- #59783 is now open to better document the intent of Core-only.
Both the
$pre_
and$post_callback
functions that are given as arguments totraverse_and_serialize_block(s)
receive a reference to the current block as its first argument. However, while any changes that the "pre" callback makes to the block are actually respected during serialization, the same isn't true for the "post" callback: Any changes that it makes are only applied after the block has already been serialized. For applications like #59412, we probably want to change that.Trac ticket: https://core.trac.wordpress.org/ticket/59669