Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何停止发表评论_Php_Wordpress - Fatal编程技术网

Php 如何停止发表评论

Php 如何停止发表评论,php,wordpress,Php,Wordpress,我在wp comments表单上使用Captcha…当Captcha不匹配时会出现错误消息…但问题是,在刷新页面时,我看到我的评论张贴在那里…当Captcha代码不匹配时,我如何停止张贴评论..我使用“comment_post”钩子。这是我的密码 add_action( 'comment_post', 'captcha_comment_post' ); function captcha_comment_post() { if (isset($_POST["security_check"]))

我在wp comments表单上使用Captcha…当Captcha不匹配时会出现错误消息…但问题是,在刷新页面时,我看到我的评论张贴在那里…当Captcha代码不匹配时,我如何停止张贴评论..我使用“comment_post”钩子。这是我的密码

add_action( 'comment_post', 'captcha_comment_post' );
function captcha_comment_post()
{
  if (isset($_POST["security_check"])) 
  {
    $code = str_decrypt($_POST["security_check"]);
    if (!( empty($code)) && !($code == $_POST['security_code'] ))
    {
        wp_die( 'Error, the Security Code does not match. Please Try Again.');
    }
   }
else {
    return ;
   }
}
如果未设置
$\u POST[“安全检查”]
,则不会进行检查。您的脚本应该只在安全代码匹配时通过(不要检查是否失败,检查是否通过)


另外,我刚刚读了一些关于Wordpress的文章,但是你可能想在它发布之前使用
pre\u comment\u on\u post
,而不是
comment\u post
,我尝试了所有这些解决方案,但都没有成功。我最终将wp_comments表重命名为wp_comments_none

当没有设置安全代码时,我的错误消息会出现,但是当我刷新页面后检查时,我的评论已经发布在那里了…当安全代码不匹配时,我想停止发布评论..使用pre_comment_on_post hook我的错误消息没有显示。。。我刚刚尝试了注释\文本过滤器挂钩。。。每件事都很好,但现在我的文字,我张贴,而不是显示。。。