The network_site_new_created_user WordPress PHP action is triggered after a new user is created via the network site-new.php page.
Usage
add_action('network_site_new_created_user', 'your_custom_function', 10, 1);
function your_custom_function($user_id) {
// Your custom code here
}
Parameters
$user_id(int) – ID of the newly created user.
More information
See WordPress Developer Resources: network_site_new_created_user
Examples
Send a welcome email to the new user
add_action('network_site_new_created_user', 'send_welcome_email', 10, 1);
function send_welcome_email($user_id) {
$user_info = get_userdata($user_id);
$to = $user_info->user_email;
$subject = 'Welcome to Our Network!';
$message = 'Hi ' . $user_info->display_name . ', welcome to our network of sites!';
wp_mail($to, $subject, $message);
}
Assign a custom role to the new user
add_action('network_site_new_created_user', 'assign_custom_role', 10, 1);
function assign_custom_role($user_id) {
$user = new WP_User($user_id);
$user->set_role('custom_role');
}
Log the user creation event
add_action('network_site_new_created_user', 'log_user_creation', 10, 1);
function log_user_creation($user_id) {
$log_message = "User ID: $user_id has been created.";
error_log($log_message);
}
Add a user meta value upon user creation
add_action('network_site_new_created_user', 'add_custom_user_meta', 10, 1);
function add_custom_user_meta($user_id) {
update_user_meta($user_id, 'custom_meta_key', 'custom_meta_value');
}
Notify the admin of a new user creation
add_action('network_site_new_created_user', 'notify_admin_new_user', 10, 1);
function notify_admin_new_user($user_id) {
$user_info = get_userdata($user_id);
$to = get_option('admin_email');
$subject = 'A new user has joined the network';
$message = 'User ID: ' . $user_id . ' (' . $user_info->user_login . ') has joined the network.';
wp_mail($to, $subject, $message);
}