Page 1 of 1

conditional statement for user level logins?

PostPosted: July 26th, 2011, 10:32 am
by rwilki
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

Re: conditional statement for user level logins?

PostPosted: July 27th, 2011, 1:03 am
by Cristián Lávaque
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. :)

Re: conditional statement for user level logins?

PostPosted: July 27th, 2011, 1:11 am
by rwilki
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? :)

Re: conditional statement for user level logins?

PostPosted: July 27th, 2011, 2:38 am
by Cristián Lávaque
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. :|

Re: conditional statement for user level logins?

PostPosted: July 27th, 2011, 3:05 am
by rwilki
this is terrific! thanks!

Re: conditional statement for user level logins?

PostPosted: July 27th, 2011, 3:16 am
by rwilki
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

Re: conditional statement for user level logins?

PostPosted: July 27th, 2011, 3:18 am
by Cristián Lávaque
Could you quote here the exact code you used that caused that error, please?

Re: conditional statement for user level logins?

PostPosted: July 27th, 2011, 3:26 am
by rwilki
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...

Re: conditional statement for user level logins?

PostPosted: July 27th, 2011, 3:35 am
by Cristián Lávaque
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 } ?>


Re: conditional statement for user level logins?

PostPosted: July 27th, 2011, 4:06 am
by rwilki
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!

Re: conditional statement for user level logins?

PostPosted: July 27th, 2011, 1:59 pm
by Cristián Lávaque
Glad it worked. :)

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


What do you mean?

Re: conditional statement for user level logins?

PostPosted: July 27th, 2011, 2:21 pm
by rwilki
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...

Re: conditional statement for user level logins?

PostPosted: July 27th, 2011, 3:03 pm
by Cristián Lávaque
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?