Make WordPress Core

Changeset 36362


Ignore:
Timestamp:
01/20/2016 08:32:00 AM (9 years ago)
Author:
dd32
Message:

Comments: Ignore hierarchy in pagination calculation when comment threading is disabled.

In order to calculate comment pagination when newest comments are displayed
first, comments_template() must perform a separate query to determine the
total number of paginating comments available on a post. See [34729], #8071,
pagination calculation - can be defined as a top-level comment, or a comment
with parent=0. However, when comment threading is disabled, yet comments
exist in the database that have parents, all comments - even those with a
parent - are "paginating". (This typically happens when comments threading was
once enabled, but has since been turned off.) As such, the total-paginating-
comments query should only be limited to top-level comments when
'thread_comments' is disabled.

Merges [36275] to the 4.4 branch.
Props jmdodd.
Fixes #35419.

Location:
branches/4.4
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/4.4

  • branches/4.4/src/wp-includes/comment-template.php

    r36360 r36362  
    13231323                'orderby' => false,
    13241324                'post_id' => $post->ID,
    1325                 'parent'  => 0,
    13261325                'status'  => 'approve',
    13271326            );
     1327
     1328            if ( $comment_args['hierarchical'] ) {
     1329                $top_level_args['parent'] = 0;
     1330            }
    13281331
    13291332            if ( isset( $comment_args['include_unapproved'] ) ) {
  • branches/4.4/tests/phpunit/tests/comment/commentsTemplate.php

    r36353 r36362  
    729729        $this->assertSame( array( $comment_2, $comment_3, $comment_1 ), $found_cids );
    730730    }
     731
     732    /**
     733     * @ticket 35419
     734     */
     735    public function test_pagination_calculation_should_ignore_comment_hierarchy_when_threading_is_disabled() {
     736        $now = time();
     737        $p = self::factory()->post->create();
     738        $comment_1 = self::factory()->comment->create( array(
     739            'comment_post_ID' => $p,
     740            'comment_content' => '1',
     741            'comment_approved' => '1',
     742            'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 300 ),
     743        ) );
     744        $comment_2 = self::factory()->comment->create( array(
     745            'comment_post_ID' => $p,
     746            'comment_content' => '2',
     747            'comment_approved' => '1',
     748            'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
     749        ) );
     750        $comment_3 = self::factory()->comment->create( array(
     751            'comment_post_ID' => $p,
     752            'comment_content' => '3',
     753            'comment_approved' => '1',
     754            'comment_parent' => $comment_1,
     755            'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
     756        ) );
     757
     758        update_option( 'thread_comments', 0 );
     759
     760        update_option( 'comment_order', 'asc' );
     761        update_option( 'comments_per_page', 2 );
     762        update_option( 'page_comments', 1 );
     763        update_option( 'default_comments_page', 'newest' );
     764
     765        $this->go_to( get_permalink( $p ) );
     766        $found = get_echo( 'comments_template' );
     767
     768        // Find the found comments in the markup.
     769        preg_match_all( '|id="comment-([0-9]+)|', $found, $matches );
     770
     771        $found_cids = array_map( 'intval', $matches[1] );
     772        $this->assertSame( array( $comment_3 ), $found_cids );
     773    }
    731774}
Note: See TracChangeset for help on using the changeset viewer.