Customizing the Multisite Activation Email with a Plugin
One of Multisite’s useful features is the way it lets you change the experience users get when they first register a site on your network. You can edit their welcome email and change the default content that’s created for their site.
You do this by configuring your network settings in Settings > Network Settings.
But there are two emails that are sent out and this is the second of them. Before the site is activated, WordPress sends out an activation email with a link the user must click on in order to make their site active. Unfortunately, the settings screens don’t give you the option to edit this.
So is there a workaround? The good news is yes, you can write a plugin that amends this email. And in this post I’ll show you just how to do that.
Getting Started Customizing Your Multisite Activation Email
Before you start, you’ll need a few things:
- A development WordPress installation with Multisite activated – don’t try this on your live network until you’re happy with it.
- A code editor with FTP access, or a code editor and a FTP client.
If you still need to activate Multisite, our uptime guide to Multisite will show you how.
In this post, I’ll walk you through the code in a core WordPress file but you won’t be editing that file. Editing core file is a very bad idea: it could break WordPress and it means all your changes will be lost next time you upgrade. Instead, we’ll write a plugin that you’ll save in your site’s plugins folder and activate for your network.
The Default Email and Code
Here’s the default activation email that’s sent out when someone registers a site on your network:
The email subject is ‘Activate [link]’ where [link] is the link to the new site. All a bit uninviting, in my humble opinion!
The code that generates this is in the ms-functions.php file in the wp-includes folder of your WordPress installation. There are two filter hooks, one for the content of the email and the other for the subject.
The first is called
wpmu_signup_blog_notification_email and it lets you filter the default contents of the email itself. In the current version (3.6.1) it’s at line 820 in the ms-functions.php file:
This uses placeholders for internationalization and it also uses variables which are defined immediately above that filter. We’ll be using the
$content variable to define the new version of the content. Each instance of
\n is a line break and
\n%s inserts the path to the blog. We’ll use those again in our plugin.
Note: For more on internationalization and placeholders, see our developer’s guide to internationalization.
The second filter is
wpmu_signup_blog_notification_subject, which defines the subject line of the email. Here’s the code (at line 844):
Creating the Plugin
So now we know which filters we’ll be targeting, we can write our plugin with functions that’ll be hooked to those filters.
Create a new file for your plugin (in the wp-content/plugins folder) and give it a suitable name: I’m calling mine wpmu-ms-activation-email.php.
Add an opening to your plugin to tell WordPress what it is:
Editing the Email Subject
First let’s create a function that defines the subject of our new version of the email.
Start by creating an empty function and hooking it to the correct filter hook:
Now let’s populate that function. Inside the braces, add this code:
That has some new text but it also uses the
$1$s placeholder to show the value of the network’s title, which is provided in the original file by the
Save your plugin file and we’ll move on to editing the email content.
We are the Multisite Experts. Period.
We’ve been developing plugins for WordPress Multisite for the past 10 years. With WPMU DEV you get our most popular plugins like Domain Mapping, Snapshot, Pro Sites, Support System, User Switching and bucket loads of others tailored specifically for Multisite! Woop!TRY OUR MULTISITE PLUGINS FREE LEARN MORE
Editing the Email Content
The second function will amend the contents of the email.
In your plugin file, add a second empty function hooked to the correct filter hook:
Now populate that function with the following:
Again that’s using a placeholder: this time it’s
n%s, which displays the link to the new site and is provided by the
$activate_url variable in the original function in the core file.
Here’s the full content of your plugin:
Activating and Testing the Plugin
Now save your file and go to the Plugins screen in your network admin screens. Network activate the new plugin.
Sign out of your site and go to http://mydomain.com/wp-signup.php, where mydomain is your own network’s domain name.
Work through the site creation process and wait for the system to send you the activation email. You should find it’s changed.
Customizing the Activation Email Improves the Experience for Your Users
So you now have a plugin that customizes the site activation email and makes it more appropriate to your network and more user-friendly. I think a friendly email like this improves the user experience and should reduce the number of people who don’t get past this part of the site creation process.
You can edit the text in my plugin so that it’s better for your network and your users, and you might want to try testing it on some users too before you go live. You should also take the time to edit the welcome email that users will receive once they’ve gone through the activation process – you can do that via the Network Settings screen.
Note: If you’d like to copy the original code fom my plugin or use it for your own site, you can find it on Github.