allow_password_reset
云策文档标注
概述
allow_password_reset 是一个 WordPress 过滤器钩子,用于控制是否允许用户重置密码。开发者可以通过此钩子自定义密码重置的逻辑,例如基于用户角色或状态进行限制。
关键要点
- 钩子名称:allow_password_reset
- 参数:$allow(布尔值,默认 true)和 $user_id(整数,用户 ID)
- 返回值:布尔值,true 表示允许重置,false 表示禁止
- 相关函数:wp_is_password_reset_allowed_for_user()
- 引入版本:WordPress 2.7.0
代码示例
// 示例:禁止特定用户重置密码
add_filter('allow_password_reset', function($allow, $user_id) {
if ($user_id == 123) {
return false; // 禁止用户 ID 为 123 的用户重置密码
}
return $allow;
}, 10, 2);注意事项
- 此钩子位于 wp-includes/user.php 文件中,使用时需确保 WordPress 版本不低于 2.7.0。
- 在自定义逻辑中,应谨慎处理返回值,避免意外阻止所有用户重置密码。
原文内容
Filters whether to allow a password to be reset.
Parameters
$allowbool-
Whether to allow the password to be reset. Default true.
$user_idint-
The ID of the user attempting to reset a password.
Source
return apply_filters( 'allow_password_reset', $allow, $user->ID );
Changelog
| Version | Description |
|---|---|
| 2.7.0 | Introduced. |
Skip to note 3 content
Edi
Source file is now wp-includes/user.php.
Skip to note 4 content
Jose Lazo
$allow = apply_filters('allow_password_reset', true, $user_data->ID); if (!$allow) { return false; } else if (is_wp_error($allow)) { return false; }