wordpress注册验证 拒绝恶意注册

博客运维评论5,741

编辑主题,在主题文件functions.php,添加以下代码:(可以任意修改代码第四行和倒数第四行验证答案)

add_action( 'register_form', 'add_security_question' );
function add_security_question() { ?>
    <p>
    <label><?php _e('请输入博主呼号:bh8sel') ?><br />
        <input type="text" name="user_proof" id="user_proof" class="input" size="25" tabindex="20" /></label>
    </p>
<?php }
     
add_action( 'register_post', 'add_security_question_validate', 10, 3 );
function add_security_question_validate( $sanitized_user_login, $user_email, $errors) {
    // 如果没有回答
    if (!isset($_POST[ 'user_proof' ]) || empty($_POST[ 'user_proof' ])) {
        return $errors->add( 'proofempty', '<strong>错误</strong>: 您还没有回答问题。'  );
    // 如果答案不正确
    } elseif ( strtolower( $_POST[ 'user_proof' ] ) != 'bh8sel' ) {
        return $errors->add( 'prooffail', '<strong>错误</strong>: 您的回答不正确。'  );
    }
}

效果如下图:文章源自HAM小站-https://bh8sel.com/719.html

文章源自HAM小站-https://bh8sel.com/719.html

文章来源:http://www.chukuangren.com/wp-zhuceyanzheng.html文章源自HAM小站-https://bh8sel.com/719.html 文章源自HAM小站-https://bh8sel.com/719.html

 最后更新:2020-8-31
匿名

发表评论

匿名网友
:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:
确定

拖动滑块以完成验证