diff --git src/wp-includes/sitemaps.php src/wp-includes/sitemaps.php
index f556246be5..6bc4d71e69 100644
|
|
|
22 | 22 | function wp_sitemaps_get_server() { |
23 | 23 | global $wp_sitemaps; |
24 | 24 | |
25 | | $is_enabled = (bool) get_option( 'blog_public' ); |
26 | | |
27 | 25 | // If there isn't a global instance, set and bootstrap the sitemaps system. |
28 | 26 | if ( empty( $wp_sitemaps ) ) { |
29 | 27 | $wp_sitemaps = new WP_Sitemaps(); |
… |
… |
function wp_sitemaps_get_server() { |
51 | 49 | * |
52 | 50 | * @return WP_Sitemaps_Provider[] Array of sitemap providers. |
53 | 51 | */ |
54 | | function wp_get_sitemaps() { |
| 52 | function wp_get_sitemaps_providers() { |
55 | 53 | $sitemaps = wp_sitemaps_get_server(); |
56 | | |
57 | | if ( ! $sitemaps ) { |
58 | | return array(); |
59 | | } |
60 | | |
61 | 54 | return $sitemaps->registry->get_providers(); |
62 | 55 | } |
63 | 56 | |
… |
… |
function wp_get_sitemaps() { |
72 | 65 | */ |
73 | 66 | function wp_register_sitemap( $name, WP_Sitemaps_Provider $provider ) { |
74 | 67 | $sitemaps = wp_sitemaps_get_server(); |
75 | | |
76 | | if ( ! $sitemaps ) { |
77 | | return false; |
78 | | } |
79 | | |
80 | 68 | return $sitemaps->registry->add_provider( $name, $provider ); |
81 | 69 | } |
82 | 70 | |
diff --git src/wp-includes/sitemaps/class-wp-sitemaps-registry.php src/wp-includes/sitemaps/class-wp-sitemaps-registry.php
index 1235670a27..f4aec2f41a 100644
|
|
class WP_Sitemaps_Registry { |
49 | 49 | * @since 5.5.0 |
50 | 50 | * |
51 | 51 | * @param string $name Sitemap provider name. |
52 | | * @return WP_Sitemaps_Provider|null Sitemaps provider if it exists, null otherwise. |
| 52 | * @return WP_Sitemaps_Provider|null Sitemap provider if it exists, null otherwise. |
53 | 53 | */ |
54 | 54 | public function get_provider( $name ) { |
55 | 55 | if ( ! isset( $this->providers[ $name ] ) ) { |
diff --git tests/phpunit/tests/sitemaps/functions.php tests/phpunit/tests/sitemaps/functions.php
index dd4796b438..2c4cce5a35 100644
|
|
class Test_Sitemaps_Functions extends WP_UnitTestCase { |
43 | 43 | /** |
44 | 44 | * Test wp_get_sitemaps default functionality |
45 | 45 | */ |
46 | | public function test_wp_get_sitemaps() { |
47 | | $sitemaps = wp_get_sitemaps(); |
| 46 | public function test_wp_get_sitemaps_providers() { |
| 47 | $sitemaps = wp_get_sitemaps_providers(); |
48 | 48 | |
49 | 49 | $expected = array( |
50 | 50 | 'posts' => 'WP_Sitemaps_Posts', |
diff --git tests/phpunit/tests/sitemaps/sitemaps-registry.php tests/phpunit/tests/sitemaps/sitemaps-registry.php
index faeba78852..b5ac7e952c 100644
|
|
class Test_WP_Sitemaps_Registry extends WP_UnitTestCase { |
8 | 8 | $provider = new WP_Sitemaps_Test_Provider(); |
9 | 9 | $registry = new WP_Sitemaps_Registry(); |
10 | 10 | |
11 | | $actual = $registry->add_provider( 'foo', $provider ); |
12 | | $sitemaps = $registry->get_providers(); |
| 11 | $actual = $registry->add_provider( 'foo', $provider ); |
| 12 | $providers = $registry->get_providers(); |
13 | 13 | |
14 | 14 | $this->assertTrue( $actual ); |
15 | | $this->assertCount( 1, $sitemaps ); |
16 | | $this->assertSame( $sitemaps['foo'], $provider, 'Can not confirm sitemap registration is working.' ); |
| 15 | $this->assertCount( 1, $providers ); |
| 16 | $this->assertSame( $providers['foo'], $provider, 'Can not confirm sitemap registration is working.' ); |
17 | 17 | } |
18 | 18 | |
19 | 19 | public function test_add_provider_prevent_duplicates() { |
… |
… |
class Test_WP_Sitemaps_Registry extends WP_UnitTestCase { |
21 | 21 | $provider2 = new WP_Sitemaps_Test_Provider(); |
22 | 22 | $registry = new WP_Sitemaps_Registry(); |
23 | 23 | |
24 | | $actual1 = $registry->add_provider( 'foo', $provider1 ); |
25 | | $actual2 = $registry->add_provider( 'foo', $provider2 ); |
26 | | $sitemaps = $registry->get_providers(); |
| 24 | $actual1 = $registry->add_provider( 'foo', $provider1 ); |
| 25 | $actual2 = $registry->add_provider( 'foo', $provider2 ); |
| 26 | $providers = $registry->get_providers(); |
27 | 27 | |
28 | 28 | $this->assertTrue( $actual1 ); |
29 | 29 | $this->assertFalse( $actual2 ); |
30 | | $this->assertCount( 1, $sitemaps ); |
31 | | $this->assertSame( $sitemaps['foo'], $provider1, 'Can not confirm sitemap registration is working.' ); |
| 30 | $this->assertCount( 1, $providers ); |
| 31 | $this->assertSame( $providers['foo'], $provider1, 'Can not confirm sitemap registration is working.' ); |
32 | 32 | } |
33 | 33 | } |
diff --git tests/phpunit/tests/sitemaps/sitemaps.php tests/phpunit/tests/sitemaps/sitemaps.php
index 35a5d6e8b6..d00e89d163 100644
|
|
class Test_Sitemaps extends WP_UnitTestCase { |
100 | 100 | public function _get_sitemap_entries() { |
101 | 101 | $entries = array(); |
102 | 102 | |
103 | | $providers = wp_get_sitemaps(); |
| 103 | $providers = wp_get_sitemaps_providers(); |
104 | 104 | |
105 | 105 | foreach ( $providers as $provider ) { |
106 | 106 | // Using `array_push` is more efficient than `array_merge` in the loop. |
… |
… |
class Test_Sitemaps extends WP_UnitTestCase { |
218 | 218 | * Tests getting a URL list for post type post. |
219 | 219 | */ |
220 | 220 | public function test_get_url_list_post() { |
221 | | $providers = wp_get_sitemaps(); |
| 221 | $providers = wp_get_sitemaps_providers(); |
222 | 222 | |
223 | 223 | $post_list = $providers['posts']->get_url_list( 1, 'post' ); |
224 | 224 | |
… |
… |
class Test_Sitemaps extends WP_UnitTestCase { |
234 | 234 | // Short circuit the show on front option. |
235 | 235 | add_filter( 'pre_option_show_on_front', '__return_true' ); |
236 | 236 | |
237 | | $providers = wp_get_sitemaps(); |
| 237 | $providers = wp_get_sitemaps_providers(); |
238 | 238 | |
239 | 239 | $post_list = $providers['posts']->get_url_list( 1, 'page' ); |
240 | 240 | |
… |
… |
class Test_Sitemaps extends WP_UnitTestCase { |
247 | 247 | * Tests getting a URL list for post type page with included home page. |
248 | 248 | */ |
249 | 249 | public function test_get_url_list_page_with_home() { |
250 | | $providers = wp_get_sitemaps(); |
| 250 | $providers = wp_get_sitemaps_providers(); |
251 | 251 | |
252 | 252 | $post_list = $providers['posts']->get_url_list( 1, 'page' ); |
253 | 253 | |
… |
… |
class Test_Sitemaps extends WP_UnitTestCase { |
270 | 270 | public function test_get_url_list_private_post() { |
271 | 271 | wp_set_current_user( self::$editor_id ); |
272 | 272 | |
273 | | $providers = wp_get_sitemaps(); |
| 273 | $providers = wp_get_sitemaps_providers(); |
274 | 274 | |
275 | 275 | $post_list_before = $providers['posts']->get_url_list( 1, 'post' ); |
276 | 276 | |
… |
… |
class Test_Sitemaps extends WP_UnitTestCase { |
297 | 297 | |
298 | 298 | $ids = self::factory()->post->create_many( 10, array( 'post_type' => $post_type ) ); |
299 | 299 | |
300 | | $providers = wp_get_sitemaps(); |
| 300 | $providers = wp_get_sitemaps_providers(); |
301 | 301 | |
302 | 302 | $post_list = $providers['posts']->get_url_list( 1, $post_type ); |
303 | 303 | |
… |
… |
class Test_Sitemaps extends WP_UnitTestCase { |
320 | 320 | |
321 | 321 | self::factory()->post->create_many( 10, array( 'post_type' => $post_type ) ); |
322 | 322 | |
323 | | $providers = wp_get_sitemaps(); |
| 323 | $providers = wp_get_sitemaps_providers(); |
324 | 324 | |
325 | 325 | $post_list = $providers['posts']->get_url_list( 1, $post_type ); |
326 | 326 | |
… |
… |
class Test_Sitemaps extends WP_UnitTestCase { |
348 | 348 | |
349 | 349 | self::factory()->post->create_many( 10, array( 'post_type' => $post_type ) ); |
350 | 350 | |
351 | | $providers = wp_get_sitemaps(); |
| 351 | $providers = wp_get_sitemaps_providers(); |
352 | 352 | |
353 | 353 | $post_list = $providers['posts']->get_url_list( 1, $post_type ); |
354 | 354 | |
… |
… |
class Test_Sitemaps extends WP_UnitTestCase { |
391 | 391 | public function test_register_sitemap_provider() { |
392 | 392 | wp_register_sitemap( 'test_sitemap', self::$test_provider ); |
393 | 393 | |
394 | | $sitemaps = wp_get_sitemaps(); |
| 394 | $sitemaps = wp_get_sitemaps_providers(); |
395 | 395 | |
396 | 396 | $this->assertEquals( $sitemaps['test_sitemap'], self::$test_provider, 'Can not confirm sitemap registration is working.' ); |
397 | 397 | } |