I get several emails weekly about how I handle memberships on Theme Hybrid. After a few years of these emails, I figured it was about time to share how I do things. You’ll probably be surprised how simple it is.
In this tutorial, I will be covering how I handle membership after the initial registration and payment. The current plugin I use for the payment system is only held together by the numerous code fixes I’ve had to put together and is not something I’d recommend to others.
However, I’ve used Gravity Forms, plus its User Registration and PayPal add-ons, successfully on numerous other sites to handle registration and payment. I highly recommend using this plugin if starting a paid membership site.
Required plugins
Any good membership site (free or paid) needs a way for the admins to handle permissions. This is why I originally created the Members plugin. Members is basically just a UI layered over what’s already available in WordPress. It gives you access to WordPress’ built-in roles and capabilities, creating a powerful and robust permissions system, especially if you plan to have any custom permissions.
Members also has some other features baked in, but I don’t really use them. I use the main role editor for my site because it’s all I need for handling content.
You don’t need any other plugins unless you need a way to handle payments. In that case, go with Gravity Forms as I mentioned earlier.
The rest of this tutorial will assume that you’re using the Members plugin.
Creating a new capability
On Theme Hybrid, you must be a member of the club to view certain parts of the site, such as plugin and theme documentation. WordPress doesn’t have a good, built-in way to hide these parts of the site by default. So, I created a new capability (i.e., permission) called view_club_content. Basically, this capability decides whether a user can view content that’s restricted to club members.
The first step is creating this capability and adding it to the Administrator role because I, the administrator, should be able to view club content. I do this by the following steps.
- Go to the “Users > Roles” screen in the admin.
- Click on the “Administrator” role.
- Scroll down to the “Custom Capabilities” section and click “Add New.”
- Type
view_club_contentin the input box. - Click the “Update Role” button.
That’s all it takes to create and add a new capability to the role. Now, any site administrators will have access to club content.
The following screenshot shows how this is done.

Creating a club member role
All club members are given the “Club Member” role. I separate paying members from non-paying members by giving them different roles (actually, I have several roles for other purposes not being covered in this tutorial). Since WordPress doesn’t have a Club Member role by default, I need to create one.
The following steps describes how to create the custom role.
- Go to the “Users > Add New Role” screen in the admin.
- Type
club_memberin the “Role Name” input box. - Type “Club Member” in the “Role Label” input box.
- Select the
view_club_contentcapability from the capabilities list. - Click the “Add Role” button.
The following screenshot shows how a new role is added.

