Changing the username character limit from four to less characters

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?

2 s
2

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;
}

Leave a Comment