Make WordPress Core

Ticket #9134: 9134-v3.diff

File 9134-v3.diff, 4.3 KB (added by realloc, 10 years ago)

The comments node seems to be optional.

  • src/wp-includes/feed-atom.php

     
    7878         * @since 2.0.0
    7979         */
    8080        do_action( 'atom_entry' );
     81
     82    if ( has_comments_link() ) :
    8183                ?>
    8284                <link rel="replies" type="<?php bloginfo_rss('html_type'); ?>" href="<?php the_permalink_rss() ?>#comments" thr:count="<?php echo get_comments_number()?>"/>
    8385                <link rel="replies" type="application/atom+xml" href="<?php echo esc_url( get_post_comments_feed_link(0, 'atom') ); ?>" thr:count="<?php echo get_comments_number()?>"/>
    8486                <thr:total><?php echo get_comments_number()?></thr:total>
     87    <?php endif; ?>
    8588        </entry>
    8689        <?php endwhile ; ?>
    8790</feed>
  • src/wp-includes/feed-rss2.php

     
    8383        <item>
    8484                <title><?php the_title_rss() ?></title>
    8585                <link><?php the_permalink_rss() ?></link>
    86                 <comments><?php comments_link_feed(); ?></comments>
    87                 <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate>
     86    <?php if ( has_comments_link() ) : ?>
     87        <comments><?php comments_link_feed(); ?></comments>
     88    <?php endif; ?>
     89        <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate>
    8890                <dc:creator><![CDATA[<?php the_author() ?>]]></dc:creator>
    8991                <?php the_category_rss('rss2') ?>
    9092
     
    100102                <content:encoded><![CDATA[<?php the_excerpt_rss(); ?>]]></content:encoded>
    101103        <?php endif; ?>
    102104<?php endif; ?>
     105    <?php if ( has_comments_link() ) : ?>
    103106                <wfw:commentRss><?php echo esc_url( get_post_comments_feed_link(null, 'rss2') ); ?></wfw:commentRss>
    104107                <slash:comments><?php echo get_comments_number(); ?></slash:comments>
     108    <?php endif; ?>
    105109<?php rss_enclosure(); ?>
    106110        <?php
    107111        /**
  • src/wp-includes/feed.php

     
    260260}
    261261
    262262/**
     263 * Whether we have to show comments links because the post type supports it and comments are open
     264 * @param int|WP_Post|null $post Optional. Post ID or post object. Default is global $post.
     265 * @return bool
     266 */
     267function has_comments_link( $post = null ) {
     268    $has_comments_link = ( post_type_supports( get_post_type( $post ), 'comments' ) && comments_open( $post ) );
     269
     270    return apply_filters( 'has_comments_link', $has_comments_link );
     271}
     272
     273/**
    263274 * Display the feed GUID for the current comment.
    264275 *
    265276 * @since 2.5.0
  • tests/phpunit/tests/feed/rss2.php

     
    148148                        $comments_link = xml_find( $items[$key]['child'], 'comments' );
    149149                        $this->assertEquals( get_permalink( $post) . '#respond', $comments_link[0]['content'] );
    150150
     151            // Ticket https://core.trac.wordpress.org/ticket/9134
     152            $this->assertTrue( has_comments_link() );
     153
    151154                        // pub date
    152155                        $pubdate = xml_find( $items[$key]['child'], 'pubDate' );
    153156                        $this->assertEquals( strtotime( $post->post_date_gmt ), strtotime( $pubdate[0]['content'] ) );
     
    201204                        $this->assertEquals( html_entity_decode( get_post_comments_feed_link( $post->ID) ), $comment_rss[0]['content'] );
    202205                }
    203206        }
     207
     208    // @ticket 9134
     209    function test_has_comments_link() {
     210        $post_id = wp_insert_post(
     211            array(
     212                'post_author' => 1,
     213                'post_status' => 'publish',
     214                'post_content' => rand_str(),
     215                'post_title' => rand_str(),
     216                'post_status' => 'open'
     217            )
     218        );
     219        $this->assertTrue( has_comments_link( $post_id ) );
     220
     221        $post_id = wp_insert_post(
     222            array(
     223                'post_author' => 1,
     224                'post_status' => 'publish',
     225                'post_content' => rand_str(),
     226                'post_title' => rand_str(),
     227                'comment_status' => 'closed'
     228            )
     229        );
     230        $this->assertFalse( has_comments_link( $post_id ) );
     231    }
    204232}