Changeset 48133
- Timestamp:
- 06/23/2020 05:22:39 AM (4 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/comment-template.php
r48104 r48133 1331 1331 * 1332 1332 * @since 1.5.0 1333 * @since 5.5.0 Removed the need to use the $user_ID global. 1333 1334 * 1334 1335 * @global WP_Query $wp_query WordPress Query object. … … 1338 1339 * @global WP_Comment $comment Global comment object. 1339 1340 * @global string $user_login 1340 * @global int $user_ID1341 1341 * @global string $user_identity 1342 1342 * @global bool $overridden_cpage … … 1348 1348 */ 1349 1349 function comments_template( $file = '/comments.php', $separate_comments = false ) { 1350 global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ ID, $user_identity, $overridden_cpage;1350 global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_identity, $overridden_cpage; 1351 1351 1352 1352 if ( ! ( is_single() || is_page() || $withcomments ) || empty( $post ) ) { … … 1397 1397 } 1398 1398 1399 if ( $user_ID ) { 1400 $comment_args['include_unapproved'] = array( $user_ID ); 1401 } else { 1402 $unapproved_email = wp_get_unapproved_comment_author_email(); 1403 1404 if ( $unapproved_email ) { 1405 $comment_args['include_unapproved'] = array( $unapproved_email ); 1406 } 1399 $include_unapproved = wp_get_include_unapproved_comments_argument(); 1400 if ( $include_unapproved ) { 1401 $comment_args['include_unapproved'] = $include_unapproved; 1407 1402 } 1408 1403 -
trunk/src/wp-includes/comment.php
r48121 r48133 1133 1133 ); 1134 1134 1135 $include_unapproved = wp_get_include_unapproved_comments_argument(); 1136 if ( $include_unapproved ) { 1137 $comment_args['include_unapproved'] = $include_unapproved; 1138 } 1139 1140 /** 1141 * Filters the arguments used to query comments in get_page_of_comment(). 1142 * 1143 * @since 5.5.0 1144 * 1145 * @see WP_Comment_Query::__construct() 1146 * 1147 * @param array $comment_args { 1148 * Array of WP_Comment_Query arguments. 1149 * 1150 * @type string $type Limit paginated comments to those matching a given type. Accepts 'comment', 1151 * 'trackback', 'pingback', 'pings' (trackbacks and pingbacks), or 'all'. 1152 * Default is 'all'. 1153 * @type int $post_id ID of the post. 1154 * @type string $fields Comment fields to return. 1155 * @type bool $count Whether to return a comment count (true) or array of 1156 * comment objects (false) 1157 * @type string $status Comment status. 1158 * @type int $parent Parent ID of comment to retrieve children of. 1159 * @type array $date_query Date query clauses to limit comments by. See WP_Date_Query. 1160 * @type array $include_unapproved Array of IDs or email addresses whose unapproved comments 1161 * will be included in paginated comments. 1162 * } 1163 */ 1164 $comment_args = apply_filters( 'get_page_of_comment_query_args', $comment_args ); 1135 1165 $comment_query = new WP_Comment_Query(); 1136 1166 $older_comment_count = $comment_query->query( $comment_args ); … … 1895 1925 1896 1926 return $commenter_email; 1927 } 1928 1929 /** 1930 * Get include unapproved comments query argument. 1931 * 1932 * Used to include unapproved comments of currrent commenters to 1933 * keep them informed their comments were successfully saved. 1934 * 1935 * @since 5.5.0 1936 * 1937 * @return array The unapproved comments query argument. 1938 */ 1939 function wp_get_include_unapproved_comments_argument() { 1940 $user_id = get_current_user_id(); 1941 $include_unapproved = array(); 1942 1943 if ( $user_id ) { 1944 $include_unapproved = array( $user_id ); 1945 } else { 1946 $unapproved_email = wp_get_unapproved_comment_author_email(); 1947 1948 if ( $unapproved_email ) { 1949 $include_unapproved = array( $unapproved_email ); 1950 } 1951 } 1952 1953 return $include_unapproved; 1897 1954 } 1898 1955 -
trunk/tests/phpunit/tests/comment/getPageOfComment.php
r47122 r48133 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( 475 array( 476 'number' => 3, 477 'paged' => $page, 478 'post_id' => $post, 479 'status' => 'approve', 480 'include_unapproved' => array( 'foo@bar.test' ), 481 'orderby' => 'comment_date_gmt', 482 'order' => 'ASC', 483 ) 484 ); 485 486 remove_filter( 'wp_get_current_commenter', array( $this, 'get_current_commenter' ) ); 487 488 $this->assertContains( $new_unapproved, wp_list_pluck( $comments, 'comment_ID' ) ); 489 } 490 491 /** 492 * @ticket 8973 493 */ 494 public function test_page_number_when_unapproved_comments_are_included_for_current_user() { 495 $current_user = get_current_user_id(); 496 $post = self::factory()->post->create(); 497 $user = self::factory()->user->create_and_get(); 498 $comment_args = array( 499 'comment_post_ID' => $post, 500 'comment_approved' => 0, 501 'comment_author_email' => $user->user_email, 502 'comment_author' => $user->display_name, 503 'comment_author_url' => $user->user_url, 504 'user_id' => $user->ID, 505 ); 506 507 for ( $i = 1; $i < 4; $i++ ) { 508 self::factory()->comment->create( 509 array_merge( 510 $comment_args, 511 array( 512 'comment_date_gmt' => gmdate( 'Y-m-d H:i:s', time() - ( $i * 1000 ) ), 513 ) 514 ) 515 ); 516 } 517 518 $new_unapproved = self::factory()->comment->create( 519 $comment_args 520 ); 521 522 wp_set_current_user( $user->ID ); 523 524 $page = get_page_of_comment( $new_unapproved, array( 'per_page' => 3 ) ); 525 $comments = get_comments( 526 array( 527 'number' => 3, 528 'paged' => $page, 529 'post_id' => $post, 530 'status' => 'approve', 531 'include_unapproved' => array( $user->ID ), 532 'orderby' => 'comment_date_gmt', 533 'order' => 'ASC', 534 ) 535 ); 536 537 $this->assertContains( $new_unapproved, wp_list_pluck( $comments, 'comment_ID' ) ); 538 539 wp_set_current_user( $current_user ); 540 } 541 542 public function get_current_commenter() { 543 return array( 544 'comment_author_email' => 'foo@bar.test', 545 'comment_author' => 'Foo', 546 'comment_author_url' => 'https://bar.test', 547 ); 548 } 442 549 }
Note: See TracChangeset
for help on using the changeset viewer.