How to use wp_insert_user on WordPress Multisite?

I previously had a WordPressMU install, but this is deprecated and I’m trying to find my way around multisite.

I need to programatically create a new user account for a particular site. wp_insert_user looks like it does everything except say which site the user is for (perhaps it takes this from the domain the request was sent to?).

Read More

It’s important that the created user is a member on one blog (site), but not the other(s).

Related posts

2 comments

  1. You can use the add_user_to_blog function after creating the user.

    $userid = 1;
    $blogid = 5;
    $role = 'administrator';
    add_user_to_blog( $blogid, $userid, $role );
    
  2. Assuming you have WordPress Multisite, with sites: example.com, foo.example.com and bar.example.com and you want to add a new user to foo.example.com, then create a script and execute that script via a URL containing foo.example.com/path/to/your/script.ph.

    WordPress detects the URL, maps it to a blog and assigns users created by wp_insert_user() to that blog, and not to the other blogs.

    See the answer by Chittaranjan if you then want to add the user to a other blogs/sites, too.

Comments are closed.