[wp-trac] [WordPress Trac] #59551: Respect non-null values from the `pre_render_block` filter
WordPress Trac
noreply at wordpress.org
Mon Nov 13 22:58:20 UTC 2023
#59551: Respect non-null values from the `pre_render_block` filter
--------------------------+------------------------------
Reporter: danieliser | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Editor | Version: 6.0
Severity: normal | Resolution:
Keywords: | Focuses:
--------------------------+------------------------------
Changes (by jeremyfelt):
* version: => 6.0
* component: General => Editor
Comment:
IMO, the general promise with `pre_` filters in core is that I can short-
circuit something entirely.
In `pre_render_block`'s current form, if I `add_filter(
'pre_render_block', '__return_empty_string', 1 );`, I would expect that
all blocks are rendered as an empty string.
Because core's own use of `pre_render_block` does not respect the value of
`$pre_render` set earlier than priority 10, the filter doesn't work as
promised. Instead, I need to set my priority so that it runs after core.
If I shift my priority to 11, and acknowledge that core will always
process this block before I decide alter its output, then core will always
prepare styles that I may not need via
`wp_render_elements_support_styles()` and
`_wp_add_block_level_preset_styles()`. That's somewhat annoying, but not
as annoying as the block continuing to render. :)
It seems that if these two functions are treating `pre_render_block` as an
action rather than a filter, they should pass through the value of
`$pre_render` untouched rather than force it to always be `null`. That's
the patch I would propose here.
I agree with @danieliser that the style processing should ideally not run
at all if `! is_null( $pre_render )`, but I also understand the
complication here. I'm not sure what a way forward to solve this looks
like other than removing those hooks whenever my pre_render filters
something.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/59551#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list