wordpress - 在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'] );
}
有人知道如何获取管理员为用户更改的密码吗?
解决方案
如果在管理员点击“更新个人资料”按钮的同时触发电子邮件发送,那么您可以使用帖子数据:($_POST['pass1']
或$_POST['pass1-text']
)。您可以将行更改为如下
$pass_change_email['message']=str_replace( '###PASSWORD###',$_POST['pass1'], $pass_change_email['message'] );
如果这些电子邮件是异步生成的,那么您可能无法获得该值,因为密码通常是经过哈希处理的。不推荐,但解决此问题的一种方法是将密码作为计划文本保存在自定义字段中,发送电子邮件然后删除该自定义字段。
推荐阅读
- android - 从 api 获取数据并将其设置为消失后,进度条不会消失
- python - 使用 Angular http 客户端和烧瓶的 Kubernetes 微服务开发不起作用
- .net-core - Azure Pipeline dotnet push 错误查找 nuget 包
- css - 轮播中的活动图像
- c - 音频 PCM 信号中的忙音检测
- c# - 如何更改 TimePicker 的样式和颜色
- android - Android Studio:无法恢复密钥,有没有办法恢复 Android 密钥别名密码
- php - Xdebug: [Step Debug] 连接调试客户端超时,等待:200 ms。试过:本地主机:9003
- javascript - 如何将“数字”从巨大的数据集文件转换为实际数字?
- r - 从 read.table 获取数据的 ggplot2 直方图