Make WordPress Core


Ignore:
Timestamp:
07/21/2020 04:12:49 PM (4 years 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.

File:
1 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        }
Note: See TracChangeset for help on using the changeset viewer.