How to Add a User to All Sites in a Multisite Network

Here I will show you three ways how we can add a user to all sites in a multisite network:

  • First of all, we will do it with the help of a WordPress plugin,
  • Second, I will show you how to do it manually,
  • And finally, we will take a look at a programmatic approach (both when adding a user to a site automatically every time a user is self-registered or created in the Network Admin > Users page, and with the help of custom bulk actions).

Now, let’s dive straight into it.

Add Users to All Sites in a WordPress Multisite Using a Plugin

In this chapter, we will mostly talk about my Simple Multisite User Sync plugin. It comes with a bunch of features that allow you to simplify the whole WordPress multisite user management thing.

For example, we can easily add a user to multiple sites (or all sites), or select as many users as we want on the Users > All Users page and sync all of them in one click to a specific sub-site of a network. Let’s take a quick look at both of these scenarios.

Add a User to Specific Sites

When you create a new user from your Network admin dashboard or edit the user profile there, the plugin allows you to choose multiple sites to which the user is going to be added.

WordPress Multisite add user to multiple sites
The very cool thing about these checkboxes is that you can select all of them at once by holding the SHIFT key on your keyboard.

Selecting multiple users using bulk actions

On the other hand, if your WordPress multisite network has a lot of users, then, most likely, you would like to have the possibility to sync all of them at the same time.

It can be achieved with the bulk actions available in the plugin:

Bulk user sync feature in WordPress Multisite.

Last but not least, the plugin comes with a bunch of settings that allow you to:

  • Exclude specific sub-sites of your multisite network from user syncing.
  • Change a user’s role depending on the site where the user is synced to.
  • and so on…

Learn more about the plugin Simple Multisite User Sync.

Manual Way of Adding a User to a Site

This way is simple, and I am pretty sure you already know about it; however, it would be great to mention it as well.

Basically, you need to go to every sub-site settings (Sites > All Sites, then click the “Edit” link), then switch to the “Users” tab, and make use of the “Add Existing User” form.

Check the screenshot below to have a clear understanding of what I mean:

Add an existing user to a specific sub-site of a Multisite network

This way is kind of OK, if you have, let’s say, 5 sub-sites in a multisite network, but what if you have tens or even hundreds of sub-sites?

Add Users to All Sites Programmatically

Automatically upon a user registration using wpmu_new_user hook

First of all, we need to decide which one of WordPress hooks to use here.

It is quite easy, there is the only action hook that is triggered when a user is either self-registered or created by a super-admin in a multisite network, is it wpmu_new_user.

So, our function, which is going to automatically add users to all sub-sites, is going to look something like this:

add_action( 'wpmu_new_user', function( $user_id ) {
	
	// do stuff here
	
} );

And here is the complete code, which you can feel free to use as a plugin, the only thing – don’t forget to activate it for the whole network here.

<?php
/*
 * Plugin name: WordPress Multisite Add Users to All Sites
 * Author: Misha Rudrastyh
 * Plugin URI: https://rudrastyh.com/wordpress-multisite/add-user-to-all-sites.html
 * Network: true
 */
add_action( 'wpmu_new_user', function( $user_id ) {
	
	$sites = get_sites( 
		array(
			'fields' => 'ids',
			'spam' => 0,
			'deleted' => 0,
			'archived' => 0,
			'mature' => 0,
			'number' => 500,
		)
	);
	
	foreach( $sites as $site_id ) {
		add_user_to_blog( $site_id, $user_id, 'subscriber' );
	}
	
} );

Using bulk actions

If you want, you can read a little bit more about bulk actions in this tutorial.

Here we’re going to make use of three WordPress hooks:

  • bulk_actions-{SCREEN ID},
  • handle_network_bulk_actions-{SCREEN ID},
  • and network_admin_notices.

The first hook is the usual one we just use bulk_actions-{SCREEN ID}, and users-network is a screen ID of the Network Admin > Users page.

So, that’s the first part of the code.

// bulk_actions-{SCREEN ID}
add_action( 'bulk_actions-users-network', function( $bulk_actions ) {
	
	$bulk_actions[ 'add_to_sites' ] = 'Add to all sites';
	return $bulk_actions;
	
} );

After activating this snippet network-wide, you may notice that our custom bulk action will appear on the “Users” page.

WordPress Multisite bulk actions users page

But this bulk action will do nothing; that’s why we need the second part of the code:

// handle_bulk_actions-{SCREEN ID}
add_action( 'handle_network_bulk_actions-users-network', function( $redirect_to, $doaction, $user_ids ) {

	if( 'add_to_sites' !== $doaction ) {
		return $redirect_to;
	}

	// get sites first
	$sites = get_sites(
		array(
			'fields' => 'ids',
			'spam' => 0,
			'deleted' => 0,
			'archived' => 0,
			'mature' => 0,
		)
	);

	// a simple count for admin notices
	$count = 0;

	foreach( $user_ids as $user_id ) {
		// we definitely don't need to add superadmin to all sites
		if( is_super_admin( $user_id ) ) {
			continue;
		}
		// now let's add this user to all sites
		foreach( $sites as $site_id ) {
			add_user_to_blog( $site_id, $user_id, 'subscriber' );
		}
		$count++;

	}

	$redirect_to = add_query_arg( 'added_to_all_sites', $count, $redirect_to );

	return $redirect_to;

}, 10, 3 );

Last but not least, displaying admin notices:

add_action( 'network_admin_notices', function() {

	if( ! empty( $_REQUEST[ 'added_to_all_sites' ] ) ) {

		$count = (int) $_REQUEST[ 'added_to_all_sites' ];
		$message = sprintf(
			_n(
				'%d user has been added to all sites.',
				'%d users have been added to all sites.',
				$count
			),
			$count
		);

		echo "<div class=\"updated notice is-dismissible\"><p>{$message}</p></div>";

	}

} );

And here we go:

WordPress Multisite add users to all sites
Misha Rudrastyh

Misha Rudrastyh

Hey guys and welcome to my website. For more than 15 years I've been doing my best to share with you some superb WordPress guides and tips for free.

Need some developer help? Contact me

Follow me on X