Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to create a user account on my multi-site installation of Wordpress with a username less than 4 characters. But since Wordpress has a limit of usernames at least being 4 characters, this error message is shown:

Username must be at least 4 characters.

I found a solution involving a mu-plugins folder in the wp-content folder, but it doesn't work. Is there any possible way that would allow me to create a user account with a username less than 4 characters?

share|improve this question
    
If there are problems with my answer it would be useful to know what didn’t work. I have tested it as a plugin on a multisite and successfully registered the users a, b and c. –  toscho Jul 27 '12 at 12:49
    
Actually it's not about your answer being unable to solve my problem. It was just not very useful to me, personally, since I am new to Wordpress. –  Ratul Jul 29 '12 at 19:29
    
Just save the code as shortnames.php in your plugin directory and activate it. –  toscho Jul 29 '12 at 19:37
    
Thanks for taking your time to help me. –  Ratul Jul 29 '12 at 19:47

1 Answer 1

up vote 6 down vote accepted

You can filter 'wpmu_validate_user_signup' and check if the error code matches the 4 character warning. Then just unset the error code.

Sample plugin:

<?php # -*- coding: utf-8 -*-
/* Plugin Name: Allow short user names for multi site. */

add_filter( 'wpmu_validate_user_signup', 'wpse_59760_short_user_names' );

/**
 * Allow very short user names.
 *
 * @wp-hook wpmu_validate_user_signup
 * @param   array $result
 * @return  array
 */
function wpse_59760_short_user_names( $result )
{
    $error_name = $result[ 'errors' ]->get_error_message( 'user_name' );
    if ( empty ( $error_name )
        or $error_name !== __( 'Username must be at least 4 characters.' )
    )
    {
        return $result;
    }

    unset ( $result[ 'errors' ]->errors[ 'user_name' ] );
    return $result;
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.