Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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!!

share|improve this question
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 Jan 9 '12 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 Jan 9 '12 at 20:30

2 Answers 2

up vote 3 down vote accepted

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.

share|improve this answer
    
This is exactly what I needed. Thank you so much! –  Josh Allen Jan 11 '12 at 22:58

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

share|improve this answer
    
This and the chosen answer both do what I want. Thank you for your quick replies! –  Josh Allen Jan 11 '12 at 22:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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