From 66c6ad97bc141f0019acc3d440e9e35c46d35573 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Tue, 14 Jul 2020 11:43:03 +0000 Subject: [PATCH] Sitemaps: Pass full paths to `home_url()` calls. This makes it easier for plugins using the `home_url` filter to detect sitemap URLs. Props Chouby. Fixes #50592. Built from https://develop.svn.wordpress.org/trunk@48470 git-svn-id: http://core.svn.wordpress.org/trunk@48239 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../sitemaps/class-wp-sitemaps-index.php | 2 +- .../sitemaps/class-wp-sitemaps-provider.php | 37 +++++++------------ .../sitemaps/class-wp-sitemaps-renderer.php | 4 +- wp-includes/version.php | 2 +- 4 files changed, 17 insertions(+), 28 deletions(-) diff --git a/wp-includes/sitemaps/class-wp-sitemaps-index.php b/wp-includes/sitemaps/class-wp-sitemaps-index.php index d558870bb0..4ec1b07d92 100644 --- a/wp-includes/sitemaps/class-wp-sitemaps-index.php +++ b/wp-includes/sitemaps/class-wp-sitemaps-index.php @@ -75,7 +75,7 @@ class WP_Sitemaps_Index { global $wp_rewrite; if ( ! $wp_rewrite->using_permalinks() ) { - return add_query_arg( 'sitemap', 'index', home_url( '/' ) ); + return home_url( '/?sitemap=index' ); } return home_url( '/wp-sitemap.xml' ); diff --git a/wp-includes/sitemaps/class-wp-sitemaps-provider.php b/wp-includes/sitemaps/class-wp-sitemaps-provider.php index 924aca068c..3440f62b34 100644 --- a/wp-includes/sitemaps/class-wp-sitemaps-provider.php +++ b/wp-includes/sitemaps/class-wp-sitemaps-provider.php @@ -145,35 +145,24 @@ abstract class WP_Sitemaps_Provider { public function get_sitemap_url( $name, $page ) { global $wp_rewrite; - if ( ! $wp_rewrite->using_permalinks() ) { - return add_query_arg( - // Accounts for cases where name is not included, ex: sitemaps-users-1.xml. - array_filter( - array( - 'sitemap' => $this->name, - 'sitemap-subtype' => $name, - 'paged' => $page, - ) - ), - home_url( '/' ) - ); - } + // Accounts for cases where name is not included, ex: sitemaps-users-1.xml. + $params = array_filter( + array( + 'sitemap' => $this->name, + 'sitemap-subtype' => $name, + 'paged' => $page, + ) + ); $basename = sprintf( '/wp-sitemap-%1$s.xml', - implode( - '-', - // Accounts for cases where name is not included, ex: sitemaps-users-1.xml. - array_filter( - array( - $this->name, - $name, - (string) $page, - ) - ) - ) + implode( '-', $params ) ); + if ( ! $wp_rewrite->using_permalinks() ) { + $basename = '/?' . http_build_query( $params, null, '&' ); + } + return home_url( $basename ); } diff --git a/wp-includes/sitemaps/class-wp-sitemaps-renderer.php b/wp-includes/sitemaps/class-wp-sitemaps-renderer.php index c313585d22..0069b11126 100644 --- a/wp-includes/sitemaps/class-wp-sitemaps-renderer.php +++ b/wp-includes/sitemaps/class-wp-sitemaps-renderer.php @@ -67,7 +67,7 @@ class WP_Sitemaps_Renderer { $sitemap_url = home_url( '/wp-sitemap.xsl' ); if ( ! $wp_rewrite->using_permalinks() ) { - $sitemap_url = add_query_arg( 'sitemap-stylesheet', 'sitemap', home_url( '/' ) ); + $sitemap_url = home_url( '/?sitemap-stylesheet=sitemap' ); } /** @@ -98,7 +98,7 @@ class WP_Sitemaps_Renderer { $sitemap_url = home_url( '/wp-sitemap-index.xsl' ); if ( ! $wp_rewrite->using_permalinks() ) { - $sitemap_url = add_query_arg( 'sitemap-stylesheet', 'index', home_url( '/' ) ); + $sitemap_url = home_url( '/?sitemap-stylesheet=index' ); } /** diff --git a/wp-includes/version.php b/wp-includes/version.php index 622dea580e..4d6736c4d5 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.5-beta1-48469'; +$wp_version = '5.5-beta1-48470'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.