Page 1 of 1

Page Restriction not working on "Posts page"

PostPosted: December 14th, 2011, 2:05 am
by ignite
I'm using a static front page on my site with all of the pages restricted to members, except the "front page" (and, of course, the Membership Options Page). s2Member Pro protects all of the restricted pages, with one exception. For some reason, the page I have designated as the "posts page" is accessible to everyone, even though it is clearly marked as restricted to "Level #0 Or Higher".
In addition, if I change the designated "posts page" to another restricted page, that page becomes accessible to everyone and the original page is protected. Basically, any restricted page that I select as the "posts page" becomes visible to the world.
It seems like a couple of other people in this forum have the same problem (like kerner1), but no one has offered a solution to this problem. I tried the Alternative View Protection option too, but it had no effect.
BTW, I'm using s2Member Pro (Version: 111206) with the s2Clean Theme (Version: 110813) on WordPress 3.3 (although the problem also existed on WordPress 3.2.1).
Any suggestions?

Re: Page Restriction not working on "Posts page"

PostPosted: December 15th, 2011, 12:23 am
by Raam Dev
Hi ignite,

This is caused by the way WordPress works. Whatever page you select for the posts page, that page gets replaced by the main loop in the themes index.php file.

For example, let's say you have a page called "Blog" and that's what you select for the "Posts page" in WP Admin -> General -> Reading. Now, when you visit the Blog page, WordPress will take the theme's index.php file (where the main loop displays the latest blog posts) and use that when the Blog page is requested.

When the Blog page is selected as the Posts page, it ceases being the Blog page "page" and becomes a special WordPress generated page (using the theme's index.php file) to display the latest posts.

So, to solve your problem here's what you could do: You could modify your theme's index.php file and add some PHP code above the main loop that checks if the person visiting the page is logged in. Something like this:

Code: Select all
if(!is_user_logged_in()) {
    echo 'Sorry, you must be logged in to access this page';
}
 else {
    // Main loop code goes here
} 


If you want to automatically redirect non-logged in users to the Membership Options page, you could modify the above code by adding some JavaScript that redirects non-logged in users:

Code: Select all
if(!is_user_logged_in()) {
    echo '<script type="text/javascript">
<!--
window.location = "http://example.com/membership-options/"
//-->
</script>'
;
}
 else {
    // Main loop code goes here
} 


The downsides to this way of redirecting would be that it wouldn't work for anyone with JavaScript disabled.

The other downside is that the redirect wouldn't pass any of the Membership Options Variables that normally get passed during an s2Member redirect (although I suppose with a little work you could build the redirect URL manually to include those variables).