diff --git a/src/wp-includes/sitemaps/class-wp-sitemaps-registry.php b/src/wp-includes/sitemaps/class-wp-sitemaps-registry.php index f4aec2f41a..5cb2e2fa45 100644 --- a/src/wp-includes/sitemaps/class-wp-sitemaps-registry.php +++ b/src/wp-includes/sitemaps/class-wp-sitemaps-registry.php @@ -25,19 +25,32 @@ class WP_Sitemaps_Registry { private $providers = array(); /** - * Adds a sitemap with route to the registry. + * Adds a new sitemap provider. * * @since 5.5.0 * * @param string $name Name of the sitemap provider. * @param WP_Sitemaps_Provider $provider Instance of a WP_Sitemaps_Provider. - * @return bool True if the provider was added, false if it is already registered. + * @return bool Whether the provider was added successfully. */ public function add_provider( $name, WP_Sitemaps_Provider $provider ) { if ( isset( $this->providers[ $name ] ) ) { return false; } + /** + * Filters the sitemap provider before it is added. + * + * @since 5.5.0 + * + * @param WP_Sitemaps_Provider $provider Instance of a WP_Sitemaps_Provider. + * @param string $name Name of the sitemap provider. + */ + $provider = apply_filters( 'wp_sitemaps_add_provider', $provider, $name ); + if ( ! $provider instanceof WP_Sitemaps_Provider ) { + return false; + } + $this->providers[ $name ] = $provider; return true; diff --git a/src/wp-includes/sitemaps/class-wp-sitemaps.php b/src/wp-includes/sitemaps/class-wp-sitemaps.php index 01f1bf8b35..ff79d711f2 100644 --- a/src/wp-includes/sitemaps/class-wp-sitemaps.php +++ b/src/wp-includes/sitemaps/class-wp-sitemaps.php @@ -110,29 +110,12 @@ class WP_Sitemaps { * @since 5.5.0 */ public function register_sitemaps() { - /** - * Filters the list of registered sitemap providers. - * - * @since 5.5.0 - * - * @param array $providers { - * Array of WP_Sitemaps_Provider objects keyed by their name. - * - * @type WP_Sitemaps_Posts $posts The WP_Sitemaps_Posts object. - * @type WP_Sitemaps_Taxonomies $taxonomies The WP_Sitemaps_Taxonomies object. - * @type WP_Sitemaps_Users $users The WP_Sitemaps_Users object. - * } - */ - $providers = apply_filters( - 'wp_sitemaps_register_providers', - array( - 'posts' => new WP_Sitemaps_Posts(), - 'taxonomies' => new WP_Sitemaps_Taxonomies(), - 'users' => new WP_Sitemaps_Users(), - ) + $providers = array( + 'posts' => new WP_Sitemaps_Posts(), + 'taxonomies' => new WP_Sitemaps_Taxonomies(), + 'users' => new WP_Sitemaps_Users(), ); - // Register each supported provider. /* @var WP_Sitemaps_Provider $provider */ foreach ( $providers as $name => $provider ) { $this->registry->add_provider( $name, $provider );