Ticket #8973: 8973.2.diff
File 8973.2.diff, 6.1 KB (added by , 6 years ago) |
---|
-
src/wp-includes/comment-template.php
723 723 'per_page' => '', 724 724 'max_depth' => '', 725 725 'cpage' => null, 726 'include_unapproved' => '', 726 727 ); 727 728 $args = wp_parse_args( $args, $defaults ); 728 729 … … 745 746 746 747 $cpage = $args['page']; 747 748 749 if ( is_user_logged_in() ) { 750 $args['include_unapproved'] = get_current_user_id(); 751 } else { 752 $commenter = wp_get_current_commenter(); 753 if ( $commenter['comment_author_email'] ) { 754 $args['include_unapproved'] = $commenter['comment_author_email']; 755 } 756 } 757 748 758 if ( '' == $cpage ) { 749 759 if ( ! empty( $in_comment_loop ) ) { 750 760 $cpage = get_query_var( 'cpage' ); … … 1310 1320 * @global int $id 1311 1321 * @global WP_Comment $comment 1312 1322 * @global string $user_login 1313 * @global int $user_ID1314 1323 * @global string $user_identity 1315 1324 * @global bool $overridden_cpage 1316 1325 * @global bool $withcomments … … 1320 1329 * Default false. 1321 1330 */ 1322 1331 function comments_template( $file = '/comments.php', $separate_comments = false ) { 1323 global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ ID, $user_identity, $overridden_cpage;1332 global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_identity, $overridden_cpage; 1324 1333 1325 1334 if ( ! ( is_single() || is_page() || $withcomments ) || empty( $post ) ) { 1326 1335 return; … … 1332 1341 1333 1342 $req = get_option( 'require_name_email' ); 1334 1343 1335 /*1336 * Comment author information fetched from the comment cookies.1337 */1338 $commenter = wp_get_current_commenter();1339 1340 /*1341 * The name of the current comment author escaped for use in attributes.1342 * Escaped by sanitize_comment_cookies().1343 */1344 $comment_author = $commenter['comment_author'];1345 1346 /*1347 * The email address of the current comment author escaped for use in attributes.1348 * Escaped by sanitize_comment_cookies().1349 */1350 $comment_author_email = $commenter['comment_author_email'];1351 1352 /*1353 * The url of the current comment author escaped for use in attributes.1354 */1355 $comment_author_url = esc_url( $commenter['comment_author_url'] );1356 1357 1344 $comment_args = array( 1358 1345 'orderby' => 'comment_date_gmt', 1359 1346 'order' => 'ASC', … … 1369 1356 $comment_args['hierarchical'] = false; 1370 1357 } 1371 1358 1372 if ( $user_ID ) { 1373 $comment_args['include_unapproved'] = array( $user_ID ); 1374 } elseif ( ! empty( $comment_author_email ) ) { 1375 $comment_args['include_unapproved'] = array( $comment_author_email ); 1359 if ( is_user_logged_in() ) { 1360 $comment_args['include_unapproved'] = get_current_user_id(); 1361 } else { 1362 $commenter = wp_get_current_commenter(); 1363 if ( $commenter['comment_author_email'] ) { 1364 $comment_args['include_unapproved'] = $commenter['comment_author_email']; 1365 } 1376 1366 } 1377 1367 1378 1368 $per_page = 0; -
src/wp-includes/comment.php
1034 1034 'page' => '', 1035 1035 'per_page' => '', 1036 1036 'max_depth' => '', 1037 'include_unapproved' => '', 1037 1038 ); 1038 1039 $args = wp_parse_args( $args, $defaults ); 1039 1040 $original_args = $args; … … 1078 1079 'fields' => 'ids', 1079 1080 'count' => true, 1080 1081 'status' => 'approve', 1082 'include_unapproved' => $args['include_unapproved'], 1081 1083 'parent' => 0, 1082 1084 'date_query' => array( 1083 1085 array( -
tests/phpunit/tests/comment/getPageOfComment.php
429 429 430 430 $this->assertEquals( 2, get_page_of_comment( $c3 ) ); 431 431 } 432 433 /** 434 * @ticket 8973 435 */ 436 public function test_page_number_when_user_has_unapproved_comments() { 437 $p = self::factory()->post->create(); 438 439 // page 3 440 $comment_last = self::factory()->comment->create_post_comments( $p, 1, array( 'comment_author' => 'Test Commenter', 'comment_author_email' => 'example@example.com', 'comment_date' => '2013-09-20 00:00:00' ) ); 441 442 // page 2 443 self::factory()->comment->create_post_comments( $p, 1, array( 'comment_author' => 'Test Commenter', 'comment_author_email' => 'example@example.com', 'comment_approved' => 0, 'comment_date' => '2013-09-19 00:00:00' ) ); 444 self::factory()->comment->create_post_comments( $p, 1, array( 'comment_author' => 'Test Commenter', 'comment_author_email' => 'example@example.com', 'comment_approved' => 0, 'comment_date' => '2013-09-18 00:00:00' ) ); 445 self::factory()->comment->create_post_comments( $p, 1, array( 'comment_author' => 'Test Commenter', 'comment_author_email' => 'example@example.com', 'comment_approved' => 0, 'comment_date' => '2013-09-17 00:00:00' ) ); 446 447 // page 1 448 $unapproved = self::factory()->comment->create_post_comments( $p, 1, array( 'comment_author' => 'Test Commenter', 'comment_author_email' => 'example@example.com', 'comment_approved' => 0, 'comment_date' => '2013-09-16 00:00:00' ) ); 449 self::factory()->comment->create_post_comments( $p, 1, array( 'comment_author' => 'Test Commenter', 'comment_author_email' => 'example@example.com', 'comment_date' => '2013-09-15 00:00:00' ) ); 450 self::factory()->comment->create_post_comments( $p, 1, array( 'comment_author' => 'Test Commenter', 'comment_author_email' => 'example@example.com', 'comment_date' => '2013-09-14 00:00:00' ) ); 451 452 $this->assertEquals( 1, get_page_of_comment( $comment_last[0], array( 'per_page' => 3 ) ) ); 453 $this->assertEquals( 3, get_page_of_comment( $comment_last[0], array( 'per_page' => 3, 'include_unapproved' => 'example@example.com' ) ) ); 454 455 self::factory()->comment->update_object( $unapproved[0], array( 'comment_approved' => 1 )); 456 457 $this->assertEquals( 2, get_page_of_comment( $comment_last[0], array( 'per_page' => 3 ) ) ); 458 $this->assertEquals( 3, get_page_of_comment( $comment_last[0], array( 'per_page' => 3, 'include_unapproved' => 'example@example.com' ) ) ); 459 } 432 460 }