Editor: Move pre_render_block, render_block_data, render_block_context

Move the pre_render_block, render_block_data, and render_block_context
filters from render_block() to WP_Block. This ensures that they are
called for all blocks, including nested blocks, not just top-level
blocks.

Fixes #51612.
Props gaambo, gziolo, TimothyBlynJacobs.


git-svn-id: https://develop.svn.wordpress.org/trunk@49608 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Robert Anderson
2020-11-16 00:45:55 +00:00
parent 2425a11255
commit 7a42314c8b
3 changed files with 367 additions and 111 deletions

View File

@@ -662,7 +662,8 @@ function render_block( $parsed_block ) {
global $post, $wp_query;
/**
* Allows render_block() to be short-circuited, by returning a non-null value.
* Allows render_block() or WP_Block::render() to be short-circuited, by
* returning a non-null value.
*
* @since 5.1.0
*
@@ -674,18 +675,6 @@ function render_block( $parsed_block ) {
return $pre_render;
}
$source_block = $parsed_block;
/**
* Filters the block being rendered in render_block(), before it's processed.
*
* @since 5.1.0
*
* @param array $parsed_block The block being rendered.
* @param array $source_block An un-modified copy of $parsed_block, as it appeared in the source content.
*/
$parsed_block = apply_filters( 'render_block_data', $parsed_block, $source_block );
$context = array();
if ( $post instanceof WP_Post ) {
@@ -707,16 +696,6 @@ function render_block( $parsed_block ) {
}
}
/**
* Filters the default context provided to a rendered block.
*
* @since 5.5.0
*
* @param array $context Default context.
* @param array $parsed_block Block being rendered, filtered by `render_block_data`.
*/
$context = apply_filters( 'render_block_context', $context, $parsed_block );
$block = new WP_Block( $parsed_block, $context );
return $block->render();