Skip to content

Commit

Permalink
Sitemaps: Rename wp_get_sitemaps() to wp_get_sitemaps_providers()
Browse files Browse the repository at this point in the history
Following [48536], rename the function to match the rest of the sitemaps logic.

Also eliminates some dead code after [48523].

Props pbiron.
See #50724. See #50643.

git-svn-id: https://develop.svn.wordpress.org/trunk@48540 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
swissspidy committed Jul 21, 2020
1 parent 3269e83 commit 83b94f5
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 34 deletions.
14 changes: 1 addition & 13 deletions src/wp-includes/sitemaps.php
Expand Up @@ -22,8 +22,6 @@
function wp_sitemaps_get_server() {
global $wp_sitemaps;

$is_enabled = (bool) get_option( 'blog_public' );

// If there isn't a global instance, set and bootstrap the sitemaps system.
if ( empty( $wp_sitemaps ) ) {
$wp_sitemaps = new WP_Sitemaps();
Expand Down Expand Up @@ -51,13 +49,8 @@ function wp_sitemaps_get_server() {
*
* @return WP_Sitemaps_Provider[] Array of sitemap providers.
*/
function wp_get_sitemaps() {
function wp_get_sitemaps_providers() {
$sitemaps = wp_sitemaps_get_server();

if ( ! $sitemaps ) {
return array();
}

return $sitemaps->registry->get_providers();
}

Expand All @@ -72,11 +65,6 @@ function wp_get_sitemaps() {
*/
function wp_register_sitemap( $name, WP_Sitemaps_Provider $provider ) {
$sitemaps = wp_sitemaps_get_server();

if ( ! $sitemaps ) {
return false;
}

return $sitemaps->registry->add_provider( $name, $provider );
}

Expand Down
2 changes: 1 addition & 1 deletion src/wp-includes/sitemaps/class-wp-sitemaps-registry.php
Expand Up @@ -49,7 +49,7 @@ public function add_provider( $name, WP_Sitemaps_Provider $provider ) {
* @since 5.5.0
*
* @param string $name Sitemap provider name.
* @return WP_Sitemaps_Provider|null Sitemaps provider if it exists, null otherwise.
* @return WP_Sitemaps_Provider|null Sitemap provider if it exists, null otherwise.
*/
public function get_provider( $name ) {
if ( ! isset( $this->providers[ $name ] ) ) {
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/tests/sitemaps/functions.php
Expand Up @@ -43,8 +43,8 @@ public function _filter_max_url_value( $max_urls, $type ) {
/**
* Test wp_get_sitemaps default functionality
*/
public function test_wp_get_sitemaps() {
$sitemaps = wp_get_sitemaps();
public function test_wp_get_sitemaps_providers() {
$sitemaps = wp_get_sitemaps_providers();

$expected = array(
'posts' => 'WP_Sitemaps_Posts',
Expand Down
18 changes: 9 additions & 9 deletions tests/phpunit/tests/sitemaps/sitemaps-registry.php
Expand Up @@ -8,26 +8,26 @@ public function test_add_provider() {
$provider = new WP_Sitemaps_Test_Provider();
$registry = new WP_Sitemaps_Registry();

$actual = $registry->add_provider( 'foo', $provider );
$sitemaps = $registry->get_providers();
$actual = $registry->add_provider( 'foo', $provider );
$providers = $registry->get_providers();

$this->assertTrue( $actual );
$this->assertCount( 1, $sitemaps );
$this->assertSame( $sitemaps['foo'], $provider, 'Can not confirm sitemap registration is working.' );
$this->assertCount( 1, $providers );
$this->assertSame( $providers['foo'], $provider, 'Can not confirm sitemap registration is working.' );
}

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_provider( 'foo', $provider1 );
$actual2 = $registry->add_provider( 'foo', $provider2 );
$sitemaps = $registry->get_providers();
$actual1 = $registry->add_provider( 'foo', $provider1 );
$actual2 = $registry->add_provider( 'foo', $provider2 );
$providers = $registry->get_providers();

$this->assertTrue( $actual1 );
$this->assertFalse( $actual2 );
$this->assertCount( 1, $sitemaps );
$this->assertSame( $sitemaps['foo'], $provider1, 'Can not confirm sitemap registration is working.' );
$this->assertCount( 1, $providers );
$this->assertSame( $providers['foo'], $provider1, 'Can not confirm sitemap registration is working.' );
}
}
18 changes: 9 additions & 9 deletions tests/phpunit/tests/sitemaps/sitemaps.php
Expand Up @@ -100,7 +100,7 @@ public static function wpSetUpBeforeClass( $factory ) {
public function _get_sitemap_entries() {
$entries = array();

$providers = wp_get_sitemaps();
$providers = wp_get_sitemaps_providers();

foreach ( $providers as $provider ) {
// Using `array_push` is more efficient than `array_merge` in the loop.
Expand Down Expand Up @@ -218,7 +218,7 @@ public function test_get_sitemap_entries_not_publicly_queryable_post_types() {
* Tests getting a URL list for post type post.
*/
public function test_get_url_list_post() {
$providers = wp_get_sitemaps();
$providers = wp_get_sitemaps_providers();

$post_list = $providers['posts']->get_url_list( 1, 'post' );

Expand All @@ -234,7 +234,7 @@ public function test_get_url_list_page() {
// Short circuit the show on front option.
add_filter( 'pre_option_show_on_front', '__return_true' );

$providers = wp_get_sitemaps();
$providers = wp_get_sitemaps_providers();

$post_list = $providers['posts']->get_url_list( 1, 'page' );

Expand All @@ -247,7 +247,7 @@ public function test_get_url_list_page() {
* Tests getting a URL list for post type page with included home page.
*/
public function test_get_url_list_page_with_home() {
$providers = wp_get_sitemaps();
$providers = wp_get_sitemaps_providers();

$post_list = $providers['posts']->get_url_list( 1, 'page' );

Expand All @@ -270,7 +270,7 @@ public function test_get_url_list_page_with_home() {
public function test_get_url_list_private_post() {
wp_set_current_user( self::$editor_id );

$providers = wp_get_sitemaps();
$providers = wp_get_sitemaps_providers();

$post_list_before = $providers['posts']->get_url_list( 1, 'post' );

Expand All @@ -297,7 +297,7 @@ public function test_get_url_list_cpt() {

$ids = self::factory()->post->create_many( 10, array( 'post_type' => $post_type ) );

$providers = wp_get_sitemaps();
$providers = wp_get_sitemaps_providers();

$post_list = $providers['posts']->get_url_list( 1, $post_type );

Expand All @@ -320,7 +320,7 @@ public function test_get_url_list_cpt_private() {

self::factory()->post->create_many( 10, array( 'post_type' => $post_type ) );

$providers = wp_get_sitemaps();
$providers = wp_get_sitemaps_providers();

$post_list = $providers['posts']->get_url_list( 1, $post_type );

Expand Down Expand Up @@ -348,7 +348,7 @@ public function test_get_url_list_cpt_not_publicly_queryable() {

self::factory()->post->create_many( 10, array( 'post_type' => $post_type ) );

$providers = wp_get_sitemaps();
$providers = wp_get_sitemaps_providers();

$post_list = $providers['posts']->get_url_list( 1, $post_type );

Expand Down Expand Up @@ -391,7 +391,7 @@ static function ( $post ) {
public function test_register_sitemap_provider() {
wp_register_sitemap( 'test_sitemap', self::$test_provider );

$sitemaps = wp_get_sitemaps();
$sitemaps = wp_get_sitemaps_providers();

$this->assertEquals( $sitemaps['test_sitemap'], self::$test_provider, 'Can not confirm sitemap registration is working.' );
}
Expand Down

0 comments on commit 83b94f5

Please sign in to comment.