From a4af7d0a82c8dd16e4f72b23128aef3646cf8f69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?O=20Andr=C3=A9?= Date: Mon, 26 Oct 2020 09:33:36 +0100 Subject: [PATCH] Fix WP_Block_Supports class compatibility with Gutenberg-provided class (#26417) This PR ports the changes from the core PR at https://github.com/WordPress/wordpress-develop/pull/640 Co-authored-by: Jon Surrell Co-authored-by: Miguel Fonseca --- lib/class-wp-block-supports.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/class-wp-block-supports.php b/lib/class-wp-block-supports.php index 45b6bd018920a8..47f66d35281b64 100644 --- a/lib/class-wp-block-supports.php +++ b/lib/class-wp-block-supports.php @@ -207,9 +207,20 @@ function get_block_wrapper_attributes( $extra_attributes = array() ) { * @return array Block attributes. */ function wp_block_supports_track_block_to_render( $args ) { - if ( null !== $args['render_callback'] ) { + if ( is_callable( $args['render_callback'] ) ) { $block_render_callback = $args['render_callback']; - $args['render_callback'] = function( $attributes, $content, $block ) use ( $block_render_callback ) { + $args['render_callback'] = function( $attributes, $content, $block = null ) use ( $block_render_callback ) { + // Check for null for back compatibility with WP_Block_Type->render + // which is unused since the introduction of WP_Block class. + // + // See: + // - https://core.trac.wordpress.org/ticket/49927 + // - commit 910de8f6890c87f93359c6f2edc6c27b9a3f3292 at wordpress-develop. + + if ( null === $block ) { + return $block_render_callback( $attributes, $content ); + } + $parent_block = WP_Block_Supports::$block_to_render; WP_Block_Supports::$block_to_render = $block->parsed_block; $result = $block_render_callback( $attributes, $content, $block );