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™

conditional statement for user level logins?

s2Member Plugin. A Membership plugin for WordPress®.

conditional statement for user level logins?

Postby rwilki » July 26th, 2011, 10:32 am

Is it possible to put some php in the functions file to have two different membership signup pages depending upon the level someone is clicking to...

In other words,

If someone clicks on a link to a level#0 post, this is the url...
http://www.domain.com/membership-signup ... evel_req=0

If someone clicks on a link to a level#1 post, this is the url...
http://www.domain.com/membership-signup ... evel_req=1

so that they have a custom signup members page only showing the signup level they need.

Thanks,
Bob
User avatar
rwilki
Registered User
Registered User
 
Posts: 61
Joined: July 22, 2011

Re: conditional statement for user level logins?

Postby Cristián Lávaque » July 27th, 2011, 1:03 am

Sure, using conditionals that check the Membership Options Page Variable s2member_level_required at the end of those URLs, you can customize the message to have the user register for free or paying. E.g.:

Code: Select all
<?php

if 
(!isset($_GET['s2member_level_required'])) {
    // Message for someone that didn't arrive from a restricted page, maybe came clicking the link to the Membership Options Page in the navigation.
} elseif ($_GET['s2member_level_required'] === '0') {
    // Ask him to create a free account.
} elseif ($_GET['s2member_level_required'] === '1') {
    // Ask him to get a paid account. If he already has a free account, have him login first so he upgrades it.
}

?>


I hope it helps. :)
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: conditional statement for user level logins?

Postby rwilki » July 27th, 2011, 1:11 am

this looks great!!! does this go on the page with phpexec or in the hacks.php file or functions? sorry have to ask this too, can this be done in shortcode? or does it have to be php? :)
User avatar
rwilki
Registered User
Registered User
 
Posts: 61
Joined: July 22, 2011

Re: conditional statement for user level logins?

Postby Cristián Lávaque » July 27th, 2011, 2:38 am

That's PHP that goes in the Membership Options Page, so yes, you'll need to have Exec PHP installed and use the HTML editor only (don't switch to the Visual one, it'll break your code). https://wordpress.org/extend/plugins/exec-php/

I don't know how to do it with shortcodes, sorry. :|
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: conditional statement for user level logins?

Postby rwilki » July 27th, 2011, 3:05 am

this is terrific! thanks!
User avatar
rwilki
Registered User
Registered User
 
Posts: 61
Joined: July 22, 2011

Re: conditional statement for user level logins?

Postby rwilki » July 27th, 2011, 3:16 am

got the same error...
Parse error: syntax error, unexpected T_FOR in /home/ebrief/public_html/wp-content/plugins/exec-php/includes/runtime.php(42) : eval()&#8217;d code on line 4
User avatar
rwilki
Registered User
Registered User
 
Posts: 61
Joined: July 22, 2011

Re: conditional statement for user level logins?

Postby Cristián Lávaque » July 27th, 2011, 3:18 am

Could you quote here the exact code you used that caused that error, please?
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: conditional statement for user level logins?

Postby rwilki » July 27th, 2011, 3:26 am

I first put this...
<?php

if (!isset($_GET['s2member_level_required'])) {
// Message for someone that didn't arrive from a restricted page, maybe came clicking the link to the Membership Options Page in the navigation.
} elseif ($_GET['s2member_level_required'] === '0') {
// Ask him to create a free account.
} elseif ($_GET['s2member_level_required'] === '1') {
// Ask him to get a paid account. If he already has a free account, have him login first so he upgrades it.
}

?>

but nothing showed up...
User avatar
rwilki
Registered User
Registered User
 
Posts: 61
Joined: July 22, 2011

Re: conditional statement for user level logins?

Postby Cristián Lávaque » July 27th, 2011, 3:35 am

That'd be because those notes I added are PHP comments. Try this:

Code: Select all
<?php if (!isset($_GET['s2member_level_required'])) { ?>
Message for someone that didn't arrive from a restricted page, maybe came clicking the link to the Membership Options Page in the navigation.
<?php } elseif ($_GET['s2member_level_required'] === '0') { ?>
Ask him to create a free account.
<?php } elseif ($_GET['s2member_level_required'] === '1') { ?>
Ask him to get a paid account. If he already has a free account, have him login first so he upgrades it.
<?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: conditional statement for user level logins?

Postby rwilki » July 27th, 2011, 4:06 am

that worked great!!!! i thought there were some syntax errors. is there any way people can know which level protected link they just clicked?

I guess that will have to be from the shortcode I've wrapped. I was hoping not to have to wrap every post in shortcode, but I don't see a way around it...

thanks very much!
User avatar
rwilki
Registered User
Registered User
 
Posts: 61
Joined: July 22, 2011

Re: conditional statement for user level logins?

Postby Cristián Lávaque » July 27th, 2011, 1:59 pm

Glad it worked. :)

rwilki wrote:is there any way people can know which level protected link they just clicked?


What do 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: conditional statement for user level logins?

Postby rwilki » July 27th, 2011, 2:21 pm

this is my only negative comment about your program from the beginning. if I have 2 levels of protected posts, but only one membership options page with both options available, how do people know which level subscription they need?

in other words, if a post about "puppies, trees, and flowers" is level #0 and a post about "planes, trains, and automobiles" is level #1, when they are redirected to the membership options page, it's not obvious which level subscription that referring link was part of. obviously, i could tell from the url having a "=0" or "=1" but it's not as intuitive as I had hoped.

or maybe i'm not getting it...
User avatar
rwilki
Registered User
Registered User
 
Posts: 61
Joined: July 22, 2011

Re: conditional statement for user level logins?

Postby Cristián Lávaque » July 27th, 2011, 3:03 pm

That's why you can use those vars to customize the message he gets in the Membership Options Page.

Now, you seem to want something almost custom to each page the user may not be allowed to. What I can suggest is to use conditionals in each protected post. WP Admin -> s2Member -> API / Scripting -> Simple/Shortcode Conditionals

Wrap the whole post in a condition that checks the right access to it and displays the content or a message if he doesn't have the access. Then each message can be custom to the specific post he's in.

Would that work better for what you want to accomplish?
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 2 guests

cron