craigsul
Forum Replies Created
Viewing 1 replies (of 1 total)
-
@missveronicatv
It worked! You’re the best, thanks, have a great day too. (:
I also modified it a bit so that whenever someone has the same first and last name, it will automatically add a number at the end, and the numbers will increase with every user of the same name; john.doe, john.doe.1, john.doe.2 etc.add_filter( 'um_add_user_frontend_submitted', 'um_add_user_frontend_submitted_username', 10, 2 );
function um_add_user_frontend_submitted_username( $args, $form_data ) {
if ( $form_data['mode'] == 'register' ) {
// Get and sanitize first name and last name
$firstname = strtolower( sanitize_text_field( $args['first_name'] ));
$lastname = strtolower( sanitize_text_field( $args['last_name'] ));
// Generate initial username
$username = $firstname . '.' . $lastname;
// Ensure username is unique
$unique_username = $username;
$counter = 1; // Start counter for duplicates
while ( username_exists( $unique_username ) ) {
$unique_username = $username . '.' . $counter; // Append counter to username
$counter++;
}
// Assign the unique username to the args
$args['user_login'] = $unique_username;
}
return $args;
}
Viewing 1 replies (of 1 total)