From 041471735adfd5eed122f23258f662701beb7614 Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Thu, 10 Jan 2019 23:15:49 +0000 Subject: [PATCH] Blocks: Add the `pre_render_block` and `render_block_data` filters. At the start of `render_block()`, the `pre_render_block` filter allows the function to be short-circuited, and the `render_block_data` filter is applied to the `$block` parameter before it's processed. Props kkarpieszuk, pento. Fixes #45451. git-svn-id: https://develop.svn.wordpress.org/trunk@44553 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/blocks.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index ee66f0aa6c..cefe9cfbb5 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -175,6 +175,28 @@ function excerpt_remove_blocks( $content ) { function render_block( $block ) { global $post; + /** + * Allows render_block() to be shortcircuited, by returning a non-null value. + * + * @since 5.1.0 + * + * @param string $pre_render The pre-rendered content. Default null. + * @param array $block The block being rendered. + */ + $pre_render = apply_filters( 'pre_render_block', null, $block ); + if ( is_null( $pre_render ) ) { + return $pre_render; + } + + /** + * Filters the block being rendered in render_block(), before it's processed. + * + * @since 5.1.0 + * + * @param array $block The block being rendered. + */ + $block = apply_filters( 'render_block_data', $block ); + $block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] ); $is_dynamic = $block['blockName'] && null !== $block_type && $block_type->is_dynamic(); $block_content = '';