I’ve been working on a pretty complex project with WordPress MultiUser (soon to be MultiSite). This client needs several sites with hundreds of users divided into each site. I will be integrating the backend authentication with LDAP and discovered that a small percentage of their users have usernames with fewer than four characters.
WordPress MU currently has a minimum limit of four characters set in its core. Unfortunately, this limit is still imposed in WordPress MS 3.0. The limit is probably there because usernames were used for the domain too and WP-Devs didn’t want to conflict with country codes. But that is not an issue for my client, so I wanted to kill the limit (without touching core).
Basically, I wrote a quick mu-plugin that unset the error message when someone tries to add a user with fewer than four characters. Doing this removes any halts that would stop processing the new user. Here is my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
function remove_username_char_limit($result) { if ( is_wp_error( $result[ 'errors' ] ) && !empty( $result[ 'errors' ]->errors ) ) { // Get all the error messages from $result $messages = $result['errors']->get_error_messages(); $i = 0; foreach ( $messages as $message ) { // Check if any message is the char limit message if ( 0 == strcasecmp("Username must be at least 4 characters", $message)) { // Unset whole 'user_name' error array if only 1 message exists // and that message is the char limit error if ( 1 == count($messages) ) { unset( $result['errors']->errors['user_name'] ); } else { // Otherwise just unset the char limit message unset( $result['errors']->errors['user_name'][$i] ); } } $i++; } } return $result; } add_action('wpmu_validate_user_signup', 'remove_username_char_limit'); |