send_password_change_email
云策文档标注
概述
send_password_change_email 是一个 WordPress 过滤器钩子,用于控制是否发送密码更改邮件。它允许开发者通过修改返回值来启用或禁用邮件发送。
关键要点
- 这是一个过滤器钩子,应用于 wp_update_user() 函数中,影响密码更改时的邮件通知。
- 参数包括 $send(布尔值,决定是否发送邮件)、$user(原始用户数组)和 $userdata(更新后的用户数组)。
- 默认返回 true,表示发送邮件;可通过过滤器返回 false 来禁用邮件。
代码示例
// 禁用密码更改邮件通知
function disable_password_change_email( $send ) {
return false;
}
add_filter( 'send_password_change_email', 'disable_password_change_email' );
// 更简洁的方式
add_filter( 'send_password_change_email', '__return_false' );注意事项
- 该钩子自 WordPress 4.3.0 版本引入,使用时需确保版本兼容性。
- 相关函数 wp_insert_user() 和 wp_update_user() 的文档可参考以了解 $user 和 $userdata 字段详情。
原文内容
Filters whether to send the password change email.
Description
See also
- wp_insert_user(): For
$userand$userdatafields.
Parameters
$sendbool-
Whether to send the email.
$userarray-
The original user array.
$userdataarray-
The updated user array.
Source
$send_password_change_email = apply_filters( 'send_password_change_email', true, $user, $userdata );
Changelog
| Version | Description |
|---|---|
| 4.3.0 | Introduced. |
Skip to note 3 content
GenerateWP
To disable Password Change notifications:
function disable_password_change_email( $send ) { return false; } add_filter( 'send_password_change_email', 'disable_password_change_email' );Or even shorter:
add_filter( 'send_password_change_email', '__return_false' );Skip to note 4 content
Steven Lin
Example migrated from Codex:
To disable the notice of changed password sent by the wp_update_user() function, simply use the filter hook to __return_false():
add_filter( 'send_password_change_email', '__return_false' );