How to add multiple existing users to a multisite site?

I have a multisite instance of WordPress, and I need to add 50 existing users to each of 20 new sites.

One by one is going to take a very long time, and will send each person 20 emails confirming that they have been added to the blogs.

Is there a method I can use to easily add man existing users to a site at once ? What how about SQL statements to insert into the database directly ? I can do that if I knew which table(s) needed to be inserted.

Solutions Collecting From Web of "How to add multiple existing users to a multisite site?"

I’d try this with two steps.

First, install the Multisite User Plugin or grab the useful bits from its code. Short version: It hooks into user_register and loops through each blog in a multisite, adding the user to each one with a preset role. Handy.

Second, use wp-cli to import a CSV of users:

wp user import-csv /path/to/users.csv

By default, this will not email users. If you want it to email users, add --send-email to the command.

Not having actually done this, I’m not sure if WordPress is going to try to send 19 emails to each user when they’re added to each network site. There are plenty of email blocking plugins out there that you could engage for the import, just in case.