WordPress.org

Make WordPress Core

Changeset 48536


Ignore:
Timestamp:
07/21/2020 03:27:48 PM (14 months ago)
Author:
SergeyBiryukov
Message:

Sitemaps: Rename 'sitemap' to 'provider' in WP_Sitemaps_Registry class.

This class is for registering sitemap providers, not individual sitemaps.

Props swissspidy.
Fixes #50724.

Location:
trunk
Files:
6 edited

Legend:

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

    r48523 r48536  
    5959    }
    6060
    61     return $sitemaps->registry->get_sitemaps();
     61    return $sitemaps->registry->get_providers();
    6262}
    6363
     
    7878    }
    7979
    80     return $sitemaps->registry->add_sitemap( $name, $provider );
     80    return $sitemaps->registry->add_provider( $name, $provider );
    8181}
    8282
  • trunk/src/wp-includes/sitemaps/class-wp-sitemaps-index.php

    r48532 r48536  
    5555        $sitemaps = array();
    5656
    57         $providers = $this->registry->get_sitemaps();
     57        $providers = $this->registry->get_providers();
    5858        /* @var WP_Sitemaps_Provider $provider */
    5959        foreach ( $providers as $name => $provider ) {
  • trunk/src/wp-includes/sitemaps/class-wp-sitemaps-registry.php

    r48532 r48536  
    33 * Sitemaps: WP_Sitemaps_Registry class
    44 *
    5  * Handles registering sitemaps.
     5 * Handles registering sitemap providers.
    66 *
    77 * @package WordPress
     
    1717class WP_Sitemaps_Registry {
    1818    /**
    19      * Registered sitemaps.
     19     * Registered sitemap providers.
    2020     *
    2121     * @since 5.5.0
    2222     *
    23      * @var WP_Sitemaps_Provider[] Array of registered sitemaps.
     23     * @var WP_Sitemaps_Provider[] Array of registered sitemap providers.
    2424     */
    25     private $sitemaps = array();
     25    private $providers = array();
    2626
    2727    /**
     
    3030     * @since 5.5.0
    3131     *
    32      * @param string               $name     Name of the sitemap.
     32     * @param string               $name     Name of the sitemap provider.
    3333     * @param WP_Sitemaps_Provider $provider Instance of a WP_Sitemaps_Provider.
    34      * @return bool True if the sitemap was added, false if it is already registered.
     34     * @return bool True if the provider was added, false if it is already registered.
    3535     */
    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 ] ) ) {
    3838            return false;
    3939        }
    4040
    41         $this->sitemaps[ $name ] = $provider;
     41        $this->providers[ $name ] = $provider;
    4242
    4343        return true;
     
    4545
    4646    /**
    47      * Returns a single registered sitemaps provider.
     47     * Returns a single registered sitemap provider.
    4848     *
    4949     * @since 5.5.0
     
    5252     * @return WP_Sitemaps_Provider|null Sitemaps provider if it exists, null otherwise.
    5353     */
    54     public function get_sitemap( $name ) {
    55         if ( ! isset( $this->sitemaps[ $name ] ) ) {
     54    public function get_provider( $name ) {
     55        if ( ! isset( $this->providers[ $name ] ) ) {
    5656            return null;
    5757        }
    5858
    59         return $this->sitemaps[ $name ];
     59        return $this->providers[ $name ];
    6060    }
    6161
     
    6767     * @return WP_Sitemaps_Provider[] Array of sitemap providers.
    6868     */
    69     public function get_sitemaps() {
    70         return $this->sitemaps;
     69    public function get_providers() {
     70        return $this->providers;
    7171    }
    7272}
  • trunk/src/wp-includes/sitemaps/class-wp-sitemaps.php

    r48523 r48536  
    136136        /* @var WP_Sitemaps_Provider $provider */
    137137        foreach ( $providers as $name => $provider ) {
    138             $this->registry->add_sitemap( $name, $provider );
     138            $this->registry->add_provider( $name, $provider );
    139139        }
    140140    }
     
    213213        }
    214214
    215         $provider = $this->registry->get_sitemap( $sitemap );
     215        $provider = $this->registry->get_provider( $sitemap );
    216216
    217217        if ( ! $provider ) {
  • trunk/tests/phpunit/tests/sitemaps/sitemaps-index.php

    r48532 r48536  
    1414         * Hence, 3*4*2=24.
    1515         */
    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' ) );
    1818
    1919        $sitemap_index = new WP_Sitemaps_Index( $registry );
     
    3030
    3131        // 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 ) );
    3535
    3636        $count = 0;
    37         foreach ( $registry->get_sitemaps() as $provider ) {
     37        foreach ( $registry->get_providers() as $provider ) {
    3838            $count += count( $provider->get_url_list( 1 ) );
    3939        }
     
    4747        $registry = new WP_Sitemaps_Registry();
    4848
    49         $registry->add_sitemap( 'foo', new WP_Sitemaps_Empty_Test_Provider( 'foo' ) );
     49        $registry->add_provider( 'foo', new WP_Sitemaps_Empty_Test_Provider( 'foo' ) );
    5050
    5151        $sitemap_index = new WP_Sitemaps_Index( $registry );
  • trunk/tests/phpunit/tests/sitemaps/sitemaps-registry.php

    r48072 r48536  
    55 */
    66class Test_WP_Sitemaps_Registry extends WP_UnitTestCase {
    7     public function test_add_sitemap() {
     7    public function test_add_provider() {
    88        $provider = new WP_Sitemaps_Test_Provider();
    99        $registry = new WP_Sitemaps_Registry();
    1010
    11         $actual   = $registry->add_sitemap( 'foo', $provider );
    12         $sitemaps = $registry->get_sitemaps();
     11        $actual   = $registry->add_provider( 'foo', $provider );
     12        $sitemaps = $registry->get_providers();
    1313
    1414        $this->assertTrue( $actual );
     
    1717    }
    1818
    19     public function test_add_sitemap_prevent_duplicates() {
     19    public function test_add_provider_prevent_duplicates() {
    2020        $provider1 = new WP_Sitemaps_Test_Provider();
    2121        $provider2 = new WP_Sitemaps_Test_Provider();
    2222        $registry  = new WP_Sitemaps_Registry();
    2323
    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();
    2727
    2828        $this->assertTrue( $actual1 );
Note: See TracChangeset for help on using the changeset viewer.