wp_new_user_notification_email
云策文档标注
概述
wp_new_user_notification_email 是一个 WordPress 过滤器,用于自定义发送给新用户的注册通知邮件内容。它允许开发者修改邮件的主题、正文、收件人等参数。
关键要点
- 这是一个过滤器 Hook,名称为 wp_new_user_notification_email,用于修改新用户通知邮件的参数数组。
- 参数包括 $wp_new_user_notification_email(数组,包含 to、subject、message、headers 等键值),$user(WP_User 对象),$blogname(站点标题字符串)。
- 通过 apply_filters 调用,开发者可以添加回调函数来调整邮件内容,例如添加自定义消息或修改收件人。
- 相关函数 wp_new_user_notification() 用于发送邮件,此过滤器在其内部被调用。
- 自 WordPress 4.9.0 版本引入。
代码示例
function myplugin_new_user_notification_email_callback( $email ) {
$email['message'] .= "rn" . __( 'Thank you for register on site.', 'textdomain' );
return $email;
}
add_filter( 'wp_new_user_notification_email', 'myplugin_new_user_notification_email_callback' );
原文内容
Filters the contents of the new user notification email sent to the new user.
Parameters
$wp_new_user_notification_emailarray-
Used to build wp_mail() .
tostringThe intended recipient – New user email address.subjectstringThe subject of the email.messagestringThe body of the email.headersstringThe headers of the email.
$userWP_User-
User object for new user.
$blognamestring-
The site title.
Source
$wp_new_user_notification_email = apply_filters( 'wp_new_user_notification_email', $wp_new_user_notification_email, $user, $blogname );
Changelog
| Version | Description |
|---|---|
| 4.9.0 | Introduced. |
Skip to note 3 content
Jim
Actually I found a function that does it pretty painlessly – parse_str – takes the variables out of a URLfunction fp_wp_new_user_notification_email( $array, $user, $blogname ) { parse_str( $array[‘message’] ); . . . And now my function contains all the variables in the URL, including $key, with the same names!
Skip to note 4 content
Abdul Wahab
/** * Filter the new user notification email. * * @param $email array New user notification email parameters. * @return $email array New user notification email parameters. */ function myplugin_new_user_notification_email_callback( $email ) { $email['message'] .= "rn" . __( 'Thank you for register on site.', 'textdomain' ); return $email; } add_filter( 'wp_new_user_notification_email', 'myplugin_new_user_notification_email_callback' );