WP_REST_Controller::prepare_response_for_collection( WP_REST_Response $response ): array|mixed

In this article

Prepares a response for insertion into a collection.

Parameters

$responseWP_REST_Responserequired
Response object.

Return

array|mixed Response data, ready for insertion into collection data.

Source

public function prepare_response_for_collection( $response ) {
	if ( ! ( $response instanceof WP_REST_Response ) ) {
		return $response;
	}

	$data   = (array) $response->get_data();
	$server = rest_get_server();
	$links  = $server::get_compact_response_links( $response );

	if ( ! empty( $links ) ) {
		$data['_links'] = $links;
	}

	return $data;
}

Changelog

VersionDescription
4.7.0Introduced.

User Contributed Notes

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