WC_REST_Customer_Downloads_V2_Controller::prepare_item_for_response
Prepare a single download output for response.
Method of the class: WC_REST_Customer_Downloads_V2_Controller{}
Hooks from the method
Returns
WP_REST_Response. $response Response data.
Usage
$WC_REST_Customer_Downloads_V2_Controller = new WC_REST_Customer_Downloads_V2_Controller(); $WC_REST_Customer_Downloads_V2_Controller->prepare_item_for_response( $download, $request );
- $download(stdClass) (required)
- Download object.
- $request(WP_REST_Request) (required)
- Request object.
WC_REST_Customer_Downloads_V2_Controller::prepare_item_for_response() WC REST Customer Downloads V2 Controller::prepare item for response code WC 10.3.6
public function prepare_item_for_response( $download, $request ) {
$data = array(
'download_id' => $download->download_id,
'download_url' => $download->download_url,
'product_id' => $download->product_id,
'product_name' => $download->product_name,
'download_name' => $download->download_name,
'order_id' => $download->order_id,
'order_key' => $download->order_key,
'downloads_remaining' => '' === $download->downloads_remaining ? 'unlimited' : $download->downloads_remaining,
'access_expires' => $download->access_expires ? wc_rest_prepare_date_response( $download->access_expires ) : 'never',
'access_expires_gmt' => $download->access_expires ? wc_rest_prepare_date_response( get_gmt_from_date( $download->access_expires ) ) : 'never',
'file' => $download->file,
);
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
$data = $this->add_additional_fields_to_object( $data, $request );
$data = $this->filter_response_by_context( $data, $context );
// Wrap the data in a response object.
$response = rest_ensure_response( $data );
$response->add_links( $this->prepare_links( $download, $request ) );
/**
* Filter customer download data returned from the REST API.
*
* @param WP_REST_Response $response The response object.
* @param stdClass $download Download object used to create response.
* @param WP_REST_Request $request Request object.
*/
return apply_filters( 'woocommerce_rest_prepare_customer_download', $response, $download, $request );
}