Make WordPress Core


Ignore:
Timestamp:
07/14/2020 11:41:47 AM (6 years ago)
Author:
swissspidy
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/sitemaps/class-wp-sitemaps-provider.php

    r48100 r48470  
    146146                global $wp_rewrite;
    147147
    148                 if ( ! $wp_rewrite->using_permalinks() ) {
    149                         return add_query_arg(
    150                                 // Accounts for cases where name is not included, ex: sitemaps-users-1.xml.
    151                                 array_filter(
    152                                         array(
    153                                                 'sitemap'         => $this->name,
    154                                                 'sitemap-subtype' => $name,
    155                                                 'paged'           => $page,
    156                                         )
    157                                 ),
    158                                 home_url( '/' )
    159                         );
    160                 }
     148                // Accounts for cases where name is not included, ex: sitemaps-users-1.xml.
     149                $params = array_filter(
     150                        array(
     151                                'sitemap'         => $this->name,
     152                                'sitemap-subtype' => $name,
     153                                'paged'           => $page,
     154                        )
     155                );
    161156
    162157                $basename = sprintf(
    163158                        '/wp-sitemap-%1$s.xml',
    164                         implode(
    165                                 '-',
    166                                 // Accounts for cases where name is not included, ex: sitemaps-users-1.xml.
    167                                 array_filter(
    168                                         array(
    169                                                 $this->name,
    170                                                 $name,
    171                                                 (string) $page,
    172                                         )
    173                                 )
    174                         )
     159                        implode( '-', $params )
    175160                );
     161
     162                if ( ! $wp_rewrite->using_permalinks() ) {
     163                        $basename = '/?' . http_build_query( $params, null, '&' );
     164                }
    176165
    177166                return home_url( $basename );
Note: See TracChangeset for help on using the changeset viewer.