编辑主题,在主题文件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>: 您的回答不正确。' ); } }
效果如下图:
文章来源:http://www.chukuangren.com/wp-zhuceyanzheng.html