PriMoThemes — now s2Member® (official notice)

This is now a very OLD forum system. It's in READ-ONLY mode.
All community interaction now occurs at WP Sharks™. See: new forums @ WP Sharks™

Page Restriction not working on "Posts page"

s2Member Plugin. A Membership plugin for WordPress®.

Page Restriction not working on "Posts page"

Postby ignite » December 14th, 2011, 2:05 am

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?
User avatar
ignite
Registered User
Registered User
 
Posts: 1
Joined: September 28, 2011

Re: Page Restriction not working on "Posts page"

Postby Raam Dev » December 15th, 2011, 12:23 am

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).
Raam Dev || Wherever you are, be there. || Please rate s2Member!
User avatar
Raam Dev
Developer
Developer
 
Posts: 810
Joined: October 26, 2011


Return to s2Member Plugin

Who is online

Users browsing this forum: Exabot [Bot], Google [Bot] and 2 guests

cron