Changeset 1431102
- Timestamp:
- 06/06/16 04:09:10 (4 months ago)
- Location:
- akismet/trunk
- Files:
-
- 3 edited
-
class.akismet-admin.php (modified) (1 diff)
-
class.akismet-cli.php (modified) (1 diff)
-
class.akismet.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
akismet/trunk/class.akismet-admin.php
r1431089 r1431102 399 399 400 400 foreach ( $moderation as $comment_id ) { 401 $ is_spam= Akismet::recheck_comment( $comment_id, 'recheck_queue' );402 403 if ( 'true' == $is_spam) {401 $api_response = Akismet::recheck_comment( $comment_id, 'recheck_queue' ); 402 403 if ( 'true' === $api_response ) { 404 404 ++$result_counts['spam']; 405 405 } 406 elseif ( 'false' == $is_spam) {406 elseif ( 'false' === $api_response ) { 407 407 ++$result_counts['ham']; 408 408 } -
akismet/trunk/class.akismet-cli.php
r1431095 r1431102 27 27 if ( isset( $assoc_args['noaction'] ) ) { 28 28 // Check the comment, but don't reclassify it. 29 $ is_spam= Akismet::check_db_comment( $comment_id, 'wp-cli' );29 $api_response = Akismet::check_db_comment( $comment_id, 'wp-cli' ); 30 30 } 31 31 else { 32 $ is_spam= Akismet::recheck_comment( $comment_id, 'wp-cli' );32 $api_response = Akismet::recheck_comment( $comment_id, 'wp-cli' ); 33 33 } 34 34 35 if ( 'true' === $ is_spam) {35 if ( 'true' === $api_response ) { 36 36 WP_CLI::line( sprintf( __( "Comment #%d is spam.", 'akismet' ), $comment_id ) ); 37 37 } 38 else if ( 'false' === $ is_spam) {38 else if ( 'false' === $api_response ) { 39 39 WP_CLI::line( sprintf( __( "Comment #%d is not spam.", 'akismet' ), $comment_id ) ); 40 40 } 41 41 else { 42 WP_CLI::warning( sprintf( __( "Comment #%d could not be checked.", 'akismet' ), $comment_id ) ); 42 if ( false === $api_response ) { 43 WP_CLI::error( __( "Failed to connect to Akismet.", 'akismet' ) ); 44 } 45 else if ( is_wp_error( $api_response ) ) { 46 WP_CLI::warning( sprintf( __( "Comment #%d could not be checked.", 'akismet' ), $comment_id ) ); 47 } 43 48 } 44 49 } -
akismet/trunk/class.akismet.php
r1431089 r1431102 450 450 451 451 $c = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->comments} WHERE comment_ID = %d", $id ), ARRAY_A ); 452 if ( !$c ) 453 return; 452 453 if ( ! $c ) { 454 return new WP_Error( 'invalid-comment-id', __( 'Comment not found.', 'akismet' ) ); 455 } 454 456 455 457 $c['user_ip'] = $c['comment_author_IP']; … … 462 464 $c['recheck_reason'] = $recheck_reason; 463 465 464 if ( self::is_test_mode() )465 $c['is_test'] = 'true';466 467 $response = self::http_post( Akismet::build_query( $c ), 'comment-check' );468 469 return ( is_array( $response ) && ! empty( $response[1] ) ) ? $response[1] : false;470 }471 472 public static function recheck_comment( $id, $recheck_reason = 'recheck_queue' ) {473 $is_spam = self::check_db_comment( $id );474 475 $c = get_comment( $id, ARRAY_A );476 477 if ( ! $c ) {478 return false;479 }480 481 $c['user_ip'] = $c['comment_author_IP'];482 $c['user_agent'] = $c['comment_agent'];483 $c['referrer'] = '';484 $c['blog'] = get_option( 'home' );485 $c['blog_lang'] = get_locale();486 $c['blog_charset'] = get_option('blog_charset');487 $c['permalink'] = get_permalink($c['comment_post_ID']);488 489 466 $c['user_role'] = ''; 490 467 if ( isset( $c['user_ID'] ) ) 491 468 $c['user_role'] = Akismet::get_user_roles($c['user_ID']); 492 469 493 if ( Akismet::is_test_mode() )470 if ( self::is_test_mode() ) 494 471 $c['is_test'] = 'true'; 495 472 496 add_comment_meta( $c['comment_ID'], 'akismet_rechecking', true ); 497 498 $response = Akismet::http_post( Akismet::build_query( $c ), 'comment-check' ); 499 500 if ( 'true' == $response[1] ) { 501 wp_set_comment_status( $c['comment_ID'], 'spam' ); 502 update_comment_meta( $c['comment_ID'], 'akismet_result', 'true' ); 503 delete_comment_meta( $c['comment_ID'], 'akismet_error' ); 504 delete_comment_meta( $c['comment_ID'], 'akismet_delayed_moderation_email' ); 505 Akismet::update_comment_history( $c['comment_ID'], '', 'recheck-spam' ); 506 } elseif ( 'false' == $response[1] ) { 507 update_comment_meta( $c['comment_ID'], 'akismet_result', 'false' ); 508 delete_comment_meta( $c['comment_ID'], 'akismet_error' ); 509 delete_comment_meta( $c['comment_ID'], 'akismet_delayed_moderation_email' ); 510 Akismet::update_comment_history( $c['comment_ID'], '', 'recheck-ham' ); 511 } else { 473 $response = self::http_post( Akismet::build_query( $c ), 'comment-check' ); 474 475 if ( ! empty( $response[1] ) ) { 476 return $response[1]; 477 } 478 479 return false; 480 } 481 482 public static function recheck_comment( $id, $recheck_reason = 'recheck_queue' ) { 483 add_comment_meta( $id, 'akismet_rechecking', true ); 484 485 $api_response = self::check_db_comment( $id, $recheck_reason ); 486 487 delete_comment_meta( $id, 'akismet_rechecking' ); 488 489 if ( is_wp_error( $api_response ) ) { 490 // Invalid comment ID. 491 } 492 else if ( 'true' === $api_response ) { 493 wp_set_comment_status( $id, 'spam' ); 494 update_comment_meta( $id, 'akismet_result', 'true' ); 495 delete_comment_meta( $id, 'akismet_error' ); 496 delete_comment_meta( $id, 'akismet_delayed_moderation_email' ); 497 Akismet::update_comment_history( $id, '', 'recheck-spam' ); 498 } 499 elseif ( 'false' === $api_response ) { 500 update_comment_meta( $id, 'akismet_result', 'false' ); 501 delete_comment_meta( $id, 'akismet_error' ); 502 delete_comment_meta( $id, 'akismet_delayed_moderation_email' ); 503 Akismet::update_comment_history( $id, '', 'recheck-ham' ); 504 } 505 else { 512 506 // abnormal result: error 513 update_comment_meta( $ c['comment_ID'], 'akismet_result', 'error' );507 update_comment_meta( $id, 'akismet_result', 'error' ); 514 508 Akismet::update_comment_history( 515 $ c['comment_ID'],509 $id, 516 510 '', 517 511 'recheck-error', 518 array( 'response' => substr( $ response[1], 0, 50 ) )512 array( 'response' => substr( $api_response, 0, 50 ) ) 519 513 ); 520 514 } 521 515 522 delete_comment_meta( $c['comment_ID'], 'akismet_rechecking' ); 523 524 return $response[1]; 516 return $api_response; 525 517 } 526 518
Note: See TracChangeset
for help on using the changeset viewer.