That’s how easy it is to create a new role. It’s also all the functionality I really need from the Members plugin.
Hiding club member content
The Members plugin has a component called “Content Permissions” that you may enable to hide content on a post-by-post basis. While that’s a cool feature, it doesn’t work well for those times when you want to hide groups of content, such as all tutorials. For that, I use a little custom code.
I’m going to keep this pretty simple. The actual code for my site is a bit more complex but not by much.
What I do is create a custom template in my theme called club-content-no.php. This template is shown on any page that the current user can’t view. The template code is similar to the following.
<?php get_header(); // Loads the header.php template. ?>
<div id="content">
<div class="hfeed">
<h1 class="entry-title">Club Member Content</h1>
<div class="alert">
<?php if ( !is_user_logged_in() ) { ?>
<p>This page can only be viewed by exclusive members of the Theme Hybrid club. If you're already a member, please take a moment to log into the site. If not, please consider joining our awesome community of people. Just head on over the the <a href="/club">club page</a> and sign up!</p>
<?php } else { ?>
<p>This page can only be viewed by exclusive members of the Theme Hybrid club. Please consider joining our awesome community of people. Just head on over the the <a href="/club">club page</a> and upgrade your membership!</p>
<?php } ?>
</div>
</div><!-- .hfeed -->
</div><!-- #content -->
<?php get_footer(); // Loads the footer.php template. ?>
Now that I have a template, I need a way to show that template to users who don’t have permission to view certain pages. WordPress has a filter hook called template_include that works perfectly in this situation. This hook is executed before deciding and loading the template to use on the current page.
Let’s assume that we don’t want users to see tutorials and theme documentation pages (two custom post types I use). The following code will handle this.
add_filter( 'template_include', 'th3_club_member_template', 99 );
function th3_club_member_template( $template ) {
if ( is_singular( array( 'tutorial', 'doc_theme' ) ) && !current_user_can( 'view_club_content' ) )
$template = locate_template( array( 'club-content-no.php' ) );
return $template;
}
That’s a total of 6 lines of code for the real functionality behind my membership system. This code does a few things:
- It filters with a priority of
99to make sure it’s executed after any other filters. - The code checks if the user is currently viewing a single
tutorialordoc_themepost. - It checks if the current user has permission to
view_club_content(the custom capability I used). - It loads the
club-content-no.phptemplate if the user doesn’t have permission to view the page.
It’s easy to run a membership site
Traditionally, in the WordPress community, membership systems have been overpriced, are overly complex, and often work outside of the WordPress roles/caps system. This is another major reason I created the Members plugin. You can download and use it for free.
There’s no magic here. It’s not even something that’s extremely complex for the average site owner. WordPress already has the tools built in. The Members plugin just gives you access to those tools.
I realize that my example is simple. There are much more complex membership sites out there. However, this tutorial should give you a solid base for working within the system and allow you to build whatever type of membership site you need.
Well written and easy to understand, thank you! This is great for newcomers like myself
I agree
Great tutorial for a plugin that I have been using since it first came out, thanks Justin!
One thing though that I am a bit disappointed about is that from someone like you I would have expected your code to be internationalised…
All my plugins and themes are internationalized.
what I (obviously) meant was in the code above you are not using any internationalisation.
That wasn’t obvious in your first comment. I assumed you were talking about the plugin. The code above has no need for internationalization though.
hi justin.
i wonder how did you handle subscription in theme hybrid?
so, the user will change role if subscribtion end?
is it a feature of gravity form?
thanks.
Assuming a one year subscription: The easiest way is to save the last payment date as user metadata. From there, you can run a check against that meta on the
inithook. Or, you can run a daily cron job and query all users with today’s date minus one year saved as meta. You check if the date saved in the meta is over a year old. If so, switch the user roles. Of course, you’d need another payment form to resubscribe via Gravity Forms.I’ll have to save the detailed information for later, but that’s the quick explanation of that.
wow, thanks justin.
i think i get it.
great tutorial, as always
well indeed if you want to export the data for wordpress how can you do it and also if you work on back-end development then how can u live you on server side?
Hi,
I am new to WordPress and am hoping build up my experience.
I need to do something similar to this but I want to limit portions of my Posts/Pages by Role. I would then like to return a block of html (probably with an image to sign-up) instead of the taking up the whole page.
How can I do this?
Can the functions be in a file that is not tied to the theme?
Thanks Justin
I know other why to do that and it’s using groups plugin and you have the option to open a premium groupe so only the users who have a paid membership in your site can see a content you selected to them only
but thanks justin you are always coming up with the new things
It would be awesome if this plugin was able to specific content on a given page/post that’s only viewable to the member.
Like for ex.
The surrounded short code would be the following below
Here’s my latest Art tutorial:
[jt_membership]My new art drawing tutorial:[/jt_membership]
Displayed on front end for non member (below)
Here’s my latest Art tutorial:
sorry you must be a member to see this page (member text will link would point to a signup/payment gateway page)
This plugin would rock if it was able to do that instead of hiding an entire post or page.
It’s still useful otherwise.
You can already do this with the Members plugin. This process is described in the plugin’s documentation.
Well actually that partial solves the problem but creates another. When using the shortcode indicated in your doc file.
[access role="editor"]Hide this content from everyone but editors.[/access]
I don’t want the content to be hidden but rather replaced with custom text like “You must login or signup to see this content” in a specified area.
Your shortcode only hides the content but doesn’t allow a person to know that there’s hidden content on the page. Am I missing something here?
Hi..
Awesome plugin..I really need it to create wordpress membership site like forum..Members can asked question/Theard and others will be able to answer post,Don’t won’t pay for membership..I will try your plugin
Thanks lot of
Thank you, I was looking for this.
The feature most organizations want is for a member contact page to be visible to visitors to the site. Do you know of any WP plugins that does this other than a subscription site like Wild Apricot?
Like a contact form for individual users? I’m sure something like that is possible with Gravity Forms (mentioned above). There are tons of ways of handling the functionality. I don’t know of any plugins specifically for that offhand though.
Ever thought about Recurly, Chargify or Spreedly? They manage membership fantastically, for a price…
Congrats on your new plugin, more than 133K downloads already with 4.6 stars out of 5… impressive. At the moment I’m not really planning to set up a membership site, but I was always curious if there is an relatively easy way to do it, and now it seems there is.
Could I just ask you about the differences between doing this and BuddyPress.
BuddyPress is a complete social networking plugin. This is not. Have you used BuddyPress before? These two things have nothing to do with each other.
Hi Justin!
Thanks for the helpful and interesting tutorial. I really appreciate it; it’s so generous of you to share this info with us. You make it sound so easy. I’ve been considering starting a membership site to share some of my craft patterns, and your post has me feeling really excited and energized at the possibilities.
I’m actually here with a question about the Unique theme. It looks like such a nice theme, and I’m considering a purchase. I’m wondering if the slideshow items can be linked to pages within the same Wordpress site, or even URLs elsewhere on the Internet. Or is it limited to only linking to posts within the blog? It’s hard for me to tell from the demo.
Either way, congrats on the theme. It looks great!
Also, thanks for the Grid Columns plugin. I’ll be messing around with that one shortly and I’m really excited to have found it. Thank you, thank you, thank you for making it available. I really appreciate all you do for the Wordpress community.
Best,
Amy
Thanks a ton for this and the members plugin. Very helpful.
Good Luck budy.
Thanks for the tip
Amazing tutorial and very usefull for me. Thanks!
Whaw, thats cool justin. I think i will make some sites and i love your way to make a membership page. Thanks..
Hi
Just came across this. How difficult would it be to amend it with a rule like this
user A logs in, can see all pages on site, and one specific post/page/gallery that is associated with his login.
user B, see’s everything else that A see, apart from page “A” and so on
thanks
Jody
just install wordpress put the plugin for member nothing easyer.
Great work mate, I will need that membership system for the new blog I am starting. Those roles will help me greatly, bookmarked the post and gonna give it a good read later, thanks a lot.
I’ve been searching for days. Is this what I need to have a client login?
Here’s what I’m trying to do:
1. Have some pages accessible to everyone.
2. Have a login/registration for clients to see pricing and other restricted pages.
3. A registration page with required fields with an approval option before granting access.
Wowo thanks, I’ve been thinking about turning a part of my blog into a members-only-area, I’ll try your plugin as soon as I’ve got time.
Thanks for the tip !
I had previously been working with God-awful solutions like Amember and Digital Access Pass which are ugly and not WordPress-standardized. I was so happy when Pippin Williamson released Restrict Content Pro – it’s an excellent hands-off approach to it, though having read this article, you’ve made it quite apparent just how easy it can be to do it yourself manually.
This sounds quite easy to implement, lets see if I can manage it
Thanks for sharing!
great tutorial, as always
thank for this tutorial . i try it.
Wonderful tutorial, Justin! Thanks for sharing! It’s good to see alternatives to the bloated membership plugins.
FWIW, Gravity Forms offers recurring payments and subscriptions: http://www.gravityforms.com/add-ons/paypal/
Congratulations on a wonderful article, and the simplicity that you explained it all!
I can`t find out how to install this plugin on my blog. Does it work with the older versions of WP?
I offer plugin support on the Theme Hybrid forums if you need help. It should work with WordPress 3.4+.
Thanks For the codes
Great work I wish you good success
thanks for providing the Code . Great Job………….
Thanks for the excellent information! Looking to use Gravity Forms and appreciate your insight.
thanks for info .. i will try it .:)
Thanks for the info and code..
Thanks for the code, and also the plugin, Justin. I have been hesitating to get membership working on a client’s site, as I don’t ‘know’ enough about it. Now, having reading your tutorial and seen your plugin I’m feeling confident that this is the solution that I need to explore and test.
Thanks, you’ll see me as a member soon.
thanks for it one question will it work smoothly with older version or i have to look out for some other options
Thanks, this is a wonderful plugin and functionality, thank you so much for your generosity. I have it working great based on your documentation, but there is one functionality that I would like to know how to do:
when users are logged in, they see the default “complete” list of posts. Is it possible to only show posts to which the user is a member of/ allowed access to instead of the full posts list?
Thanks again!
Wonderful I didn’t know having to limited certain users from viewing some parts of content while the administrator can view them all, can be done so simple, this is very useful for a newbie like me. Thanks for the guide Justin.
Thank you for your template!
As I am realy beginner, I dont understand where you put this part of code:
This should go in the theme’s functions.php file.
Hi Justin.
Thank you so much for the plugin. I love it.
I would appreciate some of your valuable time to answer this… where and what code do I add for a “Logout” button?
I’m OK with php. I can find my way around most code, and have searched the heck out of your site and the code but for the life of me I can’t find how to do it.
I have added the “Login Form” widget to a Sidebar. Would love to add a logout button to the same.
Thanks
Mike
Thanks for the post.
How would users cancel their subscription in your model?
I don’t have a subscription. It’s a one-payment system. But, if you go with a subscription-based model, I know PayPal makes it fairly easy to cancel any subscriptions you have as a buyer.
You have covered it great with this plugin, really clear short and easily grabbed tutorial, perfect to see administrator rights with viewing some parts of the content and hiding from audience!
Great article. ! Newbie question.. I’ve never been a big fan of paypal.. are their any other payment solutions you would recommend?
What is difference between membership site and fourm ?
A membership site is a Web site that you must be a member of to participate in some way.
A forum is a part of a Web site in which people write messages to each other. Most sites with forums require membership to write in the forums but not all.
Cool. This is exactly the plugin that I need.
Good tutorial, Justin! Thanks. I saw an interesting solution recently – private sale script from Plumrocket. A number of magento extensions and magento private sales theme, -I think it is worth seeing.
Hello,
I am getting a social media site designed. I want people to join to post stories and comments. Will using WP and its pluggins cause problems with the site when there is a new version o releasedf WP? I have been told it us better for me to use PHP, what is your opinion?
Hi Justin,
I’m playing with your fantastic plugin to build a client area in my site. Is it possible to use Members to limit logged in users to a specific page only (built off a custom post type)?
So if Joe Bloggs logs in, he can only access http://www.domain.co.uk/clients/joe-bloggs
Ideally I don’t want to install another plugin for this…
This looks like a simple way, will try this weekend to install it!
Great tutorial – thank you very much! And also thank you very much for providing the members plugin!
With your tutorial and the members plugin I was able to setup a Wordpress blog that only my family and close friends can read. However pictures and videos from the media gallery do not seem to work with the “Content Permissions” widget. So if you know the URL to a specific video or picture you can access it without being in a specific group.
How are you protecting your media library items? I assume some of your items are valuable as well – e.g. video tutorials, screen shots or some architecture diagrams.