diff --git a/src/wp-includes/class-wp-block-supports.php b/src/wp-includes/class-wp-block-supports.php index a14efa36bd603..f67c62f070627 100644 --- a/src/wp-includes/class-wp-block-supports.php +++ b/src/wp-includes/class-wp-block-supports.php @@ -67,6 +67,18 @@ public static function init() { $instance->register_attributes(); } + /** + * Applies the render_block filter. + * + * @param string $block_content Rendered block content. + * @param array $block Block object. + * @return string Filtered block content. + */ + public static function render( $block_content, $block ) { + $instance = self::get_instance(); + return $instance->render_block_supports( $block_content, $block ); + } + /** * Registers a block support. * @@ -155,6 +167,37 @@ private function register_attributes() { } } } + + /** + * Modify the rendered block content with additional filters. + * + * @param string $block_content Rendered block content. + * @param array $block Block object. + * @return string Filtered block content. + */ + public function render_block_supports( $block_content, $block ) { + $block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] ); + $block_attributes = $block['attrs']; + + if ( ! $block_type ) { + return $block_content; + } + + foreach ( $this->block_supports as $name => $block_support_config ) { + if ( ! isset( $block_support_config['render_block'] ) ) { + continue; + } + + $block_content = call_user_func( + $block_support_config['render_block'], + $block_type, + $block_attributes, + $block_content + ); + } + + return $block_content; + } } /** diff --git a/src/wp-includes/default-filters.php b/src/wp-includes/default-filters.php index e8e0a84d45eb3..c4e07e29cfb58 100644 --- a/src/wp-includes/default-filters.php +++ b/src/wp-includes/default-filters.php @@ -315,6 +315,7 @@ add_action( 'init', '_register_core_block_patterns_and_categories' ); add_action( 'init', 'check_theme_switched', 99 ); add_action( 'init', array( 'WP_Block_Supports', 'init' ), 22 ); +add_filter( 'render_block', array( 'WP_Block_Supports', 'render' ), 10, 2 ); add_action( 'after_switch_theme', '_wp_menus_changed' ); add_action( 'after_switch_theme', '_wp_sidebars_changed' ); add_action( 'wp_print_styles', 'print_emoji_styles' );