Automattic\WooCommerce\StoreApi\Utilities
Pagination::add_headers()
Add pagination headers to a response object.
Method of the class: Pagination{}
No Hooks.
Return
\WP_REST_Response
.
Usage
$Pagination = new Pagination(); $Pagination->add_headers( $response, $request, $total_items, $total_pages );
- $response(\WP_REST_Response) (required)
- Reference to the response object.
- $request(\WP_REST_Request) (required)
- The request object.
- $total_items(int) (required)
- Total items found.
- $total_pages(int) (required)
- Total pages found.
Pagination::add_headers() Pagination::add headers code WC 9.8.2
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; }