wppaste
WordPress

WP_Sitemaps_Index

Since
5.5.0
Source
wp-includes/sitemaps/class-wp-sitemaps-index.php:18
Class WP_Sitemaps_Index.

Description

Builds the sitemap index page that lists the links to all of the sitemaps.

Compatibility

WordPress
since 5.5.0
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0).

Properties · 2

$registryWP_Sitemaps_Registryprotected
The main registry of supported sitemaps.
$max_sitemapsintprivate
Maximum number of sitemaps to include in an index.

Methods · 3

Source code

#[AllowDynamicProperties]class WP_Sitemaps_Index {	/**	 * The main registry of supported sitemaps.	 *	 * @since 5.5.0	 * @var WP_Sitemaps_Registry	 */	protected $registry; 	/**	 * Maximum number of sitemaps to include in an index.	 *	 * @since 5.5.0	 *	 * @var int Maximum number of sitemaps.	 */	private $max_sitemaps = 50000; 	/**	 * WP_Sitemaps_Index constructor.	 *	 * @since 5.5.0	 *	 * @param WP_Sitemaps_Registry $registry Sitemap provider registry.	 */	public function __construct( WP_Sitemaps_Registry $registry ) {		$this->registry = $registry;	} 	/**	 * Gets a sitemap list for the index.	 *	 * @since 5.5.0	 *	 * @return array[] Array of all sitemaps.	 */	public function get_sitemap_list() {		$sitemaps = array(); 		$providers = $this->registry->get_providers();		/* @var WP_Sitemaps_Provider $provider */		foreach ( $providers as $name => $provider ) {			$sitemap_entries = $provider->get_sitemap_entries(); 			// Prevent issues with array_push and empty arrays on PHP < 7.3.			if ( ! $sitemap_entries ) {				continue;			} 			// Using array_push is more efficient than array_merge in a loop.			array_push( $sitemaps, ...$sitemap_entries );			if ( count( $sitemaps ) >= $this->max_sitemaps ) {				break;			}		} 		return array_slice( $sitemaps, 0, $this->max_sitemaps, true );	} 	/**	 * Builds the URL for the sitemap index.	 *	 * @since 5.5.0	 *	 * @global WP_Rewrite $wp_rewrite WordPress rewrite component.	 *	 * @return string The sitemap index URL.	 */	public function get_index_url() {		global $wp_rewrite; 		if ( ! $wp_rewrite->using_permalinks() ) {			return home_url( '/?sitemap=index' );		} 		return home_url( '/wp-sitemap.xml' );	}}

Changelog

Introduced in 5.5.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 6.7.7 tag, from src/wp-includes/sitemaps/class-wp-sitemaps-index.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.