Disable BuddyPress 4 character User name limit
In BuddyPress, there is a requirement that user names(user login) must have atleast 4 characters. It comes from the WPMU days of BuddyPress(WordPress multisite still imposes this limit on user names).
It is very easy to disable this limit or customize it.
Completely disable Username length limit for BuddyPress:-
If you use the following code, the limit imposed on username will be removedĀ completely. Users can now register a user name which has one or more characters.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | // disable 4 letter limit in BuddyPress Username. add_filter( 'bp_core_validate_user_signup', function ( $result ) { // let us not worry if there are no errors or user name length is not the root cause. if ( ! isset( $result['errors'] ) || ! is_wp_error( $result['errors'] ) || empty( $result['user_name'] ) || is_numeric( $result['user_name'] ) ) { return $result; } // make sure it is our 4 letter error. if ( ! empty( $result['user_name'] ) && strlen( $result['user_name'] ) < 4 ) { $result['errors']->remove( 'user_name' ); } return $result; } ); |
Here is a screenshot showing me using the letter 'b' as my username.
In case you want to set it to 2 letters or 3 letters, you can use the following code instead.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | // disable 4 letter limit in BuddyPress Username, set at atleast 2. add_filter( 'bp_core_validate_user_signup', function ( $result ) { // let us not worry if there are no errors or user name length is not the root cause. if ( ! isset( $result['errors'] ) || ! is_wp_error( $result['errors'] ) || empty( $result['user_name'] ) || is_numeric( $result['user_name'] ) ) { return $result; } // make sure it is our 4 letter issue. if ( ! empty( $result['user_name'] ) && strlen( $result['user_name'] ) < 4 ) { $result['errors']->remove( 'user_name' ); // let us allow 2 letter or above. $allowed_length = 2; // change it to impose your own limit. if ( strlen( $result['user_name'] ) < $allowed_length ) { $result['errors']->add( 'user_name', __( 'Username should have atleast 2 characters' ) ); } } return $result; } ); |
You can put the snippet in your bp-custom.php or your theme's functions.php.
Have fun building your community!