[wp-trac] [WordPress Trac] #59131: Introduce filters to modify/inspect the blocks returned by `do_blocks()`

WordPress Trac noreply at wordpress.org
Fri Sep 8 14:40:03 UTC 2023


#59131: Introduce filters to modify/inspect the blocks returned by `do_blocks()`
--------------------------------------------------+-----------------------
 Reporter:  luisherranz                           |       Owner:  gziolo
     Type:  enhancement                           |      Status:  assigned
 Priority:  normal                                |   Milestone:  6.4
Component:  Editor                                |     Version:  trunk
 Severity:  normal                                |  Resolution:
 Keywords:  has-patch has-unit-tests 2nd-opinion  |     Focuses:
--------------------------------------------------+-----------------------

Comment (by luisherranz):

 Hey @azaozz, thanks for the feedback 🙂

 I should have given more context for the need for these filters in the
 description. Sorry about that.

 `the_content` filters only the post content, whereas blocks are nowadays
 also used on the theme (templates and template parts) and other places
 where they are not filtered by `the_content`.

 `render_blocks` filters are great, but they are limited in the order they
 run and the information they have: `render_block_data` and
 `render_block_context` are top-down and can only access the block instance
 information, not the final rendering. `render_block` has the final
 rendering, but it's bottom-up. The render is also difficult to inspect
 because each block contains not only its own render, but also the render
 of its inner blocks. The main need for these filters came from the
 Interactivity API directive processing, which needs to process things top-
 down and be able to separate the render of interactive blocks from their
 (non-interactive) inner-blocks. But according to @dmsnell, the need for
 this filter also arose during the work on footnotes (even though they
 finally took a different approach). This is also potentially useful for
 things like word counters, advertising placement and so on.

 All in all, we don't have a good way to hook into the start and end of the
 blocks rendering, and these filters would provide a convenient way to
 modify blocks from a global perspective without having to resort to hacky
 and prone-to-error implementations.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/59131#comment:13>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list