Home > Back-end >  How can I get the id of a user just by writing their email in php?
How can I get the id of a user just by writing their email in php?

Time:04-08

I am creating an endpoint to be able to send an email to a user in case they have forgotten their password, just entering their email to be able to send them an email to reset a new password, I only need to be able to obtain the id of said email that they enter to change your password in php mailer

CodePudding user response:

There is a built-in WordPress function that can get a user ID by email address:

Try get_user_by() see here: https://developer.wordpress.org/reference/functions/get_user_by/

Please note that this function does not return the user ID, but a WP_User object (which includes the user ID)

Also note that WordPress already have a password reset function for users, here are the instructions for a password reset: https://wordpress.org/support/article/resetting-your-password/#through-the-automatic-emailer

In addition, as @maggiathor commented, there is also a WordPress function to initiate a password reset programmatically called retrieve_password() see here: https://developer.wordpress.org/reference/functions/retrieve_password/

  • Related