WordPress.org

Make WordPress Core

Changeset 48540


Ignore:
Timestamp:
07/21/2020 03:55:21 PM (14 months ago)
Author:
swissspidy
Message:

Sitemaps: Rename wp_get_sitemaps() to wp_get_sitemaps_providers()

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.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/sitemaps.php

    r48536 r48540  
    2222function wp_sitemaps_get_server() {
    2323    global $wp_sitemaps;
    24 
    25     $is_enabled = (bool) get_option( 'blog_public' );
    2624
    2725    // If there isn't a global instance, set and bootstrap the sitemaps system.
     
    5250 * @return WP_Sitemaps_Provider[] Array of sitemap providers.
    5351 */
    54 function wp_get_sitemaps() {
     52function wp_get_sitemaps_providers() {
    5553    $sitemaps = wp_sitemaps_get_server();
    56 
    57     if ( ! $sitemaps ) {
    58         return array();
    59     }
    60 
    6154    return $sitemaps->registry->get_providers();
    6255}
     
    7366function wp_register_sitemap( $name, WP_Sitemaps_Provider $provider ) {
    7467    $sitemaps = wp_sitemaps_get_server();
    75 
    76     if ( ! $sitemaps ) {
    77         return false;
    78     }
    79 
    8068    return $sitemaps->registry->add_provider( $name, $provider );
    8169}
  • trunk/src/wp-includes/sitemaps/class-wp-sitemaps-registry.php

    r48536 r48540  
    5050     *
    5151     * @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.
    5353     */
    5454    public function get_provider( $name ) {
  • trunk/tests/phpunit/tests/sitemaps/functions.php

    r48072 r48540  
    4444     * Test wp_get_sitemaps default functionality
    4545     */
    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();
    4848
    4949        $expected = array(
  • trunk/tests/phpunit/tests/sitemaps/sitemaps-registry.php

    r48536 r48540  
    99        $registry = new WP_Sitemaps_Registry();
    1010
    11         $actual   = $registry->add_provider( 'foo', $provider );
    12         $sitemaps = $registry->get_providers();
     11        $actual    = $registry->add_provider( 'foo', $provider );
     12        $providers = $registry->get_providers();
    1313
    1414        $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.' );
    1717    }
    1818
     
    2222        $registry  = new WP_Sitemaps_Registry();
    2323
    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();
    2727
    2828        $this->assertTrue( $actual1 );
    2929        $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.' );
    3232    }
    3333}
  • trunk/tests/phpunit/tests/sitemaps/sitemaps.php

    r48523 r48540  
    101101        $entries = array();
    102102
    103         $providers = wp_get_sitemaps();
     103        $providers = wp_get_sitemaps_providers();
    104104
    105105        foreach ( $providers as $provider ) {
     
    219219     */
    220220    public function test_get_url_list_post() {
    221         $providers = wp_get_sitemaps();
     221        $providers = wp_get_sitemaps_providers();
    222222
    223223        $post_list = $providers['posts']->get_url_list( 1, 'post' );
     
    235235        add_filter( 'pre_option_show_on_front', '__return_true' );
    236236
    237         $providers = wp_get_sitemaps();
     237        $providers = wp_get_sitemaps_providers();
    238238
    239239        $post_list = $providers['posts']->get_url_list( 1, 'page' );
     
    248248     */
    249249    public function test_get_url_list_page_with_home() {
    250         $providers = wp_get_sitemaps();
     250        $providers = wp_get_sitemaps_providers();
    251251
    252252        $post_list = $providers['posts']->get_url_list( 1, 'page' );
     
    271271        wp_set_current_user( self::$editor_id );
    272272
    273         $providers = wp_get_sitemaps();
     273        $providers = wp_get_sitemaps_providers();
    274274
    275275        $post_list_before = $providers['posts']->get_url_list( 1, 'post' );
     
    298298        $ids = self::factory()->post->create_many( 10, array( 'post_type' => $post_type ) );
    299299
    300         $providers = wp_get_sitemaps();
     300        $providers = wp_get_sitemaps_providers();
    301301
    302302        $post_list = $providers['posts']->get_url_list( 1, $post_type );
     
    321321        self::factory()->post->create_many( 10, array( 'post_type' => $post_type ) );
    322322
    323         $providers = wp_get_sitemaps();
     323        $providers = wp_get_sitemaps_providers();
    324324
    325325        $post_list = $providers['posts']->get_url_list( 1, $post_type );
     
    349349        self::factory()->post->create_many( 10, array( 'post_type' => $post_type ) );
    350350
    351         $providers = wp_get_sitemaps();
     351        $providers = wp_get_sitemaps_providers();
    352352
    353353        $post_list = $providers['posts']->get_url_list( 1, $post_type );
     
    392392        wp_register_sitemap( 'test_sitemap', self::$test_provider );
    393393
    394         $sitemaps = wp_get_sitemaps();
     394        $sitemaps = wp_get_sitemaps_providers();
    395395
    396396        $this->assertEquals( $sitemaps['test_sitemap'], self::$test_provider, 'Can not confirm sitemap registration is working.' );
Note: See TracChangeset for help on using the changeset viewer.