Hi Tosin,
Thank you for the question.I have written a blog post today about the same.
https://buddydev.com/disable-buddypress-4-character-user-name-limit/
Hope that helps.
Regards
BrajeshThank you brajesh the code below worked
// 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 must be at least 2 characters' ) ); } } return $result; } );
But I think there is a conflict with the WordPress Username Availability Checker plugin while this plugin is activated the old error message ( ‘Username must be at least 4 characters’ ) is still showing instead of the new error message ( ‘Username must be at least 2 characters’ )
Thanks
Hi Tosin,
yes, this code will not work with User Name availability checker. I will need to check that plugin and add compatibility. Please allow me 1-2 days to check that.Thank you
BrajeshHi Tosin,
Thank you for reminding. I will be looking into it today.Regards
BrajeshHi Tosin,
I am sorry for the delayed reply.You can add the following code to make it work with the user name availability checker too.
/** * For Username availability checker. */ add_filter( 'buddydev_uachecker_username_error', function ( $message, $username ) { // There was no error, return. if ( empty( $message ) ) { return $message; } // make sure it is our 4 letter issue. if ( ! empty( $username ) && strlen( $username ) < 4 ) { // let us allow 2 letter or above. $allowed_length = 2; // change it to impose your own limit. if ( strlen( $username ) < $allowed_length ) { $message = __( 'Username should have atleast 2 characters' ); } else { $message = ''; // reset. } } return $message; }, 10, 2 );
Regards
Brajesh
The topic ‘ [Resolved] Change buddypress username minimum length to 3’ is closed to new replies.