首页 > 解决方案 > 在wordpress中使用密码编辑密码更新电子邮件给用户

问题描述

嗨,我想在管理员更改用户密码时编辑密码更改电子邮件的模板我想通过电子邮件将密码发送给用户我尝试编辑代码但没有用。这是我的代码

.
if ( ! empty( $send_password_change_email ) ) {
            /* translators: Do not translate USERNAME, ADMIN_EMAIL, EMAIL, SITENAME, SITEURL: those are placeholders. */
            $pass_change_text = __( 'Hi ###USERNAME###,

This notice confirms that your password was changed on ###SITENAME###.
your new password is this :###PASSWORD###
If you did not change your password, please contact the Site Administrator at
###ADMIN_EMAIL###

This email has been sent to ###EMAIL###

Regards,
All at ###SITENAME###
###SITEURL###' );

            $pass_change_email = array(
                'to'      => $user['user_email'],
                /* translators: User password change notification email subject. 1: Site name */
                'subject' => __( '[%s] Notice of Password Change' ),
                'message' => $pass_change_text,
                'headers' => '',
            );

            /**
             * Filters the contents of the email sent when the user's password is changed.
             *
             * @since 4.3.0
             *
             * @param array $pass_change_email {
             *            Used to build wp_mail().
             *            @type string $to      The intended recipients. Add emails in a comma separated string.
             *            @type string $subject The subject of the email.
             *            @type string $message The content of the email.
             *                The following strings have a special meaning and will get replaced dynamically:
             *                - ###USERNAME###    The current user's username.
             *                - ###ADMIN_EMAIL### The admin email in case this was unexpected.
             *                - ###EMAIL###       The user's email address.
             *                - ###SITENAME###    The name of the site.
             *                - ###SITEURL###     The URL to the site.
             *            @type string $headers Headers. Add headers in a newline (\r\n) separated string.
             *        }
             * @param array $user     The original user array.
             * @param array $userdata The updated user array.
             *
             */
            $pass_change_email = apply_filters( 'password_change_email', $pass_change_email, $user, $userdata );
            $pass_change_email['message']=str_replace( '###PASSWORD###',$user['user_password'], $pass_change_email['message'] );
            $pass_change_email['message'] = str_replace( '###USERNAME###', $user['user_login'], $pass_change_email['message'] );
            $pass_change_email['message'] = str_replace( '###ADMIN_EMAIL###', get_option( 'admin_email' ), $pass_change_email['message'] );
            $pass_change_email['message'] = str_replace( '###EMAIL###', $user['user_email'], $pass_change_email['message'] );
            $pass_change_email['message'] = str_replace( '###SITENAME###', $blog_name, $pass_change_email['message'] );
            $pass_change_email['message'] = str_replace( '###SITEURL###', home_url(), $pass_change_email['message'] );

            wp_mail( $pass_change_email['to'], sprintf( $pass_change_email['subject'], $blog_name ), $pass_change_email['message'], $pass_change_email['headers'] );
        }

有人知道如何获取管理员为用户更改的密码吗?

标签: wordpressemailpasswords

解决方案


如果在管理员点击“更新个人资料”按钮的同时触发电子邮件发送,那么您可以使用帖子数据:($_POST['pass1']$_POST['pass1-text'])。您可以将行更改为如下

$pass_change_email['message']=str_replace( '###PASSWORD###',$_POST['pass1'], $pass_change_email['message'] );

如果这些电子邮件是异步生成的,那么您可能无法获得该值,因为密码通常是经过哈希处理的。不推荐,但解决此问题的一种方法是将密码作为计划文本保存在自定义字段中,发送电子邮件然后删除该自定义字段。


推荐阅读