[wp-trac] [WordPress Trac] #56941: Fatal error produced by block using closure as render_callback
WordPress Trac
noreply at wordpress.org
Tue Nov 1 09:35:14 UTC 2022
#56941: Fatal error produced by block using closure as render_callback
--------------------------+------------------------------
Reporter: andrewleap | Owner: (none)
Type: defect (bug) | Status: assigned
Priority: normal | Milestone: Awaiting Review
Component: Themes | Version: 6.1
Severity: blocker | Resolution:
Keywords: | Focuses:
--------------------------+------------------------------
Comment (by andrewleap):
Apologies, This was my mistake. I was panicking as the new version is
being released imminently .
The culprit was actually this in my theme:
{{{
/**
* Add a reference to block parent in render function.
*
* @param array $parsed_block Block data.
*/
function xd_append_parent_block_data( $parsed_block ) {
$block = new WP_Block( $parsed_block );
foreach ( $parsed_block['innerBlocks'] as &$inner_block ) {
$inner_block['parent'] = array(
'name' => $block->name,
'props' => $block->attributes,
'block' => $block,
);
}
return $parsed_block;
}
add_filter( 'render_block_data', 'xd_append_parent_block_data' );
}}}
We add a reference to the parent block in the block data as this allows us
to contextually change the output in the render function. That parent
block will also have a closure for its render callback function. Of
Course, the block serialization that was recently added will not play nice
when trying to serialize a callback.
{{{#!php
<?php
function wp_get_elements_class_name( $block ) {
return 'wp-elements-' . md5( serialize( $block ) );
}
}}}
We can fix this with update to our plugin. Thanks for taking the time to
look at this.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/56941#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list