WordPress.org

Make WordPress Core

Changeset 48543


Ignore:
Timestamp:
07/21/2020 04:12:49 PM (14 months ago)
Author:
swissspidy
Message:

Sitemaps: Replace wp_sitemaps_register_providers filter with more suitable wp_sitemaps_add_provider filter.

The previous filter failed the goal of allowing developers to filter all providers before they are registered, since it only filtered the built-in ones.

The more specific wp_sitemaps_add_provider filter enables exactly that, as it filters every sitemap provider right before it is added to the sitemaps registry.

Props pbiron, pfefferle, Chouby, swissspidy.
Fixes #50660.

Location:
trunk/src/wp-includes/sitemaps
Files:
2 edited

Legend:

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

    r48540 r48543  
    2626
    2727    /**
    28      * Adds a sitemap with route to the registry.
     28     * Adds a new sitemap provider.
    2929     *
    3030     * @since 5.5.0
     
    3232     * @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 provider was added, false if it is already registered.
     34     * @return bool Whether the provider was added successfully.
    3535     */
    3636    public function add_provider( $name, WP_Sitemaps_Provider $provider ) {
    3737        if ( isset( $this->providers[ $name ] ) ) {
     38            return false;
     39        }
     40
     41        /**
     42         * Filters the sitemap provider before it is added.
     43         *
     44         * @since 5.5.0
     45         *
     46         * @param WP_Sitemaps_Provider $provider Instance of a WP_Sitemaps_Provider.
     47         * @param string               $name     Name of the sitemap provider.
     48         */
     49        $provider = apply_filters( 'wp_sitemaps_add_provider', $provider, $name );
     50        if ( ! $provider instanceof WP_Sitemaps_Provider ) {
    3851            return false;
    3952        }
  • trunk/src/wp-includes/sitemaps/class-wp-sitemaps.php

    r48536 r48543  
    111111     */
    112112    public function register_sitemaps() {
    113         /**
    114          * Filters the list of registered sitemap providers.
    115          *
    116          * @since 5.5.0
    117          *
    118          * @param array $providers {
    119          *     Array of WP_Sitemaps_Provider objects keyed by their name.
    120          *
    121          *     @type WP_Sitemaps_Posts      $posts      The WP_Sitemaps_Posts object.
    122          *     @type WP_Sitemaps_Taxonomies $taxonomies The WP_Sitemaps_Taxonomies object.
    123          *     @type WP_Sitemaps_Users      $users      The WP_Sitemaps_Users object.
    124          * }
    125          */
    126         $providers = apply_filters(
    127             'wp_sitemaps_register_providers',
    128             array(
    129                 'posts'      => new WP_Sitemaps_Posts(),
    130                 'taxonomies' => new WP_Sitemaps_Taxonomies(),
    131                 'users'      => new WP_Sitemaps_Users(),
    132             )
     113        $providers = array(
     114            'posts'      => new WP_Sitemaps_Posts(),
     115            'taxonomies' => new WP_Sitemaps_Taxonomies(),
     116            'users'      => new WP_Sitemaps_Users(),
    133117        );
    134118
    135         // Register each supported provider.
    136119        /* @var WP_Sitemaps_Provider $provider */
    137120        foreach ( $providers as $name => $provider ) {
Note: See TracChangeset for help on using the changeset viewer.