Change the username system to User Registration Addon function for multisite

when i register user in multisite if i want use Full name as username the system return error, because accept only lower case letter and accept only letter and number, and some time if the last name have whitespace (example “De Minicis”), the white space is a problem .

i have edit this function.

add_filter( 'gform_username' , 'auto_username', 10, 4 );
function auto_username( $username, $feed, $form, $entry ) {

GFCommon::log_debug( __METHOD__ . '(): running.' );

if($form['id'] === 4) {
$username = strtolower( rgar( $entry, '1.3' ) . rgar( $entry, '1.6' ) );

}
if ( empty( $username ) ) {
GFCommon::log_debug( __METHOD__ . '(): Value for username is empty.' );
return $username;
}

if ( ! function_exists( 'username_exists' ) ) {
require_once( ABSPATH . WPINC . '/registration.php' );
}

if ( username_exists( $username ) ) {
GFCommon::log_debug( __METHOD__ . '(): Username already exists, generating a new one.' );
$i = 2;
while ( username_exists( $username . $i ) ) {
$i++;
}
$username = $username . $i;
GFCommon::log_debug( __METHOD__ . '(): New username: ' . $username );
};
$search = array( '\\', "\0", "'", "\x8" /* BS */, "\n", "\r", "\t", "\x1A" /* Ctrl+Z */,"\x0B", " ", "\s" );

$username = str_replace($search,'',$username);
$username = strtolower($username);

return $username;

}

could you create such a default function in the add-on?

Hi Edoardo. This is a perfect use for the gform_username filter as you have done. I’ll discuss it with the team and we’ll see if there is any interest in incorporating this into the core. Thank you.

1 Like

thx, unfortunately in the multisite, there are many problems with the registration form.
because even the email cannot be used because the @ is seen as an illegal character. so it’s a big mess it’s like the add on isn’t working properly.