Yes, this is possible. WordPress defines a function named wp_new_user_notification
. You can override this function by creating your own version (also named wp_new_user_notification
) in your own theme or plugin.
You may wish to start by copying the contents of the existing core version into your own copy. You can now customize the logic for your own needs.
Since this function passes the $user_id
as the first argument, you can use get_userdata
to obtain more information about the user (for example that user’s roles) and then send different content depending on their role.
$user_data = get_userdata( $user_id );
if ( ! empty( $user_data->roles ) ) {
if ( in_array( 'role_a', $user_data->roles, true ) {
// custom content for role a
} elseif ( in_array( 'role_b', $user_data->roles, true ) {
// custom content for role b
}
}