User Without Email?

When creating a user in WordPress an email address is required for that user. The website I’m working on requires that users remain anonymous (it’s part of a research study) and I’d consider email to be an identifying piece of data. Users will be added manually, so email is not required to confirm accounts or prevent spam sign-ups.

Am I going to have to provide a fake email address for each account, or is there a way to leave this field blank?

Related posts

Leave a Reply

6 comments

  1. It’s possible, just not so easily via the Users page without some hackery.

    The WordPress Function wp_create_user will let you insert users without email addresses, so a little custom plugin to accept a login name and password, and a call to wp_insert_user or wp_update_user should work for you. Unfortunately I don’t have time to code it up for you, but perhaps this will point you in a direction.

    $userdata = array ('user_login' => 'someuser', 'user_pass' => 'swordfish');
    $new_user_id = wp_update_user( $userdata );
    

    Update for people looking for a solution with the REST-API:
    Unfortunately, this is not possible by the rest-api. the email is required there. see: https://developer.wordpress.org/rest-api/reference/users/#create-a-user

  2. Using WordPress 4.7.2, I solved this with the following hooks:

    // 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
    }
    
  3. This is a pretty old question, but is still relevant.

    Anyway, @Milo definitely had the right idea.

    Here is what I use and it works great. This is very convenient when you want to create users, but prefer to keep your wordpress backend on lockdown. For example if you have a blog and prefer your content authors submit their work to you, this enables you create a user for them while not actually giving them access. Or if you prefer to blog under an alias. Or it’s even useful for testing purposes or I guess those “sketchy” people who want to make up a bunch of fake users for their site (you know who you are).

    Add this to functions.php temporarily or use it with a useful plugin like code snippets.

    function wpse_22754_insert_new_user() {
    
        $user_data = array(
        'ID' => '', // automatically created
        'user_pass' => 'swordfish',
        'user_login' => 'someuser',
        'user_nicename' => 'Some User',
        'user_email' => '',
        'display_name' => 'John',
        'nickname' => 'jsmith',
        'first_name' => 'John',
        'last_name' => 'John',
        'user_url' => '',
        'user_registered' => '2015-06-26 10:55:55', // leave empty for auto
        'role' => get_option('default_role') // administrator, editor, subscriber, author, etc
        );
    
        $user_id = wp_insert_user( $user_data );
    
        }
    add_action( 'admin_init', 'wpse_22754_insert_new_user' );
    

    If you are looking to update users from the backend after creating them, add this and you’ll avoid getting the error/warning notification.

    function wpse_22754_empty_email_error( $arg ) {
        if ( !empty( $arg->errors['empty_email'] ) ) unset( $arg->errors['empty_email'] );
    }
    add_action( 'user_profile_update_errors', 'wpse_22754_empty_email_error' );
    

    If you’d rather use a plugin this one will do the job most likely:

    https://wordpress.org/plugins/allow-multiple-accounts/

  4. The “Import Users from CSV” plugin will allow you to create users with no email address. I added them with…

    last_name,first_name,display_name,user_login
    Gamble,Bill,Bill Gamble,BillGamble
    

    Our club leverages the WordPress wp_users database, but we need to have on file even those members who have no email

  5. I find a way on youtube , when I search “how to create users without email in wordpress” !

    1. install “code snippets” plugin
    2. choose “add new” in this plugin
    3. choose a name for that. for example “Email not required code”

    4.Enter this code:

    // 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 remove the '(required)' textin the label
    // Work 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">
    jQuary('#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
    }
    
    
    1. select “only run in administrayion area and choose “save changes and activate
    2. now check , it works!