LLMS_REST_Controller::add_header_pagination( WP_REST_Response $response, array $pagination, WP_REST_Request $request )

Add pagination info and links to the response header.


Parameters Parameters

$response

(WP_REST_Response) (Required) Current response being served.

$pagination

(array) (Required) Pagination array.

$request

(WP_REST_Request) (Required) Full details about the request.


Top ↑

Return Return

(WP_REST_Response)


Top ↑

Source Source

File: libraries/lifterlms-rest/includes/abstracts/class-llms-rest-controller.php

	protected function prepare_collection_items_for_response( $objects, $request ) {

		$items = array();

		foreach ( $objects as $object ) {
			$object = $this->get_object( $object, false );

			if ( ! $this->check_read_object_permissions( $object ) ) {
				continue;
			}

			$item = $this->prepare_item_for_response( $object, $request );
			if ( ! is_wp_error( $item ) ) {
				$items[] = $this->prepare_response_for_collection( $item );
			}
		}

		return $items;
	}

	/**
	 * Add pagination info and links to the response header.
	 *
	 * @since 1.0.0-beta.7
	 *
	 * @param WP_REST_Response $response   Current response being served.
	 * @param array            $pagination Pagination array.
	 * @param WP_REST_Request  $request    Full details about the request.
	 * @return WP_REST_Response
	 */
	protected function add_header_pagination( $response, $pagination, $request ) {

		$response->header( 'X-WP-Total', $pagination['total_results'] );
		$response->header( 'X-WP-TotalPages', $pagination['total_pages'] );

		$base = add_query_arg( urlencode_deep( $request->get_query_params() ), rest_url( $request->get_route() ) );

		// First page link.


Top ↑

Changelog Changelog

Changelog
Version Description
1.0.0-beta.7 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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