WordPress.org

Make WordPress Core

Opened 7 weeks ago

Last modified 7 weeks ago

#51280 assigned defect (bug)

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

Reported by: MadtownLems Owned by: pbiron
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.5
Component: Sitemaps Keywords:
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 (4)

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


7 weeks ago

#2 @johnbillion
7 weeks ago

  • Version set to 5.5

#3 @pbiron
7 weeks 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.

Note: See TracTickets for help on using tickets.