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™

How do I display required level to view a page?

s2Member Plugin. A Membership plugin for WordPress®.

How do I display required level to view a page?

Postby moonviper » December 21st, 2010, 3:35 pm

I am running s2member with two membership levels (free and paid).

Essentially, a member must register for free to view SOME content, but even more is unlocked with a paid upgrade.

If the member does not have the proper credentials to view that particular piece of content, the system takes them to the upgrade page, as intended.

I'd like to display on that page a notification of what membership level you would need to be able to read that particular bit of content.

Anyone know how I do this?

PS... Installation at http://www.moonviperweb.com for reference
User avatar
moonviper
Registered User
Registered User
 
Posts: 2
Joined: December 21, 2010

Re: How do I display required level to view a page?

Postby Cristián Lávaque » December 27th, 2010, 1:13 am

You can so something like

Code: Select all

<?php if (current_user_can("access_s2member_level1")){ ?>
    Some content for Members who are logged in with an s2Member Level >= 1.
<?php } else { ?>
    Message telling the person that he needs Level 1 access to see the content in this page.
<?php } ?> 


Is that what you mean?
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: How do I display required level to view a page?

Postby candy » February 19th, 2011, 10:56 pm

And what if you have 3 levels and do not know which user landed there from where?!?!
<?php if (current_user_can("access_s2member_level1")){ ?> is not the right answer, as I do not know at that stage which user (with which permission level) happened to land on the page in question.
What would be needed (personally I was not able to find that anywhere, and I think it's very strange that such a basic shortcode is not provided) would be the shortcode (or function) to dynamically retrieve the current required level (smth. like [s2current_level_req] ( no this code does not work, I have tried!)
Should be smth. like that though)

Anyone?!?!

Thankx!
User avatar
candy
Registered User
Registered User
 
Posts: 102
Joined: November 16, 2010

Re: How do I display required level to view a page?

Postby Cristián Lávaque » February 20th, 2011, 3:19 pm

I read all the API scripting codes and didn't find what you're looking for. They either weren't documented, or don't exist. Sorry I can't help you with that. :(
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: How do I display required level to view a page?

Postby candy » February 20th, 2011, 4:25 pm

thanks a lot for trying :-)

I also read all those APIs and found nothing.

And I am really stuck with a very basic issue, makes me really wonder what did they think of when made the landing page "fix" no matter where the user comes from and which permission he has!

How will he know which membership he has to purchase to access that page, if there's NO WAY to show him that !??!

Developers please ??!>?
(I have no high hopes they will respond unfortunately, but I never give up hope!)
User avatar
candy
Registered User
Registered User
 
Posts: 102
Joined: November 16, 2010

Re: How do I display required level to view a page?

Postby Cristián Lávaque » February 20th, 2011, 5:09 pm

Well, if I'm understanding your problem correctly, you can always tell the person yourself what the level required is... You can check if he can access that content with his current level and if he can't, show him a message saying what it is, like I showed in the example few messages above.

candy wrote:And what if you have 3 levels and do not know which user landed there from where?!?!


You can figure out the where from using $_SERVER and the extra levels would just use more conditionals, which you already need there to show the content, to say what level they need to view when they can't. The user ID you know, and what he can access too.

What exactly are you trying to achieve that you aren't being able to? Maybe if you're more specific, I may be able to help you solve it better.
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: How do I display required level to view a page?

Postby candy » February 20th, 2011, 5:32 pm

Hiii,

