WP_REST_Template_Autosaves_Controller::prepare_item_for_response()publicWP 6.4.0

Prepares the item for the REST response.

Method of the class: WP_REST_Template_Autosaves_Controller{}

No Hooks.

Return

WP_REST_Response. Response object.

Usage

$WP_REST_Template_Autosaves_Controller = new WP_REST_Template_Autosaves_Controller();
$WP_REST_Template_Autosaves_Controller->prepare_item_for_response( $item, $request );
$item(WP_Post) (required)
Post revision object.
$request(WP_REST_Request) (required)
Request object.

Changelog

Since 6.4.0 Introduced.

WP_REST_Template_Autosaves_Controller::prepare_item_for_response() code WP 6.6.2

public function prepare_item_for_response( $item, $request ) {
	$template = _build_block_template_result_from_post( $item );
	$response = $this->parent_controller->prepare_item_for_response( $template, $request );

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

	if ( in_array( 'parent', $fields, true ) ) {
		$data['parent'] = (int) $item->post_parent;
	}

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

	// Wrap the data in a response object.
	$response = new WP_REST_Response( $data );

	if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
		$links = $this->prepare_links( $template );
		$response->add_links( $links );
	}

	return $response;
}