public static function submit_nonspam_comment($comment_id) { global $wpdb, $current_user, $current_site; $comment_id = (int) $comment_id; $comment = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->comments} WHERE comment_ID = %d", $comment_id)); if (!$comment) { // it was deleted return; } // use the original version stored in comment_meta if available $as_submitted = get_comment_meta($comment_id, 'akismet_as_submitted', true); if ($as_submitted && is_array($as_submitted) && isset($as_submitted['comment_content'])) { $comment = (object) array_merge((array) $comment, $as_submitted); } $comment->blog = get_bloginfo('url'); $comment->blog_lang = get_locale(); $comment->blog_charset = get_option('blog_charset'); $comment->permalink = get_permalink($comment->comment_post_ID); $comment->user_role = ''; if (is_object($current_user)) { $comment->reporter = $current_user->user_login; } if (is_object($current_site)) { $comment->site_domain = $current_site->domain; } if (isset($comment->user_ID)) { $comment->user_role = Akismet::get_user_roles($comment->user_ID); } if (Akismet::is_test_mode()) { $comment->is_test = 'true'; } $post = get_post($comment->comment_post_ID); $comment->comment_post_modified_gmt = $post->post_modified_gmt; $response = Akismet::http_post(http_build_query($comment), 'submit-ham'); if ($comment->reporter) { Akismet::update_comment_history($comment_id, sprintf(__('%s reported this comment as not spam', 'akismet'), $comment->reporter), 'report-ham'); update_comment_meta($comment_id, 'akismet_user_result', 'false'); update_comment_meta($comment_id, 'akismet_user', $comment->reporter); } do_action('akismet_submit_nonspam_comment', $comment_id, $response[1]); }
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'], __('Akismet re-checked and caught this comment as spam', 'akismet'), 'check-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'], __('Akismet re-checked and cleared this comment', 'akismet'), '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)', 'akismet'), 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; } }
function akismet_test_mode() { return Akismet::is_test_mode(); }
function akismet_test_mode() { _deprecated_function(__FUNCTION__, '3.0', 'Akismet::is_test_mode()'); return Akismet::is_test_mode(); }
/** * Contact Akismet to check if this is spam or ham. * * Props to WordPress core Akismet plugin for a lot of this. * * @since 1.6.0 * * @param array $activity_data Packet of information to submit to Akismet. * @param string $check "check" or "submit". * @param string $spam "spam" or "ham". * @return array $activity_data Activity data, with Akismet data added. */ public function send_akismet_request($activity_data, $check = 'check', $spam = 'spam') { $query_string = $path = ''; $activity_data['blog'] = bp_get_option('home'); $activity_data['blog_charset'] = bp_get_option('blog_charset'); $activity_data['blog_lang'] = get_locale(); $activity_data['referrer'] = $_SERVER['HTTP_REFERER']; $activity_data['user_agent'] = bp_core_current_user_ua(); $activity_data['user_ip'] = bp_core_current_user_ip(); if (Akismet::is_test_mode()) { $activity_data['is_test'] = 'true'; } // Loop through _POST args and rekey strings. foreach ($_POST as $key => $value) { if (is_string($value) && 'cookie' != $key) { $activity_data['POST_' . $key] = $value; } } // Keys to ignore. $ignore = array('HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW'); // Loop through _SERVER args and remove whitelisted keys. foreach ($_SERVER as $key => $value) { // Key should not be ignored. if (!in_array($key, $ignore) && is_string($value)) { $activity_data[$key] = $value; // Key should be ignored. } else { $activity_data[$key] = ''; } } foreach ($activity_data as $key => $data) { $query_string .= $key . '=' . urlencode(stripslashes($data)) . '&'; } if ('check' == $check) { $path = 'comment-check'; } elseif ('submit' == $check) { $path = 'submit-' . $spam; } // Send to Akismet. add_filter('akismet_ua', array($this, 'buddypress_ua')); $response = Akismet::http_post($query_string, $path); remove_filter('akismet_ua', array($this, 'buddypress_ua')); // Get the response. if (!empty($response[1]) && !is_wp_error($response[1])) { $activity_data['bp_as_result'] = $response[1]; } else { $activity_data['bp_as_result'] = false; } // Perform a daily tidy up. if (!wp_next_scheduled('bp_activity_akismet_delete_old_metadata')) { wp_schedule_event(time(), 'daily', 'bp_activity_akismet_delete_old_metadata'); } return $activity_data; }