Make WordPress Core

Opened 22 months ago

Last modified 4 months ago

#56417 new defect (bug)

Changes from 'render_block_data' filter not always applied to inner blocks

Reported by: isabel_brison's profile isabel_brison Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Editor Keywords:
Focuses: Cc:


When changes are made to $parsed_block['innerContent'] using the 'render_block_data' filter, those changes are only applied to top-level blocks, not to inner blocks.

The issue is how we deal with inner blocks in class WP_Block's render method: we don't create a new instance between applying the filter and calling render on the inner block, so changes to innerContent aren't actually applied.

Ideally we should apply the same logic here as we do in the render_block function:

Change History (4)

#1 @talldanwp
22 months ago

I haven't looked too deeply into this, but I wonder if in both places, rendering of blocks could be implemented as something like $html = $blockList->render().

It'd mean a new render function in the WP_Block_List class, but it would be one way of using the same code in both places and reducing inconsistencies.

#2 @noisysocks
21 months ago

  • Milestone changed from Awaiting Review to Future Release

Do you have some code that demonstrates the problem?

#3 @isabel_brison
20 months ago

Do you have some code that demonstrates the problem?

I have a draft PR: where I'm trying to change a block's inner wrapper in a 'render_block_data' filter so the $block_content passed to the subsequent 'render_block' filter already has those changes. Will that work as a demonstration?

#4 @wildworks
4 months ago

Gutenberg now has the ability to randomize order in the Gallery block.

This feature is achieved by using render_block_data hooks and shuffling $parsed_block['innerBlocks']. However, I found that this feature does not work when blocks are nested.

I'm concerned that the underlying issue is similar to what was reported in this ticket.

Similar to this problem this hook that gives the image block the data-id attribute also doesn't seem to work when the blocks are nested.

Note: See TracTickets for help on using tickets.