Ticket #8973: 8973.3.diff
File 8973.3.diff, 6.8 KB (added by , 5 years ago) |
---|
-
src/wp-includes/comment-template.php
From 26bec5a5b5df846c859c6f7cacded7fb2f5cbae1 Mon Sep 17 00:00:00 2001 From: Matteo Giaccone <matteo@turnintocoders.it> Date: Fri, 6 Apr 2018 16:24:19 +0200 Subject: [PATCH] Patch 8973 --- src/wp-includes/comment-template.php | 39 +++++++------------ src/wp-includes/comment.php | 2 + .../tests/comment/getPageOfComment.php | 28 +++++++++++++ 3 files changed, 43 insertions(+), 26 deletions(-) diff --git a/src/wp-includes/comment-template.php b/src/wp-includes/comment-template.php index 41031cba93..ae04ba3d27 100644
a b function get_comment_link( $comment = null, $args = array() ) { 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 … … function get_comment_link( $comment = null, $args = array() ) { 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' ); … … function wp_comment_form_unfiltered_html_nonce() { 1311 1321 * @global int $id 1312 1322 * @global WP_Comment $comment 1313 1323 * @global string $user_login 1314 * @global int $user_ID1315 1324 * @global string $user_identity 1316 1325 * @global bool $overridden_cpage 1317 1326 * @global bool $withcomments … … function wp_comment_form_unfiltered_html_nonce() { 1321 1330 * Default false. 1322 1331 */ 1323 1332 function comments_template( $file = '/comments.php', $separate_comments = false ) { 1324 global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ ID, $user_identity, $overridden_cpage;1333 global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_identity, $overridden_cpage; 1325 1334 1326 1335 if ( ! ( is_single() || is_page() || $withcomments ) || empty( $post ) ) { 1327 1336 return; … … function comments_template( $file = '/comments.php', $separate_comments = false 1333 1342 1334 1343 $req = get_option( 'require_name_email' ); 1335 1344 1336 /*1337 * Comment author information fetched from the comment cookies.1338 */1339 $commenter = wp_get_current_commenter();1340 1341 /*1342 * The name of the current comment author escaped for use in attributes.1343 * Escaped by sanitize_comment_cookies().1344 */1345 $comment_author = $commenter['comment_author'];1346 1347 /*1348 * The email address of the current comment author escaped for use in attributes.1349 * Escaped by sanitize_comment_cookies().1350 */1351 $comment_author_email = $commenter['comment_author_email'];1352 1353 /*1354 * The url of the current comment author escaped for use in attributes.1355 */1356 $comment_author_url = esc_url( $commenter['comment_author_url'] );1357 1358 1345 $comment_args = array( 1359 1346 'orderby' => 'comment_date_gmt', 1360 1347 'order' => 'ASC', … … function comments_template( $file = '/comments.php', $separate_comments = false 1370 1357 $comment_args['hierarchical'] = false; 1371 1358 } 1372 1359 1373 if ( $user_ID) {1374 $comment_args['include_unapproved'] = array( $user_ID);1360 if ( is_user_logged_in() ) { 1361 $comment_args['include_unapproved'] = get_current_user_id(); 1375 1362 } else { 1376 1363 $unapproved_email = wp_get_unapproved_comment_author_email(); 1377 1364 -
src/wp-includes/comment.php
diff --git a/src/wp-includes/comment.php b/src/wp-includes/comment.php index 5e89ef7695..89ef6aa2e3 100644
a b function get_page_of_comment( $comment_ID, $args = array() ) { 1047 1047 'page' => '', 1048 1048 'per_page' => '', 1049 1049 'max_depth' => '', 1050 'include_unapproved' => '', 1050 1051 ); 1051 1052 $args = wp_parse_args( $args, $defaults ); 1052 1053 $original_args = $args; … … function get_page_of_comment( $comment_ID, $args = array() ) { 1091 1092 'fields' => 'ids', 1092 1093 'count' => true, 1093 1094 'status' => 'approve', 1095 'include_unapproved' => $args['include_unapproved'], 1094 1096 'parent' => 0, 1095 1097 'date_query' => array( 1096 1098 array( -
tests/phpunit/tests/comment/getPageOfComment.php
diff --git a/tests/phpunit/tests/comment/getPageOfComment.php b/tests/phpunit/tests/comment/getPageOfComment.php index 509ecffad6..23e23aa46e 100644
a b public function test_should_ignore_default_comment_page() { 437 437 438 438 $this->assertEquals( 2, get_page_of_comment( $c3 ) ); 439 439 } 440 441 /** 442 * @ticket 8973 443 */ 444 public function test_page_number_when_user_has_unapproved_comments() { 445 $p = self::factory()->post->create(); 446 447 // page 3 448 $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' ) ); 449 450 // page 2 451 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' ) ); 452 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' ) ); 453 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' ) ); 454 455 // page 1 456 $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' ) ); 457 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' ) ); 458 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' ) ); 459 460 $this->assertEquals( 1, get_page_of_comment( $comment_last[0], array( 'per_page' => 3 ) ) ); 461 $this->assertEquals( 3, get_page_of_comment( $comment_last[0], array( 'per_page' => 3, 'include_unapproved' => 'example@example.com' ) ) ); 462 463 self::factory()->comment->update_object( $unapproved[0], array( 'comment_approved' => 1 )); 464 465 $this->assertEquals( 2, get_page_of_comment( $comment_last[0], array( 'per_page' => 3 ) ) ); 466 $this->assertEquals( 3, get_page_of_comment( $comment_last[0], array( 'per_page' => 3, 'include_unapproved' => 'example@example.com' ) ) ); 467 } 440 468 }