3

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?).

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

4

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 );
| improve this answer | |
  • Hmm. creating the user already adds the user to the blog on the URL used to create the user. – artfulrobot Nov 28 '13 at 13:38
1

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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