From bb041c2503e8c367556aa046a2c8f4e9fdcb3715 Mon Sep 17 00:00:00 2001 From: antpb Date: Tue, 8 Jun 2021 23:00:59 +0000 Subject: [PATCH] Feeds: Avoid notices in `get_post_comments_feed_link()`. When an feed request is made to a non-existent page, surpress the notice. Props dd32, SergeyBiryukov, mukesh27, hellofromTonya. Fixes #52814. Built from https://develop.svn.wordpress.org/trunk@51121 git-svn-id: http://core.svn.wordpress.org/trunk@50730 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/link-template.php | 10 ++++++++-- wp-includes/version.php | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/wp-includes/link-template.php b/wp-includes/link-template.php index 3b38e0334c..0ff33466e8 100644 --- a/wp-includes/link-template.php +++ b/wp-includes/link-template.php @@ -735,7 +735,7 @@ function get_feed_link( $feed = '' ) { * @param int $post_id Optional. Post ID. Default is the ID of the global `$post`. * @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'. * Default is the value of get_default_feed(). - * @return string The permalink for the comments feed for the given post. + * @return string The permalink for the comments feed for the given post on success, empty string on failure. */ function get_post_comments_feed_link( $post_id = 0, $feed = '' ) { $post_id = absint( $post_id ); @@ -748,7 +748,13 @@ function get_post_comments_feed_link( $post_id = 0, $feed = '' ) { $feed = get_default_feed(); } - $post = get_post( $post_id ); + $post = get_post( $post_id ); + + // Bail out if the post does not exist. + if ( ! $post instanceof WP_Post ) { + return ''; + } + $unattached = 'attachment' === $post->post_type && 0 === (int) $post->post_parent; if ( get_option( 'permalink_structure' ) ) { diff --git a/wp-includes/version.php b/wp-includes/version.php index 604e963028..c5d48c54d6 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.8-alpha-51120'; +$wp_version = '5.8-alpha-51121'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.