Skip to content

Commit

Permalink
Fix WP_Block_Supports class compatibility with Gutenberg-provided cla…
Browse files Browse the repository at this point in the history
…ss (#26417)

This PR ports the changes from the core PR at WordPress/wordpress-develop#640

Co-authored-by: Jon Surrell <jon.surrell@automattic.com>
Co-authored-by: Miguel Fonseca <miguelcsf@gmail.com>
  • Loading branch information
3 people authored Oct 26, 2020
1 parent e3781b5 commit a4af7d0
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lib/class-wp-block-supports.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down

0 comments on commit a4af7d0

Please sign in to comment.