如何仅通过在 php 中写入用户的电子邮件来获取用户的 ID?

How can I get the id of a user just by writing their email in php?

我正在创建一个端点,以便能够在用户忘记密码时向其发送电子邮件,只需输入他们的电子邮件即可向他们发送电子邮件以重置新密码,我只需要能够获得他们在 php mailer

中输入的用于更改密码的所述电子邮件的 ID

有一个 built-in WordPress 函数可以通过电子邮件地址获取用户 ID:

试试 get_user_by() 看这里:https://developer.wordpress.org/reference/functions/get_user_by/

请注意,此函数不是 return 用户 ID,而是 WP_User 对象(包括用户 ID)

另请注意,WordPress 已经为用户提供了密码重置功能,以下是密码重置说明:https://wordpress.org/support/article/resetting-your-password/#through-the-automatic-emailer

此外,正如@maggiathor 评论的那样,还有一个 WordPress 函数以编程方式启动密码重置,称为 retrieve_password() 参见此处:https://developer.wordpress.org/reference/functions/retrieve_password/