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™

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

s2Member Plugin. A Membership plugin for WordPress®.

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

Postby candy » February 20th, 2011, 11:32 am

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!
User avatar
candy
Registered User
Registered User
 
Posts: 102
Joined: November 16, 2010

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

Postby Cristián Lávaque » February 20th, 2011, 8:30 pm

Where did you see that code mentioned?
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

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

Postby candy » February 20th, 2011, 9:29 pm

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 :-(
User avatar
candy
Registered User
Registered User
 
Posts: 102
Joined: November 16, 2010

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

Postby Cristián Lávaque » February 20th, 2011, 11:14 pm

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.
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

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

Postby candy » February 21st, 2011, 8:05 am

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!
User avatar
candy
Registered User
Registered User
 
Posts: 102
Joined: November 16, 2010

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

Postby Cristián Lávaque » February 21st, 2011, 11:19 am

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.
Last edited by Cristián Lávaque on February 21st, 2011, 3:39 pm, edited 1 time in total.
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

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

Postby candy » February 23rd, 2011, 6:07 am

Thank you very much!
I am still struggling, did not manage to get it work ...
User avatar
candy
Registered User
Registered User
 
Posts: 102
Joined: November 16, 2010


Return to s2Member Plugin

Who is online

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

cron