public function add_pagination_headers($query)
{
// WP_User_Query
if (is_a($query, 'WP_User_Query')) {
$page = $query->page;
$single = count($query->get_results()) == 1;
$total = $query->get_total();
$total_pages = $query->total_pages;
// WP_Query
} else {
$page = $query->get('paged');
$single = $query->is_single();
$total = $query->found_posts;
$total_pages = $query->max_num_pages;
}
if (!$page) {
$page = 1;
}
$next_page = absint($page) + 1;
if (!$single) {
// first/prev
if ($page > 1) {
$this->link_header('first', $this->get_paginated_url(1));
$this->link_header('prev', $this->get_paginated_url($page - 1));
}
// next
if ($next_page <= $total_pages) {
$this->link_header('next', $this->get_paginated_url($next_page));
}
// last
if ($page != $total_pages) {
$this->link_header('last', $this->get_paginated_url($total_pages));
}
}
$this->header('X-WC-Total', $total);
$this->header('X-WC-TotalPages', $total_pages);
do_action('woocommerce_api_pagination_headers', $this, $query);
}