Automattic\WooCommerce\Admin\API
Notes::prepare_item_for_response()
Prepare a note object for serialization.
Method of the class: Notes{}
Hooks from the method
Return
WP_REST_Response
. $response Response data.
Usage
$Notes = new Notes(); $Notes->prepare_item_for_response( $data, $request );
- $data(array) (required)
- Note data.
- $request(WP_REST_Request) (required)
- Request object.
Notes::prepare_item_for_response() Notes::prepare item for response code WC 9.7.1
public function prepare_item_for_response( $data, $request ) { $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; $data = $this->add_additional_fields_to_object( $data, $request ); $data['date_created_gmt'] = wc_rest_prepare_date_response( $data['date_created'] ); $data['date_created'] = wc_rest_prepare_date_response( $data['date_created'], false ); $data['date_reminder_gmt'] = wc_rest_prepare_date_response( $data['date_reminder'] ); $data['date_reminder'] = wc_rest_prepare_date_response( $data['date_reminder'], false ); $data['title'] = stripslashes( $data['title'] ); $data['content'] = stripslashes( $data['content'] ); $data['is_snoozable'] = (bool) $data['is_snoozable']; $data['is_deleted'] = (bool) $data['is_deleted']; $data['is_read'] = (bool) $data['is_read']; foreach ( (array) $data['actions'] as $key => $value ) { $data['actions'][ $key ]->label = stripslashes( $data['actions'][ $key ]->label ); $data['actions'][ $key ]->url = $this->maybe_add_nonce_to_url( $this->prepare_query_for_response( $data['actions'][ $key ]->query ), (string) $data['actions'][ $key ]->nonce_action, (string) $data['actions'][ $key ]->nonce_name ); $data['actions'][ $key ]->status = stripslashes( $data['actions'][ $key ]->status ); } $data = $this->filter_response_by_context( $data, $context ); // Wrap the data in a response object. $response = rest_ensure_response( $data ); $response->add_links( array( 'self' => array( 'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $data['id'] ) ), ), 'collection' => array( 'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ), ), ) ); /** * Filter a note returned from the API. * * Allows modification of the note data right before it is returned. * * @param WP_REST_Response $response The response object. * @param array $data The original note. * @param WP_REST_Request $request Request used to generate the response. * @since 3.9.0 */ return apply_filters( 'woocommerce_rest_prepare_note', $response, $data, $request ); }