[wp-trac] [WordPress Trac] #51612: `render_block_data` for nested blocks - WP_Block::render vs render_block

WordPress Trac noreply at wordpress.org
Mon Nov 9 09:09:16 UTC 2020


#51612: `render_block_data` for nested blocks - WP_Block::render vs render_block
-------------------------------------------------+-------------------------
 Reporter:  gaambo                               |       Owner:  noisysocks
     Type:  defect (bug)                         |      Status:  accepted
 Priority:  normal                               |   Milestone:  Future
                                                 |  Release
Component:  Editor                               |     Version:  5.5
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch needs-testing has-unit-    |     Focuses:
  tests                                          |
-------------------------------------------------+-------------------------

Comment (by gaambo):

 The original issue (filters not being called) is now solved, but there are
 a few things (which you also commented in GitHub):
 1. `render_block_data` (WP_Block::constructor) now get's called **before**
 `pre_render_block` (WP_Block::render) - which may make sense, but it's
 still different to before, so I think that should be documented somewhere
 in the changelog (dev-note?).
 2. `pre_render_block` get's called multiple times for top-level items.
 Again: May make sense, but I've run into a couple of problems in the past
 when filters/actions were being called multiple times for the same object.
 In my case (see below) I just check if it's the same `$block['blockName']`
 as run before, that's only needed for top level blocks.
 Maybe add an extra argument whether it's a top-level/it's in render_block?
 Or is that to confusing?

 **To better describe my usecase:**
 It's on a very customized site - some of the blocks need to be rendered
 differently if they are nested (eg with/without margin/padding; I'm not
 using groups/covers/containers etc here so the client only has to insert
 the content-blocks and styling is all done via css/html).
 So until WP 5.4 I hook into `pre_render_block` on the last priority and if
 it didn't return null I registered the currentRenderedBlock in an internal
 array. On `render_block` (again last priorty) I deregistered the block
 again. In between a block could check if it's nested if the
 currentRenderedBlocks is an array with more than one item.

 I may have to adapt this to the new order of hooks being called, but that
 should be possible - or maybe it's even possible via block context to
 check if it's nested. Gotta figure that out.

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


More information about the wp-trac mailing list