钩子文档

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.

User Contributed Notes

  1. Skip to note 6 content

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