WordPress.org

Make WordPress Core

#51708 closed defect (bug) (duplicate)

Editor: Block render filters are not called on nested blocks

Reported by: noisysocks Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Editor Keywords: needs-patch
Focuses: Cc:

Description

First reported here: https://github.com/WordPress/gutenberg/issues/25900

pre_render_block, render_block_data and render_block_context are only called for top-level blocks which isn't what you would expect from reading those filters' documentation and likely causes unexpected bugs e.g. that the Latest Posts block does not have its attributes migrated.

We should be applying these filters inside WP_Block::_construct as well.

To test, add these filters and then open a post that has some blocks inside a Group block. Note that the filters aren't called for the inner blocks.

<?php
add_filter(
        'pre_render_block',
        function( $pre_render, $parsed_block ) {
                var_dump( 'pre_render_block', $pre_render, $parsed_block );
        },
        10,
        2
);

add_filter(
        'render_block_data',
        function( $parsed_block, $source_block ) {
                var_dump( 'render_block_data', $parsed_block, $source_block );
        },
        10,
        2
);

add_filter(
        'render_block_context',
        function( $context, $parsed_block ) {
                var_dump( 'render_block_context', $context, $parsed_block );
        },
        10,
        2
);

Change History (2)

#1 @noisysocks
11 months ago

cc. @gziolo

#2 @noisysocks
11 months ago

  • Milestone 5.7 deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Oops, this was already ticketed: #51612

Note: See TracTickets for help on using tickets.