Page 1 of 1

S2Member - List restricted pages

PostPosted: March 23rd, 2011, 10:43 am
by prema
Hi,

I m using S2 member plugin & restricted few pages & posts.
How to display a list of restricted pages & posts in right side bar ?

Re: S2Member - List restricted pages

PostPosted: March 23rd, 2011, 9:01 pm
by Cristián Lávaque
Hi Prema.

You'll need to create a widget with some PHP to show that custom output.

You could update the list with an array containing the IDs of the pages that you protected and then foreach it to create the HTML list in the widget.

If you also want to display in some way if the current user has access to each page or not, you'd need to use some advanced query conditionals too: WP Admin -> s2Member -> API / Scripting -> Advanced Query Conditionals.

Hope that helps. :)

Re: S2Member - List restricted pages

PostPosted: March 24th, 2011, 3:51 am
by prema
Thanks for reply.
But how to get an array of restricted Post Titles ?

Re: S2Member - List restricted pages

PostPosted: March 25th, 2011, 12:11 am
by Cristián Lávaque
Since you're the one protecting them, you'd know which they are.

If you protected IDs 123,345,456,567 then your array could be

Code: Select all
$my_protected_ids = array(123,345,456,567); 

Re: S2Member - List restricted pages

PostPosted: March 25th, 2011, 6:28 am
by prema
Thanks Lávaque.

How to get dynamically through code instead of hard coding like

$my_protected_ids = array(123,345,456,567);

?

Re: S2Member - List restricted pages

PostPosted: March 26th, 2011, 4:09 am
by Jason Caldwell
Thanks for the excellent question.
~ and thank you for bringing this to my attention Cristián.


s2Member stores this information in it's array of configured options.
Code: Select all
<?php
$protected_level1_posts_array 
= preg_split ("/[\r\n\t\s;,]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level1_posts"]);
$protected_level1_pages_array = preg_split ("/[\r\n\t\s;,]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level1_pages"]);
$protected_level1_posts_pages_array = array_merge ($protected_level1_posts_array, $protected_level1_pages_array);

$my_protected_ids = $protected_level1_posts_pages_array;
?>
* Of course, you may need to alter this code ( or add to it )
if you have protected Posts/Pages at many different Membership Levels.

Re: S2Member - List restricted pages

PostPosted: March 26th, 2011, 7:03 am
by prema
Thats Great!!

One more doubt.

Can we get these restricted IDs after a s2Member login ?

Coz, Before logging in its working fine, didnt give any output after login.


!!!!

Re: S2Member - List restricted pages

PostPosted: March 26th, 2011, 9:36 pm
by Jason Caldwell
You're very welcome. Thanks for the follow-up.
prema wrote:Thats Great!!
One more doubt.
Can we get these restricted IDs after a s2Member login ?
Coz, Before logging in its working fine, didnt give any output after login.

These options only change when you modify your s2Member configuration in the s2Member -> General Options panel. If you are seeing differences between being logged-in vs. not logged-in; I suspect the issue is originating from something other than the code sample above. So to answer your question, no. These option values do not change; even when a User/Member is logged-in.