Hooks into the REST API response for the Posts endpoint and adds the first and last inner blocks.
Parameters
$response
WP_REST_Responserequired- The response object.
$post
WP_Postrequired- Post object.
Source
function insert_hooked_blocks_into_rest_response( $response, $post ) { if ( empty( $response->data['content']['raw'] ) ) { return $response; } $response->data['content']['raw'] = apply_block_hooks_to_content_from_post_object( $response->data['content']['raw'], $post, 'insert_hooked_blocks_and_set_ignored_hooked_blocks_metadata' ); // If the rendered content was previously empty, we leave it like that. if ( empty( $response->data['content']['rendered'] ) ) { return $response; } // `apply_block_hooks_to_content` is called above. Ensure it is not called again as a filter. $priority = has_filter( 'the_content', 'apply_block_hooks_to_content_from_post_object' ); if ( false !== $priority ) { remove_filter( 'the_content', 'apply_block_hooks_to_content_from_post_object', $priority ); } /** This filter is documented in wp-includes/post-template.php */ $response->data['content']['rendered'] = apply_filters( 'the_content', $response->data['content']['raw'] ); // Restore the filter if it was set initially. if ( false !== $priority ) { add_filter( 'the_content', 'apply_block_hooks_to_content_from_post_object', $priority ); } return $response; }
Hooks
- apply_filters( ‘the_content’,
string $content ) Filters the post content.
User Contributed Notes
You must log in before being able to contribute a note or feedback.