Sitemaps: Improve `sitemap.xml` redirects when using custom permalinks.

Changes the way redirects from `sitemap.xml` to `wp-sitemap.xml` happen, so that they also work when using a more complex custom rewrite structure.

Props gmariani405, swissspidy, euthelup, peterwilsoncc.
Fixes #61931.
Built from https://develop.svn.wordpress.org/trunk@59228


git-svn-id: http://core.svn.wordpress.org/trunk@58620 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Pascal Birchler 2024-10-14 08:49:19 +00:00
parent b99b8161e4
commit 7d9a297eb4
3 changed files with 7 additions and 4 deletions

View File

@ -1287,6 +1287,9 @@ class WP_Rewrite {
// favicon.ico -- only if installed at the root.
$favicon_rewrite = ( empty( $home_path['path'] ) || '/' === $home_path['path'] ) ? array( 'favicon\.ico$' => $this->index . '?favicon=1' ) : array();
// sitemap.xml -- only if installed at the root.
$sitemap_rewrite = ( empty( $home_path['path'] ) || '/' === $home_path['path'] ) ? array( 'sitemap\.xml' => $this->index . '??sitemap=index' ) : array();
// Old feed and service files.
$deprecated_files = array(
'.*wp-(atom|rdf|rss|rss2|feed|commentsrss2)\.php$' => $this->index . '?feed=old',
@ -1449,9 +1452,9 @@ class WP_Rewrite {
// Put them together.
if ( $this->use_verbose_page_rules ) {
$this->rules = array_merge( $this->extra_rules_top, $robots_rewrite, $favicon_rewrite, $deprecated_files, $registration_pages, $root_rewrite, $comments_rewrite, $search_rewrite, $author_rewrite, $date_rewrite, $page_rewrite, $post_rewrite, $this->extra_rules );
$this->rules = array_merge( $this->extra_rules_top, $robots_rewrite, $favicon_rewrite, $sitemap_rewrite, $deprecated_files, $registration_pages, $root_rewrite, $comments_rewrite, $search_rewrite, $author_rewrite, $date_rewrite, $page_rewrite, $post_rewrite, $this->extra_rules );
} else {
$this->rules = array_merge( $this->extra_rules_top, $robots_rewrite, $favicon_rewrite, $deprecated_files, $registration_pages, $root_rewrite, $comments_rewrite, $search_rewrite, $author_rewrite, $date_rewrite, $post_rewrite, $page_rewrite, $this->extra_rules );
$this->rules = array_merge( $this->extra_rules_top, $robots_rewrite, $favicon_rewrite, $sitemap_rewrite, $deprecated_files, $registration_pages, $root_rewrite, $comments_rewrite, $search_rewrite, $author_rewrite, $date_rewrite, $post_rewrite, $page_rewrite, $this->extra_rules );
}
/**

View File

@ -75,7 +75,6 @@ class WP_Sitemaps {
$this->register_sitemaps();
// Add additional action callbacks.
add_filter( 'pre_handle_404', array( $this, 'redirect_sitemapxml' ), 10, 2 );
add_filter( 'robots_txt', array( $this, 'add_robots' ), 0, 2 );
}
@ -223,6 +222,7 @@ class WP_Sitemaps {
* Redirects a URL to the wp-sitemap.xml
*
* @since 5.5.0
* @deprecated 6.7.0 Deprecated in favor of {@see WP_Rewrite::rewrite_rules()}
*
* @param bool $bypass Pass-through of the pre_handle_404 filter value.
* @param WP_Query $query The WP_Query object.

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.7-beta2-59227';
$wp_version = '6.7-beta2-59228';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.