Limit multisite/network site names to a property of the user

We need to limit the blog names users may choose when they create their own blogs.

We have a WordPress Network configured to have all blogs share a domain name. E.g., domain.name.com/x, domain.name.com/y, etc.

We have integrated our WordPress Network with our corporate Active Directory using the Active Directory Integration plugin. That plugin puts the user’s mailnickname attribute (the part of the email address before the @) into the nickname field.

I would like to allow users to self-create their own blogs but restrict blog names names so that it must match the nickname field of their WordPress account. E.g., a user with nickname jdoe could only create a blog named domain.name.com/jdoe.

Ideally, on /wp-signup.php, it would be best if the blogname field doesn’t even display.

Is there a way to do this without PHP customization? I was hoping a plugin would already exist, but I can’t find one.

1 Answer
1

Looking at the source of wp-signup.php, it looks like your best bet might be to filter signup_blog_init (line 303 in v. 3.5.1):

/*
add_filter( 'signup_blog_init', 'wpse103022_blog_name' );
function wpse103022_blog_name( $blog_details ) {
    // Set $username to the user's username
    $blog_details['blogname'] = $username;
    return $blog_details;
}
*/
// see code below for replacement

I’m not 100% sure this will work, but it’s worth a try.

Edited

OK, after your comment below, I took a look at validate_blog_signup(). It calls wpmu_validate_blog_signup(), and that provides a filter — wpmu_validate_blog_signup. Looking at the code, it appears that something like the following should work:

add_filter( 'wpmu_validate_blog_signup', 'wpse103039_blog_name' );
function wpse103039_blog_name( $blog_details ) {
    $blog_details['path'] = "https://wordpress.stackexchange.com/" . $desired_blogname; // however you get it
    return $blog_details;
}

If I’m reading the code right, you can filter:

  • domain
  • path
  • blogname
  • blog_title
  • user
  • errors

Leave a Comment