Customize user signup, activation process in multisite

Often you want to customize user registration and activation process in multisite. I customized my multisite by creating two new page templates Register and Activate. To completed this, I created two new WordPress pages using those templates and then used a filter in my functions.php file to modify the behaviour of wpmu_signup_user_notification. Steps below will help to customize user signup, activation process in multisite.

To summarize this, here is the steps by step process”
1. Create two page templates Activate and Register

2. Users will register on this new Register page and they will be sent an email linking to the new Activation page.

Register Template

In the Register template, I copied the code from wp-signup.php and removed the following lines from the beginning:

require( dirname(__FILE__) . '/wp-load.php' );
require( './wp-blog-header.php' );

Also change the form action value from action=”” to action=””

Here, you can customize the message, use HTML to meet your needs.

3. Create Activate page Template
Activate Template

In the Activate template, I copied the code from wp-activate.php and removed the following lines from the beginning:

define( 'WP_INSTALLING', true );
/** Sets up the WordPress Environment. */
require( dirname(__FILE__) . '/wp-load.php' );
require( './wp-blog-header.php' );

Again, change all the form actions to action=”” . Here, you can customize the message, use HTML to meet your needs.

4. Functions.php

Copy the wpmu_signup_user_notification function from wp-includes/ms-functions.php into functions.php file and rename it so something unique. I renamed it to: bithero_wpmu_signup_user_notification We used filter ‘wpmu_signup_user_notification’ to bypass this function or replace it with your own notification behavior.

Remove the following:

if ( !apply_filters('wpmu_signup_user_notification', $user, $user_email, $key, $meta) )
return false;

Also change the line site_url( “wp-activate.php/?key=$key” ) to site_url( “activate/?key=$key” ) since activate is the page slug of the Activate page.

Then I applied it as a filter with the following code:

5. Using wpmu_signup_user_notification filter.
add_filter(‘wpmu_signup_user_notification’, ‘bithero_wpmu_signup_user_notification’, 10, 4);

This code worked for me and served my purpose. Its bit tricky steps but it works fine. My functions.php code looks something like :


/**
 * This filter is required to use custom activate page
 */
add_filter('wpmu_signup_user_notification', 'bithero_wpmu_signup_user_notification', 10, 4);
/**
 * Notify user of signup success.
 *
 * This is the notification function used when no new site has
 * been requested.
 *
 * Filter 'wpmu_signup_user_notification' to bypass this function or
 * replace it with your own notification behavior.
 *
 * Filter 'wpmu_signup_user_notification_email' and
 * 'wpmu_signup_user_notification_subject' to change the content
 * and subject line of the email sent to newly registered users.
 *
 * @since MU
 *
 * @param string $user       The user's login name.
 * @param string $user_email The user's email address.
 * @param string $key        The activation key created in wpmu_signup_user()
 * @param array  $meta       By default, an empty array.
 * @return bool
 */
function bithero_wpmu_signup_user_notification( $user, $user_email, $key, $meta = array() ) {
	/**
	 * Filter whether to bypass the email notification for new user sign-up.
	 *
	 * @since MU
	 *
	 * @param string $user       User login name.
	 * @param string $user_email User email address.
	 * @param string $key        Activation key created in wpmu_signup_user().
	 * @param array  $meta       Signup meta data.
	 */
	

	// Send email with activation link.
	$admin_email = get_site_option( 'admin_email' );
	if ( $admin_email == '' )
		$admin_email = 'support@' . $_SERVER['SERVER_NAME'];
	$from_name = get_site_option( 'site_name' ) == '' ? 'WordPress' : esc_html( get_site_option( 'site_name' ) );
	$message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";
	$message = sprintf(
		/**
		 * Filter the content of the notification email for new user sign-up.
		 *
		 * Content should be formatted for transmission via wp_mail().
		 *
		 * @since MU
		 *
		 * @param string $content    Content of the notification email.
		 * @param string $user       User login name.
		 * @param string $user_email User email address.
		 * @param string $key        Activation key created in wpmu_signup_user().
		 * @param array  $meta       Signup meta data.
		 */
		apply_filters( 'wpmu_signup_user_notification_email',
			__( "To activate your user, please click the following link:\n\n%s\n\nAfter you activate, you will receive *another email* with your login." ),
			$user, $user_email, $key, $meta
		),
		site_url( "activate/?key=$key" )
	);
	// TODO: Don't hard code activation link.
	$subject = sprintf(
		/**
		 * Filter the subject of the notification email of new user signup.
		 *
		 * @since MU
		 *
		 * @param string $subject    Subject of the notification email.
		 * @param string $user       User login name.
		 * @param string $user_email User email address.
		 * @param string $key        Activation key created in wpmu_signup_user().
		 * @param array  $meta       Signup meta data.
		 */
		apply_filters( 'wpmu_signup_user_notification_subject',
			__( '[%1$s] Activate %2$s' ),
			$user, $user_email, $key, $meta
		),
		$from_name,
		$user
	);
	wp_mail( $user_email, wp_specialchars_decode( $subject ), $message, $message_headers );
	return false;
}

6. Make sure, from the function, bithero_wpmu_signup_user_notification return false. This step is required otherwise, you might end up getting two separate emails. To customize the subject of the email notification, follow the following article.

About the Author

dr.code.skm

I am backend developer with passion in Web Application development using latest technologies like Laravel, PHP7, React, ECMAScript 6 and WordPress. I prefer spending time analyzing big data with Apache Spark. Apart from that, I do photography.