Skip to content

Instantly share code, notes, and snippets.

@alordiel
Created August 16, 2018 12:30
Show Gist options
  • Save alordiel/41c2c12db43f4311c40663370992b732 to your computer and use it in GitHub Desktop.
Save alordiel/41c2c12db43f4311c40663370992b732 to your computer and use it in GitHub Desktop.
WordPress - create unique username by provided email
<?php
function create_unique_user_name_by_email ($email) {
$email_name = explode( '@', $email );
if ( ! get_user_by( 'login', $email_name[0] ) ) {
$username = $email_name[0];
} else {
$username = uniqid( $email_name[0], false );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment