Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#51416 closed defect (bug) (fixed)

PHP Warning during sitemap generation

Reported by: dd32's profile dd32 Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 5.6 Priority: normal
Severity: normal Version:
Component: Sitemaps Keywords: has-patch
Focuses: Cc:


The below error can be encountered during a sitemap render, this happens as the Taxonomy Sitemap provider doesn't expect that get_term_link() might return a WP_Error.

E_WARNING: wp-includes/formatting.php:4309 - ltrim() expects parameter 1 to be string, object given

In this case, WP_Error was returning ambiguous_term_id - Term ID is shared between multiple taxonomies which is actually a second bug here, that the $taxonomy parameter isn't being passed to properly disambiguate the call.

Attached PR fixes this up.

Attachments (1)

51416-class-wp-sitemaps-taxonomies.2.patch (885 bytes) - added by ravipatel 4 years ago.
short code for a link issue.

Download all attachments as: .zip

Change History (6)

This ticket was mentioned in PR #557 on WordPress/wordpress-develop by dd32.

4 years ago

  • Keywords has-patch added

Avoid a PHP warning on taxonomy sitemaps by checking for error conditions, and avoid error conditions by passing the taxonomy through.

As experienced on

Trac ticket:

4 years ago

short code for a link issue.

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

4 years ago

#3 @SergeyBiryukov
4 years ago

  • Milestone changed from Awaiting Review to 5.6
  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

#4 @SergeyBiryukov
4 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 49137:

Sitemaps: Check the result of get_term_link() when collecting the URLs in WP_Sitemaps_Taxonomies::get_url_list().

This avoids a PHP warning during sitemap generation if get_term_link() returns an error, e.g. due to term ID being shared between multiple taxonomies.

Additionally, pass the $taxonomy argument to get_term_link() to properly disambiguate the call.

Props dd32.
Fixes #51416.

Note: See TracTickets for help on using tickets.