wp_new_user_notification_email
Allows you to change the contents of the email sent to a new user upon registration.
Usage
add_filter( 'wp_new_user_notification_email', 'wp_kama_new_user_notification_email_filter', 10, 3 );
/**
* Function for `wp_new_user_notification_email` filter-hook.
*
* @param array $wp_new_user_notification_email Used to build wp_mail().
* @param WP_User $user User object for new user.
* @param string $blogname The site title.
*
* @return array
*/
function wp_kama_new_user_notification_email_filter( $wp_new_user_notification_email, $user, $blogname ){
// filter...
return $wp_new_user_notification_email;
}
- $wp_new_user_notification_email(array)
An array of data passed to wp_mail(), excluding attachments. Array keys:
-
to
Email address of the newly registered user. -
subject
Email subject. -
message
Email body (content). - headers
Email headers that specify its attributes.
-
- $user(WP_User)
- The new user's WP_User object.
- $blogname(string)
- The site name obtained through
get_option('blogname').
Examples
#1 Change the registration email content
Suppose we have a custom role named price_list__subscriber that grants access to the Price List page. When a user with this role registers, the default WordPress email can be supplemented with information about that access.
add_filter( 'wp_new_user_notification_email', 'hpl_user_notification_email', 10, 3 );
/**
* Changes the email sent when a new user with a specific role registers.
*
* @param array $email_data
* @param WP_User $user
* @param string $blogname
*
* @return array
*/
function hpl_user_notification_email( $email_data, $user, $blogname ) {
if ( user_can( $user, 'price_list__subscriber' ) ) {
$text = "You have been granted access to the price list page. \r\n\r\n";
$text .= "The page is located at http://example.com/price-list/. \r\n\r\n";
$text .= "A temporary login password was generated automatically. Set your own password using the link below. \r\n\r\n";
$email_data['subject'] = 'Price list access granted - ' . wp_specialchars_decode( $blogname );
$email_data['message'] = $text . $email_data['message'];
}
return $email_data;
}Changelog
| Since 4.9.0 | Introduced. |
Where the hook is called
wp_new_user_notification_email
wp-includes/pluggable.php 2416
$wp_new_user_notification_email = apply_filters( 'wp_new_user_notification_email', $wp_new_user_notification_email, $user, $blogname );