• Resolved superbr

    (@superbr)


    Hello! Awesome plugin! Could you help me with a question?

    When a user registers on the site, WordPress allows the username of this new member to have up to 60 characters.

    Is it possible to limit the number of characters in the username? If possible, I would like to have a minimum number of 7 characters and a maximum of 25 characters during registration.

    • This topic was modified 2 days, 15 hours ago by superbr.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support alexandrubodea

    (@alexandrubodea)

    Hi @superbr,

    While this functionality is not directly added to our plugin, you should be able to achieve this while using the following code:

    function wppb_check_username_length_custom( $message, $field, $request_data, $form_location ) {
    $min_length = '5';
    $max_length = '25';

    if( !empty( $request_data['username'] ) ){
    $length = strlen( $request_data['username'] );

    if ( $length > $max_length ) {
    return __('Your username exceeds the maximum length allowed.', 'profile-builder');
    }
    elseif ( $length < $min_length ) {
    return __('Your username is under the minimum required length.', 'profile-builder');
    }
    }
    }
    add_filter( 'wppb_check_form_field_default-username', 'wppb_check_username_length_custom', 10, 4 );

    Note: You can add the code to your site by adding it to your theme’s ‘functions.php’ file or by creating a new plugin as described?here.

    Note 2: You can edit the ‘$max_length’ and ‘$min_length’ variables and also the ‘Your username exceeds the maximum length allowed.’ and ‘Your username is under the minimum required length.‘ messages.

    Best regards,

    Thread Starter superbr

    (@superbr)

    Amazing! Exactly what I was looking for

    Thank you so much! It worked perfectly!

    Plugin Support alexandrubodea

    (@alexandrubodea)

    Glad to hear this!

    Hope you have a great week ahead!

    Kind regards,

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.