Enter

Development / 4 min read

WordPress Multisite: How to Add a User to All Sites

A laptop with a colorful keyboard in a dim-lit room

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.

the My Sites menu in the WordPress admin

Once on the Sites screen, click on the subdomain to which you plan to add the user.

Highlighting a site in a multisite network, in the WordPress "Sites" menu

On the Edit Site screen, click on the Users tab.

Highlighting the "Users" tab in WordPress's "Edit Site" menu screen

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.

The "Add Existing User" menu in WordPress

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.

The "Add New User" menu in WordPress

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 functions.php file.

/**
 * 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.

The WordPress interface showing that you've successfully added the admin user new_network_admin@wcanvas.com by using a custom function

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.

WordPress user management interface, showing a newly added 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.

The WordPress interface showing that you failed to add a new admin user

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!