Bringing the Membership Process to the Front of Your Site

Bringing the Membership Process to the Front of Your Site

Tutorial Details
  • Programs: WordPress, Text Editor, FTP Program
  • Difficulty: Intermediate
  • Estimated Completion Time: 1 - 2 hours

WordPress ships with the ability to add users, either manually or via registration. This includes the ability to assign various roles and capabilities. But more often than not you don’t want users to be exposed to the WordPress backend. In this tutorial I’ll show you how to create a custom registration form on the front of your site as well as a custom profile form. Users will also receive custom emails with each step of the registration process. Please note, this tutorial won’t be covering membership payments.


Some Background & What We’ll Be Covering

We’ll be using the TwentyEleven theme where we’ll be editing the functions.php and the header.php. Some people might prefer to use BuddyPress for a task like this, and that’s cool, but I feel like why have all those features if you’re not going to use them.

This is what we’ll be doing

  • Installing required plugins
  • Configuring plugins
  • Adapting our menus
  • Creating a custom profile page
  • Creating a custom registration page
  • Creating custom emails for each stage of the registration process

It’s kind of a lengthy process so grab a coffee or beer and knuckle down.


Step 1 Get the Plugins

Okay so first things first, let’s get the plugins we need. I’ll be adding them using the WordPress interface but if you’d prefer you can use the links below to download and install them manually.

Get the Plugins


Step 2 Configure

“Make sure you have ‘Anyone can register’ ticked under General Settings”

Time to configure our plugins, but before that though make sure you have Anyone can register ticked under Settings -> General.

Okay, now onto the plugin configuration, lets start with:

Theme My Login – Basic Setup

Theme My Login creates a “login/logout” page once installed and by default it adds it to your pagelist. For more control let’s set it up manually:

  1. Go to Settings -> Theme My Login and untick the option “Show in Pagelist”
  2. Click “Save Changes”
  3. Navigate to Appearance -> Menus and add it to your menu (if your theme supports more than one menu you can put it anywhere)*

*Not sure how to use the menu? Read here

Alright – so now if you jump to the front of your website you’ll notice you have a login/logout menu item. It should say “Log Out” as you are logged in. Nice one!

But let’s say you don’t want it in your menu? No problem, you can remove it from your menu and add it as a widget. Luckily Jeff Farthing (creator of the plugin) has included a nifty widget with loads of options. They are all pretty self-explanatory so I won’t go through it. Just head to Appearance -> Widgets and drag the Theme My Login widget to the desired widget area. I prefer it in my menu, but you could have both.

Now lets set up some of the modules.

Theme My Login – Modules Setup

Jump back to Settings -> Theme My Login -> Modules and enable the following:

  • Enable Custom E-mail
  • Enable Custom Redirection
  • Enable Security
  • Enable Themed Profiles
  • Enable User Moderation

Great. Now let’s configure those modules starting with E-mail. Basically you are required to create custom email content for each phase of the membership process (New User, Retrieve Password, Reset Password, User Activation, User Approval, User Denial). Obviously this is up to you what you write, but make sure:

  • For the “From E-mail” use something like no-reply@yourdomain.com
  • You’ll want the “E-mail Format” to be Plain Text.

It’s a good idea to make use of the email variables – %user_login%, %user_email%, %user_pass% – but don’t worry too much about nutting it out perfectly right now. We’ll be sending a few tests so you can polish it later.

Okay ready for some Redirection magic? As Administrator you’ll still want to be taken to the backend/dashboard when you login so you’ll want to leave the Administrator role as is (Don’t lock yourself out). I want my users to be taken to their profile when they login so I’m going to change all the other roles. So for “Log in”:

  • Use the “custom location” option and enter something like http://yourdomain/profile
    (assuming your permalink structure is /%category%/%postname%/)

and for “Log out”:

  • I’m putting “Referer”. That way when users log out they stay on the page they were on.

For Security I’m just going to leave as is, but it’s worth having a look to see if those settings suit you. Finally Moderation. As we are running a free-to-join site, choose E-mail Confirmation for User Moderation.

Okay let’s apply some profile goodness.

Theme My Profile

