Ticket #8973: 8973.4.patch
File 8973.4.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 b10fe1415e..687aecdf52 100644
function wp_comment_form_unfiltered_html_nonce() { 1302 1302 * Will not try to get the comments if the post has none. 1303 1303 * 1304 1304 * @since 1.5.0 1305 * @since 5.3.0 Removed the need to use the $user_ID global. 1305 1306 * 1306 1307 * @global WP_Query $wp_query WordPress Query object. 1307 1308 * @global WP_Post $post Global post object. … … function wp_comment_form_unfiltered_html_nonce() { 1309 1310 * @global int $id 1310 1311 * @global WP_Comment $comment 1311 1312 * @global string $user_login 1312 * @global int $user_ID1313 1313 * @global string $user_identity 1314 1314 * @global bool $overridden_cpage 1315 1315 * @global bool $withcomments … … function wp_comment_form_unfiltered_html_nonce() { 1319 1319 * Default false. 1320 1320 */ 1321 1321 function comments_template( $file = '/comments.php', $separate_comments = false ) { 1322 global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ ID, $user_identity, $overridden_cpage;1322 global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_identity, $overridden_cpage; 1323 1323 1324 1324 if ( ! ( is_single() || is_page() || $withcomments ) || empty( $post ) ) { 1325 1325 return; … … function comments_template( $file = '/comments.php', $separate_comments = false 1368 1368 $comment_args['hierarchical'] = false; 1369 1369 } 1370 1370 1371 if ( $user_ID ) { 1372 $comment_args['include_unapproved'] = array( $user_ID ); 1373 } else { 1374 $unapproved_email = wp_get_unapproved_comment_author_email(); 1375 1376 if ( $unapproved_email ) { 1377 $comment_args['include_unapproved'] = array( $unapproved_email ); 1378 } 1371 $include_unapproved = wp_get_include_unapproved_comments_argument(); 1372 if ( $include_unapproved ) { 1373 $comment_args['include_unapproved'] = $include_unapproved; 1379 1374 } 1380 1375 1381 1376 $per_page = 0; -
src/wp-includes/comment.php
diff --git src/wp-includes/comment.php src/wp-includes/comment.php index 4b192ea02e..d60ff78797 100644
function get_page_of_comment( $comment_ID, $args = array() ) { 1102 1102 ), 1103 1103 ); 1104 1104 1105 $include_unapproved = wp_get_include_unapproved_comments_argument(); 1106 if ( $include_unapproved ) { 1107 $comment_args['include_unapproved'] = $include_unapproved; 1108 } 1109 1110 /** 1111 * Filters the arguments used to query comments in get_page_of_comment(). 1112 * 1113 * @since 5.3.0 1114 * 1115 * @see WP_Comment_Query::__construct() 1116 * 1117 * @param array $comment_args { 1118 * Array of WP_Comment_Query arguments. 1119 * 1120 * @type string $type Limit paginated comments to those matching a given type. Accepts 'comment', 1121 * 'trackback', 'pingback', 'pings' (trackbacks and pingbacks), or 'all'. 1122 * Default is 'all'. 1123 * @type int $post_id ID of the post. 1124 * @type string $fields Comment fields to return. 1125 * @type bool $count Whether to return a comment count (true) or array of 1126 * comment objects (false) 1127 * @type string $status Comment status. 1128 * @type int $parent Parent ID of comment to retrieve children of. 1129 * @type array $date_query Date query clauses to limit comments by. See WP_Date_Query. 1130 * @type array $include_unapproved Array of IDs or email addresses whose unapproved comments 1131 * will be included in paginated comments. 1132 * } 1133 */ 1134 $comment_args = apply_filters( 'get_page_of_comment_query_args', $comment_args ); 1105 1135 $comment_query = new WP_Comment_Query(); 1106 1136 $older_comment_count = $comment_query->query( $comment_args ); 1107 1137 … … function wp_get_unapproved_comment_author_email() { 1824 1854 return $commenter_email; 1825 1855 } 1826 1856 1857 /** 1858 * Get include unapproved comments query argument. 1859 * 1860 * Used to include unapproved comments of currrent commenters to 1861 * keep them informed their comments were successfully saved. 1862 * 1863 * @since 5.3.0 1864 * 1865 * @return array The unapproved comments query argument. 1866 */ 1867 function wp_get_include_unapproved_comments_argument() { 1868 $user_id = get_current_user_id(); 1869 $include_unapproved = array(); 1870 1871 if ( $user_id ) { 1872 $include_unapproved = array( $user_id ); 1873 } else { 1874 $unapproved_email = wp_get_unapproved_comment_author_email(); 1875 1876 if ( $unapproved_email ) { 1877 $include_unapproved = array( $unapproved_email ); 1878 } 1879 } 1880 1881 return $include_unapproved; 1882 } 1883 1827 1884 /** 1828 1885 * Inserts a comment into the database. 1829 1886 * -
tests/phpunit/tests/comment/getPageOfComment.php
diff --git tests/phpunit/tests/comment/getPageOfComment.php tests/phpunit/tests/comment/getPageOfComment.php index e6527ffb94..614c45284f 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 }