Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

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@gmail.com";
    $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 );

}
share|improve this answer
    
doesn't seem to work. –  JonnyPlow Sep 26 '11 at 23:16
    
Where did you add this code –  Hansy Schmitt Sep 26 '11 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 '11 at 23:52
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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