The plugin filters what is in WP’s $content variable during The Loop based on whether or not the user is logged in. In its most basic form, if the user is logged in, it allows the content to be displayed. If the user is not logged in, it empties this value and replaces it with the login and registration form.
Back in 2005-2006 when the plugin originated, this was a very simple process. Today, not so much. Today we have custom post types, visual page builders, plugins that are really a full blown application such as WooCommerce or BuddyPress, and countless other possibilities.
The plugin has kept pace with these developments while remaining true to its original purpose and use; but the answer to “why isn’t the plugin blocking my content?” has become a far more complicated answer. I’m hoping this post lends some clarity to some of these possibilities.
Let me assure you the plugin is not broken. Thousands of users use the plugin quite effectively. It even runs on this site for all of the member-driven content, subscription processing, user expiration, etc. In other words, I not only trust my own business to it, it actually runs my business.
Let’s cover some of the common situations that occur.
Archives and The Read More Tag
Officially, blocking only directly occurs on single posts and pages. The plugin’s primary objective is to drive user conversion (registration). It does this by displaying excerpts of posts with the “read more” tag (or the plugin’s auto excerpt setting) as teaser content which then directs the user to the single post requiring the user to log in or register.
So the plugin does not natively block content on archive templates. What is an archive template? Essentially, all displays of posts that are not a single post – monthly archives, category listings, search results, etc.
Suppose that you don’t want to display excerpts. Can archive templates be blocked at all? Not directly. But there are multiple ways to handle this.
The best way is to redirect the user to a login page that will redirect them back to the content upon logging in. You can see how this works by clicking this link to members only forums on this site which will redirect you to the login form if you’re not logged in.
Since you’ll find redirection a common theme among these possibilities, there is a larger discussion of it at the end of this article.
The addition of certain shortcodes can interfere with the way the plugin handles The Loop.
This most definitely is not intended to say that ALL shortcodes interfere with this, because that is not the case. But some shortcodes, depending on how they process and what they process can cause content to not be blocked.
Solving this can be tracking down those offending shortcodes an removing them, finding alternatives, or finding alternatives to blocking the content. This might include using the [wpmem_logged_in /] shortcode, which may solve the issue, or redirecting the user to a login page.
WooCommerce is a tremendous (and popular) plugin. However, it really is a full application that has a lot of its own processes that function outside of WP’s processes. Primarily, the main thing that happens with WC is that it does not use the WordPress Loop. It has its own Loop. It uses its own templates and template functions.
Because of this, the WP-Members filter on the_content does not effect WooCommerce’s page displays. This is because that content is not going through WP’s the_content filter.
Generally, any time you find a plugin that uses its own templates and template functions outside of WordPress, you will find that you have a situation that will require special attention in order to get WP-Members to handle the process.
Similar to WooCommerce, there are other plugins that also implement their own features outside of The Loop. Sometimes, they just use Custom Post Types and in that case, they can be addressed like any other post or page – the CPT just needs to be identified in the WP-Members settings (more on this below).
In other cases, the plugin may use post meta fields for containing and displaying its content. In this kind of case, the content is unknown to WP-Members so it isn’t blocked. This is content that is outside the main $content variable.
This kind of issue comes up with event calendar plugins and LMS (learning management system) plugins as they tend to store a lot of information in post meta.
The simplest solution to these is to use the Advanced Options extension and redirect away from the content. That way the page cannot be accessed.
Custom Post Types
Custom Post Types are just that – custom. So not every use of a CPT will function the same. This is why WP-Members does not automatically attempt to manage CPTs in your installation.
In general, if a CPT operates similarly to a regular post or page, then blocking/unblocking should operate similarly as well. But compatibility in this area depends on the CPT in question.
WP-Members can be set to attempt to handle a given CPT as it would a post or a page by adding the CPT to the WP-Members options. This can be done in the Custom Post Types section below the main options in the Options tab. Once a CPT is added, it can be managed in the main options in addition to posts and pages.
If a CPT is not able to be blocked like a regular post or page, the second option is to redirect the user to the login.
The above list is not exhaustive. There are just too many possibilities to consider all of them. Keep in mind, this is a WordPress plugin – not a (fill in plugin or theme name) plugin.
My best advice when testing out is to keep things simple. If you introduce WP-Members to a complex WP setup with 40 plugins, 10 Custom Post Types, a visual builder, and a theme that tries to be an application with bells and whistles that should be plugins, well then it’s going to be difficult to determine incompatibilities.
However, if you begin with a basic setup it will be easier for you to learn how the plugin works and it will be easier to work with additional plugins and themes.
That’s certainly not to say that it can’t be compatible with complex installs. It is very adaptable and extensible because of it’s framework of filters, actions, and API functions.
If you want the easiest path to handle complex installs, I highly recommend the Advanced Options Extension. This extension was designed to offer a number of options that could be enabled very easily. All of its options are as simple as checking a box.
How to handle redirection
You can handle this in a couple of different ways. Redirecting to the login page can be customized into your process by using the wpmem_redirect_to_login() API function. Of course it would generally have to be hooked to an action to process. I recommend using ‘template_redirect’ as this happens early enough that you can still safely redirect the user, but late enough that the post information should be loaded so you can find out what page you are on.
A very simple solution that also provides you quite a number of additional settings is the Advanced Options extension. For redirecting away from blocked content, it has several options. You can set it to redirect all content to the login page, just blocked content, or just selected content.