Ticket #16979: comment.diff
| File comment.diff, 9.9 KB (added by , 11 years ago) |
|---|
-
src/wp-comments-post.php
126 126 } 127 127 } 128 128 129 if ( '' == $comment_content ) {130 wp_die( __( '<strong>ERROR</strong>: please type a comment.' ), 200 );131 }132 133 129 $comment_parent = isset($_POST['comment_parent']) ? absint($_POST['comment_parent']) : 0; 134 130 135 131 $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'comment_parent', 'user_ID'); -
src/wp-includes/comment.php
1350 1350 function wp_allow_comment( $commentdata ) { 1351 1351 global $wpdb; 1352 1352 1353 // Simple duplicate check1354 // expected_slashed ($comment_post_ID, $comment_author, $comment_author_email, $comment_content)1355 $dupe = $wpdb->prepare(1356 "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_parent = %s AND comment_approved != 'trash' AND ( comment_author = %s ",1357 wp_unslash( $commentdata['comment_post_ID'] ),1358 wp_unslash( $commentdata['comment_parent'] ),1359 wp_unslash( $commentdata['comment_author'] )1360 );1361 if ( $commentdata['comment_author_email'] ) {1362 $dupe .= $wpdb->prepare(1363 "OR comment_author_email = %s ",1364 wp_unslash( $commentdata['comment_author_email'] )1365 );1366 }1367 $dupe .= $wpdb->prepare(1368 ") AND comment_content = %s LIMIT 1",1369 wp_unslash( $commentdata['comment_content'] )1370 );1371 if ( $wpdb->get_var( $dupe ) ) {1372 /**1373 * Fires immediately after a duplicate comment is detected.1374 *1375 * @since 3.0.01376 *1377 * @param array $commentdata Comment data.1378 */1379 do_action( 'comment_duplicate_trigger', $commentdata );1380 if ( defined( 'DOING_AJAX' ) ) {1381 die( __('Duplicate comment detected; it looks as though you’ve already said that!') );1382 }1383 wp_die( __( 'Duplicate comment detected; it looks as though you’ve already said that!' ), 409 );1384 }1385 1386 1353 /** 1387 1354 * Fires immediately before a comment is marked approved. 1388 1355 * … … 1398 1365 'check_comment_flood', 1399 1366 $commentdata['comment_author_IP'], 1400 1367 $commentdata['comment_author_email'], 1401 $commentdata['comment_date_gmt'] 1368 $commentdata['comment_date_gmt'], 1369 $commentdata 1402 1370 ); 1403 1371 1404 1372 if ( ! empty( $commentdata['user_id'] ) ) { … … 1453 1421 } 1454 1422 1455 1423 /** 1424 * Check whether the comment has been posted already 1425 * 1426 * 1427 * @since 4.3.0 1428 * @uses $wpdb 1429 * @uses do_action() Calls 'comment_duplicate_trigger' action with the comment data 1430 * 1431 * @param string $ip Comment IP. 1432 * @param string $email Comment author email address. 1433 * @param string $date MySQL time string. 1434 * @param array $commentdata The pre-processed comment data 1435 */ 1436 function check_comment_flood_duplicate( $ip, $email, $date, $commentdata ) { 1437 global $wpdb; 1438 1439 // Simple duplicate check 1440 // expected_slashed ($comment_post_ID, $comment_author, $comment_author_email, $comment_content) 1441 $dupe = $wpdb->prepare( 1442 "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_parent = %s AND comment_approved != 'trash' AND ( comment_author = %s ", 1443 wp_unslash( $commentdata['comment_post_ID'] ), 1444 wp_unslash( $commentdata['comment_parent'] ), 1445 wp_unslash( $commentdata['comment_author'] ) 1446 ); 1447 if ( $commentdata['comment_author_email'] ) { 1448 $dupe .= $wpdb->prepare( 1449 "OR comment_author_email = %s ", 1450 wp_unslash( $commentdata['comment_author_email'] ) 1451 ); 1452 } 1453 $dupe .= $wpdb->prepare( 1454 ") AND comment_content = %s LIMIT 1", 1455 wp_unslash( $commentdata['comment_content'] ) 1456 ); 1457 if ( $wpdb->get_var( $dupe ) ) { 1458 /** 1459 * Fires immediately after a duplicate comment is detected. 1460 * 1461 * @since 3.0.0 1462 * 1463 * @param array $commentdata Comment data. 1464 */ 1465 do_action( 'comment_duplicate_trigger', $commentdata ); 1466 if ( defined( 'DOING_AJAX' ) ) { 1467 die( __('Duplicate comment detected; it looks as though you’ve already said that!') ); 1468 } 1469 wp_die( __( 'Duplicate comment detected; it looks as though you’ve already said that!' ), 409 ); 1470 } 1471 } 1472 1473 /** 1456 1474 * Check whether comment flooding is occurring. 1457 1475 * 1458 1476 * Won't run, if current user can manage options, so to not block … … 1503 1521 } 1504 1522 } 1505 1523 1524 /** 1525 * Blocks empty comments by wp_die()'ing on empty comments 1526 * 1527 * This function is hooked as such: 1528 * <code>add_filter( 'preprocess_comment', 'disallow_empty_comments', 5 );</code> 1529 * 1530 * @since 4.3.0 1531 * 1532 * @param array $commentdata the comment data 1533 * @return array the comment data 1534 */ 1535 function disallow_empty_comments( $commentdata ) { 1536 if ( '' == $commentdata[ 'comment_content' ] ) { 1537 wp_die( __( '<strong>ERROR</strong>: please type a comment.' ), 200 ); 1538 } 1539 1540 return $commentdata; 1541 } 1542 1506 1543 /** 1507 1544 * Separates an array of comments into an array keyed by comment_type. 1508 1545 * … … 2193 2230 $user_id = ! isset( $data['user_id'] ) ? 0 : $data['user_id']; 2194 2231 2195 2232 $compacted = compact( 'comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_date', 'comment_date_gmt', 'comment_content', 'comment_karma', 'comment_approved', 'comment_agent', 'comment_type', 'comment_parent', 'user_id' ); 2233 2234 $compacted = apply_filters( 'wp_insert_comment_data', $compacted ); 2235 2196 2236 if ( ! $wpdb->insert( $wpdb->comments, $compacted ) ) { 2197 2237 return false; 2198 2238 } … … 2375 2415 2376 2416 $commentdata['comment_approved'] = wp_allow_comment($commentdata); 2377 2417 2418 $commentdata = apply_filters( 'process_comment', $commentdata ); 2419 2378 2420 $comment_ID = wp_insert_comment($commentdata); 2379 2421 if ( ! $comment_ID ) { 2380 2422 $fields = array( 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content' ); -
src/wp-includes/default-filters.php
185 185 add_filter( 'teeny_mce_before_init', '_mce_set_direction' ); 186 186 add_filter( 'pre_kses', 'wp_pre_kses_less_than' ); 187 187 add_filter( 'sanitize_title', 'sanitize_title_with_dashes', 10, 3 ); 188 add_action( 'check_comment_flood', 'check_comment_flood_duplicate', 10, 4); 188 189 add_action( 'check_comment_flood', 'check_comment_flood_db', 10, 3 ); 189 190 add_filter( 'comment_flood_filter', 'wp_throttle_comment_flood', 10, 3 ); 190 191 add_filter( 'pre_comment_content', 'wp_rel_nofollow', 15 ); … … 197 198 add_filter( 'editable_slug', 'urldecode' ); 198 199 add_filter( 'editable_slug', 'esc_textarea' ); 199 200 add_filter( 'nav_menu_meta_box_object', '_wp_nav_menu_meta_box_object' ); 201 add_filter( 'preprocess_comment', 'disallow_empty_comments', 5 ); 200 202 add_filter( 'pingback_ping_source_uri', 'pingback_ping_source_uri' ); 201 203 add_filter( 'xmlrpc_pingback_error', 'xmlrpc_pingback_error' ); 202 204 add_filter( 'title_save_pre', 'trim' ); -
tests/phpunit/tests/comment/duplicateContent.php
1 <?php 2 /** 3 * @group comment 4 */ 5 class Tests_Comment_DuplicateContent extends WP_UnitTestCase { 6 7 function test_comment_allow_duplicate_content_after_filter_removed() { 8 $user = $this->factory->user->create(); 9 $post_id = $this->factory->post->create(); 10 11 $content = 'test_content'; 12 13 $data = array( 14 'comment_post_ID' => $post_id, 15 'comment_author' => $user, 16 'comment_author_IP' => '192.168.1.1', 17 'comment_author_url' => '', 18 'comment_author_email' => '', 19 'comment_type' => '', 20 'comment_date_gmt' => '2015-01-01 10:00:00', 21 'comment_content' => $content, 22 ); 23 24 $id_first = wp_new_comment( $data ); 25 $comment_first = get_comment( $id_first ); 26 27 remove_action( 'check_comment_flood', 'check_comment_flood_duplicate', 10 ); 28 29 $data[ 'comment_date_gmt' ] = '2015-02-02 10:00:00'; 30 31 $id_next = wp_new_comment( $data ); 32 $comment_next = get_comment( $id_next ); 33 34 add_action( 'check_comment_flood', 'check_comment_flood_duplicate', 10, 4 ); 35 36 $this->assertEquals( $data[ 'comment_author' ], $comment_first->comment_author ); 37 $this->assertEquals( $data[ 'comment_author' ], $comment_next->comment_author ); 38 } 39 40 } 41 No newline at end of file -
tests/phpunit/tests/comment/emptyContent.php
1 <?php 2 /** 3 * @group comment 4 */ 5 class Tests_Comment_EmptyContent extends WP_UnitTestCase { 6 7 function test_comment_allow_empty_content_after_filter_removed() { 8 $post_id = $this->factory->post->create(); 9 10 $data = array( 11 'comment_post_ID' => $post_id, 12 'comment_author' => 'test_author', 13 'comment_author_IP' => '192.168.1.1', 14 'comment_author_url' => '', 15 'comment_author_email' => '', 16 'comment_type' => '', 17 'comment_content' => '', 18 ); 19 20 remove_filter( 'preprocess_comment', 'disallow_empty_comments', 5 ); 21 22 $id = wp_new_comment( $data ); 23 24 add_filter( 'preprocess_comment', 'disallow_empty_comments', 5 ); 25 26 $comment = get_comment( $id ); 27 28 $this->assertEquals( $data[ 'comment_content' ], $comment->comment_content ); 29 $this->assertEquals( $data[ 'comment_post_ID' ], $comment->comment_post_ID ); 30 $this->assertEquals( $data[ 'comment_author' ], $comment->comment_author ); 31 $this->assertEquals( $data[ 'comment_author_IP' ], $comment->comment_author_IP ); 32 } 33 34 }
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)