3

We are using wordpress in multi sub-domains at work. So we have administrator for each domain who can create users for subscribing editing contributing. The problem is, our company edit the rule that all logins/usernames have to be like this "first-name.family-name" ex "barack.obama"... :-) But the administrator can not do it, only super admin can do it ! In sub-domain administrator mode, there is a message that says : "Only the lowercase letters a-z and numbers allowed".

So we want to make it possible to admin to create users with first-name.family-name, but we try to search how to change it in the code, without finding it.

If someone can help, thanks !

Dan D.
  • 73,243
  • 15
  • 104
  • 123
Jaswinder Kaur
  • 190
  • 1
  • 3
  • 10

1 Answers1

2

In multisite usernames are validated with wpmu_validate_user_signup, which you can find in /wp-includes/ms-functions.php#L462.

You can add a dot there, after the 0-9, which is not recommended, since you will then hate to update WordPress core.

if ( $user_name != $orig_username || preg_match( '/[^a-z0-9.]/', $user_name ) ) {

So, a better solution would be to create a plugin for it.

You could try to add the following in a php-file and add it to /wp-content/mu-plugins/

<?php
/*
Plugin Name: wpmu no username error
*/

function wpmu_no_username_error( $result ) {
    $error_name = $result[ 'errors' ]->get_error_messages( 'user_name' );
    if ( empty ( $error_name ) 
        or false===$key=array_search( __( 'Only lowercase letters (a-z) and numbers are allowed.' ), $error_name)
    ) {
    return $result;
    }
//  only remove the error we are disabling, leaving all others
    unset ( $result[ 'errors' ]->errors[ 'user_name' ][$key] );
/**
 *  re-sequence errors in case a non sequential array matters
 *  e.g. if a core change put this message in element 0 then get_error_message() would not behave as expected)
 */
    $result[ 'errors' ]->errors[ 'user_name' ] = array_values( $result[ 'errors' ]->errors[ 'user_name' ] );
    return $result;
}
add_filter( 'wpmu_validate_user_signup', 'wpmu_no_username_error' );

I didn't try it though. This is based on "Changing the username character limit from four to less characters".

I hope this helps. At least it should get you close. GL with it!

Community
  • 1
  • 1
Axel
  • 411
  • 3
  • 5
  • Thx ECO13 for your help – Jaswinder Kaur Aug 19 '15 at 09:50
  • 1
    I don't agree with the change, Brian. And feel only one reviewer bothered to read the context. The point is that people would **hate** to update their WordPress installation if they have to make changes to the core over and over again. Now that sentence doesn't make much sense. – Axel Feb 02 '17 at 14:19