Username only lowercase and numbers in WP multi?

We are using wordpress in multi sub-domains at work.
So we have administrator for each domain who can create users for subscribing editing contributing.
The problem is, our company edit the rule that all logins/usernames have to be like this “first-name.family-name” ex “barack.obama”… 🙂
But the administrator can not do it, only super admin can do it !
In sub-domain administrator mode, there is a message that says : “Only the lowercase letters a-z and numbers allowed”.

So we want to make it possible to admin to create users with first-name.family-name, but we try to search how to change it in the code, without finding it.

Read More

If someone can help, thanks !

Related posts

1 comment

  1. In multisite usernames are validated with wpmu_validate_user_signup, which you can find in /wp-includes/ms-functions.php#L462.

    You can add a dot there, after the 0-9, which is not recommended, since you will then hate to update WordPress core.

    if ( $user_name != $orig_username || preg_match( '/[^a-z0-9.]/', $user_name ) ) {
    

    So, a better solution would be to create a plugin for it.

    You could try to add the following in a php-file and add it to /wp-content/mu-plugins/

    <?php
    /*
    Plugin Name: wpmu no username error
    */
    
    function wpmu_no_username_error( $result ) {
        $error_name = $result[ 'errors' ]->get_error_messages( 'user_name' );
        if ( empty ( $error_name ) 
            or false===$key=array_search( __( 'Only lowercase letters (a-z) and numbers are allowed.' ), $error_name)
        ) {
        return $result;
        }
    //  only remove the error we are disabling, leaving all others
        unset ( $result[ 'errors' ]->errors[ 'user_name' ][$key] );
    /**
     *  re-sequence errors in case a non sequential array matters
     *  e.g. if a core change put this message in element 0 then get_error_message() would not behave as expected)
     */
        $result[ 'errors' ]->errors[ 'user_name' ] = array_values( $result[ 'errors' ]->errors[ 'user_name' ] );
        return $result;
    }
    add_filter( 'wpmu_validate_user_signup', 'wpmu_no_username_error' );
    

    I didn’t try it though. This is based on “Changing the username character limit from four to less characters“.

    I hope this helps. At least it should get you close. GL with it!

Comments are closed.