Skip to content

Instantly share code, notes, and snippets.

@terence1990
Last active January 22, 2021 11:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save terence1990/223aa816df7d600005e55c39e9598b5d to your computer and use it in GitHub Desktop.
Save terence1990/223aa816df7d600005e55c39e9598b5d to your computer and use it in GitHub Desktop.
Adjusting Gutenberg Block output in REST Response
<?php
#resources/controllers/ApiController.php
public function boot(Request $request) {
filter('rest_response_parse_blocks', function( $blocks ) {
foreach($blocks as &$block) {
$block = (object) [
'name' => $block->blockName,
'innerBlocks' => $block->innerBlocks,
'innerText' => trim(preg_replace('/\s\s+/', ' ', strip_tags( $block->innerHTML ))),
'data' => $block->attrs
];
}
return $blocks;
}, 20);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment