/**
* Get set of sitemap link data.
*
* @param string $type Sitemap type.
* @param int $max_entries Entries per sitemap.
* @param int $current_page Current page of the sitemap.
*
* @return array
*/
public function get_sitemap_links($type, $max_entries, $current_page)
{
$links = array();
$post_type = $type;
if (!$this->is_valid_post_type($post_type)) {
return $links;
}
$steps = min(100, $max_entries);
$offset = $current_page > 1 ? ($current_page - 1) * $max_entries : 0;
$total = $offset + $max_entries;
$typecount = $this->get_post_type_count($post_type);
if ($total > $typecount) {
$total = $typecount;
}
if ($current_page === 1) {
$links = array_merge($links, $this->get_first_links($post_type));
}
if ($typecount === 0) {
return $links;
}
$stacked_urls = array();
while ($total > $offset) {
$posts = $this->get_posts($post_type, $steps, $offset);
$offset += $steps;
if (empty($posts)) {
continue;
}
$post_ids = wp_list_pluck($posts, 'ID');
$this->image_parser->cache_attachments($post_ids);
$posts_to_exclude = explode(',', $this->options['excluded-posts']);
foreach ($posts as $post) {
if (WPSEO_Meta::get_value('meta-robots-noindex', $post->ID) === '1') {
continue;
}
if (in_array($post->ID, $posts_to_exclude)) {
continue;
}
$url = $this->get_url($post);
if (!isset($url['loc']) || in_array($url['loc'], $stacked_urls)) {
continue;
}
/**
* Filter URL entry before it gets added to the sitemap.
*
* @param array $url Array of URL parts.
* @param string $type URL type.
* @param object $user Data object for the URL.
*/
$url = apply_filters('wpseo_sitemap_entry', $url, 'post', $post);
if (!empty($url)) {
$links[] = $url;
$stacked_urls[] = $url['loc'];
}
}
unset($post, $url);
}
return $links;
}