user_registration_email
云策文档标注
概述
user_registration_email 是一个 WordPress 过滤器,用于在用户注册过程中过滤新用户的电子邮件地址。它位于 register_new_user() 函数的起始位置,允许开发者在数据进一步处理前修改电子邮件字段或相关 $_POST 数据。
关键要点
- 过滤器名称:user_registration_email,参数为 $user_email(字符串类型),表示新用户的电子邮件地址。
- 钩子位置:在 wp-login.php 的 register_new_user() 函数中,用户数据经过清理后立即调用,是注册流程中的第一个过滤器。
- 用途:可用于自定义电子邮件地址,例如将其设置为与用户名相同,或进行其他表单定制操作。
- 注意事项:由于 register_new_user() 可能在没有表单提交的情况下调用,依赖 $_POST 数据可能导致问题。
代码示例
function wpdocs_use_email_as_username( $user_email ) {
return $_POST['user_login'];
}
add_filter( 'user_registration_email', 'wpdocs_use_email_as_username' );
原文内容
Filters the email address of a user being registered.
Parameters
$user_emailstring-
The email address of the new user.
Source
$user_email = apply_filters( 'user_registration_email', $user_email );
Changelog
| Version | Description |
|---|---|
| 2.1.0 | Introduced. |
Skip to note 2 content
Collins Mbaka
An Example
function wpdocs_use_email_as_username( $user_email ) { return $_POST['user_login']; } add_filter( 'user_registration_email', 'wpdocs_use_email_as_username' );register_new_user()may be called without form submission, so the use of$_POSTwould present problems in that context.