WordPress.org

Make WordPress Core

Ticket #15610: 15610.patch

File 15610.patch, 1.7 KB (added by jbrinley, 5 years ago)
  • src/wp-includes/query.php

    diff --git src/wp-includes/query.php src/wp-includes/query.php
    index bd2ebc1..497da39 100644
    class WP_Query { 
    30803080                                $cgroupby = "$wpdb->comments.comment_id";
    30813081                        } else { // Other non singular e.g. front
    30823082                                $cjoin = "JOIN $wpdb->posts ON ( $wpdb->comments.comment_post_ID = $wpdb->posts.ID )";
    3083                                 $cwhere = "WHERE post_status = 'publish' AND comment_approved = '1'";
     3083                                $cwhere = "WHERE ( post_status = 'publish' OR ( post_status = 'inherit' && post_type = 'attachment' ) ) AND comment_approved = '1'";
    30843084                                $cgroupby = '';
    30853085                        }
    30863086
  • new file tests/phpunit/tests/comment/feed.php

    diff --git tests/phpunit/tests/comment/feed.php tests/phpunit/tests/comment/feed.php
    new file mode 100644
    index 0000000..b65da97
    - +  
     1<?php
     2
     3
     4class Test_Comment_Feed extends WP_UnitTestCase {
     5
     6        /**
     7         * Comments on attachments should be included in the site comments feed
     8         *
     9         * @ticket 15610
     10         */
     11        public function test_attachment_comments_in_feed() {
     12                $attachment_id = wp_insert_attachment(array(
     13                        'post_status' => 'publish',
     14                        'post_title' => __CLASS__,
     15                        'post_content_filtered' => __FILE__,
     16                        'post_excerpt' => __LINE__,
     17                ));
     18                $comment_id = $this->factory->comment->create(array(
     19                        'comment_post_ID' => $attachment_id,
     20                ));
     21
     22                // this is the query that runs for the comments feed
     23                $query = new WP_Query();
     24                $query->query(array(
     25                        'withcomments' => 1,
     26                        'feed' => 'feed',
     27                ));
     28
     29                $this->assertTrue( $query->have_comments() );
     30                $comment = $query->next_comment();
     31                $this->assertEquals( $comment_id, $comment->comment_ID );
     32        }
     33}
     34 No newline at end of file