I'm working on an email system, and I'm onto the unsubscribing stage. Since most of my users would not know their user ID, I'm asking them to put their email into a text box (definitely preferred, since this IS an email system). In order to change their user meta (their subscribed status), I need to know the users ID. I mean I suppose I could pass it into an email and put it in the unsubscribe link, but I'm planning on sending out emails to people who don't have wordpress accounts.

So my main question is this:

What logic or functions should I use to determine a users ID from an inputted email address, and if none are found, store them in the wordpress database?

Thanks, I appreciate every answer!!

  • 1
    Could use generate a random key for each userid and then have an unsubscribe link that contains e-mail and key? If you're doing it by means of a form, pass the e-mail to POST and then lookup/unsubscribe from there?
    – Noel Tock
    Commented Jan 9, 2012 at 15:52
  • I see what you mean. I could probably add their email and their ID (if they have one), and if not provide a random nonce or random number to verify. However, in the case that they decide to just go to that page (instead of using the link), I don't want to save an email to the database (of unsubbed users) when it could correlate with a user (and therefore their own user meta).
    – Josh Allen
    Commented Jan 9, 2012 at 20:30

3 Answers 3


You are probably looking for the user_exists function. http://codex.wordpress.org/Function_Reference/email_exists

This function will check whether or not a given email address ($email) has already been registered to a username, and returns that users ID (or false if none exists).

If the email address does not exist (user_exists returns false), you may want to use the wp_create_user function. http://codex.wordpress.org/Function_Reference/wp_create_user

The wp_create_user function allows you to insert a new user into the WordPress database

Only do that if you want to create a WordPress user though, which you may or may not. I'm a bit confused by this part of the question.

  • This is exactly what I needed. Thank you so much!
    – Josh Allen
    Commented Jan 11, 2012 at 22:58

Couldn't you use: http://codex.wordpress.org/Function_Reference/get_user_by

  • This and the chosen answer both do what I want. Thank you for your quick replies!
    – Josh Allen
    Commented Jan 11, 2012 at 22:59

You can only get this email and verify if there is any user have this email then change this email by the correspond username like this

$login ='[email protected]';
if(is_email( $login )){
            if( email_exists( $login )) {
              $userID__ = email_exists($login);
              $user_info_kim = get_userdata($userID__);
              $login  = $user_info_kim->user_login;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.