Layout: ensure block content is always returned as a string after processing #45330
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.
What?
Follow-up to: #44600
When using
WP_HTML_Tag_Processor
inlayout.php
, we need to make sure that we cast to a string, otherwise we return aWP_HTML_Tag_Processor
object instead of a string. Although it can be treated as a string, if we have other hooks that also act on the block content and that are registered after the existing layout support, then without this change, they can accidentally encounter an object instead of a string.Why?
While rebasing #44723, I ran into a PHP fatal when I attempted to do more processing in an additional hook on
render_block
because the$block_content
was not a string as expected. This change should resolve that.How?
Add
(string)
casts before output when usingWP_HTML_Tag_Processor
inlayout.php
Testing Instructions
Smoke test and ensure that layout output is still working as expected (e.g. add a few group blocks to a page, set some block spacing, save, and view on site front-end, and ensure there are no PHP errors or warnings)