after_password_reset
云策文档标注
概述
after_password_reset 是一个 WordPress Action Hook,在用户密码重置后触发。它主要用于在密码重置过程中执行自定义操作,例如发送通知或记录日志。
关键要点
- 触发时机:仅在“忘记密码”重置流程中触发,不适用于所有密码更改场景。
- 参数:接收两个参数:$user(WP_User 对象,包含用户信息)和 $new_pass(字符串,新密码的明文)。
- 相关函数:与 reset_password() 函数关联,用于处理密码重置。
- 版本历史:自 WordPress 4.4.0 版本引入。
代码示例
add_action('after_password_reset', 'after_password_reset_action', 10, 2);
function after_password_reset_action($user, $new_pass) {
// 获取用户邮箱
$email = $user->data->user_email;
// 获取新密码(明文)
$password = $new_pass;
// 执行自定义操作,如发送邮件或记录日志
}注意事项
- 此 Hook 仅针对密码重置流程,如需监控所有密码更改,需额外使用 'profile_update' Hook。
- $new_pass 参数是明文密码,使用时需注意安全处理,避免存储或日志记录明文。
原文内容
Fires after the user’s password is reset.
Parameters
$userWP_User-
The user.
$new_passstring-
New user password.
Source
do_action( 'after_password_reset', $user, $new_pass );
Changelog
| Version | Description |
|---|---|
| 4.4.0 | Introduced. |
Skip to note 4 content
jon
As the name and description imply, this Action only fires during the Lost Password reset process. If you want to detect all password changes, you will also need to set up an Action for
'profile_update'described at https://developer.wordpress.org/reference/hooks/profile_update/Skip to note 5 content
Alexandre Froger
Remark: the
$new_passparameter is the “New password for the user in plaintext” originally passed toreset_password( $user, $new_pass ).Skip to note 6 content
Sayedul Sayem
add_action('after_password_reset', 'after_password_reset_action', 10, 2); function after_password_reset_action($user, $new_pass) { // user email. $user return full user info $email = $user->data->user_email; // new entered password (plain text) $password = $new_pass; // Do whatever you want... }