From ca8419d8dba8defeae21babe4bc01b6dd73fa784 Mon Sep 17 00:00:00 2001 From: Tremi Dkhar Date: Tue, 10 Nov 2026 14:36:48 +0530 Subject: [PATCH] Sitemaps: Support provider names containing dashes, digits, and underscores. --- .../sitemaps/class-wp-sitemaps.php | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/sitemaps/class-wp-sitemaps.php b/src/wp-includes/sitemaps/class-wp-sitemaps.php index 92c3375912cba..7b57ad8099a75 100644 --- a/src/wp-includes/sitemaps/class-wp-sitemaps.php +++ b/src/wp-includes/sitemaps/class-wp-sitemaps.php @@ -126,6 +126,7 @@ public function register_sitemaps() { * Registers sitemap rewrite tags and routing rules. * * @since 5.5.0 + * @since 7.3.0 Provider names may contain digits and underscores. */ public function register_rewrites() { // Add rewrite tags. @@ -137,12 +138,12 @@ public function register_rewrites() { // Register routes for providers. add_rewrite_rule( - '^wp-sitemap-([a-z]+?)-([a-z\d_-]+?)-(\d+?)\.xml$', + '^wp-sitemap-([a-z\d_-]+?)-([a-z\d_-]+?)-(\d+?)\.xml$', 'index.php?sitemap=$matches[1]&sitemap-subtype=$matches[2]&paged=$matches[3]', 'top' ); add_rewrite_rule( - '^wp-sitemap-([a-z]+?)-(\d+?)\.xml$', + '^wp-sitemap-([a-z\d_-]+?)-(\d+?)\.xml$', 'index.php?sitemap=$matches[1]&paged=$matches[2]', 'top' ); @@ -152,6 +153,7 @@ public function register_rewrites() { * Renders sitemap templates based on rewrite rules. * * @since 5.5.0 + * @since 7.3.0 Resolves providers whose names contain dashes. */ public function render_sitemaps() { /* @@ -192,6 +194,25 @@ public function render_sitemaps() { $provider = $this->registry->get_provider( $sitemap ); + if ( $object_subtype && ( ! $provider || ! array_key_exists( $object_subtype, $provider->get_object_subtypes() ) ) ) { + $route = $sitemap . '-' . $object_subtype; + + if ( $this->registry->get_provider( $route ) ) { + $provider = $this->registry->get_provider( $route ); + $object_subtype = ''; + } else { + foreach ( $this->registry->get_providers() as $name => $candidate ) { + if ( str_starts_with( $route, $name . '-' ) + && array_key_exists( substr( $route, strlen( $name ) + 1 ), $candidate->get_object_subtypes() ) + ) { + $provider = $candidate; + $object_subtype = substr( $route, strlen( $name ) + 1 ); + break; + } + } + } + } + // Force a 404 and bail early if the requested provider is not registered. if ( ! $provider ) { $this->send_404();