We are going to need a page to house our user profile in so head over to Pages -> Add New. Give your page a title, something like “Profile”, and paste this shortcode [theme-my-profile] into the content (make sure you’re in the HTML edit mode). Take note of the page ID and publish.

Go to Settings -> Theme My Profile. Apply these settings but please be careful not to lock yourself out of the backend:

  1. Enter the page ID of the newly created “Profile” page
  2. Make sure Show in Pagelist “Never” is selected (we’re using WP 3 Menus)
  3. Use theme-my-profile.css is ticked.
  4. For the template settings check out the image below:

Save the changes.


Step 3 Setting Up the Menus

Basically we will be using two menus: one for signed-in users, and one for signed-out users or non-members. So open your FTP program and download header.php from your theme. We want to add an if statement to the code that sets up the menu. It’s line 118 if you are using TwentyEleven.

Replace this:

	<?php wp_nav_menu( array( 'theme_location' => 'primary' ) ); ?>

With this:

	  <?php if ( is_user_logged_in() ) { ?>
          <?php wp_nav_menu( array( 'theme_location' => 'user-menu', 'items_wrap' => '<ul id="menu-menu" class="menu">%3$s</ul>', 'container_class' => 'menu-menu-container' ) );?> <!-- sign out --> 
      <?php } else { ?>
          <?php wp_nav_menu( array( 'theme_location' => 'main-menu', 'items_wrap' => '<ul id="menu-menu" class="menu">%3$s</ul>', 'container_class' => 'menu-menu-container' ) );?> <!-- sign in --> 
      <?php } ?>

If you’d like to, you can read more about wp_nav_menu in the WordPress Codex.

Okay now get the functions.php file and change line 101 in the header.php to reflect the updates.

Replace this:

	register_nav_menu( 'primary', __( 'Primary Menu', 'twentyeleven' ) );

With this:

	register_nav_menus(
			array(
				'main-menu' => __( 'Main Menu' ),
				'user-menu' => __( 'User Menu' ),
			)
		);

Now upload those files to your theme directory and jump to the WordPress backend. Let’s set up the menus, go to Appearance -> Menus. You should now have two menus available to you: “main menu” and “user menu”, activate both.

  • Under main menu have “Login” page
  • Under user menu have “Login” and “Profile” pages

Save the changes and let’s get into some custom email templates.


Step 4 WP Better Emails – Setup

Alrighty time to get some custom emails happening so jump to Settings -> WP Better Emails. For the “Name” and “Email address” inputs use something like Blog Name and no-reply@yourdomain.com. Okay great, now scroll down and send yourself a preview. Hop over to your email client and you should have a pretty nice looking email waiting for you. Not bad but lets customise it a little. Jump back to WordPress and copy all that HTML and paste it into your favourite text editor. It’s really up to you how much you want to edit this. Let’s keep it simple and just change the logo. So create an image 500px wide by 100px heigh. Upload it to your server and copy the path.

On line 22 in the HTML replace the %blog_name% with your image, something like this:

	<td style="line-height: 32px; padding-left: 30px;" valign="baseline"><span style="font-size: 32px;"><a href="%blog_url%" style="text-decoration: none;" target="_blank"><img src="http://yourdomain.com/wp-content/uploads/email-logo.jpg" /></a></span></td>

Now send yourself another test and you should have something like this:


Step 5 Custom Registration Page

Things are taking shape, but you have use the register link under the login form to register. Bummer. I want the “register” to be part of my menu. So head over to Appearance -> Menus and add a new menu item to the “main menu” using the “Custom Links” panel. I’ve called mine “Sign up” and the URL is http://yourdomain.com/login?action=register (assuming your permalinks are set to%category%/%postname%).

Great so now we have a “sign-up” tab that takes people to the registration page. Nice right? But let’s say you want to include some custom fields? Like first name, website and postcode.

Theme My Login ships with some template forms. So you can can download the forms wp-content -> plugins -> theme-my-login -> templates and edit them and upload to your theme directory. But let’s do it using our functions.php. So download your functions.php and paste this after all the existing code.

