REST API: Apply all relevant block rendering filters when rendering block previews.
Several filters were introduced to the render_block method since the initial implementation of the block-renderer/ endpoints, causing the output of those endpoints to diverge from the rendered content of blocks on the frontend. Props kadamwhite, TimothyBlynJacobs, miinasikk. Fixes #49387. Built from https://develop.svn.wordpress.org/trunk@47360 git-svn-id: http://core.svn.wordpress.org/trunk@47147 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
67a6527d51
commit
8faf366ab9
|
@ -135,9 +135,8 @@ class WP_REST_Block_Renderer_Controller extends WP_REST_Controller {
|
|||
setup_postdata( $post );
|
||||
}
|
||||
$registry = WP_Block_Type_Registry::get_instance();
|
||||
$block = $registry->get_registered( $request['name'] );
|
||||
|
||||
if ( null === $block ) {
|
||||
if ( null === $registry->get_registered( $request['name'] ) ) {
|
||||
return new WP_Error(
|
||||
'block_invalid',
|
||||
__( 'Invalid block.' ),
|
||||
|
@ -147,8 +146,19 @@ class WP_REST_Block_Renderer_Controller extends WP_REST_Controller {
|
|||
);
|
||||
}
|
||||
|
||||
$attributes = $request->get_param( 'attributes' );
|
||||
|
||||
// Create an array representation simulating the output of parse_blocks.
|
||||
$block = array(
|
||||
'blockName' => $request['name'],
|
||||
'attrs' => $attributes,
|
||||
'innerHTML' => '',
|
||||
'innerContent' => array(),
|
||||
);
|
||||
|
||||
// Render using render_block to ensure all relevant filters are used.
|
||||
$data = array(
|
||||
'rendered' => $block->render( $request->get_param( 'attributes' ) ),
|
||||
'rendered' => render_block( $block ),
|
||||
);
|
||||
|
||||
return rest_ensure_response( $data );
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '5.4-beta2-47359';
|
||||
$wp_version = '5.4-beta2-47360';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue