Editor: Remove render_block hooks from WP_Block

Reverts the move of pre_render_block, render_block_data, and
render_block_context to WP_Block.

This change has more implications than first thought so will be revisted later
in 5.7.

Reverts [49609,49608].
See #51612.


git-svn-id: https://develop.svn.wordpress.org/trunk@49695 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Robert Anderson
2020-11-25 01:18:25 +00:00
parent c8f7440c6a
commit a86bedfc92
3 changed files with 111 additions and 367 deletions

View File

@@ -662,8 +662,7 @@ function render_block( $parsed_block ) {
global $post, $wp_query;
/**
* Allows render_block() or WP_Block::render() to be short-circuited, by
* returning a non-null value.
* Allows render_block() to be short-circuited, by returning a non-null value.
*
* @since 5.1.0
*
@@ -675,6 +674,18 @@ 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 ) {
@@ -696,6 +707,16 @@ 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();