Paid Memberships Pro adds content restriction settings for your WordPress ‘posts’ and ‘pages’ by default. This article will show you how to extend the core functionality to also protect a Custom Post Type or CPT.
Leveraging the “Require Membership” Settings for your CPT
If the Custom Post Type Membership Access Add On is not the right fit for your project, here is another method to require membership for your CPTs. It is specifically useful for plugin developers who want to build-in this setting for a CPT and are ready to take the next steps to lock down their CPTs.
By default, PMPro will filter anything output through the the_content()
function. If your CPT does not use this function to output content, you will need to either use code like this to redirect away from member content or update your CPT’s single view to lock down the content appropriately.
Here is an example recipe that can be added to your plugin to require membership for a CPT:
Why can’t PMPro do this automatically?
Awhile back, we had shared that we were looking for a way to make the plugin automatically discover CPTs. I’ve learned that it doesn’t really make sense to do this.
We have no way of knowing what the CPT is or how to protect it for members. CPTs are, by definition, custom. The setting to require membership for your CPT is only the first step in restricting it. For example, if an ecommerce product were marked for members only, does this mean users shouldn’t see the product at all? Or should they just not be allowed to purchase it or add it to their cart? Should the product show up in searches?…and so on, and so on.
Our strategy is to work with plugin developers to help them update their plugins to support Paid Memberships Pro or develop official Add Ons for popular plugins with CPTs as we have for bbPress, BuddyPress, and WooCommerce.
Adding the recipe to your website
You can add this recipe to your site by creating a custom plugin or using the Code Snippets plugin available for free in the WordPress repository. Read this companion article for step-by-step directions on either method.