如何停止发表评论

时间:2013-09-05 09:23:12

标签: php wordpress

我在wp-comments表单上使用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 ;
   }
}

2 个答案:

答案 0 :(得分:2)

如果未设置$_POST["security_check"],则不会进行检查。您的脚本只应在安全代码匹配时传递(不检查失败,检查传递)。

此外,我刚刚阅读了一些关于Wordpress的内容,但似乎您可能希望在使用pre_comment_on_post而不是comment_post发布评论之前将评论挂钩。

答案 1 :(得分:0)

我已经尝试过所有这些解决方案而没有运气。我最后只是将wp_comments表重命名为wp_comments_none。