BuddyDev

Search

[Resolved] Change buddypress username minimum length to 3

  • Participant
    Level: Guru
    Posts: 900
    Tosin on #31772

    Hello,

    Is it possible to change the username minimum character limit to 3 instead of 4

    Thanks

  • Participant
    Level: Guru
    Posts: 900
    Tosin on #31773

    I know this is a security feature but login with username is disabled in my site, users can only login with email address.

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #31785

    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
    Brajesh

  • Participant
    Level: Guru
    Posts: 900
    Tosin on #31788

    Thank 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

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #31789

    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
    Brajesh

  • Participant
    Level: Guru
    Posts: 900
    Tosin on #31849

    Good day sir, I just want to remind you about this request

    Thank you

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #31858

    Hi Tosin,
    Thank you for reminding. I will be looking into it today.

    Regards
    Brajesh

  • Participant
    Level: Guru
    Posts: 900
    Tosin on #31909

    Good day sir, Any update sir

    Thanks

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #31915

    Hi 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

  • Participant
    Level: Guru
    Posts: 900
    Tosin on #31939

    it worked perfectly thank you very much

The topic ‘ [Resolved] Change buddypress username minimum length to 3’ is closed to new replies.

This topic is: resolved