简体   繁体   English

WordPress的发送用户密码

[英]Wordpress Send User's Password

I have created a function which should let people to by email their password by typing their registered email address. 我创建了一个函数,该函数应允许人们通过输入注册的电子邮件地址来通过电子邮件发送密码。 But for some reasons wordpress doesn't send any emails or showing any error for example if email not recognised in the user database: 但是由于某些原因,wordpress不会发送任何电子邮件或显示任何错误,例如,如果用户数据库中未识别电子邮件:

 function wp_user_password($user_id) {

     function get_userdata($user_id) {
         return get_user_by('email', $_REQUEST['email']);
     }

     $user = get_userdata($user_id);

     $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);

     $message = sprintf(__('Your registration details:'), $blogname)."\r\n\r\n";
     $message. = sprintf(__('E-mail: %s'), $user - > user_email)."\r\n";
     $message. = sprintf(__('Password: %s'), $plaintext_pass)."\r\n";

     @wp_mail(get_option('admin_email'), sprintf(__('Requested Registration Details'), $blogname), $message);

     if (empty($plaintext_pass)) return;

     $message = sprintf(__('Username: %s'), $user - > user_login)."\r\n";
     $message. = sprintf(__('Password: %s'), $plaintext_pass)."\r\n";

     wp_mail($user - > user_email, sprintf(__('[%s] Your username and password'), $blogname), $message);
 }
 $this - > output(1, 'Email sent successfully');

I would really appreciate if you can help me with amending the code above. 如果您能帮助我修改上面的代码,我将不胜感激。 Many thanks. 非常感谢。

It seems like the goal you are trying to achieve here of sending user their existing password is not doable. 似乎您要在此处实现的目标是无法实现的,即向用户发送其现有密码。

Wordpress encrypts the passwords for every user when a user is registered and stores it in database. 当用户注册时,Wordpress会为每个用户加密密码,并将其存储在数据库中。 The encryption is one way and thus the password can never be recovered. 加密是一种方法,因此永远无法恢复密码。

Problems with your code: 您的代码有问题:

~ What is the use of $user_id here ? 〜$ user_id在这里有什么用?

function get_userdata($user_id) {
   return get_user_by('email', $_REQUEST['email']);
}

~ $plaintext_pass is uninitialized, so below statement will always be true 〜$ plaintext_pass未初始化,因此以下语句始终为真

if (empty($plaintext_pass)) return;

If you are trying to create Forget password functionality, then you can use the existing wordpress functionality for it. 如果您尝试创建“忘记密码”功能,则可以使用现有的wordpress功能。 This might be helpfull WP_LOSTPASSWORD_URL WP_LOSTPASSWORD_URL可能会有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM