2

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

2

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'] = '/' . $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
11
  • Thank you! Our usernames are random 8 digit numbers, so I need to use the user's nickname attribute. Commented Jun 15, 2013 at 13:04
  • OK, I'm finally in to this deeply now. It looks like signup_blog_init is just for making the signup form, not for processing the signup after the user presses submit. It looks like validate_blog_signup is what I'm after here, and it appears to have no hooks. :-( Specifically, looks like I need to replace instances of $_POST['blogname'] with the value that I need to use instead. Commented Jul 16, 2013 at 16:45
  • Updated answer with new info -- hopefully this'll do what you need.
    – Pat J
    Commented Jul 16, 2013 at 18:51
  • I appreciate the discovery. I didn't think to look in ms-functions.php. Still has no effect. Looking further. Commented Jul 17, 2013 at 13:52
  • OK, this is it: $blog_details['path'] = "/".$desired_blogname;. Update your answer and I'll mark as accepted. Commented Jul 17, 2013 at 14:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.