Post Content block: Allow Block Hooks child insertion #56972
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Untested; this code probably doesn't work yet.
What?
Try allowing
first_child
andlast_child
insertion into the Post Content block.This is experimental; there's a pretty good chance that we'll never merge this code due to its limitations (see "Notes" section below).
Why?
It was brought up that this would be beneficial e.g. for inserting a Like Button block as the Post Content block's
last_child
(rather thanafter
) for consistency with the Classic Theme way of doing this (using thethe_content
filter).How?
By manually applying the
hooked_block_types
filter inside the Post Content block.Testing Instructions
Basically, follow Block Hooks instructions to insert a block as
core/post-content
'slast_child
.Notes
Note that due to the fact that we're doing this manually, this approach has a number of significant shortcomings, among them:
$context
available.Alternatives considered
We could run our Block Hooks logic on the
$content
returned fromget_the_content()
(in the Post Content block's render method), or even generically on all post content (in any given context; e.g. when runningdo_blocks
).However, that would present a pretty big departure from how it's worked up to now (which was pretty much limited to templates, parts, and patterns). It's something to consider for WP 6.5 (since it might be possible thanks to the new mechanism we're using), but it'll require careful deliberation.