Make WordPress Core

Ticket #50724: 50724.3.diff

File 50724.3.diff, 7.2 KB (added by swissspidy, 5 years ago)
  • src/wp-includes/sitemaps.php

    diff --git src/wp-includes/sitemaps.php src/wp-includes/sitemaps.php
    index f556246be5..6bc4d71e69 100644
     
    2222function wp_sitemaps_get_server() {
    2323        global $wp_sitemaps;
    2424
    25         $is_enabled = (bool) get_option( 'blog_public' );
    26 
    2725        // If there isn't a global instance, set and bootstrap the sitemaps system.
    2826        if ( empty( $wp_sitemaps ) ) {
    2927                $wp_sitemaps = new WP_Sitemaps();
    function wp_sitemaps_get_server() { 
    5149 *
    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}
    6356
    function wp_get_sitemaps() { 
    7265 */
    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}
    8270
  • src/wp-includes/sitemaps/class-wp-sitemaps-registry.php

    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 { 
    4949         * @since 5.5.0
    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 ) {
    5555                if ( ! isset( $this->providers[ $name ] ) ) {
  • tests/phpunit/tests/sitemaps/functions.php

    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 { 
    4343        /**
    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(
    5050                        'posts'      => 'WP_Sitemaps_Posts',
  • tests/phpunit/tests/sitemaps/sitemaps-registry.php

    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 { 
    88                $provider = new WP_Sitemaps_Test_Provider();
    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
    1919        public function test_add_provider_prevent_duplicates() {
    class Test_WP_Sitemaps_Registry extends WP_UnitTestCase { 
    2121                $provider2 = new WP_Sitemaps_Test_Provider();
    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}
  • tests/phpunit/tests/sitemaps/sitemaps.php

    diff --git tests/phpunit/tests/sitemaps/sitemaps.php tests/phpunit/tests/sitemaps/sitemaps.php
    index 35a5d6e8b6..d00e89d163 100644
    class Test_Sitemaps extends WP_UnitTestCase { 
    100100        public function _get_sitemap_entries() {
    101101                $entries = array();
    102102
    103                 $providers = wp_get_sitemaps();
     103                $providers = wp_get_sitemaps_providers();
    104104
    105105                foreach ( $providers as $provider ) {
    106106                        // Using `array_push` is more efficient than `array_merge` in the loop.
    class Test_Sitemaps extends WP_UnitTestCase { 
    218218         * Tests getting a URL list for post type post.
    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' );
    224224
    class Test_Sitemaps extends WP_UnitTestCase { 
    234234                // Short circuit the show on front option.
    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' );
    240240
    class Test_Sitemaps extends WP_UnitTestCase { 
    247247         * Tests getting a URL list for post type page with included home 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' );
    253253
    class Test_Sitemaps extends WP_UnitTestCase { 
    270270        public function test_get_url_list_private_post() {
    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' );
    276276
    class Test_Sitemaps extends WP_UnitTestCase { 
    297297
    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 );
    303303
    class Test_Sitemaps extends WP_UnitTestCase { 
    320320
    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 );
    326326
    class Test_Sitemaps extends WP_UnitTestCase { 
    348348
    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 );
    354354
    class Test_Sitemaps extends WP_UnitTestCase { 
    391391        public function test_register_sitemap_provider() {
    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.' );
    397397        }