WP_REST_Blocks_Controller::filter_response_by_context
Filters a response based on the context defined in the schema.
Method of the class: WP_REST_Blocks_Controller{}
No Hooks.
Returns
Array. Filtered response.
Usage
$WP_REST_Blocks_Controller = new WP_REST_Blocks_Controller(); $WP_REST_Blocks_Controller->filter_response_by_context( $data, $context );
- $data(array) (required)
- Response data to filter.
- $context(string) (required)
- Context defined in the schema.
Changelog
| Since 5.0.0 | Introduced. |
| Since 6.3.0 | Adds the wp_pattern_sync_status postmeta property to the top level of response. |
WP_REST_Blocks_Controller::filter_response_by_context() WP REST Blocks Controller::filter response by context code WP 7.0
public function filter_response_by_context( $data, $context ) {
$data = parent::filter_response_by_context( $data, $context );
/*
* Remove `title.rendered` and `content.rendered` from the response.
* It doesn't make sense for a pattern to have rendered content on its own,
* since rendering a block requires it to be inside a post or a page.
*/
unset( $data['title']['rendered'] );
unset( $data['content']['rendered'] );
// Add the core wp_pattern_sync_status meta as top level property to the response.
$data['wp_pattern_sync_status'] = $data['meta']['wp_pattern_sync_status'] ?? '';
unset( $data['meta']['wp_pattern_sync_status'] );
return $data;
}