dqb78642 2015-03-05 10:45
浏览 15

Wordpress发送用户密码

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:

 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)."

";
     $message. = sprintf(__('E-mail: %s'), $user - > user_email)."
";
     $message. = sprintf(__('Password: %s'), $plaintext_pass)."
";

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

     if (empty($plaintext_pass)) return;

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

     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.

  • 写回答

1条回答 默认 最新

  • doubiaode0460 2015-03-05 11:24
    关注

    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. 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 ?

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

    ~ $plaintext_pass is uninitialized, so below statement will always be true

    if (empty($plaintext_pass)) return;
    

    If you are trying to create Forget password functionality, then you can use the existing wordpress functionality for it. This might be helpfull WP_LOSTPASSWORD_URL

    评论

报告相同问题?

悬赏问题

  • ¥15 关于Lammps建模的描述
  • ¥15 #lingo#请问一下为什么会出现以下情况,是因为l第一个值是0的缘故吗?
  • ¥15 设计格雷码同步八进制计数器
  • ¥100 改写matlab程序(关键词-系统对)
  • ¥15 函数信号发生器仿真电路
  • ¥15 Qt的pixmap和image图片加载都导致程序崩溃怎么办
  • ¥15 Kali木马生成问题求解
  • ¥30 求一下解题思路,完全不懂
  • ¥15 C51单片机串口控制JQ6500语音模块
  • ¥30 想给yolo5模型加一个图片识别界面,但是图片还没有检测出来就闪退了