Multisite site name limitations

Do you guys know of a workaround for the mulitisite domain name limitations? Currently it only allows lowercase letters and numbers. I found this plugin "TuKod MultiSite Site Names", and tried installing it but it doesn't seem to be working or supported anymore.

I'm just looking to be able to create a domain name with dashes in it. For example :

Thanks for the help.

  • Vaughan

    Hi Chris,

    Hope you're well?

    I haven't tested this, but this might work in a mu-plugin

    Create a file called wpmu-site-names.php

    add the following;

    add_filter( 'wpmu_validate_blog_signup', 'wpmu_allow_hyphens', 20 );
    function wpmu_allow_hyphens($result) {
        $olderrors = $result[ 'errors' ];
        $errors = new WP_Error();
        			foreach ( $olderrors->errors as $code => $error ) {
    				if ( $code == 'blogname' ) {
    					// Sort the 'blogname' error $value with this loop.
    					foreach ( $error as $key => $value ) {
    						// Switch each action based on the $error $value
    						// and our slected options.
    						switch ( $value ) {
    							case "Only lowercase letters and numbers allowed":
    								$ok_chars = '';
    								$ok_chars .= '-';
    								$pattern = '/^[a-z0-9]+([' . $ok_chars . ']?[a-z0-9]+)*$/' . $u_case;
    								preg_match( $pattern, $result[ 'blogname' ], $match );
    								if ( $result[ 'blogname' ] != $match[ 0 ] ) {
    									// Build a new error to add to the $errors object
    									$ok_chars .= 'internal "-" dashes or hyphens';
    								$errors->add( 'blogname', $value );
    						} // end switch ($value)
    					} // end foreach ($error as $key => $value)
    				} else {
    					// Add other errors to $error object from the nested arrays.
    					foreach ( $error as $key => $value ) {
    						$errors->add( $code, $value );
    				} // end if ($code == 'blogname')
    			} // end foreach ($olderrors->errors as $code => $error)
      			// Unset old errors object in $result
    			unset( $result[ 'errors' ] );
    			// Set new errors object in $result
    			$result[ 'errors' ] = $errors;
    			return $result;

    I just hacked it together from that tukod plugin so it may not work.

    Once you have this saved. upload the file to /wp-content/mu-plugins

    Hope this helps

  • Chris

    Thanks Vaughan. I tried putting that in my mu-plugins folder with no luck. BUT your code did provide me with some helpful clues. I looked up the hook you were using 'wpmu_validate_blog_signup' and found that WP does its actual validation in the the core wp-includes/ms-functions.php file. In there I modified the file to accept a dash. Here's what I did:

    around line 630 changed the pregmatch to be:
    if ( preg_match( "/[^a-z0-9-]+/", $blogname ) )

    Adding in a dash "-" after the 0-9.
    I'm sure modifying the core files is a no-no but for now it works for me.

    Here's the wordpress doc on the validation filter:

    Thanks for your help. And hope this helps others.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.