Ticket #56244: 56244.2.diff
| File 56244.2.diff, 4.5 KB (added by , 4 years ago) |
|---|
-
src/wp-includes/comment.php
2208 2208 function wp_new_comment( $commentdata, $wp_error = false ) { 2209 2209 global $wpdb; 2210 2210 2211 /* 2212 * Normalize `user_ID` to `user_id`, but pass the old key 2213 * to the `preprocess_comment` filter for backward compatibility. 2214 */ 2211 2215 if ( isset( $commentdata['user_ID'] ) ) { 2212 2216 $commentdata['user_ID'] = (int) $commentdata['user_ID']; 2213 2217 $commentdata['user_id'] = $commentdata['user_ID']; 2218 } elseif ( isset( $commentdata['user_id'] ) ) { 2219 $commentdata['user_id'] = (int) $commentdata['user_id']; 2220 $commentdata['user_ID'] = $commentdata['user_id']; 2214 2221 } 2215 2222 2216 2223 $prefiltered_user_id = ( isset( $commentdata['user_id'] ) ) ? (int) $commentdata['user_id'] : 0; … … 2235 2242 2236 2243 $commentdata['comment_post_ID'] = (int) $commentdata['comment_post_ID']; 2237 2244 2245 // Normalize `user_ID` to `user_id` again, after the filter. 2238 2246 if ( isset( $commentdata['user_ID'] ) && $prefiltered_user_id !== (int) $commentdata['user_ID'] ) { 2239 $commentdata['user_ID'] = (int) $commentdata['user_ID']; 2240 $commentdata['user_id'] = $commentdata['user_ID']; 2247 $commentdata['user_id'] = (int) $commentdata['user_ID']; 2241 2248 } elseif ( isset( $commentdata['user_id'] ) ) { 2242 2249 $commentdata['user_id'] = (int) $commentdata['user_id']; 2243 2250 } … … 3587 3594 3588 3595 $commentdata = array( 3589 3596 'comment_post_ID' => $comment_post_id, 3590 'user_ID' => $user_id,3591 3597 ); 3592 3598 3593 3599 $commentdata += compact( … … 3596 3602 'comment_author_url', 3597 3603 'comment_content', 3598 3604 'comment_type', 3599 'comment_parent' 3605 'comment_parent', 3606 'user_id', 3600 3607 ); 3601 3608 3602 3609 /** -
tests/phpunit/tests/comment-submission.php
795 795 * @ticket 34997 796 796 */ 797 797 public function test_comment_submission_sends_all_expected_parameters_to_preprocess_comment_filter() { 798 799 798 $user = get_userdata( self::$author_id ); 800 799 wp_set_current_user( $user->ID ); 801 800 -
tests/phpunit/tests/comment.php
8 8 protected static $post_id; 9 9 protected static $notify_message = ''; 10 10 11 protected $preprocess_comment_data = array(); 12 11 13 public function set_up() { 12 14 parent::set_up(); 13 15 reset_phpmailer_instance(); … … 403 405 } 404 406 405 407 406 public function test_ comment_field_lengths() {408 public function test_wp_new_comment_respects_comment_field_lengths() { 407 409 $data = array( 408 410 'comment_post_ID' => self::$post_id, 409 411 'comment_author' => 'Comment Author', … … 423 425 } 424 426 425 427 /** 428 * @ticket 56244 429 */ 430 public function test_wp_new_comment_sends_all_expected_parameters_to_preprocess_comment_filter() { 431 $user = get_userdata( self::$user_id ); 432 wp_set_current_user( $user->ID ); 433 434 $data = array( 435 'comment_post_ID' => self::$post_id, 436 'comment_author' => $user->display_name, 437 'comment_author_email' => $user->user_email, 438 'comment_author_url' => $user->user_url, 439 'comment_content' => 'Comment', 440 'comment_type' => '', 441 'comment_parent' => 0, 442 'user_id' => $user->ID, 443 ); 444 445 add_filter( 'preprocess_comment', array( $this, 'filter_preprocess_comment' ) ); 446 447 $comment = wp_new_comment( $data ); 448 449 remove_filter( 'preprocess_comment', array( $this, 'filter_preprocess_comment' ) ); 450 451 $this->assertNotWPError( $comment ); 452 $this->assertSameSetsWithIndex( 453 array( 454 'comment_post_ID' => self::$post_id, 455 'comment_author' => $user->display_name, 456 'comment_author_email' => $user->user_email, 457 'comment_author_url' => $user->user_url, 458 'comment_content' => $data['comment_content'], 459 'comment_type' => '', 460 'comment_parent' => 0, 461 'user_ID' => $user->ID, 462 'user_id' => $user->ID, 463 'comment_author_IP' => '127.0.0.1', 464 'comment_agent' => '', 465 ), 466 $this->preprocess_comment_data 467 ); 468 469 } 470 471 public function filter_preprocess_comment( $commentdata ) { 472 $this->preprocess_comment_data = $commentdata; 473 return $commentdata; 474 } 475 476 /** 426 477 * @ticket 32566 427 478 */ 428 479 public function test_wp_notify_moderator_should_not_throw_notice_when_post_author_is_0() {
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)