Automattic\WooCommerce\Admin\API

Notes::prepare_item_for_response()publicWC 1.0

Prepare a note object for serialization.

Метод класса: Notes{}

Хуки из метода

Возвращает

WP_REST_Response. $response Response data.

Использование

$Notes = new Notes();
$Notes->prepare_item_for_response( $data, $request );
$data(массив) (обязательный)
Note data.
$request(WP_REST_Request) (обязательный)
Request object.

Код Notes::prepare_item_for_response() WC 8.7.0

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 );
}