From b6378cd4e3bb4f623b9380931544f1d71fefba73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Fri, 23 Oct 2020 14:36:23 +0200 Subject: [PATCH 1/4] Port changes from core PR --- lib/class-wp-block-supports.php | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/class-wp-block-supports.php b/lib/class-wp-block-supports.php index 45b6bd018920a..734a65872c94a 100644 --- a/lib/class-wp-block-supports.php +++ b/lib/class-wp-block-supports.php @@ -207,14 +207,24 @@ 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 ) { - $parent_block = WP_Block_Supports::$block_to_render; - WP_Block_Supports::$block_to_render = $block->parsed_block; - $result = $block_render_callback( $attributes, $content, $block ); - WP_Block_Supports::$block_to_render = $parent_block; - return $result; + // 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 ) { + $parent_block = WP_Block_Supports::$block_to_render; + WP_Block_Supports::$block_to_render = $block->parsed_block; + $result = $block_render_callback( $attributes, $content, $block ); + WP_Block_Supports::$block_to_render = $parent_block; + return $result; + } else { + return $block_render_callback( $attributes, $content ); + } }; } return $args; From 678d5fab53d6640e12423e6761a9d0c5555d96e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Fri, 23 Oct 2020 14:48:41 +0200 Subject: [PATCH 2/4] Make linter happy --- lib/class-wp-block-supports.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/class-wp-block-supports.php b/lib/class-wp-block-supports.php index 734a65872c94a..2b61c0ff11e8a 100644 --- a/lib/class-wp-block-supports.php +++ b/lib/class-wp-block-supports.php @@ -215,7 +215,8 @@ function wp_block_supports_track_block_to_render( $args ) { // // See: // - https://core.trac.wordpress.org/ticket/49927 - // - commit 910de8f6890c87f93359c6f2edc6c27b9a3f3292 at wordpress-develop + // - commit 910de8f6890c87f93359c6f2edc6c27b9a3f3292 at wordpress-develop. + // if ( null !== $block ) { $parent_block = WP_Block_Supports::$block_to_render; WP_Block_Supports::$block_to_render = $block->parsed_block; From fec273b4a2bb516cda0958c2c12f4e86ff79ce11 Mon Sep 17 00:00:00 2001 From: Miguel Fonseca Date: Fri, 23 Oct 2020 15:28:39 +0100 Subject: [PATCH 3/4] render_callback wrapper: make 3rd param optional Co-authored-by: Jon Surrell --- lib/class-wp-block-supports.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/class-wp-block-supports.php b/lib/class-wp-block-supports.php index 2b61c0ff11e8a..1392e4b41cf5b 100644 --- a/lib/class-wp-block-supports.php +++ b/lib/class-wp-block-supports.php @@ -209,7 +209,7 @@ function get_block_wrapper_attributes( $extra_attributes = array() ) { function wp_block_supports_track_block_to_render( $args ) { 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. // From d92575bf8aa987a693bf35eba998f114f08c9de7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Fri, 23 Oct 2020 16:52:50 +0200 Subject: [PATCH 4/4] Stylistic improvements --- lib/class-wp-block-supports.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/class-wp-block-supports.php b/lib/class-wp-block-supports.php index 1392e4b41cf5b..47f66d35281b6 100644 --- a/lib/class-wp-block-supports.php +++ b/lib/class-wp-block-supports.php @@ -216,16 +216,16 @@ function wp_block_supports_track_block_to_render( $args ) { // See: // - https://core.trac.wordpress.org/ticket/49927 // - commit 910de8f6890c87f93359c6f2edc6c27b9a3f3292 at wordpress-develop. - // - if ( null !== $block ) { - $parent_block = WP_Block_Supports::$block_to_render; - WP_Block_Supports::$block_to_render = $block->parsed_block; - $result = $block_render_callback( $attributes, $content, $block ); - WP_Block_Supports::$block_to_render = $parent_block; - return $result; - } else { + + 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 ); + WP_Block_Supports::$block_to_render = $parent_block; + return $result; }; } return $args;