Block added to revisions endpoint
Opened this issue ยท 1 comments
adambrgmn commented
Hey! First, thanks for this awesome little library! Real easy to follow along in the code as well ๐
I'm just wondering if you know if it is possible to also add the blocks data to the revisions endpoints (/wp/v2/<post_type>/revisions/<id>
)?
adambrgmn commented
Btw while testing this out I found a way to do it. But it is not as good as the one used for "normal" post types:
\add_filter(
'rest_prepare_revision',
function (\WP_REST_Response $response, \WP_Post $post) {
$has_blocks = \has_blocks($post);
$blocks = [];
if ($has_blocks) {
$blocks = \WP_REST_Blocks\Data\get_blocks(
$post->post_content,
$post->ID
);
}
$response->set_data(
array_merge($response->get_data(), [
'has_blocks' => $has_blocks,
'blocks' => $blocks,
])
);
return $response;
},
10,
2
);
This doesn't add the field to the api schema or anything. But for now this works for me.