Make WordPress Core

Ticket #9134: 9134.2.diff

File 9134.2.diff, 3.5 KB (added by swissspidy, 10 years ago)
  • src/wp-includes/feed-atom.php

    diff --git src/wp-includes/feed-atom.php src/wp-includes/feed-atom.php
    index ae4cd79..fca03d5 100644
    do_action( 'rss_tag_pre', 'atom' ); 
    7878         * @since 2.0.0
    7979         */
    8080        do_action( 'atom_entry' );
     81
     82        if ( get_comments_number() || comments_open() ) :
    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

    diff --git src/wp-includes/feed-rss2.php src/wp-includes/feed-rss2.php
    index c82fc63..49368e9 100644
    do_action( 'rss_tag_pre', 'rss2' ); 
    8383        <item>
    8484                <title><?php the_title_rss() ?></title>
    8585                <link><?php the_permalink_rss() ?></link>
     86<?php if ( get_comments_number() || comments_open() ) : ?>
    8687                <comments><?php comments_link_feed(); ?></comments>
     88<?php endif; ?>
    8789                <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') ?>
    do_action( 'rss_tag_pre', 'rss2' ); 
    100102                <content:encoded><![CDATA[<?php the_excerpt_rss(); ?>]]></content:encoded>
    101103        <?php endif; ?>
    102104<?php endif; ?>
     105<?php if ( get_comments_number() || comments_open() ) : ?>
    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        /**
  • tests/phpunit/tests/feed/rss2.php

    diff --git tests/phpunit/tests/feed/rss2.php tests/phpunit/tests/feed/rss2.php
    index 7ae6e78..5c93574 100644
    class Tests_Feed_RSS2 extends WP_UnitTestCase { 
    103103
    104104                // get all the rss -> channel -> item elements
    105105                $items = xml_find($xml, 'rss', 'channel', 'item');
    106                 $posts = get_posts('numberposts='.$this->post_count);
    107106
    108107                // check each of the items against the known post data
    109108                foreach ( $items as $key => $item ) {
    class Tests_Feed_RSS2 extends WP_UnitTestCase { 
    178177                        $this->assertEquals( html_entity_decode( get_post_comments_feed_link( $post->ID) ), $comment_rss[0]['content'] );
    179178                }
    180179        }
     180
     181        /**
     182         * @ticket 9134
     183         */
     184        function test_items_comments_closed() {
     185                add_filter( 'comments_open', '__return_false' );
     186
     187                $this->go_to( '/?feed=rss2' );
     188                $feed = $this->do_rss2();
     189                $xml = xml_to_array($feed);
     190
     191                // get all the rss -> channel -> item elements
     192                $items = xml_find( $xml, 'rss', 'channel', 'item' );
     193
     194                // check each of the items against the known post data
     195                foreach ( $items as $key => $item ) {
     196                        // Get post for comparison
     197                        $guid = xml_find( $items[$key]['child'], 'guid' );
     198                        preg_match( '/\?p=(\d+)/', $guid[0]['content'], $matches );
     199                        $post = get_post( $matches[1] );
     200
     201                        // comment link
     202                        $comments_link = xml_find( $items[ $key ]['child'], 'comments' );
     203                        $this->assertEmpty( $comments_link );
     204
     205                        // comment rss
     206                        $comment_rss = xml_find( $items[ $key ]['child'], 'wfw:commentRss' );
     207                        $this->assertEmpty( $comment_rss );
     208                }
     209
     210                remove_filter( 'comments_open', '__return_false' );
     211        }
    181212}