<?php
/*
Plugin Name: Allow short username and site names for multi site.
Plugin URI: http://orthohin.com
Description: Allows short username and blog name.
Author: Md Shafail Shafa Badhon
Version: 1.0.0
Author URI: http://orthohin.com/ */

add_filter( 'wpmu_validate_user_signup', 'orthohin_com_short_user_names' );

/**
 * Allow short user names.
 *
 * @wp-hook wpmu_validate_user_signup
 * @param   array $result
 * @return  array
 */
function orthohin_com_short_user_names( $result )
{
    $error_name = $result[ 'errors' ]->get_error_messages( 'user_name' );
    if ( empty ( $error_name ) 
        or false===$key=array_search( __( 'Username must be at least 4 characters.' ), $error_name)
    )
    {
        return $result;
    }

    // remember any error data
    $data = $result[ 'errors' ]->get_error_data( 'user_name' );

    // remove all user name errors
    $result[ 'errors' ]->remove( 'user_name' );

    // add back in any other user name errors we want to keep
    foreach ( $error_name as $index=>$message ) {
        if ( $index !== $key ) 
            $result[ 'errors' ]->add( 'user_name', $message );
    }

    // restore any user_name error data that was present
    if ( !empty( $data ) ) 
        $result[ 'errors' ]->add_data( $data, 'user_name' );

    return $result;
}
add_filter( 'wpmu_validate_blog_signup', 'orthohin_com_short_bog_names' );

/**
 * Allow very short blognames.
 *
 * @wp-hook wpmu_validate_blog_signup
 * @param   array $result
 * @return  array
 */
function orthohin_com_short_bog_names( $result )
{
    $error_name = $result[ 'errors' ]->get_error_messages( 'blogname' );
    if ( empty ( $error_name ) 
        or false===$key=array_search( __( 'Site name must be at least 4 characters.' ), $error_name)
    )
    {
        return $result;
    }

    // remember any error data
    $data = $result[ 'errors' ]->get_error_data( 'blogname' );

    // remove all user name errors
    $result[ 'errors' ]->remove( 'blogname' );

    // add back in any other user name errors we want to keep
    foreach ( $error_name as $index=>$message ) {
        if ( $index !== $key ) 
            $result[ 'errors' ]->add( 'blogname', $message );
    }

    // restore any blogname error data that was present
    if ( !empty( $data ) ) 
        $result[ 'errors' ]->add_data( $data, 'blogname' );

    return $result;
}