Sitemaps: Rename 'sitemap' to 'provider' in WP_Sitemaps_Registry
class.
This class is for registering sitemap providers, not individual sitemaps. Props swissspidy. Fixes #50724. git-svn-id: https://develop.svn.wordpress.org/trunk@48536 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
5ffe591bec
commit
383540b7c4
@ -58,7 +58,7 @@ function wp_get_sitemaps() {
|
||||
return array();
|
||||
}
|
||||
|
||||
return $sitemaps->registry->get_sitemaps();
|
||||
return $sitemaps->registry->get_providers();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -77,7 +77,7 @@ function wp_register_sitemap( $name, WP_Sitemaps_Provider $provider ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $sitemaps->registry->add_sitemap( $name, $provider );
|
||||
return $sitemaps->registry->add_provider( $name, $provider );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -54,7 +54,7 @@ class WP_Sitemaps_Index {
|
||||
public function get_sitemap_list() {
|
||||
$sitemaps = array();
|
||||
|
||||
$providers = $this->registry->get_sitemaps();
|
||||
$providers = $this->registry->get_providers();
|
||||
/* @var WP_Sitemaps_Provider $provider */
|
||||
foreach ( $providers as $name => $provider ) {
|
||||
$sitemap_entries = $provider->get_sitemap_entries();
|
||||
|
@ -2,7 +2,7 @@
|
||||
/**
|
||||
* Sitemaps: WP_Sitemaps_Registry class
|
||||
*
|
||||
* Handles registering sitemaps.
|
||||
* Handles registering sitemap providers.
|
||||
*
|
||||
* @package WordPress
|
||||
* @subpackage Sitemaps
|
||||
@ -16,47 +16,47 @@
|
||||
*/
|
||||
class WP_Sitemaps_Registry {
|
||||
/**
|
||||
* Registered sitemaps.
|
||||
* Registered sitemap providers.
|
||||
*
|
||||
* @since 5.5.0
|
||||
*
|
||||
* @var WP_Sitemaps_Provider[] Array of registered sitemaps.
|
||||
* @var WP_Sitemaps_Provider[] Array of registered sitemap providers.
|
||||
*/
|
||||
private $sitemaps = array();
|
||||
private $providers = array();
|
||||
|
||||
/**
|
||||
* Adds a sitemap with route to the registry.
|
||||
*
|
||||
* @since 5.5.0
|
||||
*
|
||||
* @param string $name Name of the sitemap.
|
||||
* @param string $name Name of the sitemap provider.
|
||||
* @param WP_Sitemaps_Provider $provider Instance of a WP_Sitemaps_Provider.
|
||||
* @return bool True if the sitemap was added, false if it is already registered.
|
||||
* @return bool True if the provider was added, false if it is already registered.
|
||||
*/
|
||||
public function add_sitemap( $name, WP_Sitemaps_Provider $provider ) {
|
||||
if ( isset( $this->sitemaps[ $name ] ) ) {
|
||||
public function add_provider( $name, WP_Sitemaps_Provider $provider ) {
|
||||
if ( isset( $this->providers[ $name ] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->sitemaps[ $name ] = $provider;
|
||||
$this->providers[ $name ] = $provider;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a single registered sitemaps provider.
|
||||
* Returns a single registered sitemap provider.
|
||||
*
|
||||
* @since 5.5.0
|
||||
*
|
||||
* @param string $name Sitemap provider name.
|
||||
* @return WP_Sitemaps_Provider|null Sitemaps provider if it exists, null otherwise.
|
||||
*/
|
||||
public function get_sitemap( $name ) {
|
||||
if ( ! isset( $this->sitemaps[ $name ] ) ) {
|
||||
public function get_provider( $name ) {
|
||||
if ( ! isset( $this->providers[ $name ] ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->sitemaps[ $name ];
|
||||
return $this->providers[ $name ];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -66,7 +66,7 @@ class WP_Sitemaps_Registry {
|
||||
*
|
||||
* @return WP_Sitemaps_Provider[] Array of sitemap providers.
|
||||
*/
|
||||
public function get_sitemaps() {
|
||||
return $this->sitemaps;
|
||||
public function get_providers() {
|
||||
return $this->providers;
|
||||
}
|
||||
}
|
||||
|
@ -135,7 +135,7 @@ class WP_Sitemaps {
|
||||
// Register each supported provider.
|
||||
/* @var WP_Sitemaps_Provider $provider */
|
||||
foreach ( $providers as $name => $provider ) {
|
||||
$this->registry->add_sitemap( $name, $provider );
|
||||
$this->registry->add_provider( $name, $provider );
|
||||
}
|
||||
}
|
||||
|
||||
@ -212,7 +212,7 @@ class WP_Sitemaps {
|
||||
exit;
|
||||
}
|
||||
|
||||
$provider = $this->registry->get_sitemap( $sitemap );
|
||||
$provider = $this->registry->get_provider( $sitemap );
|
||||
|
||||
if ( ! $provider ) {
|
||||
return;
|
||||
|
@ -13,8 +13,8 @@ class Test_WP_Sitemaps_Index extends WP_UnitTestCase {
|
||||
* There are 2 providers registered.
|
||||
* Hence, 3*4*2=24.
|
||||
*/
|
||||
$registry->add_sitemap( 'foo', new WP_Sitemaps_Test_Provider( 'foo' ) );
|
||||
$registry->add_sitemap( 'bar', new WP_Sitemaps_Test_Provider( 'bar' ) );
|
||||
$registry->add_provider( 'foo', new WP_Sitemaps_Test_Provider( 'foo' ) );
|
||||
$registry->add_provider( 'bar', new WP_Sitemaps_Test_Provider( 'bar' ) );
|
||||
|
||||
$sitemap_index = new WP_Sitemaps_Index( $registry );
|
||||
$this->assertCount( 24, $sitemap_index->get_sitemap_list() );
|
||||
@ -29,12 +29,12 @@ class Test_WP_Sitemaps_Index extends WP_UnitTestCase {
|
||||
$registry = new WP_Sitemaps_Registry();
|
||||
|
||||
// add 3 providers, which combined produce more than the maximum 50000 sitemaps in the index.
|
||||
$registry->add_sitemap( 'provider_1', new WP_Sitemaps_Large_Test_Provider( 25000 ) );
|
||||
$registry->add_sitemap( 'provider_2', new WP_Sitemaps_Large_Test_Provider( 25000 ) );
|
||||
$registry->add_sitemap( 'provider_3', new WP_Sitemaps_Large_Test_Provider( 25000 ) );
|
||||
$registry->add_provider( 'provider_1', new WP_Sitemaps_Large_Test_Provider( 25000 ) );
|
||||
$registry->add_provider( 'provider_2', new WP_Sitemaps_Large_Test_Provider( 25000 ) );
|
||||
$registry->add_provider( 'provider_3', new WP_Sitemaps_Large_Test_Provider( 25000 ) );
|
||||
|
||||
$count = 0;
|
||||
foreach ( $registry->get_sitemaps() as $provider ) {
|
||||
foreach ( $registry->get_providers() as $provider ) {
|
||||
$count += count( $provider->get_url_list( 1 ) );
|
||||
}
|
||||
$this->assertGreaterThan( 50000, $count );
|
||||
@ -46,7 +46,7 @@ class Test_WP_Sitemaps_Index extends WP_UnitTestCase {
|
||||
public function test_get_sitemap_list_no_entries() {
|
||||
$registry = new WP_Sitemaps_Registry();
|
||||
|
||||
$registry->add_sitemap( 'foo', new WP_Sitemaps_Empty_Test_Provider( 'foo' ) );
|
||||
$registry->add_provider( 'foo', new WP_Sitemaps_Empty_Test_Provider( 'foo' ) );
|
||||
|
||||
$sitemap_index = new WP_Sitemaps_Index( $registry );
|
||||
$this->assertCount( 0, $sitemap_index->get_sitemap_list() );
|
||||
|
@ -4,26 +4,26 @@
|
||||
* @group sitemaps
|
||||
*/
|
||||
class Test_WP_Sitemaps_Registry extends WP_UnitTestCase {
|
||||
public function test_add_sitemap() {
|
||||
public function test_add_provider() {
|
||||
$provider = new WP_Sitemaps_Test_Provider();
|
||||
$registry = new WP_Sitemaps_Registry();
|
||||
|
||||
$actual = $registry->add_sitemap( 'foo', $provider );
|
||||
$sitemaps = $registry->get_sitemaps();
|
||||
$actual = $registry->add_provider( 'foo', $provider );
|
||||
$sitemaps = $registry->get_providers();
|
||||
|
||||
$this->assertTrue( $actual );
|
||||
$this->assertCount( 1, $sitemaps );
|
||||
$this->assertSame( $sitemaps['foo'], $provider, 'Can not confirm sitemap registration is working.' );
|
||||
}
|
||||
|
||||
public function test_add_sitemap_prevent_duplicates() {
|
||||
public function test_add_provider_prevent_duplicates() {
|
||||
$provider1 = new WP_Sitemaps_Test_Provider();
|
||||
$provider2 = new WP_Sitemaps_Test_Provider();
|
||||
$registry = new WP_Sitemaps_Registry();
|
||||
|
||||
$actual1 = $registry->add_sitemap( 'foo', $provider1 );
|
||||
$actual2 = $registry->add_sitemap( 'foo', $provider2 );
|
||||
$sitemaps = $registry->get_sitemaps();
|
||||
$actual1 = $registry->add_provider( 'foo', $provider1 );
|
||||
$actual2 = $registry->add_provider( 'foo', $provider2 );
|
||||
$sitemaps = $registry->get_providers();
|
||||
|
||||
$this->assertTrue( $actual1 );
|
||||
$this->assertFalse( $actual2 );
|
||||
|
Loading…
Reference in New Issue
Block a user