Changeset 48536
- Timestamp:
- 07/21/2020 03:27:48 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/sitemaps.php
r48523 r48536 59 59 } 60 60 61 return $sitemaps->registry->get_ sitemaps();61 return $sitemaps->registry->get_providers(); 62 62 } 63 63 … … 78 78 } 79 79 80 return $sitemaps->registry->add_ sitemap( $name, $provider );80 return $sitemaps->registry->add_provider( $name, $provider ); 81 81 } 82 82 -
trunk/src/wp-includes/sitemaps/class-wp-sitemaps-index.php
r48532 r48536 55 55 $sitemaps = array(); 56 56 57 $providers = $this->registry->get_ sitemaps();57 $providers = $this->registry->get_providers(); 58 58 /* @var WP_Sitemaps_Provider $provider */ 59 59 foreach ( $providers as $name => $provider ) { -
trunk/src/wp-includes/sitemaps/class-wp-sitemaps-registry.php
r48532 r48536 3 3 * Sitemaps: WP_Sitemaps_Registry class 4 4 * 5 * Handles registering sitemap s.5 * Handles registering sitemap providers. 6 6 * 7 7 * @package WordPress … … 17 17 class WP_Sitemaps_Registry { 18 18 /** 19 * Registered sitemap s.19 * Registered sitemap providers. 20 20 * 21 21 * @since 5.5.0 22 22 * 23 * @var WP_Sitemaps_Provider[] Array of registered sitemap s.23 * @var WP_Sitemaps_Provider[] Array of registered sitemap providers. 24 24 */ 25 private $ sitemaps = array();25 private $providers = array(); 26 26 27 27 /** … … 30 30 * @since 5.5.0 31 31 * 32 * @param string $name Name of the sitemap .32 * @param string $name Name of the sitemap provider. 33 33 * @param WP_Sitemaps_Provider $provider Instance of a WP_Sitemaps_Provider. 34 * @return bool True if the sitemapwas added, false if it is already registered.34 * @return bool True if the provider was added, false if it is already registered. 35 35 */ 36 public function add_ sitemap( $name, WP_Sitemaps_Provider $provider ) {37 if ( isset( $this-> sitemaps[ $name ] ) ) {36 public function add_provider( $name, WP_Sitemaps_Provider $provider ) { 37 if ( isset( $this->providers[ $name ] ) ) { 38 38 return false; 39 39 } 40 40 41 $this-> sitemaps[ $name ] = $provider;41 $this->providers[ $name ] = $provider; 42 42 43 43 return true; … … 45 45 46 46 /** 47 * Returns a single registered sitemap sprovider.47 * Returns a single registered sitemap provider. 48 48 * 49 49 * @since 5.5.0 … … 52 52 * @return WP_Sitemaps_Provider|null Sitemaps provider if it exists, null otherwise. 53 53 */ 54 public function get_ sitemap( $name ) {55 if ( ! isset( $this-> sitemaps[ $name ] ) ) {54 public function get_provider( $name ) { 55 if ( ! isset( $this->providers[ $name ] ) ) { 56 56 return null; 57 57 } 58 58 59 return $this-> sitemaps[ $name ];59 return $this->providers[ $name ]; 60 60 } 61 61 … … 67 67 * @return WP_Sitemaps_Provider[] Array of sitemap providers. 68 68 */ 69 public function get_ sitemaps() {70 return $this-> sitemaps;69 public function get_providers() { 70 return $this->providers; 71 71 } 72 72 } -
trunk/src/wp-includes/sitemaps/class-wp-sitemaps.php
r48523 r48536 136 136 /* @var WP_Sitemaps_Provider $provider */ 137 137 foreach ( $providers as $name => $provider ) { 138 $this->registry->add_ sitemap( $name, $provider );138 $this->registry->add_provider( $name, $provider ); 139 139 } 140 140 } … … 213 213 } 214 214 215 $provider = $this->registry->get_ sitemap( $sitemap );215 $provider = $this->registry->get_provider( $sitemap ); 216 216 217 217 if ( ! $provider ) { -
trunk/tests/phpunit/tests/sitemaps/sitemaps-index.php
r48532 r48536 14 14 * Hence, 3*4*2=24. 15 15 */ 16 $registry->add_ sitemap( 'foo', new WP_Sitemaps_Test_Provider( 'foo' ) );17 $registry->add_ sitemap( 'bar', new WP_Sitemaps_Test_Provider( 'bar' ) );16 $registry->add_provider( 'foo', new WP_Sitemaps_Test_Provider( 'foo' ) ); 17 $registry->add_provider( 'bar', new WP_Sitemaps_Test_Provider( 'bar' ) ); 18 18 19 19 $sitemap_index = new WP_Sitemaps_Index( $registry ); … … 30 30 31 31 // add 3 providers, which combined produce more than the maximum 50000 sitemaps in the index. 32 $registry->add_ sitemap( 'provider_1', new WP_Sitemaps_Large_Test_Provider( 25000 ) );33 $registry->add_ sitemap( 'provider_2', new WP_Sitemaps_Large_Test_Provider( 25000 ) );34 $registry->add_ sitemap( 'provider_3', new WP_Sitemaps_Large_Test_Provider( 25000 ) );32 $registry->add_provider( 'provider_1', new WP_Sitemaps_Large_Test_Provider( 25000 ) ); 33 $registry->add_provider( 'provider_2', new WP_Sitemaps_Large_Test_Provider( 25000 ) ); 34 $registry->add_provider( 'provider_3', new WP_Sitemaps_Large_Test_Provider( 25000 ) ); 35 35 36 36 $count = 0; 37 foreach ( $registry->get_ sitemaps() as $provider ) {37 foreach ( $registry->get_providers() as $provider ) { 38 38 $count += count( $provider->get_url_list( 1 ) ); 39 39 } … … 47 47 $registry = new WP_Sitemaps_Registry(); 48 48 49 $registry->add_ sitemap( 'foo', new WP_Sitemaps_Empty_Test_Provider( 'foo' ) );49 $registry->add_provider( 'foo', new WP_Sitemaps_Empty_Test_Provider( 'foo' ) ); 50 50 51 51 $sitemap_index = new WP_Sitemaps_Index( $registry ); -
trunk/tests/phpunit/tests/sitemaps/sitemaps-registry.php
r48072 r48536 5 5 */ 6 6 class Test_WP_Sitemaps_Registry extends WP_UnitTestCase { 7 public function test_add_ sitemap() {7 public function test_add_provider() { 8 8 $provider = new WP_Sitemaps_Test_Provider(); 9 9 $registry = new WP_Sitemaps_Registry(); 10 10 11 $actual = $registry->add_ sitemap( 'foo', $provider );12 $sitemaps = $registry->get_ sitemaps();11 $actual = $registry->add_provider( 'foo', $provider ); 12 $sitemaps = $registry->get_providers(); 13 13 14 14 $this->assertTrue( $actual ); … … 17 17 } 18 18 19 public function test_add_ sitemap_prevent_duplicates() {19 public function test_add_provider_prevent_duplicates() { 20 20 $provider1 = new WP_Sitemaps_Test_Provider(); 21 21 $provider2 = new WP_Sitemaps_Test_Provider(); 22 22 $registry = new WP_Sitemaps_Registry(); 23 23 24 $actual1 = $registry->add_ sitemap( 'foo', $provider1 );25 $actual2 = $registry->add_ sitemap( 'foo', $provider2 );26 $sitemaps = $registry->get_ sitemaps();24 $actual1 = $registry->add_provider( 'foo', $provider1 ); 25 $actual2 = $registry->add_provider( 'foo', $provider2 ); 26 $sitemaps = $registry->get_providers(); 27 27 28 28 $this->assertTrue( $actual1 );
Note: See TracChangeset
for help on using the changeset viewer.