WordPress.org

Ready to get started?Download WordPress

Forums

How to set maximum username length (4 posts)

  1. chulk607
    Member
    Posted 4 years ago #

    60 characters seems a tad excessive and is causing my theme to explode in extreme cases. Users with extremely long usernames are causing hell in my forum which pulls the usernames straight from WordPress.

    Is there any way of reducing this number (without hacking the code preferably)? I'd like to set it to, say, 20 characters... a value, which to my mind seems rather reasonable.

    As I say, I'd rather not hack the hell out of the code ideally, mainly to avoid issues caused by future updates. However, if anyone does know where to find the code that would target this, please do chime in.

    Am I missing something obvious?

  2. Agus Suhanto
    Member
    Posted 4 years ago #

    There is a filter called 'pre_user_login' that you can use to alter the username after being submitted by the user.

    Inside this filter you can cut the username length to the number you desired. This doesn't affect core WordPress code. You can write the filter inside functions.php of theme you are using.

  3. kallumamaji
    Member
    Posted 3 years ago #

    A similar post can be found in the forum titled "limiting username length" but it doesnt work for newer wordpress software.

    A slightly modified version can be found on a post "How to limit username length in wordpress?" It worked for me.

  4. dorothai
    Member
    Posted 3 years ago #

    there is no more registration.php in wp-include WP 3.1.3
    The other problem is that users actually register even with 3 letter username which causes problems too, as most db's are configured to request at least 4 characters for a search.
    Better solution: $valid = strlen($username) > 5 && strlen($username) < 30;

Topic Closed

This topic has been closed to new replies.

About this Topic