WordPress.org

Make WordPress Core


Ignore:
Timestamp:
01/20/2016 05:23:02 AM (5 years ago)
Author:
dd32
Message:

Comments: Always respect $comments array passed to wp_list_comments().

[36157] fixed a bug whereby wp_list_comments() would not properly recognize
custom pagination arguments. See #35175. However, it inadvertently introduced
a bug that caused any $comments array explicitly passed to the function to be
ignored, when that array was accompanied by pagination arguments that differ
from those in $wp_query. We address this bug by moving the logic introduced
in [36157] inside a block that only fires when no $comments array has been
provided to the function.

Merges [36276] to the 4.4 branch.
Props ivankristianto, boonebgorges.
Fixes #35356.

Location:
branches/4.4
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.4

  • branches/4.4/tests/phpunit/tests/comment/wpListComments.php

    r36158 r36356  
    111111        $this->assertSame( array( $comments[1], $comments[0] ), array_map( 'intval', $matches[1] ) );
    112112    }
     113
     114    /**
     115     * @ticket 35356
     116     * @ticket 35175
     117     */
     118    public function test_comments_param_should_be_respected_when_custom_pagination_params_are_passed() {
     119        $p = self::factory()->post->create();
     120
     121        $comments = array();
     122        $now = time();
     123        for ( $i = 0; $i <= 5; $i++ ) {
     124            $comments[] = self::factory()->comment->create( array(
     125                'comment_post_ID' => $p,
     126                'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - $i ),
     127                'comment_author' => 'Commenter ' . $i,
     128            ) );
     129        }
     130
     131        update_option( 'page_comments', true );
     132        update_option( 'comments_per_page', 2 );
     133
     134        $_comments = array( get_comment( $comments[1] ), get_comment( $comments[3] ) );
     135
     136        // Populate `$wp_query->comments` in order to show that it doesn't override `$_comments`.
     137        $this->go_to( get_permalink( $p ) );
     138        get_echo( 'comments_template' );
     139
     140        $found = wp_list_comments( array(
     141            'echo' => false,
     142            'per_page' => 1,
     143            'page' => 2,
     144        ), $_comments );
     145
     146        preg_match_all( '|id="comment\-([0-9]+)"|', $found, $matches );
     147        $this->assertSame( array( $comments[3] ), array_map( 'intval', $matches[1] ) );
     148    }
    113149}
Note: See TracChangeset for help on using the changeset viewer.