Prepare a raw block pattern category before it gets output in a REST API response.
Parameters
$item
arrayrequired- Raw category as registered, before any changes.
$request
WP_REST_Requestrequired- Request object.
Source
public function prepare_item_for_response( $item, $request ) {
$fields = $this->get_fields_for_response( $request );
$keys = array( 'name', 'label', 'description' );
$data = array();
foreach ( $keys as $key ) {
if ( isset( $item[ $key ] ) && rest_is_field_included( $key, $fields ) ) {
$data[ $key ] = $item[ $key ];
}
}
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
$data = $this->add_additional_fields_to_object( $data, $request );
$data = $this->filter_response_by_context( $data, $context );
return rest_ensure_response( $data );
}
Changelog
Version | Description |
---|---|
6.0.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.