PHP 8.2.31
Preview: Pagination.php Size: 2.05 KB
/home/nshryvcy/radiantskinclinics.org/wp-content/plugins/woocommerce/src/StoreApi/Utilities/Pagination.php

<?php
namespace Automattic\WooCommerce\StoreApi\Utilities;

/**
 * Pagination class.
 */
class Pagination {

	/**
	 * Add pagination headers to a response object.
	 *
	 * @param \WP_REST_Response $response Reference to the response object.
	 * @param \WP_REST_Request  $request The request object.
	 * @param int               $total_items Total items found.
	 * @param int               $total_pages Total pages found.
	 * @return \WP_REST_Response
	 */
	public function add_headers( $response, $request, $total_items, $total_pages ) {
		$response->header( 'X-WP-Total', $total_items );
		$response->header( 'X-WP-TotalPages', $total_pages );

		$current_page = $this->get_current_page( $request );
		$link_base    = $this->get_link_base( $request );

		if ( $current_page > 1 ) {
			$previous_page = $current_page - 1;
			if ( $previous_page > $total_pages ) {
				$previous_page = $total_pages;
			}
			$this->add_page_link( $response, 'prev', $previous_page, $link_base );
		}

		if ( $total_pages > $current_page ) {
			$this->add_page_link( $response, 'next', ( $current_page + 1 ), $link_base );
		}

		return $response;
	}

	/**
	 * Get current page.
	 *
	 * @param \WP_REST_Request $request The request object.
	 * @return int Get the page from the request object.
	 */
	protected function get_current_page( $request ) {
		return (int) $request->get_param( 'page' );
	}

	/**
	 * Get base for links from the request object.
	 *
	 * @param \WP_REST_Request $request The request object.
	 * @return string
	 */
	protected function get_link_base( $request ) {
		return esc_url( add_query_arg( $request->get_query_params(), rest_url( $request->get_route() ) ) );
	}

	/**
	 * Add a page link.
	 *
	 * @param \WP_REST_Response $response Reference to the response object.
	 * @param string            $name Page link name. e.g. prev.
	 * @param int               $page Page number.
	 * @param string            $link_base Base URL.
	 */
	protected function add_page_link( &$response, $name, $page, $link_base ) {
		$response->link_header( $name, add_query_arg( 'page', $page, $link_base ) );
	}
}

Directory Contents

Dirs: 0 × Files: 21

Name Size Perms Modified Actions
14.76 KB lrw-r--r-- 2026-02-23 17:58:34
Edit Download
1.49 KB lrw-r--r-- 2024-04-30 19:35:34
Edit Download
48.42 KB lrw-r--r-- 2026-03-12 20:10:34
Edit Download
1.81 KB lrw-r--r-- 2025-06-23 19:46:28
Edit Download
10.82 KB lrw-r--r-- 2025-06-23 19:46:28
Edit Download
1.76 KB lrw-r--r-- 2024-09-04 20:34:26
Edit Download
5.45 KB lrw-r--r-- 2025-07-29 12:34:58
Edit Download
5.67 KB lrw-r--r-- 2026-01-19 14:46:18
Edit Download
2.02 KB lrw-r--r-- 2025-03-03 22:28:12
Edit Download
3.29 KB lrw-r--r-- 2025-12-22 17:20:32
Edit Download
32.10 KB lrw-r--r-- 2026-05-05 14:26:50
Edit Download
2.05 KB lrw-r--r-- 2023-12-27 00:45:02
Edit Download
3.65 KB lrw-r--r-- 2025-05-12 21:07:28
Edit Download
3.54 KB lrw-r--r-- 2026-03-30 17:12:24
Edit Download
1.82 KB lrw-r--r-- 2026-03-30 17:12:24
Edit Download
21.61 KB lrw-r--r-- 2026-05-05 14:26:50
Edit Download
9.25 KB lrw-r--r-- 2025-07-29 12:34:58
Edit Download
10.11 KB lrw-r--r-- 2025-07-29 12:34:58
Edit Download
6.14 KB lrw-r--r-- 2025-03-03 22:28:12
Edit Download
794 B lrw-r--r-- 2024-02-27 18:59:46
Edit Download
1.73 KB lrw-r--r-- 2023-12-27 00:45:02
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).