[wp-trac] [WordPress Trac] #50592: Sitemaps: Pass full paths to home_url() (was: Confusing usage of home_url())

WordPress Trac noreply at wordpress.org
Tue Jul 14 10:58:55 UTC 2020


#50592: Sitemaps: Pass full paths to home_url()
------------------------------+-------------------------
 Reporter:  Chouby            |       Owner:  swissspidy
     Type:  defect (bug)      |      Status:  reviewing
 Priority:  normal            |   Milestone:  5.5
Component:  Sitemaps          |     Version:  trunk
 Severity:  normal            |  Resolution:
 Keywords:  has-patch commit  |     Focuses:
------------------------------+-------------------------
Changes (by swissspidy):

 * keywords:  has-patch => has-patch commit


Old description:

> When using plain permalinks, `WP_Sitemaps_Index::get_index_url()` builds
> the sitemap index url like this:
> `add_query_arg( 'sitemap', 'index', home_url( '/' ) );`
>
> See:
> https://github.com/WordPress/WordPress/blob/fe823d698f5e57135c102e02d7e23d4019ac59d5
> /wp-includes/sitemaps/class-wp-sitemaps-index.php#L78
>
> There is no issue on a fresh install but it causes issues with plugins or
> themes using the filter `home_url`. Any function hooked to this filter
> will interpret that the url beeing built is the homepage url when it's
> actually the sitemap index url which is beeing built.
>
> I propose to change this to:
> `home_url( '/?sitemap=index' );`
> The result should be the same for WordPress but would be less confusing
> for users of the `home_url` filter.
>
> I noticed 2 other similar constructions in:
> https://github.com/WordPress/WordPress/blob/fe823d698f5e57135c102e02d7e23d4019ac59d5
> /wp-includes/sitemaps/class-wp-sitemaps-renderer.php#L70 and
> https://github.com/WordPress/WordPress/blob/fe823d698f5e57135c102e02d7e23d4019ac59d5
> /wp-includes/sitemaps/class-wp-sitemaps-renderer.php#L101

New description:

 When using plain permalinks, `WP_Sitemaps_Index::get_index_url()` builds
 the sitemap index url like this:
 `add_query_arg( 'sitemap', 'index', home_url( '/' ) );`

 See:
 https://github.com/WordPress/WordPress/blob/fe823d698f5e57135c102e02d7e23d4019ac59d5
 /wp-includes/sitemaps/class-wp-sitemaps-index.php#L78

 There is no issue on a fresh install but it causes issues with plugins or
 themes using the filter `home_url`. Any function hooked to this filter
 will interpret that the url being built is the homepage url when it's
 actually the sitemap index url which is being built.

 I propose to change this to:
 `home_url( '/?sitemap=index' );`
 The result should be the same for WordPress but would be less confusing
 for users of the `home_url` filter.

 I noticed 2 other similar constructions in:
 https://github.com/WordPress/WordPress/blob/fe823d698f5e57135c102e02d7e23d4019ac59d5
 /wp-includes/sitemaps/class-wp-sitemaps-renderer.php#L70 and
 https://github.com/WordPress/WordPress/blob/fe823d698f5e57135c102e02d7e23d4019ac59d5
 /wp-includes/sitemaps/class-wp-sitemaps-renderer.php#L101

--

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/50592#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list