Skip to content

Instantly share code, notes, and snippets.

@kellymears
Created August 13, 2019 16:13
Show Gist options
  • Save kellymears/d0f55de50a1928727a4638d452f5b413 to your computer and use it in GitHub Desktop.
Save kellymears/d0f55de50a1928727a4638d452f5b413 to your computer and use it in GitHub Desktop.
<?php
add_action('rest_api_init', function () {
!function_exists('use_block_editor_for_post_type') &&
require ABSPATH . 'wp-admin/includes/post.php';
$postTypes = collect(
get_post_types_by_support(['editor'])
);
$postTypes->each(function ($postType) {
use_block_editor_for_post_type($postType)
&& register_rest_field($postType, 'blocks', [
'get_callback' => function (array $post) {
return parse_blocks($post['content']['raw']);
}
]);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment