InnerBlocks doesn't work anymore on 1.26 on Rest API
- This topic has 5 replies, 2 voices, and was last updated 1 year ago by
Peter.
-
AuthorPosts
-
April 27, 2024 at 4:31 PM #45332
Julien
ParticipantHi,
I update from 1.25.x to 1.26.2 and inside Rest API of wordpress, <InnerBlocks /> is not interprated.
It's ok on the editor, it's ok on standard webpage but on Rest API it's not.
Screenshot from Gutenberg
Screenshot from website
Screenshot from Rest API
add_filter( 'rwmb_meta_boxes', function( $meta_boxes ) { $meta_boxes[] = [ 'title' => 'Hero Content', 'id' => 'hero-content', 'description' => 'A custom hero content block', // Block settings. 'type' => 'block', 'icon' => 'awards', 'category' => 'layout', 'context' => 'side', 'render_callback' => function($attributes){ echo '<header>'.$attributes['title'].'</header><section><InnerBlocks /></section>'; }, 'enqueue_style' => get_template_directory_uri() . '/blocks/hero/style.css', 'supports' => [ 'align' => ['wide', 'full'], ], // Block fields. 'fields' => [ [ 'id' => 'title', 'name' => 'Title', ], ], ]; return $meta_boxes; } );
General informations
This test come from a new wordpress from scratch.
Edit first article, push the code inside functions.php of twentytwentyfourWordpress Version : 6.5.2
Meta Box: 5.9.7
MetaB Box AIO: 1.26.2 (only MB Block activated)
Theme Twenty Twenty-Four 1.1
PHP 8.2.18 (came from docker image)Activated plugins
Meta Box
Meta Box AIOIf I switch to meta box aio 1.25 all is fine
April 27, 2024 at 4:33 PM #45333Julien
ParticipantSorry for the images
I can't edit
Screenshot from Gutenberg
Screenshot from website
Screenshot from Rest API
April 27, 2024 at 4:37 PM #45334Julien
ParticipantOk I found the problem
We use WordPress only for backend and we use NextJS for the front-end so we need to have API return correct html.
Can you adapt with a referer or something else please ?
April 27, 2024 at 4:48 PM #45335Julien
ParticipantQuick fix could be use with REST_REQUEST: $_GET['context'] === 'edit'
// If block is called via WP-API, thats mean we are in the editor, we need to keep <InnerBlocks /> tag. if ( defined( 'REST_REQUEST' ) && REST_REQUEST && isset($_GET['context']) && $_GET['context'] === 'edit' ) { return $rendered; } $rendered = str_replace( '$', '\$', $rendered ); $rendered = preg_replace( '#<InnerBlocks([^>]*?)/>#', $content, $rendered ); return $rendered;
May 7, 2024 at 3:52 PM #45389Julien
ParticipantAny news ?
May 7, 2024 at 10:20 PM #45394Peter
ModeratorHello Julien,
Thank you for your feedback.
I've shared your idea with the development team to support other JS libraries to get the rendered HTML via Rest API. I will let you know when I have a response from the dev team.
-
AuthorPosts
- You must be logged in to reply to this topic.