Sitemaps: Correctly enforce maximum number of sitemaps in index.
Before this change, the limit of 50k entries was enforced for the number of providers, not the amount of sitemaps all providers add to the index in total. Props pbiron, swissspidy. Fixes #50666. Built from https://develop.svn.wordpress.org/trunk@48532 git-svn-id: http://core.svn.wordpress.org/trunk@48294 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
6d207771d3
commit
1f27914191
|
@ -24,6 +24,15 @@ class WP_Sitemaps_Index {
|
|||
*/
|
||||
protected $registry;
|
||||
|
||||
/**
|
||||
* Maximum number of sitemaps to include in an index.
|
||||
*
|
||||
* @sincee 5.5.0
|
||||
*
|
||||
* @var int Maximum number of sitemaps.
|
||||
*/
|
||||
private $max_sitemaps = 50000;
|
||||
|
||||
/**
|
||||
* WP_Sitemaps_Index constructor.
|
||||
*
|
||||
|
@ -47,7 +56,7 @@ class WP_Sitemaps_Index {
|
|||
|
||||
$providers = $this->registry->get_sitemaps();
|
||||
/* @var WP_Sitemaps_Provider $provider */
|
||||
foreach ( $providers as $provider ) {
|
||||
foreach ( $providers as $name => $provider ) {
|
||||
$sitemap_entries = $provider->get_sitemap_entries();
|
||||
|
||||
// Prevent issues with array_push and empty arrays on PHP < 7.3.
|
||||
|
@ -57,9 +66,12 @@ class WP_Sitemaps_Index {
|
|||
|
||||
// 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 $sitemaps;
|
||||
return array_slice( $sitemaps, 0, $this->max_sitemaps, true );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -24,15 +24,6 @@ class WP_Sitemaps_Registry {
|
|||
*/
|
||||
private $sitemaps = array();
|
||||
|
||||
/**
|
||||
* Maximum number of sitemaps to include in an index.
|
||||
*
|
||||
* @sincee 5.5.0
|
||||
*
|
||||
* @var int Maximum number of sitemaps.
|
||||
*/
|
||||
private $max_sitemaps = 50000;
|
||||
|
||||
/**
|
||||
* Adds a sitemap with route to the registry.
|
||||
*
|
||||
|
@ -69,19 +60,13 @@ class WP_Sitemaps_Registry {
|
|||
}
|
||||
|
||||
/**
|
||||
* Lists all registered sitemaps.
|
||||
* Returns all registered sitemap providers.
|
||||
*
|
||||
* @since 5.5.0
|
||||
*
|
||||
* @return WP_Sitemaps_Provider[] Array of sitemap providers.
|
||||
*/
|
||||
public function get_sitemaps() {
|
||||
$total_sitemaps = count( $this->sitemaps );
|
||||
|
||||
if ( $total_sitemaps > $this->max_sitemaps ) {
|
||||
return array_slice( $this->sitemaps, 0, $this->max_sitemaps, true );
|
||||
}
|
||||
|
||||
return $this->sitemaps;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '5.5-beta2-48531';
|
||||
$wp_version = '5.5-beta2-48532';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue