Make WordPress Core

Opened 4 years ago

Last modified 17 months ago

#51280 assigned defect (bug)

wp_register_sitemap_provider() breaks sitemap functionality if provider name contains a dash (-)

Reported by: madtownlems's profile MadtownLems Owned by: pbiron's profile pbiron
Milestone: Future Release Priority: normal
Severity: minor Version: 5.5
Component: Sitemaps Keywords: needs-patch
Focuses: Cc:

Description

The announcement post for the functionality (https://make.wordpress.org/core/2020/07/22/new-xml-sitemaps-functionality-in-wordpress-5-5/) includes the following snippet:

wp_register_sitemap_provider( 'awesome-plugin', $provider );

However, I believe that the name doesn't work in practice. From my experiences, using a dash in the sitemap provider name causes the following:

The map is listed on the index, but when trying to view it, you just view your site's home page (not a 404, and not anything sitemappy).

If you register the provider with the name 'awesome-plugin', render_sitemaps() sees the following data:

$sitemap => 'awesome' (Expected: 'awesome-plugin' )
$object_subtype => 'plugin' (Expected: null )

and then it returns early due to if ( ! $provider )

As another test, I tried simply changing the name of Core's User Sitemap from 'users' to 'foo-users' and got the same result. The map was listed on the index, but when trying to browse it, you just see your site's home page (not a 404).

Doing some debugging, render_sitemaps sees the following data:

$sitemap => 'foo'
$object_subtype => 'users'

and then it returns early due to if ( ! $provider )

Change History (5)

This ticket was mentioned in Slack in #core-sitemaps by madtownlems. View the logs.


4 years ago

#2 @johnbillion
4 years ago

  • Version set to 5.5

#3 @pbiron
4 years ago

  • Owner set to pbiron
  • Status changed from new to assigned

Thank you for the report.

I can confirm the described behavior. It's not just dash (-): any character not in the range [a-z] causes the same results.

Additionally, the $name parameter of wp_register_sitemap_provider() must be the same as the $name property of the WP_Sitemaps_Provider subclass instance passed in the $provider param...and that is not currently documented anywhere.

#5 @swissspidy
17 months ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to Future Release
  • Severity changed from normal to minor
Note: See TracTickets for help on using tickets.