我想使用 Akismet 检查自定义表单以防止垃圾邮件。我在网上搜索,发现唯一简单的方法是(见下面的代码摘录): http: //www.binarymoon.co.uk/2010/03/akismet-plugin-theme-stop-spam-dead/。不幸的是 $isSpam 返回真!
有谁知道如何施展魔法?我感谢您的帮助。
function akismet_isSpam ($content) {
// innocent until proven guilty
$isSpam = FALSE;
$content = (array) $content;
if (function_exists('akismet_init')) {
$wpcom_api_key = get_option('wordpress_api_key');
if (!empty($wpcom_api_key)) {
global $akismet_api_host, $akismet_api_port;
// set remaining required values for akismet api
$content['user_ip'] = preg_replace( '/[^0-9., ]/', '', $_SERVER['REMOTE_ADDR'] );
$content['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
$content['referrer'] = $_SERVER['HTTP_REFERER'];
$content['blog'] = get_option('home');
if (empty($content['referrer'])) {
$content['referrer'] = get_permalink();
}
$queryString = '';
foreach ($content as $key => $data) {
if (!empty($data)) {
$queryString .= $key . '=' . urlencode(stripslashes($data)) . '&';
}
}
$response = akismet_http_post($queryString, $akismet_api_host, '/1.1/comment-check', $akismet_api_port);
smart_dump($response, true);
if ($response[1] == 'true') {
update_option('akismet_spam_count', get_option('akismet_spam_count') + 1);
$isSpam = TRUE;
}
}
}
return $isSpam;
}