function akismet_recheck_queue() { global $wpdb, $akismet_api_host, $akismet_api_port; if (!(isset($_GET['recheckqueue']) || isset($_REQUEST['action']) && 'akismet_recheck_queue' == $_REQUEST['action'])) { return; } $moderation = $wpdb->get_results("SELECT * FROM {$wpdb->comments} WHERE comment_approved = '0'", 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_option('home'); $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']); } $id = (int) $c['comment_ID']; $query_string = ''; foreach ($c as $key => $data) { $query_string .= $key . '=' . urlencode(stripslashes($data)) . '&'; } $response = akismet_http_post($query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port); if ('true' == $response[1]) { wp_set_comment_status($c['comment_ID'], 'spam'); update_comment_meta($c['comment_ID'], 'akismet_result', 'true'); akismet_update_comment_history($c['comment_ID'], __('Akismet re-checked and caught this comment as spam'), 'check-spam'); } elseif ('false' == $response[1]) { update_comment_meta($c['comment_ID'], 'akismet_result', 'false'); akismet_update_comment_history($c['comment_ID'], __('Akismet re-checked and cleared this comment'), 'check-ham'); // abnormal result: error } else { update_comment_meta($c['comment_ID'], 'akismet_result', 'error'); akismet_update_comment_history($c['comment_ID'], sprintf(__('Akismet was unable to re-check this comment (response: %s)'), $response[1]), 'check-error'); } } wp_redirect($_SERVER['HTTP_REFERER']); exit; }
function akismet_cron_recheck( $data ) { global $wpdb; delete_option('akismet_available_servers'); $comment_errors = $wpdb->get_col( " SELECT comment_id FROM {$wpdb->prefix}commentmeta WHERE meta_key = 'akismet_error' " ); foreach ( (array) $comment_errors as $comment_id ) { add_comment_meta( $comment_id, 'akismet_rechecking', true ); $status = akismet_check_db_comment( $comment_id, 'retry' ); $msg = ''; if ( $status == 'true' ) { $msg = __( 'Akismet caught this comment as spam during an automatic retry.' ); } elseif ( $status == 'false' ) { $msg = __( 'Akismet cleared this comment during an automatic retry.' ); } // If we got back a legit response then update the comment history // other wise just bail now and try again later. No point in // re-trying all the comments once we hit one failure. if ( !empty( $msg ) ) { delete_comment_meta( $comment_id, 'akismet_error' ); akismet_update_comment_history( $comment_id, $msg, 'cron-retry' ); update_comment_meta( $comment_id, 'akismet_result', $status ); // make sure the comment status is still pending. if it isn't, that means the user has already moved it elsewhere. $comment = get_comment( $comment_id ); if ( $comment && 'unapproved' == wp_get_comment_status( $comment_id ) ) { if ( $status == 'true' ) { wp_spam_comment( $comment_id ); } elseif ( $status == 'false' ) { // comment is good, but it's still in the pending queue. depending on the moderation settings // we may need to change it to approved. if ( check_comment($comment->comment_author, $comment->comment_author_email, $comment->comment_author_url, $comment->comment_content, $comment->comment_author_IP, $comment->comment_agent, $comment->comment_type) ) wp_set_comment_status( $comment_id, 1 ); } } } else { delete_comment_meta( $comment_id, 'akismet_rechecking' ); wp_schedule_single_event( time() + 1200, 'akismet_schedule_cron_recheck' ); return; } } }
function akismet_cron_recheck() { global $wpdb; $status = akismet_verify_key(akismet_get_key()); if (get_option('akismet_alert_code') || $status == 'invalid') { // since there is currently a problem with the key, reschedule a check for 6 hours hence wp_schedule_single_event(time() + 21600, 'akismet_schedule_cron_recheck'); return false; } delete_option('akismet_available_servers'); $comment_errors = $wpdb->get_col("\n\t\tSELECT comment_id\n\t\tFROM {$wpdb->prefix}commentmeta\n\t\tWHERE meta_key = 'akismet_error'\n\t\tLIMIT 100\n\t"); foreach ((array) $comment_errors as $comment_id) { // if the comment no longer exists, or is too old, remove the meta entry from the queue to avoid getting stuck $comment = get_comment($comment_id); if (!$comment || strtotime($comment->comment_date_gmt) < strtotime("-15 days")) { delete_comment_meta($comment_id, 'akismet_error'); continue; } add_comment_meta($comment_id, 'akismet_rechecking', true); $status = akismet_check_db_comment($comment_id, 'retry'); $msg = ''; if ($status == 'true') { $msg = __('Akismet caught this comment as spam during an automatic retry.'); } elseif ($status == 'false') { $msg = __('Akismet cleared this comment during an automatic retry.'); } // If we got back a legit response then update the comment history // other wise just bail now and try again later. No point in // re-trying all the comments once we hit one failure. if (!empty($msg)) { delete_comment_meta($comment_id, 'akismet_error'); akismet_update_comment_history($comment_id, $msg, 'cron-retry'); update_comment_meta($comment_id, 'akismet_result', $status); // make sure the comment status is still pending. if it isn't, that means the user has already moved it elsewhere. $comment = get_comment($comment_id); if ($comment && 'unapproved' == wp_get_comment_status($comment_id)) { if ($status == 'true') { wp_spam_comment($comment_id); } elseif ($status == 'false') { // comment is good, but it's still in the pending queue. depending on the moderation settings // we may need to change it to approved. if (check_comment($comment->comment_author, $comment->comment_author_email, $comment->comment_author_url, $comment->comment_content, $comment->comment_author_IP, $comment->comment_agent, $comment->comment_type)) { wp_set_comment_status($comment_id, 1); } } } } else { delete_comment_meta($comment_id, 'akismet_rechecking'); wp_schedule_single_event(time() + 1200, 'akismet_schedule_cron_recheck'); return; } delete_comment_meta($comment_id, 'akismet_rechecking'); } $remaining = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->commentmeta} WHERE meta_key = 'akismet_error'"); if ($remaining && !wp_next_scheduled('akismet_schedule_cron_recheck')) { wp_schedule_single_event(time() + 1200, 'akismet_schedule_cron_recheck'); } }
function akismet_recheck_queue() { global $wpdb, $akismet_api_host, $akismet_api_port; 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_test_mode()) { $c['is_test'] = 'true'; } $id = (int) $c['comment_ID']; $query_string = ''; foreach ($c as $key => $data) { $query_string .= $key . '=' . urlencode(stripslashes($data)) . '&'; } add_comment_meta($c['comment_ID'], 'akismet_rechecking', true); $response = akismet_http_post($query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port); 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'); akismet_update_comment_history($c['comment_ID'], __('Akismet re-checked and caught this comment as spam'), 'check-spam'); } elseif ('false' == $response[1]) { update_comment_meta($c['comment_ID'], 'akismet_result', 'false'); delete_comment_meta($c['comment_ID'], 'akismet_error'); akismet_update_comment_history($c['comment_ID'], __('Akismet re-checked and cleared this comment'), 'check-ham'); // abnormal result: error } else { update_comment_meta($c['comment_ID'], 'akismet_result', 'error'); akismet_update_comment_history($c['comment_ID'], sprintf(__('Akismet was unable to re-check this comment (response: %s)'), substr($response[1], 0, 50)), 'check-error'); } 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; } }