[themify_is_logged_in]
[php]
function generate_unique_username( $username ) {
$username = sanitize_title( $username ); // $username = sanitize_user( $username );
static $i;
if ( null === $i ) {
$i = 1;
} else {
$i ++;
}
if ( ! username_exists( $username ) ) {
return $username;
}
$new_username = sprintf( ‚%s-%s‘, $username, $i );
if ( ! username_exists( $new_username ) ) {
return $new_username;
} else {
return call_user_func( __FUNCTION__, $username );
}
}
function nicknameToUsername( $userData ){
if ( isset( $_POST[ ’nickname‘ ] ) ) {
$new_user_name = generate_unique_username( $_POST[ ’nickname‘ ] );
$userData[ ‚user_login‘ ] = $new_user_name;
}
return $userData;
}
add_filter( ‚user_meta_pre_user_register‘, ’nicknameToUsername‘ );
[/php]
[/themify_is_logged_in]