spacedmonkey / wp-rest-blocks

Add gutenberg blocks data into post / page / widget REST API endpoints.

Home Page:https://wordpress.org/plugins/rest-api-blocks/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Incorrect core/embed block rendered property

guillaumer opened this issue · comments

Version

Wordpress 5.8.1

Problem

Core/embed block rendered property is not consistent with the regular PHP output as WP_Embed class is not run on the content.

Expected rendered block content (PHP)

\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-4-3 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe title=\"Ed Sheeran, Martin Garrix, Kygo, Dua Lipa, Avicii, The Chainsmokers Style - Feeling Me #78\" width=\"1333\" height=\"1000\" src=\"https://www.youtube.com/embed/ssYbrK0eRZw?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen></iframe>\n</div></figure>\n

API rendered block content

\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-4-3 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\nhttps://www.youtube.com/watch?v=ssYbrK0eRZw\n</div></figure>\

Proposed solution

Either run the_content filter, which might be anyway a good idea in order to get a rendered content as close as possible from the PHP rendering, or use:

global $wp_embed;
$block['rendered'] = $wp_embed->autoembed( $block['rendered'] );

Great job on the plugin, many thanks!