Well 1st ... I am not quite a programmer, so I will not be able to write all those complicated "if" conditionals all by myself if no example is provided :-(

Now what I need is quite basic:
Every page/category/post/URI whatever has a minimum "requested member level" (so page 1 only requires level1, category 2 for ex, level2).

Problem is that when a user which is either not logged in or has an inferior kind of membership that the one required by that page, will be redirected to a single page, no matter his membership level !!! (yes, in the APIs you can only define it as that "membership" page, and there's no way to add dynamic parameters to the URL either)

So as the page is only one, I have to find a way to show him which level of membership he needs to buy in the 1st place in order to be able to view the previously clicked page (or cat/URI/post) etc.

Otherwise he'd stay there and wonder: huh, and which membership do I actually need now ?!?!?
(I have 3 levels users can choose from when seeing the membership page, 0,1 and 2)

So let's take userA (level 0) tried to see pageA(requested level 1) and he also tries to look at postB (requested level 2) - he will now be redirected to the SAME memberships page. How will he know that to see postB he needs a membership level 2 while to see pageA only membership level1 ?!?!

I've got to tell him somehow what he has to buy, even if just to display the text saying "hey, you need at least membership1 if you want to see pageA" or "you need at least memebrship2 if you wanna see postB "

So somehow I have to pull the information about which minimum level of membership the previous page requires .. and combine that with membership level of the visiting user

How did you solve that !?!? Just sending the user to your memberships page and let him choose whatever?

Imagine he needs level2 and only buys level 1 - I personally don't really want to hear about his complaints :-(
User avatar
candy
Registered User
Registered User
 
Posts: 102
Joined: November 16, 2010

Re: How do I display required level to view a page?

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

Ah, I get your problem now.

Well, the only way I can think right now to solve it, is to add the protection to the content instead of the whole page. That way, instead of having the person sent to the membership options, he'd stay on the page where he is having the lack of level, where you can present him with options.

So, when you edit a post/page, you wouldn't use the box on the right to determine the level required, but the PHP conditionals in the actual content editor. See what I mean?
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: How do I display required level to view a page?

Postby candy » February 20th, 2011, 7:34 pm

Thanks a lot !
But it will not really work in may case :-(
I need a general rule to apply for everything, as I have at times pages that are protected, some times categories or URIs (coming from different plugins for ex), so it's not just about pages and posts :-(
And there will be user submitted content too ...

But I can't really imagine that there's no function for this, it just cannot be!

The only problem here is that we don't get any help from the developers here, and that's really frustrating :-(

If you have any further idea as to how to solve the puzzle, will be highly appreciated!

Thank you :-)
User avatar
candy
Registered User
Registered User
 
Posts: 102
Joined: November 16, 2010

Re: How do I display required level to view a page?

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

You're welcome.

Well, I guess you could work with the membership options page...

You'd need to use $_SERVER to find out the page they were redirected from first, and then find out what the level required for it is querying the database with custom PHP if there isn't already an s2Member function for it. The code could be swiped from existing s2Member code, but repurposed for this particular use.

Just thinking out loud here, haven't tried it, but would probably work.
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: How do I display required level to view a page?

Postby candy » February 20th, 2011, 8:46 pm

oups ... and can you give me an example as of how to use that $_SERVER ??!
I am not a programmer, so I am afraid I won't be able to do much with it ...
How would that one look like in a code !??!
I searched in those APIs, found nothing :-(

Thanks!
User avatar
candy
Registered User
Registered User
 
Posts: 102
Joined: November 16, 2010

Re: How do I display required level to view a page?

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

That's a PHP array that has a lot of information. It's explained here

http://php.net/manual/en/reserved.variables.server.php
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: How do I display required level to view a page?

Postby candy » February 21st, 2011, 10:15 am

please see my other post regarding ["s2member_level_req"]

I couldn't come any step further, I guess my "programming" knowledge is definitely not enough for that.

Code would be highly appreciated :-)

Thank you!
User avatar
candy
Registered User
Registered User
 
Posts: 102
Joined: November 16, 2010

Re: How do I display required level to view a page?

Postby Cristián Lávaque » March 14th, 2011, 11:08 pm

Sorry for taking so long to get back to you on this.

In the latest release of s2Member, we've updated the documentation on s2Member's MOP Vars ( Membership Options Page Variables ), which is what you'll probably want to use for this. Instead of redirecting a Visitor and/or existing Customer, you can dynamically modify the focal point of your s2Member installation, the Membership Options Page.

At the core of s2Member, is it's ability to protect content ( i.e. Posts, Pages, Tags, Categories, URI word fragments, etc ). Whenever a public User, or even an existing Member attempts to access an area of your site that is unavailable to them; either because they are not logged-in, not a paying Member at all; or maybe they are logged-in, but they don't have access to content you've protected at a higher Membership Level; — s2Member will always redirect these un-authenticated requests to your Membership Options Page. So your Membership Options Page is a key element of your site. It serves as the focal point of your s2Member installation.

Understanding this, it becomes important for s2Member to provide information about what the User/Member was attempting to access ( before they were redirected to the Membership Options Page ). This is where s2Member's MOP Vars come in ( i.e. Membership Options Page Variables ). Whenever s2Member redirects a User/Member to your Membership Options Page, it will include these important MOP Variables in the query string of the URL. These Variables can be used to provide more informative messages; or even to provide a different set of Membership Options ( i.e. Payment Buttons ), based on what a User/Member was attempting to access.


Please take a look in your WP Admin area, under: s2Member -> API Scripting -> Membership Options Page Variables.

Code sample ( you might do something like this in your Membership Options Page ).

First, you will need the PHP Execution plugin, or the Exec-PHP plugin also works fine:
http://wordpress.org/extend/plugins/php ... on-plugin/

Now, in your Membership Options Page, you might have something like this:

Code: Select all
<?php if(current_user_can("access_s2member_level1") && $_GET["s2member_level_req"] === "2"){ ?>
  
     .... they have access to Level #1 already, but they need to upgrade to Level #2 in order to view this content.
     Display content here ( perhaps a Modification Button or a link to a Modification Form generated with s2Member Pro )

<?php } else { ?>

     Else, display something different here.

<?php } ?>


Hopefully this will help you. :)
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


Return to s2Member Plugin

Who is online

Users browsing this forum: No registered users and 1 guest

cron