wordpress注册页面添加自定义问答

站长CMS吧 6月前 398

通过给wordpress注册页面添加一个自定义问答,可以实现引导用户关注公众号或者图文付费获取验证码的功能。

//注册自定义问答
function add_custom_registration_question() {
    // 添加一个自定义问题和答案
    $question = '注册码';
    $answer = '45365';
    // 将问题添加到注册表单
    ?>
    <p class="formrow">
        <label for="custom_question"><?php echo esc_html($question); ?><span class="required"></span>【<strong><span style="color:#ff0000;font-size:20px;"><a style="color: #ff0000;" href="https://mp.weixin.qq.com/s3423432432" target="_blank" rel="noopener">去获取</a></span></strong>
       】</label>
        <input type="text" class="inputtext" name="custom_question" id="custom_question" required>
    </p>
    <?php
}
add_action('register_form', 'add_custom_registration_question');

function validate_custom_registration_question($errors, $sanitized_user_login, $user_email) {
    if ($_POST['custom_question'] !== '45365') {
        $errors>add('custom_question_error', __('注册码不正确。'));
    }
    return $errors;
}
add_filter('registration_errors', 'validate_custom_registration_question', 10, 3);

最新回复 (0)
返回