/*-----------------------------------------------------------------------------------*/
/*	Adding required fields to the registration page
/*-----------------------------------------------------------------------------------*/	
	
	add_action('register_form','show_this');
	add_action('register_post','check_fields',10,3);
	add_action('user_register', 'register_extra_fields');
	
	function show_this()
	{
	?>
		<p>
        <label>First name</label>
		<input id="first_name" type="text" size="25" value="<?php echo $_POST['first_name']; ?>" name="first_name" /> 
        </p>   
    
		<p>
        <label>Website</label>
		<input id="website" type="text" size="25" value="<?php echo $_POST['website']; ?>" name="website" />
        </p>
        
        <p>
        <label>Postcode</label>
		<input id="postcode" type="text" size="4" value="<?php echo $_POST['postcode']; ?>" name="postcode" />
        </p>
		
	<?php
	}
	
	function check_fields ( $login, $email, $errors )
	{
		global $website;
		if ( $_POST['first_name'] == '' )
		{
			$errors->add( 'empty_realname', "<strong>ERROR</strong>: Please enter the name of your first name" );
		}
		else
		{
			$website = $_POST['first_name'];
		}
		
		global $website;
		if ( $_POST['website'] == '' )
		{
			$errors->add( 'empty_realname', "<strong>ERROR</strong>: Please enter the name of your website" );
		}
		else
		{
			$website = $_POST['website'];
		}
		
		global $postcode;
		if ( $_POST['postcode'] == '' )
		{
			$errors->add( 'empty_realname', "<strong>ERROR</strong>: Please enter your postcode" );
		}
		else
		{
			$postcode = $_POST['postcode'];
		}
	}
	
	function register_extra_fields ( $user_id, $password = "", $meta = array() )
	{
		update_user_meta( $user_id, 'first_name', $_POST['first_name'] );
		update_user_meta( $user_id, 'website', $_POST['website'] );
		update_user_meta( $user_id, 'postcode', $_POST['postcode'] );
	}

Okay so you might want to edit that to suit you. Here’s a basic breakdown:

  • The first function ( show_this ) says insert the following fields into the form
  • The second function ( check_fields ) checks if the fields are filled in and spits out errors if necessary (basic validation)
  • The third function ( register_extra_fields ) updates the user’s data – as well as the user’s profile

And for a bonus let’s change the word “register” to “join”:

/*-----------------------------------------------------------------------------------*/
/*	Change 'register' to 'join'
/*-----------------------------------------------------------------------------------*/	

	function tml_title_filter( $title, $action ) {
	if ( $action == 'register' )
		return __( 'join' );
	return $title;
	}
	add_filter( 'tml_title', 'tml_title_filter', 10, 2 );

Step 6 Custom Profile Page

Like most people it baffles me why WordPress has stuff like AIM and Jabber in the profile fields… so lets get rid of them! Paste the following code under your current functions.php code.

/*-----------------------------------------------------------------------------------*/
/*	Reomve feilds from profile
/*-----------------------------------------------------------------------------------*/
	function extra_contact_info($contactmethods) {
		unset($contactmethods['aim']);
		unset($contactmethods['yim']);
		unset($contactmethods['jabber']);
		
		$contactmethods['postcode'] = 'Post code (required)';
		
		return $contactmethods;
	}
	add_filter('user_contactmethods', 'extra_contact_info');	

Step 7 Test & Style

Alright, alright alright! (Kevin Hart style) Let’s test this! Logout of WordPress and hop to the front of your site. Click “sign-up” and go through the process.

Take note of any changes you need to make, for example, email template messages, etc. then apply them and re-test until you are happy.

Now you might want to style it up a bit, and luckily it’s easy using some appropriately named stylesheets uploaded to your theme directory. You can download these to get you started using the “Download Source Files” link at the top of this tutorial.

Using these style sheets will make sure your CSS isn’t overwritten when your theme updates.


Step 8 One More Thing

One last thing, the admin bar, let’s banish it for good. Add the code below to your functions.php.

/*-----------------------------------------------------------------------------------*/
/*   Disable admin bar for all
/*-----------------------------------------------------------------------------------*/
show_admin_bar(false);

