使用wordpress中的密码编辑密码更新电子邮件给用户

时间:2018-08-14 19:24:57

标签: wordpress email passwords

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

.
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'] );
        }

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

1 个答案:

答案 0 :(得分:1)

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

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

如果这些电子邮件是异步生成的,则您可能无法获得该值,因为通常会对密码进行哈希处理。不建议这样做,但一种解决方法是将密码作为计划文本保存在自定义字段中,发送电子邮件然后删除该自定义字段。