wordpress评论增加算数验证码和敏感词中文代码版

首先添加到主题的functions.php文件内,效果见本站~~
评论算数验证码:

//评论算数
function spam_protection_math()
{
$num1 = rand(1, 9);
$num2 = rand(1, 9);
echo "<span class="yanzheng"> {$num1} + {$num2} = <input type="text" style="width:60px;" name="sum" class="math_textfield" value="">" . "<input type="hidden" name="num1" value="{$num1}">" . "<input type="hidden" name="num2" value="{$num2}">" . "</span>";
}
function spam_protection_pre($commentdata)
{
$sum = $_POST['sum'];
switch ($sum) {
case $_POST['num1'] + $_POST['num2']:
break;
case null:
err('请输入计算结果!');
break;
default:
err('老铁数学不行啊!再算算!');
}
return $commentdata;
}
if ($comment_data['comment_type'] == '') {
add_filter('preprocess_comment', 'spam_protection_pre');
}
//评论算数
function spam_protection_math()
{
    $num1 = rand(1, 9);
    $num2 = rand(1, 9);
    echo "<span class="yanzheng"> {$num1} + {$num2} = <input type="text" style="width:60px;" name="sum" class="math_textfield" value="">" . "<input type="hidden" name="num1" value="{$num1}">" . "<input type="hidden" name="num2" value="{$num2}">" . "</span>";
}
function spam_protection_pre($commentdata)
{
    $sum = $_POST['sum'];
    switch ($sum) {
        case $_POST['num1'] + $_POST['num2']:
            break;
        case null:
            err('请输入计算结果!');
            break;
        default:
            err('老铁数学不行啊!再算算!');
    }
    return $commentdata;
}
if ($comment_data['comment_type'] == '') {
    add_filter('preprocess_comment', 'spam_protection_pre');
}
//评论算数 function spam_protection_math() { $num1 = rand(1, 9); $num2 = rand(1, 9); echo " {$num1} + {$num2} = " . "" . "" . ""; } function spam_protection_pre($commentdata) { $sum = $_POST['sum']; switch ($sum) { case $_POST['num1'] + $_POST['num2']: break; case null: err('请输入计算结果!'); break; default: err('老铁数学不行啊!再算算!'); } return $commentdata; } if ($comment_data['comment_type'] == '') { add_filter('preprocess_comment', 'spam_protection_pre'); }

敏感词和限制只能中文评论:

//评论敏感词和中文
function uedsc_fuckspam($comment)
{
if (is_super_admin()) {
return $comment;
}
if (wp_blacklist_check($comment['comment_author'], $comment['comment_author_email'], $comment['comment_author_url'], $comment['comment_content'], $comment['comment_author_IP'], $comment['comment_agent'])) {
header("Content-type: text/html; charset=utf-8");
err('您的评论内容包含敏感词汇,请检查内容后再次提交!');
} else {
return $comment;
}
}
add_filter('preprocess_comment', 'uedsc_fuckspam');
function refused_spam_comments($comment_data)
{
$pattern = '/[一-龥]/u';
if (!preg_match($pattern, $comment_data['comment_content'])) {
err('评论内容必须含中文!');
}
return $comment_data;
}
add_filter('preprocess_comment', 'refused_spam_comments');
//评论敏感词和中文
    function uedsc_fuckspam($comment)
{
    if (is_super_admin()) {
        return $comment;
    }
    if (wp_blacklist_check($comment['comment_author'], $comment['comment_author_email'], $comment['comment_author_url'], $comment['comment_content'], $comment['comment_author_IP'], $comment['comment_agent'])) {
        header("Content-type: text/html; charset=utf-8");
        err('您的评论内容包含敏感词汇,请检查内容后再次提交!');
    } else {
        return $comment;
    }
}
add_filter('preprocess_comment', 'uedsc_fuckspam');
function refused_spam_comments($comment_data)
{
    $pattern = '/[一-龥]/u';
    if (!preg_match($pattern, $comment_data['comment_content'])) {
        err('评论内容必须含中文!');
    }
    return $comment_data;
}
add_filter('preprocess_comment', 'refused_spam_comments');
//评论敏感词和中文 function uedsc_fuckspam($comment) { if (is_super_admin()) { return $comment; } if (wp_blacklist_check($comment['comment_author'], $comment['comment_author_email'], $comment['comment_author_url'], $comment['comment_content'], $comment['comment_author_IP'], $comment['comment_agent'])) { header("Content-type: text/html; charset=utf-8"); err('您的评论内容包含敏感词汇,请检查内容后再次提交!'); } else { return $comment; } } add_filter('preprocess_comment', 'uedsc_fuckspam'); function refused_spam_comments($comment_data) { $pattern = '/[一-龥]/u'; if (!preg_match($pattern, $comment_data['comment_content'])) { err('评论内容必须含中文!'); } return $comment_data; } add_filter('preprocess_comment', 'refused_spam_comments');

下面的代码用于输出调用,添加到评论文件的合适位置,一般添加在button、submit提交按钮之前。我的是在comments.php文件。

<!--?php echo spam_protection_math(); ?-->
<!--?php echo spam_protection_math(); ?-->
© 版权声明
THE END
喜欢就支持一下吧
点赞0赞赏 分享
The God only arranges a happy ending. If it is not happy, it means that it is not the final result.
上天只会安排的快乐的结局。如果不快乐,说明还不是最后结局
评论 共4条

请登录后发表评论

      • Vinay的头像 | 泰普及blogVinay等级-LV6 | 泰普及blog作者1