wp_send_new_user_notifications()
Notifies the site administrator by email about the registration of a new user, and also sends the user an email with their login and password for authentication.
This is a wrapper for the function wp_new_user_notification() with the preset parameter $notify=both, so refer to that for information on hooks and usage examples.
This wrapper was created for convenient use on user registration events. For example, it is called in the engine on the following events:
add_action( 'register_new_user', 'wp_send_new_user_notifications' ); add_action( 'edit_user_created_user', 'wp_send_new_user_notifications', 10, 2 ); add_action( 'network_site_new_created_user', 'wp_send_new_user_notifications' ); add_action( 'network_site_users_created_user', 'wp_send_new_user_notifications' ); add_action( 'network_user_new_created_user', 'wp_send_new_user_notifications' );
In WordPress 4.6.0, the parameter $notify
was changed to accept the value 'user'
for sending notifications only to the created user.
No Hooks.
Returns
null
. Nothing (null).
Usage
wp_send_new_user_notifications( $user_id, $notify );
- $user_id(number) (required)
- User ID.
- $notify(string)
Determines the type of notification.
admin
orempty string
('') - only the admin will receive the notification.user
- only the created user will receive the notification.both
- both the admin and the created user will receive notifications.
Default: 'both'
Examples
#1 Admin and new user notification about registration and sending emails to both
Suppose, when registering a user, you need to notify yourself (you are the admin) and send an email to the new user by email with a link to set a new password:
$new_user_id = 8; wp_new_user_notification( $new_user_id, 'both' );
In the result, the admin will get an email:
New user registration on your site Example: Username: user Email: [email protected]
The user will get:
Username: user To set your password, visit the following address: <http://example.com/wp-login.php?action=rp&key=1ORsgCiUtZdwDw3tss4U&login=user> http://example.com/wp-login.php
Changelog
Since 4.4.0 | Introduced. |
Since 4.6.0 | Converted the $notify parameter to accept 'user' for sending notifications only to the user created. |
wp_send_new_user_notifications() wp send new user notifications code WP 6.8.1
function wp_send_new_user_notifications( $user_id, $notify = 'both' ) { wp_new_user_notification( $user_id, null, $notify ); }