Make WordPress Core

Changeset 51121


Ignore:
Timestamp:
06/08/2021 10:59:19 PM (3 years ago)
Author:
antpb
Message:

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.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/link-template.php

    r51024 r51121  
    736736 * @param string $feed    Optional. Feed type. Possible values include 'rss2', 'atom'.
    737737 *                        Default is the value of get_default_feed().
    738  * @return string The permalink for the comments feed for the given post.
     738 * @return string The permalink for the comments feed for the given post on success, empty string on failure.
    739739 */
    740740function get_post_comments_feed_link( $post_id = 0, $feed = '' ) {
     
    749749    }
    750750
    751     $post       = get_post( $post_id );
     751    $post = get_post( $post_id );
     752
     753    // Bail out if the post does not exist.
     754    if ( ! $post instanceof WP_Post ) {
     755        return '';
     756    }
     757
    752758    $unattached = 'attachment' === $post->post_type && 0 === (int) $post->post_parent;
    753759
  • trunk/tests/phpunit/tests/link/getPostCommentsFeedLink.php

    r50454 r51121  
    139139        $this->assertSame( $expected, $link );
    140140    }
     141
     142    /**
     143     * @ticket 52814
     144     */
     145    public function test_nonexistent_page() {
     146        $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
     147
     148        // Use the largest integer to ensure the post does not exist.
     149        $post_id = PHP_INT_MAX;
     150        $link    = get_post_comments_feed_link( $post_id );
     151
     152        $this->assertEmpty( $link );
     153    }
    141154}
Note: See TracChangeset for help on using the changeset viewer.