' . esc_html__('Check for Spam', 'akismet') . '';
}
public static function recheck_queue() {
global $wpdb;
Akismet::fix_scheduled_recheck();
if ( ! ( isset( $_GET['recheckqueue'] ) || ( isset( $_REQUEST['action'] ) && 'akismet_recheck_queue' == $_REQUEST['action'] ) ) )
return;
$paginate = '';
if ( isset( $_POST['limit'] ) && isset( $_POST['offset'] ) ) {
$paginate = $wpdb->prepare( " LIMIT %d OFFSET %d", array( $_POST['limit'], $_POST['offset'] ) );
}
$moderation = $wpdb->get_results( "SELECT * FROM {$wpdb->comments} WHERE comment_approved = '0'{$paginate}", ARRAY_A );
foreach ( (array) $moderation as $c ) {
$c['user_ip'] = $c['comment_author_IP'];
$c['user_agent'] = $c['comment_agent'];
$c['referrer'] = '';
$c['blog'] = get_bloginfo('url');
$c['blog_lang'] = get_locale();
$c['blog_charset'] = get_option('blog_charset');
$c['permalink'] = get_permalink($c['comment_post_ID']);
$c['user_role'] = '';
if ( isset( $c['user_ID'] ) )
$c['user_role'] = Akismet::get_user_roles($c['user_ID']);
if ( Akismet::is_test_mode() )
$c['is_test'] = 'true';
add_comment_meta( $c['comment_ID'], 'akismet_rechecking', true );
$response = Akismet::http_post( Akismet::build_query( $c ), 'comment-check' );
if ( 'true' == $response[1] ) {
wp_set_comment_status( $c['comment_ID'], 'spam' );
update_comment_meta( $c['comment_ID'], 'akismet_result', 'true' );
delete_comment_meta( $c['comment_ID'], 'akismet_error' );
delete_comment_meta( $c['comment_ID'], 'akismet_delayed_moderation_email' );
Akismet::update_comment_history( $c['comment_ID'], '', 'recheck-spam' );
} elseif ( 'false' == $response[1] ) {
update_comment_meta( $c['comment_ID'], 'akismet_result', 'false' );
delete_comment_meta( $c['comment_ID'], 'akismet_error' );
delete_comment_meta( $c['comment_ID'], 'akismet_delayed_moderation_email' );
Akismet::update_comment_history( $c['comment_ID'], '', 'recheck-ham' );
// abnormal result: error
} else {
update_comment_meta( $c['comment_ID'], 'akismet_result', 'error' );
Akismet::update_comment_history(
$c['comment_ID'],
'',
'recheck-error',
array( 'response' => substr( $response[1], 0, 50 ) )
);
}
delete_comment_meta( $c['comment_ID'], 'akismet_rechecking' );
}
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
wp_send_json( array(
'processed' => count((array) $moderation),
));
}
else {
$redirect_to = isset( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : admin_url( 'edit-comments.php' );
wp_safe_redirect( $redirect_to );
exit;
}
}
// Adds an 'x' link next to author URLs, clicking will remove the author URL and show an undo link
public static function remove_comment_author_url() {
if ( !empty( $_POST['id'] ) && check_admin_referer( 'comment_author_url_nonce' ) ) {
$comment = get_comment( intval( $_POST['id'] ), ARRAY_A );
if ( $comment && current_user_can( 'edit_comment', $comment['comment_ID'] ) ) {
$comment['comment_author_url'] = '';
do_action( 'comment_remove_author_url' );
print( wp_update_comment( $comment ) );
die();
}
}
}
public static function add_comment_author_url() {
if ( !empty( $_POST['id'] ) && !empty( $_POST['url'] ) && check_admin_referer( 'comment_author_url_nonce' ) ) {
$comment = get_comment( intval( $_POST['id'] ), ARRAY_A );
if ( $comment && current_user_can( 'edit_comment', $comment['comment_ID'] ) ) {
$comment['comment_author_url'] = esc_url( $_POST['url'] );
do_action( 'comment_add_author_url' );
print( wp_update_comment( $comment ) );
die();
}
}
}
public static function comment_row_action( $a, $comment ) {
// failsafe for old WP versions
if ( !function_exists('add_comment_meta') )
return $a;
$akismet_result = get_comment_meta( $comment->comment_ID, 'akismet_result', true );
$akismet_error = get_comment_meta( $comment->comment_ID, 'akismet_error', true );
$user_result = get_comment_meta( $comment->comment_ID, 'akismet_user_result', true);
$comment_status = wp_get_comment_status( $comment->comment_ID );
$desc = null;
if ( $akismet_error ) {
$desc = __( 'Awaiting spam check' , 'akismet');
} elseif ( !$user_result || $user_result == $akismet_result ) {
// Show the original Akismet result if the user hasn't overridden it, or if their decision was the same
if ( $akismet_result == 'true' && $comment_status != 'spam' && $comment_status != 'trash' )
$desc = __( 'Flagged as spam by Akismet' , 'akismet');
elseif ( $akismet_result == 'false' && $comment_status == 'spam' )
$desc = __( 'Cleared by Akismet' , 'akismet');
} else {
$who = get_comment_meta( $comment->comment_ID, 'akismet_user', true );
if ( $user_result == 'true' )
$desc = sprintf( __('Flagged as spam by %s', 'akismet'), $who );
else
$desc = sprintf( __('Un-spammed by %s', 'akismet'), $who );
}
// add a History item to the hover links, just after Edit
if ( $akismet_result ) {
$b = array();
foreach ( $a as $k => $item ) {
$b[ $k ] = $item;
if (
$k == 'edit'
|| ( $k == 'unspam' && $GLOBALS['wp_version'] >= 3.4 )
) {
$b['history'] = ' '. esc_html__('History', 'akismet') . '';
}
}
$a = $b;
}
if ( $desc )
echo ''.esc_html( $desc ).'';
$show_user_comments = apply_filters( 'akismet_show_user_comments_approved', get_option('akismet_show_user_comments_approved') );
$show_user_comments = $show_user_comments === 'false' ? false : $show_user_comments; //option used to be saved as 'false' / 'true'
if ( $show_user_comments ) {
$comment_count = Akismet::get_user_comments_approved( $comment->user_id, $comment->comment_author_email, $comment->comment_author, $comment->comment_author_url );
$comment_count = intval( $comment_count );
echo ' '. sprintf( esc_html( _n( '%s approved', '%s approved', $comment_count , 'akismet') ), number_format_i18n( $comment_count ) ) . '';
}
return $a;
}
public static function comment_status_meta_box( $comment ) {
$history = Akismet::get_comment_history( $comment->comment_ID );
if ( $history ) {
echo '
';
foreach ( $history as $row ) {
$time = date( 'D d M Y @ h:i:m a', $row['time'] ) . ' GMT';
$message = '';
if ( ! empty( $row['message'] ) ) {
// Old versions of Akismet stored the message as a literal string in the commentmeta.
// New versions don't do that for two reasons:
// 1) Save space.
// 2) The message can be translated into the current language of the blog, not stuck
// in the language of the blog when the comment was made.
$message = $row['message'];
}
// If possible, use a current translation.
switch ( $row['event'] ) {
case 'recheck-spam';
$message = __( 'Akismet re-checked and caught this comment as spam.', 'akismet' );
break;
case 'check-spam':
$message = __( 'Akismet caught this comment as spam.', 'akismet' );
break;
case 'recheck-ham':
$message = __( 'Akismet re-checked and cleared this comment.', 'akismet' );
break;
case 'check-ham':
$message = __( 'Akismet cleared this comment.', 'akismet' );
break;
case 'wp-blacklisted':
$message = __( 'Comment was caught by wp_blacklist_check.', 'akismet' );
break;
case 'report-spam':
if ( isset( $row['user'] ) ) {
$message = sprintf( __( '%s reported this comment as spam.', 'akismet' ), $row['user'] );
}
else if ( ! $message ) {
$message = __( 'This comment was reported as spam.', 'akismet' );
}
break;
case 'report-ham':
if ( isset( $row['user'] ) ) {
$message = sprintf( __( '%s reported this comment as not spam.', 'akismet' ), $row['user'] );
}
else if ( ! $message ) {
$message = __( 'This comment was reported as not spam.', 'akismet' );
}
break;
case 'cron-retry-spam':
$message = __( 'Akismet caught this comment as spam during an automatic retry.' , 'akismet');
break;
case 'cron-retry-ham':
$message = __( 'Akismet cleared this comment during an automatic retry.', 'akismet');
break;
case 'check-error':
if ( isset( $row['meta'], $row['meta']['response'] ) ) {
$message = sprintf( __( 'Akismet was unable to check this comment (response: %s) but will automatically retry later.', 'akismet'), $row['meta']['response'] );
}
break;
case 'recheck-error':
if ( isset( $row['meta'], $row['meta']['response'] ) ) {
$message = sprintf( __( 'Akismet was unable to recheck this comment (response: %s).', 'akismet'), $row['meta']['response'] );
}
break;
default:
if ( preg_match( '/^status-changed/', $row['event'] ) ) {
// Half of these used to be saved without the dash after 'status-changed'.
// See https://plugins.trac.wordpress.org/changeset/1150658/akismet/trunk
$new_status = preg_replace( '/^status-changed-?/', '', $row['event'] );
$message = sprintf( __( 'Comment status was changed to %s', 'akismet' ), $new_status );
}
else if ( preg_match( '/^status-/', $row['event'] ) ) {
$new_status = preg_replace( '/^status-/', '', $row['event'] );
if ( isset( $row['user'] ) ) {
$message = sprintf( __( '%1$s changed the comment status to %2$s.', 'akismet' ), $row['user'], $new_status );
}
}
break;
}
echo '