Editor: Introduce a dynamic filter for the content of a single block:

`render_block_{$this->name}`

This complements the existing `render_block` hook and allows for filtering the content of a specific block without having to use conditionals inside the filter callback.

Props manzoorwani.jk, noisysocks, birgire, johnbillion.
Fixes #46187.
Built from https://develop.svn.wordpress.org/trunk@50123


git-svn-id: http://core.svn.wordpress.org/trunk@49802 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2021-02-01 18:06:03 +00:00
parent 2024649ea9
commit cb7d0efb45
2 changed files with 17 additions and 2 deletions

View File

@ -241,7 +241,22 @@ class WP_Block {
* @param string $block_content The block content about to be appended. * @param string $block_content The block content about to be appended.
* @param array $block The full block, including name and attributes. * @param array $block The full block, including name and attributes.
*/ */
return apply_filters( 'render_block', $block_content, $this->parsed_block ); $block_content = apply_filters( 'render_block', $block_content, $this->parsed_block );
/**
* Filters the content of a single block.
*
* The dynamic portion of the hook name, `$name`, refers to
* the block name, e.g. "core/paragraph".
*
* @since 5.7.0
*
* @param string $block_content The block content about to be appended.
* @param array $block The full block, including name and attributes.
*/
$block_content = apply_filters( "render_block_{$this->name}", $block_content, $this->parsed_block );
return $block_content;
} }
} }

View File

@ -13,7 +13,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.7-alpha-50122'; $wp_version = '5.7-alpha-50123';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.