0

Trying to figure out how to have users created automatically when a network site is created.

So currently when a new user registers, their account is created and their network site is created. That gives that new site one user already (the site's admin). But when that's created I'd like to also have 3 more users automatically created to each new network site on creation.

1 Answer 1

0

You can do that hooking into wpmu_new_blog and then creating the user if it does not exists, and adding that user to the blog being created. To do so, you will use a code like this ( only for 1 user) , as a network enabled plugin or on the main theme functions.php

add_filter('wpmu_new_blog','wpse_29543_new_blog');

function wpse_29543_new_blog($blogid){
    $user_name="user";
    $user_password="password";
    $user_email="[email protected]";
    $role="editor";
    $user_id = username_exists( $user_name );
    if ( !$user_id ) {  
        $user_id = wp_create_user( $user_name, $user_password, $user_email );
    } 
    add_user_to_blog( $blogid, $user_id, $role );

}
3
  • doesn't seem to work.
    – JonnyPlow
    Sep 26, 2011 at 23:16
  • Where did you add this code
    – hacksy
    Sep 26, 2011 at 23:21
  • I take that back. It does work. I just needed to try it when I created the new site. I was only trying on refresh. Awesome, thank you!!
    – JonnyPlow
    Sep 26, 2011 at 23: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.