register_new_user
Fires after a new user is registered, allowing an action to be performed.
The event fires at the very end of register_new_user(), after all operations.
Usage
add_action( 'register_new_user', 'wp_kama_register_new_user_action' );
/**
* Function for `register_new_user` action-hook.
*
* @param int $user_id ID of the newly registered user.
*
* @return void
*/
function wp_kama_register_new_user_action( $user_id ){
// action...
}
- $user_id(integer)
- The registered user's ID.
Examples
#1 Disable the email to the administrator about a new user registration
After a new user registers, WordPress sends a registration email to the administrator and the user. This behavior is not always needed, so change it.
For a regular WordPress installation:
// Disable emails for everyone
remove_action( 'register_new_user', 'wp_send_new_user_notifications' );
remove_action( 'edit_user_created_user', 'wp_send_new_user_notifications' );
// Add them back (if needed), but only for the user
add_action( 'register_new_user', 'my_wp_send_new_user_notifications' );
add_action( 'edit_user_created_user', 'my_wp_send_new_user_notifications' );
function my_wp_send_new_user_notifications( $user_id ) {
wp_new_user_notification( $user_id, null, 'user' );
}
For WordPress Multisite:
// Disable emails for everyone
remove_action( 'network_site_new_created_user', 'wp_send_new_user_notifications' );
remove_action( 'network_site_users_created_user', 'wp_send_new_user_notifications' );
remove_action( 'network_user_new_created_user', 'wp_send_new_user_notifications' );
// Add them back (if needed), but only for the user
add_action( 'network_site_new_created_user', 'my_wp_send_new_user_notifications' );
add_action( 'network_site_users_created_user', 'my_wp_send_new_user_notifications' );
add_action( 'network_user_new_created_user', 'my_wp_send_new_user_notifications' );
function change_network_wp_send_new_user_notifications( $user_id ) {
wp_new_user_notification( $user_id, null, 'user' );
}Changelog
| Since 4.4.0 | Introduced. |
Where the hook is called
wp-includes/user.php 3660
do_action( 'register_new_user', $user_id );
Where the hook is used in WordPress
wp-includes/default-filters.php 541
add_action( 'register_new_user', 'wp_send_new_user_notifications' );