Conclusion

So you can see it’s pretty easy to pull the membership process to the front of your website. This method is extremely flexible, the plugin configuration used in this tutorial may differ to suit your needs. It’s also fairly easy to have member specific content (try using wp-members). I’ve had success using this in commercial projects.

Please leave any feedback, or if you have suggestions I’d love to hear them, in the comments below.

Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • http://logic.lv Yuriy

    Too many plugins. It will slow down the system :(

    • http://pippinsplugins.com Pippin

      That is a completely out-dated and incorrect belief. The number of plugins does not directly effect the speed of your site. It’s all about the quality of the plugins. I personally run nearly 50 plugins on my site with very, very little impact on speed.

      • http://omarabid.com Abid Omar

        >> It’s all about the quality of the plugins

        This. and a single ‘bad’ plugin can wreak havoc on your website.

  • http://www.newsilike.in Bharat

    Hi Admin,
    Can i make this changes on my site. The theme which i use is – http://themeforest.net/item/insignio-flip-portfolio-wordpress-theme/1033674

    I am asking you this because I am scared of facing any errors on my site after i make some changes…

    Regards,
    Bharat

    • http://gavinjaynes.com/blog Gavin
      Author

      @Bharat

      I have used this method on 3 production websites and have had no problems. Obviously the code varies slightly from theme to theme so I can’t guarantee it won’t have some conflict with your theme. Always keep a copy of the original theme files and you can always go back if need be.

  • Whims

    Interesting however only one of those plugins shows as being compatible up to the current version of WP

  • http://webdesignergeeks.com Ajay Patel

    Really nice post, will help people to make front-end login/register use.
    Please do check on register page format while entering same username or mail-id, its change layout.

    BTW, aww article !

  • http://prop-14.com Randy

    This is a concept I truly believe in doing. The last site I did had a heavy amount of profile customization. I could not believe how much I still needed to hide things from basic users in the back end even though they had minimal capabilities. (ie: Do they really need to see the Dashboard?) Not to mention it can be a bear to get some kind of branding in place. There are even some plugins that will show up in the admin navigation for all users regardless of capabilities. Sure, they can’t adjust anything but there is no reason your users should see this stuff.

    For those of you asking about all the plugins to do this, you can go about all of this without plugins. It may not have been the intention of this article to teach that perhaps, but I know that it can be done. Just remember not to reinvent the wheel. Some plugins are extremely light in file size and have been well tested. Or just use these plugins as a learning base to hard code your own solution.

  • http://kg69design.com kg69design.com

    Lack of frontend registration/login/error – this is one of the biggest flaws in WordPress for me. Hopefully, in future versions of WordPress such standard for the majority of CMS will be out of the box.

    I honestly do not understand why this is not carried out, and still there is a need to depend on a heap of plugins.

  • Owen Conti

    Great article! Definitely some useful snippets in there.

    I did notice this typo though:

    /*———————————————————————————–*/
    /* Reomve feilds from profile
    /*———————————————————————————–*/

    feilds = fields :)

    • http://digiartes.net Juan

      /*———————————————————————————–*/
      /* Reomve feilds from profile
      /*———————————————————————————–*/

      yes and Reomve -> Remove… ;)

  • Pingback: Bringing the Membership Process to the Front of Your Site | Shadowtek | Hosting and Design Solutions

  • http://gavinjaynes.com/blog/ Gavin
    Author

    Hey guys, cheers for all the comments.

    I appreciate the concern surrounding using too many plugins. As Randy mentioned there are other ways to achieve a similar result without using plugins, however this method seems easiest and cross-theme compatible.

    If you are trying to cut down on the plugins you could get a similar result without using WP-Better-Emails and Theme-My-Profile. That way you are only using one plugin – Theme-My-Login and it’s less than 500kb.

    Anyhow I hope it serves as a guide to get users away from the dashboard.

  • http://www.graphismeo.com Graphismeo

    I wonder why it is so hard to do that in wordpress… I’ve got a headache each time i have to do it for my customers…

    Thank you for this tut

  • Pingback: WPTuts Plus | Dedicated to the Internet

  • http://deviantstudio.ca Richard

    I’ve noticed that some of these plugins are no longer in support from the developer.

  • http://gavinjaynes.com/blog Gavin
    Author

    Just thought people might like to know Theme My Login 6.2 beta has been released – http://www.jfarthing.com/blog/2012/03/06/theme-my-login-6-2-beta-1/

  • http://www.greyedservices.co.uk Scott S

    Nice tutorial – my only “gripe” with it would be:

    Making the changes to the registration form via the theme function file, kind of defeats the object of using plugins in the first place. With a plugin, the changes persist even if you (or the client) decide to change themes in future, whereas making the changes from within the functions file means that as soon as the theme is changed, that extra functionality is gone.

    Other than that, nicely done.

  • Pingback: Front end membership | Blog do Gabriel

  • http://www.sanjaykhemlani.com/ sanjay

    Cool post, I think WordPress User Frontend is worth a try for this http://is.gd/K7u4EO.

  • https://collectorsbluebook.com Will

    Theme My Login does not function properly with wp 3.3.2. I went against my better judgement and installed even though it states in the plugin directory not tested with 3.3.2.

    First, I had a message on my admin loggin page that never went away about incorrect user name or password. Then this morning, I awoke to find myself locked out of my site.

    After the tech at my hosting company and I messed with this for over an hour I discovered similar user experiences in the forums at WP.org.

    We deleted the plugin, and the issue was resolved. I also notice that my site is loading faster and when I did a page speed check it had jumped from a 54 to a 93. Lots of conflicts with this baby.

  • Jamie

    I have not experienced any issues really yet. Some of the styles are messed up and I am going to have to do a lot of fixing. The styles for the form didn’t work until I downloaded the styles form the link above and pasted them directly into my stylesheet.

    The one thing I don’t see is the custom information in the profile. I would like to see that on both the user profile page and the admin area. How can I go about adding these extra fields that we put in through this tutorial into the admin area? When I view the users, I want to see that data

  • http://www.brothersit.org Sumon Khan

    Oh Man! You’re great! You’ve done it. I looking for it and I got it here what I was looking :)

  • http://wpressclub.com Bob R

    I was wondering, is there a way to allow a simpler registration without plugins and without access to back end?
    What I’m looking for is to allow user registration so I can serve some content based on user being registered or guests.
    I want the readers to be able to register, go and confirm email address then next time when coming back and log in to be redirected to a page of my site rather than the WP Dashboard.
    Does anyone know how to do that?

  • http://www.familyoffestivals.com/ Hunter

    Can anyone tell me how I can set TML to fetch the 200×200 Facebook profile image and set that as the default size? I have other plugins that rely on the photo TML uses when a user signs up for my site using the “Login with Facebook” option. It would be much appreciated!

  • http://www.facebook.com/depidesign De Jay Depusoir

    Hi Gavin, In step 3, it speaks of creating menus in the header.php and functions.php. I’ve followed everything written and the main menu /user menu does not show up in there curresponding drop down menu boxes. Please help!

  • http://www.wordimpressed.com Devin Walker

    Amazingly awesome tutorial that was everything I was looking for and more!

  • http://www.facebook.com/marcio.bettencourt Márcio Bettencourt

    Hey, so my theme as more than two menus, how can I do step3?

  • http://www.facebook.com/jbeaucicaut Jo Hanz

    i cannot find theme my profile plugin it seems as if it is now part of theme my login. i cannot really follow along because of this what should i do?

    • http://www.facebook.com/jbeaucicaut Jo Hanz

      nevermind dumbest question i ever asked.. im not sober i never code sober

  • Surjith SM

    im having theme my login in my website. but there is an issue happening because of this plugin. my website is http://www.web3canvas.com . when im trying to go next page at bottom (web3canvas.com/page/2) its redirecting to homepage itself. i tried deactivating the plugin, then it works fine. i think some redirection is happening because of this plugin, is there any workaround for this ?

  • Pingback: Top 160 Tutoriais WordPress – incluindo Basico, Desenvolvimento e Plugins – Site para Empresas – Blog sobre Internet e Criação de Site