The edit_user_created_user WordPress PHP action fires after a new user has been created.
Usage
add_action('edit_user_created_user', 'your_custom_function', 10, 2);
function your_custom_function($user_id, $notify) {
// your custom code here
}
Parameters
$user_id(int|WP_Error) – ID of the newly created user or WP_Error on failure.$notify(string) – Type of notification that should happen. Seewp_send_new_user_notifications()for more information.
More information
See WordPress Developer Resources: edit_user_created_user
Examples
Log user creation
Log the user ID of the newly created user.
add_action('edit_user_created_user', 'log_user_creation', 10, 2);
function log_user_creation($user_id, $notify) {
if (!is_wp_error($user_id)) {
error_log("User created with ID: " . $user_id);
}
}
Send custom welcome email
Send a custom welcome email to the new user.
add_action('edit_user_created_user', 'send_custom_welcome_email', 10, 2);
function send_custom_welcome_email($user_id, $notify) {
if (!is_wp_error($user_id)) {
$user = get_userdata($user_id);
$email = $user->user_email;
// Send custom welcome email to the new user's email address
}
}
Assign new users to a default group
Assign new users to a specific group on registration.
add_action('edit_user_created_user', 'assign_default_group', 10, 2);
function assign_default_group($user_id, $notify) {
if (!is_wp_error($user_id)) {
// Assign the user to a default group, e.g., 'new-users' group
}
}
Add a custom role to the new user
Add a custom role to the new user.
add_action('edit_user_created_user', 'add_custom_role_to_new_user', 10, 2);
function add_custom_role_to_new_user($user_id, $notify) {
if (!is_wp_error($user_id)) {
$user = new WP_User($user_id);
$user->add_role('custom_role');
}
}
Notify an external service of new user creation
Send a notification to an external service when a new user is created.
add_action('edit_user_created_user', 'notify_external_service', 10, 2);
function notify_external_service($user_id, $notify) {
if (!is_wp_error($user_id)) {
$user = get_userdata($user_id);
$username = $user->user_login;
// Notify the external service of the new user's username
}
}