[wp-trac] [WordPress Trac] #50592: Confusing usage of home_url()

WordPress Trac noreply at wordpress.org
Tue Jul 7 14:32:52 UTC 2020


#50592: Confusing usage of home_url()
--------------------------+-----------------------------
 Reporter:  Chouby        |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Sitemaps      |    Version:  trunk
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 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

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


More information about the wp-trac mailing list