WordPress 用户管理 完全移除email邮箱 代码实例

来源: 老季博客
日期: 2020-3-23
作者: 腾讯云/服务器VPS推荐评测/Vultr
阅读数: 55

WordPress一般情况下用户的邮箱Email字段为必填项。我们记录一下在用户注册管理中,如何将email字段去除。

在functions.php中添加如下代码( 如何方便的在更新主题时保留 functions.php 里的自定义 ):

// This will suppress empty email errors when submitting the user form
add_action('user_profile_update_errors', 'my_user_profile_update_errors', 10, 3 );
function my_user_profile_update_errors($errors, $update, $user) {
    $errors->remove('empty_email');
}

// This will remove javascript required validation for email input
// It will also remove the '(required)' text in the label
// Works for new user, user profile and edit user forms
add_action('user_new_form', 'my_user_new_form', 10, 1);
add_action('show_user_profile', 'my_user_new_form', 10, 1);
add_action('edit_user_profile', 'my_user_new_form', 10, 1);
function my_user_new_form($form_type) {
    ?>
    <script type="text/javascript">
        jQuery('#email').closest('tr').removeClass('form-required').find('.description').remove();
        // Uncheck send new user email option by default
        <?php if (isset($form_type) && $form_type === 'add-new-user') : ?>
            jQuery('#send_user_notification').removeAttr('checked');
        <?php endif; ?>
    </script>
    <?php
}

remove_filter( 'authenticate', 'wp_authenticate_email_password', 20 );
链接到文章: https://jiloc.com/46658.html

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注