insert_hooked_blocks_into_rest_response()
Hooks into the REST API response for the Posts endpoint and adds the first and last inner blocks.
Hooks from the function
Returns
WP_REST_Response
. The response object.
Usage
insert_hooked_blocks_into_rest_response( $response, $post );
- $response(WP_REST_Response) (required)
- The response object.
- $post(WP_Post) (required)
- Post object.
Changelog
Since 6.6.0 | Introduced. |
Since 6.8.0 | Support non-wp_navigation post types. |
insert_hooked_blocks_into_rest_response() insert hooked blocks into rest response code WP 6.8.1
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; }