WordPress at a glance
function is not described

WP_REST_Post_Statuses_Controller::prepare_item_for_response() WP 4.7.0

Prepares a post status object for serialization.

This is a method of the class: WP_REST_Post_Statuses_Controller

Hooks from the method
Return

WP_REST_Response. Post status data.

Usage

$WP_REST_Post_Statuses_Controller = new WP_REST_Post_Statuses_Controller();
$var = $WP_REST_Post_Statuses_Controller->prepare_item_for_response( $status, $request );
$status(stdClass) (required)
Post status data.
$request(WP_REST_Request) (required)
Full details about the request.

Changelog

Since 4.7.0 Introduced.

Code of WP REST Post Statuses Controller::prepare item for response: wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php WP 5.4.1

<?php
public function prepare_item_for_response( $status, $request ) {

	$fields = $this->get_fields_for_response( $request );
	$data   = array();

	if ( in_array( 'name', $fields, true ) ) {
		$data['name'] = $status->label;
	}

	if ( in_array( 'private', $fields, true ) ) {
		$data['private'] = (bool) $status->private;
	}

	if ( in_array( 'protected', $fields, true ) ) {
		$data['protected'] = (bool) $status->protected;
	}

	if ( in_array( 'public', $fields, true ) ) {
		$data['public'] = (bool) $status->public;
	}

	if ( in_array( 'queryable', $fields, true ) ) {
		$data['queryable'] = (bool) $status->publicly_queryable;
	}

	if ( in_array( 'show_in_list', $fields, true ) ) {
		$data['show_in_list'] = (bool) $status->show_in_admin_all_list;
	}

	if ( in_array( 'slug', $fields, true ) ) {
		$data['slug'] = $status->name;
	}

	if ( in_array( 'date_floating', $fields, true ) ) {
		$data['date_floating'] = $status->date_floating;
	}

	$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
	$data    = $this->add_additional_fields_to_object( $data, $request );
	$data    = $this->filter_response_by_context( $data, $context );

	$response = rest_ensure_response( $data );

	if ( 'publish' === $status->name ) {
		$response->add_link( 'archives', rest_url( 'wp/v2/posts' ) );
	} else {
		$response->add_link( 'archives', add_query_arg( 'status', $status->name, rest_url( 'wp/v2/posts' ) ) );
	}

	/**
	 * Filters a status returned from the REST API.
	 *
	 * Allows modification of the status data right before it is returned.
	 *
	 * @since 4.7.0
	 *
	 * @param WP_REST_Response $response The response object.
	 * @param object           $status   The original status object.
	 * @param WP_REST_Request  $request  Request used to generate the response.
	 */
	return apply_filters( 'rest_prepare_status', $response, $status, $request );
}