WP_REST_Controller::prepare_response_for_collection()publicWP 4.7.0

Prepares a response for insertion into a collection.

Method of the class: WP_REST_Controller{}

No Hooks.

Return

Array|Mixed. Response data, ready for insertion into collection data.

Usage

$WP_REST_Controller = new WP_REST_Controller();
$WP_REST_Controller->prepare_response_for_collection( $response );
$response(WP_REST_Response) (required)
Response object.

Changelog

Since 4.7.0 Introduced.

WP_REST_Controller::prepare_response_for_collection() code WP 6.5.2

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