Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#50660 closed defect (bug) (fixed)

Not all sitemaps providers can be filtered

Reported by: chouby's profile Chouby Owned by: swissspidy's profile swissspidy
Milestone: 5.5 Priority: normal
Severity: normal Version: 5.5
Component: Sitemaps Keywords: has-patch commit
Focuses: Cc:

Description

For the context: to allow multilingual sitemaps with Polylang, and after
this comment, I implemented a sitemaps provider decorator replacing the existing providers with the filter wp_sitemaps_register_providers. See https://github.com/polylang/polylang/blob/2.8-beta1/modules/sitemaps/sitemaps.php#L152-L163

However I realized that if another provider is added directly, for example with wp_register_sitemap(), it is not seen by the filter wp_sitemaps_register_providers and it looks like there is no alternative to filter it.

So I suggest to add a filter allowing to filter all registered sitemap providers.

Attachments (2)

50660.diff (2.2 KB) - added by swissspidy 5 years ago.
50660.2.diff (2.7 KB) - added by swissspidy 5 years ago.

Download all attachments as: .zip

Change History (11)

#1 @swissspidy
5 years ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to 5.5
  • Type changed from enhancement to defect (bug)

Thanks for your report! Very useful feedback as always.

You're right that folks can (and should) use wp_register_sitemap() to register sitemaps, and that will not pass through the wp_sitemaps_register_providers filter.

The filter doc block is a bit misleading: "Filters the list of registered sitemap providers."

It would be more accurate to say "Filters the list of built-in sitemap providers before they are registered.". Not to mention the doc block for the class method which could be improved...

Anyway, I'd consider not being able to unregister/filter sitemaps added via wp_register_sitemap a bug, and we should fix it.

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


5 years ago

#3 @davidbaumwald
5 years ago

@swissspidy Is this still in the cards for 5.5?

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


5 years ago

#5 @swissspidy
5 years ago

@davidbaumwald If we can come up with a solution, yes

@swissspidy
5 years ago

@swissspidy
5 years ago

#6 @pbiron
5 years ago

50660.2.diff looks good to me

#7 @pbiron
5 years ago

  • Keywords has-patch added; needs-patch removed

#8 @swissspidy
5 years ago

  • Keywords commit added

#9 @swissspidy
5 years ago

  • Owner set to swissspidy
  • Resolution set to fixed
  • Status changed from new to closed

In 48543:

Sitemaps: Replace wp_sitemaps_register_providers filter with more suitable wp_sitemaps_add_provider filter.

The previous filter failed the goal of allowing developers to filter all providers before they are registered, since it only filtered the built-in ones.

The more specific wp_sitemaps_add_provider filter enables exactly that, as it filters every sitemap provider right before it is added to the sitemaps registry.

Props pbiron, pfefferle, Chouby, swissspidy.
Fixes #50660.

Note: See TracTickets for help on using tickets.