WordPress.org

Make WordPress Core

Opened 2 months ago

Last modified 2 months ago

#52814 reviewing defect (bug)

Avoid notices in `get_post_comments_feed_link()`

Reported by: dd32 Owned by: SergeyBiryukov
Milestone: 5.8 Priority: low
Severity: trivial Version:
Component: Feeds Keywords: has-patch needs-refresh
Focuses: Cc:

Description

When an atom feed request is made to a non-existent page, get_post_comments_feed_link() produces PHP Notices such as the following:

E_NOTICE: Trying to get property 'post_type' of non-object in wp-includes/link-template.php:752

Example of a URLs which can trigger this is:

OPTIONS /2021/01/feed/atom/atom/
GET /404-page/feed/atom/

(Options bypasses the canonical redirect, and outputs a post-comments feed for the page "2021/01/feed/atom")

While the code path that results in this function being called without a valid post is unexpected and the resulting url generated in the atom feed is invalid, it silences these notices, which is good for sites that log/monitor these things (Such as WordPress.org)

Attachments (1)

52814.diff (1.8 KB) - added by dd32 2 months ago.

Download all attachments as: .zip

Change History (4)

@dd32
2 months ago

#1 @dd32
2 months ago

  • Keywords has-patch added

#2 @SergeyBiryukov
2 months ago

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

#3 @mukesh27
2 months ago

  • Keywords needs-refresh added

Hi there!

I checked the 52814.diff and found one doc block change.

* @return string|false The permalink for the comments feed for the given post.

Replace to

* @return string|false The permalink for the comments feed for the given post. False if the post does not exist.

Note: See TracTickets for help on using tickets.