WC_REST_Customer_Downloads_V1_Controller::prepare_item_for_response()
Prepare a single download output for response.
Метод класса: WC_REST_Customer_Downloads_V1_Controller{}
Хуки из метода
Возвращает
WP_REST_Response
. $response Response data.
Использование
$WC_REST_Customer_Downloads_V1_Controller = new WC_REST_Customer_Downloads_V1_Controller(); $WC_REST_Customer_Downloads_V1_Controller->prepare_item_for_response( $download, $request );
- $download(stdObject) (обязательный)
- Download object.
- $request(WP_REST_Request) (обязательный)
- Request object.
Код WC_REST_Customer_Downloads_V1_Controller::prepare_item_for_response() WC REST Customer Downloads V1 Controller::prepare item for response WC 9.2.3
public function prepare_item_for_response( $download, $request ) { $data = (array) $download; $data['access_expires'] = $data['access_expires'] ? wc_rest_prepare_date_response( $data['access_expires'] ) : 'never'; $data['downloads_remaining'] = '' === $data['downloads_remaining'] ? 'unlimited' : $data['downloads_remaining']; // Remove "product_name" since it's new in 3.0. unset( $data['product_name'] ); $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 stdObject $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 ); }