Winner of the Best WordPress Business Website - WP Honors 2011
Since 2004
 

Forums

 

Manuals

 

Videos

 

Live Support

 

WPMU.org

allowing hyphens in blog names

Monthly

I am able to add hyphens when I create a new blog from the admin, but I notice this can not be done when someone signs up, same is true with capital letters. Not so concerned about the capital letters, but is there a simple solution to allow new signups the option to use hyphens in their blog name?

thanks for any input.
Tony V

Everyday at WPMU DEV we help hundreds of WP Users. Become a member today to:

  • Download 250+ Premium Plugins and Themes
  • Get unlimited support from WordPress Experts
  • Get help with your WordPress or BuddyPress projects

Help & Support from WPMU DEV members and staff

Erstwhile founder

It can be done via the "wpmu_validate_user_signup" filter. However, it's just easier to hack wpmu-functions.php.

If you're using wpmu 2.7 look at lines 893-948.

Thanks,
Andrew

Monthly

Thanks Andrew,
looks like a basket of words to me. I have this;

if ( empty( $user_name ) )
$errors->add('user_name', __("Please enter a username"));

$maybe = array();
preg_match( "/[a-z0-9]+/", $user_name, $maybe );

if( $user_name != $maybe[0] ) {
$errors->add('user_name', __("Only lowercase letters and numbers allowed"));
}

$illegal_names = get_site_option( "illegal_names" );
if( is_array( $illegal_names ) == false ) {
$illegal_names = array( "www", "web", "root", "admin", "main", "invite", "administrator" );
add_site_option( "illegal_names", $illegal_names );
}
if( in_array( $user_name, $illegal_names ) == true ) {
$errors->add('user_name', __("That username is not allowed"));
}

if( is_email_address_unsafe( $user_email ) )
$errors->add('user_email', __("You cannot use that email address to signup. We are having problems with them blocking some of our email. Please use another email provider."));

if( strlen( $user_name ) < 4 ) {
$errors->add('user_name', __("Username must be at least 4 characters"));
}

if ( strpos( " " . $user_name, "_" ) != false )
$errors->add('user_name', __("Sorry, usernames may not contain the character '_'!"));

// all numeric?
$match = array();
preg_match( '/[0-9]*/', $user_name, $match );
if ( $match[0] == $user_name )
$errors->add('user_name', __("Sorry, usernames must have letters too!"));

if ( !is_email( $user_email ) )
$errors->add('user_email', __("Please enter a correct email address"));

if ( !validate_email( $user_email ) )
$errors->add('user_email', __("Please check your email address."));

$limited_email_domains = get_site_option( 'limited_email_domains' );
if ( is_array( $limited_email_domains ) && empty( $limited_email_domains ) == false ) {
$emaildomain = substr( $user_email, 1 + strpos( $user_email, '@' ) );
if( in_array( $emaildomain, $limited_email_domains ) == false ) {
$errors->add('user_email', __("Sorry, that email address is not allowed!"));
}
}

// Check if the username has been used already.
if ( username_exists($user_name) )
$errors->add('user_name', __("Sorry, that username already exists!"));

// Check if the email address has been used already.
if ( email_exists($user_email) )
$errors->add('user_email', __("Sorry, that email address is already used!"));

can you give me a hint which I should edit to allow for hyphen only, not under scores just -

thanks for any help.

Tony V

Get personal, comprehensive and timely support and assistance
from WordPress Experts

Erstwhile founder

Oops, I actually gave you the wrong lines. For the blog names the lines are 989-1040.

You would need to modify this bit(ln 1000):
preg_match( "/[a-z0-9]+/", $blogname, $maybe );

Unfortunately that's regular expression fun which I *really* don't care for. You'll need to do a google search to read up on it a bit.

Thanks,
Andrew

Monthly

I got it, it's actually line 1000 - 1002 thanks for getting me going.

Tony V

Monthly

in case someone finds this I should point out all I did was add the hyphen after the 9 so on line 1000 instead of;

preg_match( "/[a-z0-9]+/", $blogname, $maybe );
if( $blogname != $maybe[0] ) {

I got

preg_match( "/[a-z0-9-]+/", $blogname, $maybe );
if( $blogname != $maybe[0] ) {

works great :)

Tony V

Monthly

im thinking if you wanted to allow caps you probably could just add A-Z in there as well, but I am not in need of it, so I am not going to test it.

Tony V

Get personal, comprehensive and timely support and assistance
from WordPress Experts

Keeper of the Dark Chocolate

If I had been around, I would have pointed you to the trac ticket where all this had already been discussed. :)

http://trac.mu.wordpress.org/ticket/363

Well, way back when when it got discussed.

Inactive

RE: uppercase letters in blognames

http://trac.mu.wordpress.org/ticket/777

Blogs with uppercase letteres in blognames do not work properly.

Keeper of the Dark Chocolate

They do seem to have a small problem with that:

http://trac.mu.wordpress.org/ticket/898

We can help you out. Become a member today to:

  • Let our team help you out today and access to over 250+ Premium Plugins and Themes
  • Find out why people saying "it's like having your own developer"
  • WPMU DEV - The WordPress Experts