Automattic\WooCommerce\Internal\RestApi\Routes\V4
AbstractController::prepare_item_for_response
Prepares the item for the REST response. Controllers do not need to override this method as they can define a get_item_response method to prepare items. This method will take care of filter hooks.
Method of the class: AbstractController{}
Hooks from the method
Returns
WP_REST_Response|WP_Error. Response object on success, or WP_Error object on failure.
Usage
$AbstractController = new AbstractController(); $AbstractController->prepare_item_for_response( $item, $request );
- $item(mixed) (required)
- WordPress representation of the item.
- $request(WP_REST_Request) (required)
- Request object.
Changelog
| Since 10.2.0 | Introduced. |
AbstractController::prepare_item_for_response() AbstractController::prepare item for response code WC 10.4.3
public function prepare_item_for_response( $item, $request ) {
$response_data = $this->get_item_response( $item, $request );
$response_data = $this->add_additional_fields_to_object( $response_data, $request );
$response_data = $this->filter_response_by_context( $response_data, $request['context'] ?? 'view' );
$response = rest_ensure_response( $response_data );
$response->add_links( $this->prepare_links( $item, $request, $response ) );
/**
* Filter the data for a response.
*
* @param WP_REST_Response $response The response object.
* @param mixed $item WordPress representation of the item.
* @param WP_REST_Request $request Request object.
* @since 10.2.0
*/
return rest_ensure_response( apply_filters( $this->get_hook_prefix() . 'item_response', $response, $item, $request ) );
}