I want to create a user account on my multi-site installation of WordPress with a username less than 4 characters. But since WordPress has a limit of usernames at least being 4 characters, this error message is shown:
Username must be at least 4 characters.
I found a solution involving a mu-plugins folder in the wp-content folder, but it doesn’t work.
Is there any possible way that would allow me to create a user account with a username less than 4 characters?
You can filter
'wpmu_validate_user_signup'
and check if the error code matches the 4 character warning. Then just unset the error code.Sample plugin:
As there can be more than one error for user names, the accepted answer could remove errors we would want to preserve. For example entering a user name of 123 would now pass whereas it should presumably still give the error message
'Sorry, usernames must have letters too!'
Modified sample code to fix this:
EDIT:
This works in WordPress up to version 3.9.6 and again in 4.2
Note that this does not work in WordPress 4.0 or 4.1 because https://core.trac.wordpress.org/ticket/22234 made the errors a private variable. Although a magic __get method was provided “for backwards compatability”, for arrays it returns a copy of an array (not a reference to the original) which is then not editable. If you have WP_DEBUG turned on you will get a PHP Notice saying “Notice: Indirect modification of overloaded property WP_Error::$errors has no effect in /path/to/plugin on line xxx”, otherwise the code fails silently and has no effect.
It works again in version 4.2 because https://core.trac.wordpress.org/ticket/30891 reverted the change for WP_Error and a number of other places in core, though not so that code like this would work.
For WordPress >=4.1 which gave us a remove method this also works: