WordPress Multisite: How to Add a User to All Sites
Creating users with appropriate roles is one of the most important parts of managing a multisite network. Occasionally, you may need to add a user to all sites in the WordPress multisite network.
When that happens, you have 2 options: manually add the same user to every site in the network or use a custom function to automate the process.
Let’s find out how to do both in this step-by-step guide.
How to Add a WordPress Multisite User to All Sites
Method #1: Add a User Manually to All Sites
The first method for adding a user to all sites in a multisite network is manually adding the user to every site.
On the dashboard, go to My Sites > Network Admin > Sites.
Once on the Sites screen, click on the subdomain to which you plan to add the user.
On the Edit Site screen, click on the Users tab.
Now, you can add an existing user or create a new one and assign it to this particular site.
In the Add Existing User section, you need to type the username, pick the user’s role, and click Add User.
If you instead want to create a new user and add it to the site, scroll down to the Add New User section. Create the username, assign an email address for the user, give it a role, and click on Add New User.
You need to repeat this process on every site in the network if you want to add a user to all sites.
Method #2: Add an Administrator to All Sites With a Function
Adding users manually to every site can be feasible if you manage a handful of sites, but when you manage a large network, the time it takes to add new users becomes significant. Even in smaller networks, going to every site to add multiple users gets old fast.
If you have some coding knowledge, you may benefit from adding a custom function that allows you to enter an email address and turn it into a user on every site in the network.
To programmatically add admin users to all sites in the network, add the following function, created by developer Kevin Leary, to the
file.functions.php
/**
* WPMU Add User to All Sites
*
* Add an administrator user to all sites in a WordPress multisite network
*/
function kevinlearynet_wpmu_add_user_all_sites() {
$email = isset( $_GET['wpmu_admin_sync'] ) ? esc_attr( $_GET['wpmu_admin_sync'] ) : null;
if ( ! $email ) {
return;
}
$user = get_user_by( 'email', $email );
if ( $user === false ) {
wp_die( "No user exists in this network with the email $email." );
}
$role = isset( $user->roles[0] ) ? $user->roles[0] : 'administrator';
$sites = get_sites( [
'limit' => 0,
'public' => true,
'spam' => false,
'deleted' => false,
'archived' => false,
'mature' => false,
] );
$output = [];
foreach ( $sites as $site ) {
$site_id = get_object_vars( $site )['blog_id'];
$site_name = get_blog_details( $site_id )->blogname;
$add_user = add_user_to_blog( $site_id, $user->ID, $role );
$note = "$email user to $site_name as an $role.";
$output[] = $add_user ? "Successfully added $note" : "Failed adding $note";
}
$html = wpautop( implode( PHP_EOL, $output ) );
wp_die( $html );
}
add_action( 'after_setup_theme', 'kevinlearynet_wpmu_add_user_all_sites' );
How to Use the Function?
To use the function, start by visiting your multisite network. Add the following query parameter to your network’s URL:
?wpmu_admin_sync=[user_name_here]@[domain-name_here].com
Here’s an example:
mysite.com/?wpmu_admin_sync=adminuser@mysite.com
Once you’ve added the query parameter with the email address, press Enter. The script will add a new user based on the email address to every site in the network.
After running the function, if you go to Sites > All Sites, and click on any of the sites, the go to the Users tab, you should see the newly added admin user.
Keep in mind that the email address you add must already be associated with an existing user. If you add an email address that isn’t associated with an existing user, you will see this error message.
How Does the Function Work?
This function adds a user by email to all sites in the network. It creates a list of all sites, finds an existing user by mail, and adds it to every site one by one.
The function adds a user with the administrator role by default, so you should modify it to add any other type of user.
Final Thoughts
Managing users is very important in multisite networks. Occasionally, it may be necessary to add a user to every site in the network, but WordPress doesn’t provide a native feature to automatically add the same user to every site.
Your alternatives are to manually add the same user to every site or to use a function that automates the process.
This article provided a step-by-step guide to do both, so now you know what to do next time you have to add a user to every site in your network.
If you found this post useful, read our blog and resources for more WordPress insights and guides!
Related Articles
How to... / 3 min read
How to... / 3 min read
How to Grant Secure Access to a Not Live WordPress Site During Development
When developing a WordPress site, you often need to collaborate with multiple developers and grant access to the website owner so they can review the progress themselves. However, granting access…
Read MoreIndustry Insights / 11 min read
Industry Insights / 11 min read
Do You Need a Web Developer to Build a WordPress Site?
If you’re building a WordPress site or considering building one, you wonder whether you need a web developer to create it or you can do it yourself. The answer can…
Read MoreHow to... / 6 min read
How to... / 6 min read
How to Change the Bottom Padding Dimensions on WordPress Blocks
If you're learning to modify your WordPress site's layouts and design, you may be wondering how to change the bottom padding dimensions of some of its elements. If that's the…
Read MoreHow to... / 10 min read
How to... / 10 min read
How to Disable the “Similar Posts” Section in WordPress Blogs
If you’re diving deeper into customizing your site, you may be wondering how to disable the “Similar Posts” section that appears on the bottom, sidebar, or footer of your WordPress…
Read MoreHow to... / 8 min read
How to... / 8 min read
How to Change the Width of a Blog Post on WordPress​ (3 Methods)
If you're diving deep into WordPress web design, you'll eventually need to learn how to change the width of a blog on your WordPress site. It can improve readability or…
Read More