John Russell Blog

Disable new user invitation for WordPress multisite

For the purposes of this post let’s assume that you’ve setup an instance of WordPress Multisite, there are a handful of sites (termed blogs), you’re the super admin, and there are different administrators per site. What if one of the site administrators wants to add a new user to their site? Easy enough, they can go to Users > Add New and enter a new username and email address and create a new user account. The problem is, since they’re not a super admin, this doesn’t actually create an account but rather merely create a new user signup and send them an invitation via the provided email address. The new user must then click a link within the email to accept the invitation, which actually creates the user account. Worse yet, this invitation email isn’t easily editable within the Network Admin > Settings > Network Settings, but rather only via a WordPress filter hook. This sort of workflow may make sense for a true blog site, but what about a business site where user accounts are used to manage staff bios and the web content manager needs to add or remove dozens of users? This is what I would call a hassle! It may not be the solution for everyone, but one solution is to disable the new user invitation email and automatically activate the new user signup.

The benefit to this is that web content managers no longer need to hassle people to check their email to activate their user account, and as soon as a new user is created the user account will show up in the list of users. Also the person will receive the standard “Welcome User Email” immediately after the new user account is created, which by default includes the username and password needed to login.

Thankfully, due to the power of WordPress filter hooks this is an incredibly easy solution to implement. However, since this is intended to be used across the entire WordPress network it is best to create a Must-Use Plugin, or a regular plugin that is Network Activated.

<?php

/*
 * Plugin Name: Disable User Invitation
 * Plugin URI: http://laubsterboy.com
 * Description: Disables WordPress Multisite user invitations by automatically submitting the activation key and preventing the email from sending.
 * Version: 1.0.0
 */
 
 
 
/**
 * Halts the user signup process (where a user would receive an email to activate their account)
 *		and instead automatically activates the account and sends the user welcome email (template
 *		set in network settings). This was done so that site Administrators could create new user
 *		accounts, at the blog level, and bypass the need for the user to activate the account.
 *
 * @since 1.0.0
 *
 * @param string $user			The new users username.
 * @param string $user_email	The new users email address.
 * @param string $key			The user activation key, needed to create the user account from the "signup" table
 * @param array  $meta			User meta.
 * @return boolean
 */
function laubsterboy_signup_user_notification($user, $user_email, $key, $meta) {
	// Manually activate the newly created user account
	wpmu_activate_signup($key);
	
	// Return false to prevent WordPress from sending the user signup email (which includes the account activation link)
	return false;
}
add_filter('wpmu_signup_user_notification', 'laubsterboy_signup_user_notification', 10, 4);

?>

 


Posted

in

by

Comments

6 responses to “Disable new user invitation for WordPress multisite”

  1. bailey Avatar
    bailey

    This is the kind of plugin that I assumed was a built-in feature of WP multisite. I now know better so, having found this post, am wondering how to acquire this kind of plugin. Does it exist already, or were you talking about building it?…

    looking forward to reply…

  2. laubsterboy Avatar
    laubsterboy

    Hi, Bailey. I too assumed that this functionality would be baked into WP multisite, but for whatever reason it’s not. I’m not aware of any plugins that provide this functionality, but the code in the post actually is a complete plugin and can be copied into a new php file and then placed in your WP wp-content/plugins directory and then activated in the Network Plugins screen. Keep in mind it will have no settings or options, but if activated it will prevent user activation emails from being sent and will also automatically create the user account.

  3. Shery Avatar
    Shery

    Thank you, thank you, thank you. This works great!

  4. Colleen Avatar
    Colleen

    Huge thanks for this! This is the exact set up I needed and had been struggling with the filters to make it happen on my own. Thanks again!

  5. Ben Avatar

    This does not work any more, tried on a fresh wp MU install .
    any update ? thank you

    1. John Russell Avatar
      John Russell

      Hi, Ben. Nothing has changed with the filter in the WordPress core code. How are you adding the code to your MU install? Are you using an mu-plugin, a regular plugin, adding it to your theme functions.php, or some other way? I ask because it must be added in such a way that the code is run across the network/site, so it’s ideally put into an mu-plugin or a regular network activated plugin.

Leave a Reply

Your email address will not be published. Required fields are marked *