0

我在 wp-comments 表单上使用验证码...当验证码不匹配时出现错误消息...但问题是在刷新页面时,我看到我的评论张贴在那里...我如何停止发表评论验证码不匹配..m 使用“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 ;
   }
}
4

2 回答 2

2

未设置时$_POST["security_check"],您的检查不会发生。只有当安全代码匹配时,您的脚本才应该通过(不要检查失败,检查是否通过)。

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

于 2013-09-05T09:26:18.000 回答
0

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

于 2014-08-08T00:28:48.947 回答