• I have a site that will need to have a large number (1000+) of users in the subscriber role. They are members of an organization and I have a csv file with their name and their membership number – no email addresses. I know. That would make this infinitely easier. I would like to upload them as users, using their member number as their username.

    Only members of this organization will be allowed to have a username on the site.

    Ideally, when they visit the site and log in for the first time, they put in their member number (username) and then will be able to create a password and enter their email address. Knowing their member number is all the authentication we will need.

    Is it possible to create users in this way? I think this would be an easier solution than adding member number to the signup form and crosschecking their number with the csv file to authenticate the user creation.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    WP requires all users to have an email. Getting around this would be very difficult. There’s hope though, nothing says the email has to be valid, just of the proper format. Part of your add user from CSV script (yes, it’s possible) could be to arbitrarily provide a “fake” email.

    If logins are over plain HTTP, the member number only as a login credential would be a really bad idea. If logins are forced to be authenticated HTTPS, then I’m not so concerned. There’s plugins that force HTTPS, contact your host or IT folk to set this up. I’m still concerned about disgruntled members impersonating another user. Passwords help prevent this. Even if the password is not very strong, it’s still better than no password.

    It’s your site, not mine. You may run into trouble if some sort of password is not supplied. It can be a static value in a hidden password field, but something should be supplied. You don’t have to make use of it.

    You authenticate whatever credentials are passed by hooking the “authenticate” filter. If the member number is valid, then using get_user_by() with “login” and the entered member number will return the associated WP_User object. To authenticate this user, return the WP_User object from the authenticate hook. If you need to fail the authentication, like if the number does not yield a user object, return a new WP_Error object, unless your callback was passed an error object to begin with, in which case the login already failed, so just return the passed object. You can add additional messages to this object if you like.

    Hook “authenticate” early so it gets first say in authentication, otherwise the default authentication will fail the authentication. If you still have trouble with failed logins, you’ll need to remove the default hook, which isn’t a bad thing to do anyway if you’re not authenticating by password.

    You can add users by script with wp_create_user(). Step through the CSV file and assemble the required data of each record. You can make up data like password and email if need be.

    Thread Starter awillard1208

    (@awillard1208)

    Thanks for the reply @bcworkz

    This is very helpful, and I think that using a placeholder email address would work fine until they actually log in themselves for the first time and can update their information.

    Thanks again!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Upload Users with no email addresses – have them fill in later’ is closed to new replies.