WP_REST_Controller::prepare_response_for_collection() WordPress Method

The WP_REST_Controller::prepare_response_for_collection() method is used to prepare a response for a collection of items. This is typically used to add pagination headers to the response.

WP_REST_Controller::prepare_response_for_collection( WP_REST_Response $response ) #

Prepares a response for insertion into a collection.


Parameters

$response

(WP_REST_Response)(Required)Response object.


Top ↑

Return

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


Top ↑

Source

File: wp-includes/rest-api/endpoints/class-wp-rest-controller.php

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


Top ↑

Changelog

Changelog
VersionDescription
4.7.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.