Page 1 of 1

what is this ["s2member_level_req"] ?!??!

PostPosted: February 20th, 2011, 11:32 am
by candy
Impossible to figure it out after reading all those API explanations and such .... what does this stand for and how can it be used (if at all) ?!?!

["s2member_level_req"]

As shortcode it does not work, thats for sure, so how and where to use than ?!??!

What does it do and what else is needed in oder to be able to display the current membership level (as text on the page) requested for a certain page ?!?!

Smth. like "you need THIS kind of membership in order to see this page" ?!?!

Sounds basic, but I did not find even one reference to it, and all those functions no matter how I combine just do not seem to address the issue.

What am I missing ?!??!

Thanks!

Re: what is this ["s2member_level_req"] ?!??!

PostPosted: February 20th, 2011, 8:30 pm
by Cristián Lávaque
Where did you see that code mentioned?

Re: what is this ["s2member_level_req"] ?!??!

PostPosted: February 20th, 2011, 9:29 pm
by candy
in API-Advanced query conditionals:
...........................................
Additional examples: documentation on these function calls.

Is a specific [Category, Tag, Post, Page, or URI] protected by s2Member?
<?php is_protected_by_s2member ($__id, $__type, $check_user); ?>
( * This ignores the current User/Member status.
Just "is it protected" by s2Member at all? )

If true, returns a non-empty array containing one of these elements.
["s2member_level_req"] = Level required for access.
["s2member_ccap_req"] = Custom Capability required.
["s2member_sp_req"] = "Specific Post/Page ID" required.
Otherwise returns false.
..............................................

But do not understand how to use it :-(

Re: what is this ["s2member_level_req"] ?!??!

PostPosted: February 20th, 2011, 11:14 pm
by Cristián Lávaque
I see, it's one of the elements in an array returned by that function. I missed that part of the documentation... :P

$__id - optional argument. Defaults to current $post->ID in The Loop.
$__type - optional argument. One of: `category`, `tag`, `post`, `page`, `singular`, `uri`. Defaults to: `singular`.
$check_user - optional ( consider the current User? ) defaults to: false.


Without having tried it, I'm guessing you'd use it more or less like this

Code: Select all
$check = is_protected_by_s2member(15); 


15 being the ID for the page you're checking, now $check['s2member_level_req'] would say the level required for access.

Re: what is this ["s2member_level_req"] ?!??!

PostPosted: February 21st, 2011, 8:05 am
by candy
Hiii,

Thank you v.much!
Now if you could help me understand what exactly should I put on my page so that I get the text" you need at least membership level X to see that" as an output, would be sooo great!

Maybe also combine that $check with the $_SERVER that you hinted at in other post ?!?!

As I said, I am not a programmer (so I don't understand much of that array stuff), and although I tried to read also that php stuff, I just can't move not even one step from here :-(

Thanks a lot!

Re: what is this ["s2member_level_req"] ?!??!

PostPosted: February 21st, 2011, 11:19 am
by Cristián Lávaque
Well, a variable is like a box where you can store different values, so it varies, and in PHP it's written starting with a $. An array is like a list of variables with each element in it being a variable, with the element name written between brackets right after the array's name.

Code: Select all
$variable
$array
['element'] 


Yes, you could combine this with $_SERVER as I mentioned in the other thread, but you'll need the post/page's ID and the fastest way to get it will be to have it in the URLs, I'm afraid, using %post_id% here WP Admin -> Settings -> Permalinks.

To get that URL after being redirected, I am guessing you'll find it in $_SERVER['HTTP_REFERER'], or $_SERVER['REQUEST_URI'], I'm not sure how the redirection affects this array.

So based on the format of your URL, you'll figure out what the ID of the post/page is and use it with the s2Member function to get the level required.

If the URL were formated like this http://example.com/?p=123 the code in membership options would probably be something like

Code: Select all
preg_match('~p=(\d+)~i', $_SERVER['HTTP_REFERER'], $matches);
$requirement = is_protected_by_s2member($matches[1]);

echo 'I\'m sorry, you need a level ', $requirement['s2member_level_req'], ' membership to access the content at ', $_SERVER['HTTP_REFERER'], '. Please click on this button to get it.';
// And you'd have the button here.    


It's a start, you'd need to tweak until you get it the way you want.

Hope it helps.

Re: what is this ["s2member_level_req"] ?!??!

PostPosted: February 23rd, 2011, 6:07 am
by candy
Thank you very much!
I am still struggling, did not manage to get it work ...