Ticket #8973: 8973.5.patch
File 8973.5.patch, 8.1 KB (added by , 5 years ago) |
---|
-
src/wp-includes/comment-template.php
diff --git src/wp-includes/comment-template.php src/wp-includes/comment-template.php index 9d20c6bbd2..0dd006ccd8 100644
function wp_comment_form_unfiltered_html_nonce() { 1321 1321 * Will not try to get the comments if the post has none. 1322 1322 * 1323 1323 * @since 1.5.0 1324 * @since 5.5.0 Removed the need to use the $user_ID global. 1324 1325 * 1325 1326 * @global WP_Query $wp_query WordPress Query object. 1326 1327 * @global WP_Post $post Global post object. … … function wp_comment_form_unfiltered_html_nonce() { 1328 1329 * @global int $id 1329 1330 * @global WP_Comment $comment Global comment object. 1330 1331 * @global string $user_login 1331 * @global int $user_ID1332 1332 * @global string $user_identity 1333 1333 * @global bool $overridden_cpage 1334 1334 * @global bool $withcomments … … function wp_comment_form_unfiltered_html_nonce() { 1338 1338 * Default false. 1339 1339 */ 1340 1340 function comments_template( $file = '/comments.php', $separate_comments = false ) { 1341 global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ ID, $user_identity, $overridden_cpage;1341 global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_identity, $overridden_cpage; 1342 1342 1343 1343 if ( ! ( is_single() || is_page() || $withcomments ) || empty( $post ) ) { 1344 1344 return; … … function comments_template( $file = '/comments.php', $separate_comments = false 1387 1387 $comment_args['hierarchical'] = false; 1388 1388 } 1389 1389 1390 if ( $user_ID ) { 1391 $comment_args['include_unapproved'] = array( $user_ID ); 1392 } else { 1393 $unapproved_email = wp_get_unapproved_comment_author_email(); 1394 1395 if ( $unapproved_email ) { 1396 $comment_args['include_unapproved'] = array( $unapproved_email ); 1397 } 1390 $include_unapproved = wp_get_include_unapproved_comments_argument(); 1391 if ( $include_unapproved ) { 1392 $comment_args['include_unapproved'] = $include_unapproved; 1398 1393 } 1399 1394 1400 1395 $per_page = 0; -
src/wp-includes/comment.php
diff --git src/wp-includes/comment.php src/wp-includes/comment.php index 15cb44bcc3..9c2302b815 100644
function get_page_of_comment( $comment_ID, $args = array() ) { 1113 1113 ), 1114 1114 ); 1115 1115 1116 $include_unapproved = wp_get_include_unapproved_comments_argument(); 1117 if ( $include_unapproved ) { 1118 $comment_args['include_unapproved'] = $include_unapproved; 1119 } 1120 1121 /** 1122 * Filters the arguments used to query comments in get_page_of_comment(). 1123 * 1124 * @since 5.5.0 1125 * 1126 * @see WP_Comment_Query::__construct() 1127 * 1128 * @param array $comment_args { 1129 * Array of WP_Comment_Query arguments. 1130 * 1131 * @type string $type Limit paginated comments to those matching a given type. Accepts 'comment', 1132 * 'trackback', 'pingback', 'pings' (trackbacks and pingbacks), or 'all'. 1133 * Default is 'all'. 1134 * @type int $post_id ID of the post. 1135 * @type string $fields Comment fields to return. 1136 * @type bool $count Whether to return a comment count (true) or array of 1137 * comment objects (false) 1138 * @type string $status Comment status. 1139 * @type int $parent Parent ID of comment to retrieve children of. 1140 * @type array $date_query Date query clauses to limit comments by. See WP_Date_Query. 1141 * @type array $include_unapproved Array of IDs or email addresses whose unapproved comments 1142 * will be included in paginated comments. 1143 * } 1144 */ 1145 $comment_args = apply_filters( 'get_page_of_comment_query_args', $comment_args ); 1116 1146 $comment_query = new WP_Comment_Query(); 1117 1147 $older_comment_count = $comment_query->query( $comment_args ); 1118 1148 … … function wp_get_unapproved_comment_author_email() { 1849 1879 return $commenter_email; 1850 1880 } 1851 1881 1882 /** 1883 * Get include unapproved comments query argument. 1884 * 1885 * Used to include unapproved comments of currrent commenters to 1886 * keep them informed their comments were successfully saved. 1887 * 1888 * @since 5.5.0 1889 * 1890 * @return array The unapproved comments query argument. 1891 */ 1892 function wp_get_include_unapproved_comments_argument() { 1893 $user_id = get_current_user_id(); 1894 $include_unapproved = array(); 1895 1896 if ( $user_id ) { 1897 $include_unapproved = array( $user_id ); 1898 } else { 1899 $unapproved_email = wp_get_unapproved_comment_author_email(); 1900 1901 if ( $unapproved_email ) { 1902 $include_unapproved = array( $unapproved_email ); 1903 } 1904 } 1905 1906 return $include_unapproved; 1907 } 1908 1852 1909 /** 1853 1910 * Inserts a comment into the database. 1854 1911 * -
tests/phpunit/tests/comment/getPageOfComment.php
diff --git tests/phpunit/tests/comment/getPageOfComment.php tests/phpunit/tests/comment/getPageOfComment.php index 5059625660..1501c10fd1 100644
class Tests_Comment_GetPageOfComment extends WP_UnitTestCase { 439 439 440 440 $this->assertEquals( 2, get_page_of_comment( $c3 ) ); 441 441 } 442 443 /** 444 * @ticket 8973 445 */ 446 public function test_page_number_when_unapproved_comments_are_included_for_current_commenter() { 447 $post = self::factory()->post->create(); 448 $comment_args = array( 449 'comment_post_ID' => $post, 450 'comment_approved' => 0, 451 'comment_author_email' => 'foo@bar.test', 452 'comment_author' => 'Foo', 453 'comment_author_url' => 'https://bar.test', 454 ); 455 456 for ( $i = 1 ; $i < 4 ; $i++ ) { 457 self::factory()->comment->create( 458 array_merge( 459 $comment_args, 460 array( 461 'comment_date_gmt' => gmdate( 'Y-m-d H:i:s', time() - ( $i * 1000 ) ), 462 ) 463 ) 464 ); 465 } 466 467 $new_unapproved = self::factory()->comment->create( 468 $comment_args 469 ); 470 471 add_filter( 'wp_get_current_commenter', array( $this, 'get_current_commenter' ) ); 472 473 $page = get_page_of_comment( $new_unapproved, array( 'per_page' => 3 ) ); 474 $comments = get_comments( array( 475 'number' => 3, 476 'paged' => $page, 477 'post_id' => $post, 478 'status' => 'approve', 479 'include_unapproved' => array( 'foo@bar.test' ), 480 'orderby' => 'comment_date_gmt', 481 'order' => 'ASC', 482 ) ); 483 484 remove_filter( 'wp_get_current_commenter', array( $this, 'get_current_commenter' ) ); 485 486 $this->assertContains( $new_unapproved, wp_list_pluck( $comments, 'comment_ID' ) ); 487 } 488 489 /** 490 * @ticket 8973 491 */ 492 public function test_page_number_when_unapproved_comments_are_included_for_current_user() { 493 $current_user = get_current_user_id(); 494 $post = self::factory()->post->create(); 495 $user = self::factory()->user->create_and_get(); 496 $comment_args = array( 497 'comment_post_ID' => $post, 498 'comment_approved' => 0, 499 'comment_author_email' => $user->user_email, 500 'comment_author' => $user->display_name, 501 'comment_author_url' => $user->user_url, 502 'user_id' => $user->ID, 503 ); 504 505 for ( $i = 1 ; $i < 4 ; $i++ ) { 506 self::factory()->comment->create( 507 array_merge( 508 $comment_args, 509 array( 510 'comment_date_gmt' => gmdate( 'Y-m-d H:i:s', time() - ( $i * 1000 ) ), 511 ) 512 ) 513 ); 514 } 515 516 $new_unapproved = self::factory()->comment->create( 517 $comment_args 518 ); 519 520 wp_set_current_user( $user->ID ); 521 522 $page = get_page_of_comment( $new_unapproved, array( 'per_page' => 3 ) ); 523 $comments = get_comments( array( 524 'number' => 3, 525 'paged' => $page, 526 'post_id' => $post, 527 'status' => 'approve', 528 'include_unapproved' => array( $user->ID ), 529 'orderby' => 'comment_date_gmt', 530 'order' => 'ASC', 531 ) ); 532 533 $this->assertContains( $new_unapproved, wp_list_pluck( $comments, 'comment_ID' ) ); 534 535 wp_set_current_user( $current_user ); 536 } 537 538 public function get_current_commenter() { 539 return array( 540 'comment_author_email' => 'foo@bar.test', 541 'comment_author' => 'Foo', 542 'comment_author_url' => 'https://bar.test', 543 ); 544 } 442 545 }