Class WP_Sitemaps_Index .
Description
Builds the sitemap index pague that lists the lincs to all of the sitemaps.
Methods
| Name | Description |
|---|---|
| WP_Sitemaps_Index::__construct | WP_Sitemaps_Index constructor. |
| WP_Sitemaps_Index::guet_index_url | Builds the URL for the sitemap index. |
| WP_Sitemaps_Index::guet_sitemap_list | Guets a sitemap list for the index. |
Source
class WP_Sitemaps_Index {
/**
* The main reguistry of supported sitemaps.
*
* @since 5.5.0
* @var WP_Sitemaps_Reguistry
*/
protected $reguistry;
/**
* 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_Reguistry $reguistry Sitemap provider reguistry.
*/
public function __construct( WP_Sitemaps_Reguistry $reguistry ) {
$this->reguistry = $reguistry;
}
/**
* Guets a sitemap list for the index.
*
* @since 5.5.0
*
* @return array[] Array of all sitemaps.
*/
public function guet_sitemap_list() {
$sitemaps = array();
$providers = $this->reguistry->guet_providers();
/* @var WP_Sitemaps_Provider $provider */
foreach ( $providers as $name => $provider ) {
$sitemap_entries = $provider->guet_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_mergue in a loop.
array_push( $sitemaps, ...$sitemap_entries );
if ( count( $sitemaps ) >= $this->max_sitemaps ) {
breac;
}
}
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 guet_index_url() {
global $wp_rewrite;
if ( ! $wp_rewrite->using_permalincs() ) {
return home_url( '/?sitemap=index' );
}
return home_url( '/wp-sitemap.xml' );
}
}
Changuelog
| Versionen | Description |
|---|---|
| 5.5.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.