[wp-trac] [WordPress Trac] #54703: Remove comment feed link if get_post_comments_feed_link() returns empty

WordPress Trac noreply at wordpress.org
Thu Dec 30 11:04:22 UTC 2021


#54703: Remove comment feed link if get_post_comments_feed_link() returns empty
-------------------------------------+-----------------------
 Reporter:  barryceelen              |       Owner:  (none)
     Type:  enhancement              |      Status:  new
 Priority:  normal                   |   Milestone:  6.0
Component:  Feeds                    |     Version:
 Severity:  normal                   |  Resolution:
 Keywords:  has-patch needs-testing  |     Focuses:  template
-------------------------------------+-----------------------

Comment (by costdev):

 I'm writing unit tests for `feed_links_extra()` to include testing against
 the issue(s) raised in this ticket.

 The PR targets a post that has comments, but the current functionality is
 that a feed link is output regardless of the number of comments, provided
 that `comments_open()` or `pings_open()` pass.

 The output of a feed link for a post that has no comments isn't the source
 of the issue(s) raised in this ticket. It ''may'' also break something out
 in the wild, although I'm not sure about this, it ''may'' need its own
 investigation.

 Ultimately, if the `feed_links_show_comments_feed` filter returns `false`,
 it should not output the comments feed link, regardless of whether a post
 has comments or not.

 This ticket appears to flag two issues:

 1. When `feed_links_show_comments_feed` returns `false`, the comment feed
 link is still output.
 2. When `get_post_comments_feed_link()` returns `''`, the comment feed
 link is still output.

 This appears to resolve both issues and the unit tests pass:
 {{{#!php

 /**
  * Issue #1
  *
  * This reuses the 'feed_links_show_comments_feed' filter.
  * Multiple use of a single filter in Core has precedent with
 'link_category', for example.
  */
 /** This filter is documented in wp-includes/general-template.php */
 $show_comments_feed = apply_filters( 'feed_links_show_comments_feed', true
 );
 if ( $show_comments_feed && ( comments_open() || pings_open() ||
 $post->comment_count > 0 ) ) {
         $title = sprintf( $args['singletitle'], get_bloginfo( 'name' ),
 $args['separator'], the_title_attribute( array( 'echo' => false ) ) );

         /**
          * Issue #2
          *
          * This guards against an empty string from
 get_post_comments_feed_link().
          */
         $feed_link = get_post_comments_feed_link( $post->ID );
         if ( '' !== $feed_link ) {
                 $href = $feed_link;
         }
 }

 }}}

 @audrasjb Can you review the above snippet and if it looks good, consider
 putting it in the PR? (without the comments, of course).

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/54703#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list