Skip to content

Instantly share code, notes, and snippets.

@oc
Created June 17, 2013 16:22
Show Gist options
  • Save oc/5798174 to your computer and use it in GitHub Desktop.
Save oc/5798174 to your computer and use it in GitHub Desktop.
<?php
/**
* @package WPMURemoveUsernameLimit
* @version 1.0
*/
/*
Plugin Name: WPMU Remove Username Limit
Plugin URI: http://uppercase.no
Description: WPMU Plugin to Remove Username Limit. Based on blogpost: http://fullthrottledevelopment.com/remove-username-character-limit-from-wordpress-multi-site-multi-user
Author: Ole Christian Rynning
Version: 1.0
Author URI: http://uppercase.no
*/
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('user_name');
$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');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment