WP_REST_Navigation_Fallback_Controller::prepare_item_for_response( WP_Post $item, WP_REST_Request $request ): WP_REST_Response

In this article

Matches the post data to the schema we want.

Parameters

$itemWP_Postrequired
The wp_navigation Post object whose response is being prepared.
$requestWP_REST_Requestrequired
Request object.

Return

WP_REST_Response $response The response data.

Source

public function prepare_item_for_response( $item, $request ) {
	$data = array();

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

	if ( rest_is_field_included( 'id', $fields ) ) {
		$data['id'] = (int) $item->ID;
	}

	$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 ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
		$links = $this->prepare_links( $item );
		$response->add_links( $links );
	}

	return $response;
}

Changelog

VersionDescription
6.3.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.