function is_spam_akismet($is_spam, $form = array())
{
global $akismet_api_host, $akismet_api_port;
// The signature of this function changed from accepting just $form.
// If something only sends an array, assume it's still using the old
// signature and work around it.
if (empty($form) && is_array($is_spam)) {
$form = $is_spam;
$is_spam = false;
}
// If a previous filter has alrady marked this as spam, trust that and move on.
if ($is_spam) {
return $is_spam;
}
if (!function_exists('akismet_http_post') && !defined('AKISMET_VERSION')) {
return false;
}
$query_string = http_build_query($form);
if (method_exists('Akismet', 'http_post')) {
$response = Akismet::http_post($query_string, 'comment-check');
} else {
$response = akismet_http_post($query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port);
}
$result = false;
if (isset($response[0]['x-akismet-pro-tip']) && 'discard' === trim($response[0]['x-akismet-pro-tip']) && get_option('akismet_strictness') === '1') {
$result = new WP_Error('feedback-discarded', __('Feedback discarded.', 'jetpack'));
} elseif (isset($response[1]) && 'true' == trim($response[1])) {
// 'true' is spam
$result = true;
}
/**
* Filter the results returned by Akismet for each submitted contact form.
*
* @module contact-form
*
* @since 1.3.1
*
* @param WP_Error|bool $result Is the submitted feedback spam.
* @param array|bool $form Submitted feedback.
*/
return apply_filters('contact_form_is_spam_akismet', $result, $form);
}