钩子文档

password_reset

💡 云策文档标注

概述

password_reset 是一个 WordPress 动作钩子,在用户密码重置前触发,允许开发者在密码实际设置前执行自定义操作。

关键要点

  • 触发时机:用户提交新密码后、密码实际设置前
  • 参数:$user(WP_User 对象,包含用户信息)和 $new_pass(字符串,新密码明文)
  • 用途:常用于发送通知、记录日志或执行其他与密码重置相关的自定义逻辑

代码示例

add_action('password_reset', 'password_reset_action', 10, 2);
function password_reset_action($user, $new_pass) {
    // 获取用户邮箱
    $email = $user->data->user_email;
    // 获取新密码明文
    $password = $new_pass;
    // 执行自定义操作,如发送邮件或记录日志
}

注意事项

  • 此钩子自 WordPress 1.5.0 版本引入,兼容性良好
  • 相关函数:reset_password() 用于处理密码重置逻辑
  • 开发者应确保自定义操作不影响密码重置的核心流程

📄 原文内容

Fires before the user’s password is reset.

Parameters

$userWP_User
The user.
$new_passstring
New user password.

More Information

Runs after the user submits a new password during password reset but before the new password is actually set.

Source

do_action( 'password_reset', $user, $new_pass );

Changelog

Version Description
1.5.0 Introduced.

User Contributed Notes