在自我托管的4.8.1版本的新安装中,使用2017默认主题的网站我已使用API密钥激活了Akismet插件。修改single.php
有:为什么Akismet在密钥验证中返回失败?
if (function_exists('akismet_verify_key')) :
$testing = akismet_verify_key(akismet_get_key(), site_url());
echo $testing;
endif;
,但它总是回来failed
。我已确认网站域名包含在Akismet仪表板中,但无论出于何种原因,在阅读[密钥验证文档] [1]并检测到存在函数后,它将不会返回true
。
如果我复制PHP例如,改变功能的命名约定akismet_check
:
function akismet_check($key, $blog) {
$blog = urlencode($blog);
$request = 'key='. $key .'&blog='. $blog;
$host = $http_host = 'rest.akismet.com';
$path = '/1.1/verify-key';
$port = 443;
$akismet_ua = "WordPress/4.4.1 | Akismet/3.1.7";
$content_length = strlen($request);
$http_request = "POST $path HTTP/1.0\r\n";
$http_request .= "Host: $host\r\n";
$http_request .= "Content-Type: application/x-www-form-urlencoded\r\n";
$http_request .= "Content-Length: {$content_length}\r\n";
$http_request .= "User-Agent: {$akismet_ua}\r\n";
$http_request .= "\r\n";
$http_request .= $request;
$response = '';
if (false != ($fs = @fsockopen('ssl://' . $http_host, $port, $errno, $errstr, 10))) :
fwrite($fs, $http_request);
while (!feof($fs))
$response .= fgets($fs, 1160); // One TCP-IP packet
fclose($fs);
$response = explode("\r\n\r\n", $response, 2);
endif;
if ('valid' == $response[1]) :
return true;
else :
return false;
endif;
}
,并把它传递:
echo 'Akismet shows ' . $result = akismet_check(akismet_get_key(), site_url());
我不明白,如果功能已经存在和我可以检测到为什么我会失败。 Akismet是否具有密钥验证的替代方案,因此如果akismet_verify_key
不起作用或者我做错了什么,我不需要重新编写整个函数来执行似乎已经存在的内容?