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 = self::sanitize_comment_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 = self::http_post(Akismet::build_query($comment), 'submit-ham'); if ($comment->reporter) { self::update_comment_history($comment_id, '', '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]); }
/** * Check the email for spam * * @param $email_fields * @param $instance * * @return array */ function spam_check($post_vars, $email_fields, $instance) { $errors = array(); $recaptcha_config = $instance['spam']['recaptcha']; $use_recaptcha = $recaptcha_config['use_captcha'] && !empty($recaptcha_config['site_key']) && !empty($recaptcha_config['secret_key']); if ($use_recaptcha) { $result = wp_remote_post('https://www.google.com/recaptcha/api/siteverify', array('body' => array('secret' => $instance['spam']['recaptcha']['secret_key'], 'response' => $post_vars['g-recaptcha-response'], 'remoteip' => isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null))); if (!is_wp_error($result) && !empty($result['body'])) { $result = json_decode($result['body'], true); if (isset($result['success']) && !$result['success']) { $errors['recaptcha'] = __('Error validating your Captcha response.', 'so-widgets-bundle'); } } } if ($instance['spam']['akismet']['use_akismet'] && class_exists('Akismet')) { $comment = array(); $message_text = array(); foreach ($email_fields['message'] as $m) { $message_text[] = $m['value']; } $comment['comment_text'] = $email_fields['subject'] . "\n\n" . implode("\n\n", $message_text); $comment['comment_author'] = !empty($email_fields['name']) ? $email_fields['name'] : ''; $comment['comment_author_email'] = $email_fields['email']; $comment['comment_post_ID'] = get_the_ID(); $comment['comment_type'] = 'contact-form'; $comment['user_ip'] = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null; $comment['user_agent'] = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null; $comment['referrer'] = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null; $comment['blog'] = get_option('home'); $comment['blog_lang'] = get_locale(); $comment['blog_charset'] = get_option('blog_charset'); // Pretend to check with Akismet $response = Akismet::http_post(Akismet::build_query($comment), 'comment-check'); $is_spam = !empty($response[1]) && $response[1] == 'true'; if ($is_spam) { $errors['akismet'] = __('Unfortunately our system identified your message as spam.', 'so-widgets-bundle'); } } return $errors; }
public static function verify_wpcom_key($api_key, $user_id, $extra = array()) { $akismet_account = Akismet::http_post(Akismet::build_query(array_merge(array('user_id' => $user_id, 'api_key' => $api_key, 'get_account_type' => 'true'), $extra)), 'verify-wpcom-key'); if (!empty($akismet_account[1])) { $akismet_account = json_decode($akismet_account[1]); } Akismet::log(compact('akismet_account')); return $akismet_account; }
public function is_spam($contact) { if (method_exists('Akismet', 'http_post')) { $comment = array('comment_author' => $contact['name'], 'comment_author_email' => $contact['email'], 'comment_content' => $contact['message'], 'comment_type' => $this->tag, 'user_ip' => preg_replace('/[^0-9., ]/', '', $_SERVER['REMOTE_ADDR']), 'user_agent' => $_SERVER['HTTP_USER_AGENT'], 'referrer' => $_SERVER['HTTP_REFERER'], 'blog' => get_option('home'), 'blog_lang' => get_locale(), 'blog_charset' => get_option('blog_charset')); foreach ($_SERVER as $key => $value) { if ($key != 'HTTP_COOKIE' && is_string($value)) { $comment[$key] = $value; } } $response = Akismet::http_post(Akismet::build_query($comment), 'comment-check'); if ('true' == trim($response[1])) { return true; } } return false; }