Page 1 of 1

Understanding the code...

PostPosted: August 16th, 2011, 2:04 pm
by rwilki
Hi. I'm having a bit of a hard time understanding why the variables aren't working for me.

This is my code. Shouldn't it hide the content from the level not required?
Code: Select all
<?php } elseif ($_GET['s2member_seeking'] === '0') { ?>
By registering now...
<?php } elseif ($_GET['s2member_seeking'] === '1') { ?>
By signing up for Premium Access Pass...
<?php } ?>


I've also tried...
Code: Select all
<?php } elseif ($_GET['s2member_level_required'] === '0') { ?>

and
Code: Select all
<?php } elseif ($_GET['s2member_level_required'] === '1') { ?>


I would like the MOP page to only show the option needed for access to the protected post that was clicked. Making visible ONLY the message for the required level content, not both. To me, it's confusing if both membership options show up when the visitor is just trying to get to one article.

Re: Understanding the code...

PostPosted: August 16th, 2011, 10:18 pm
by RJGonzalez
Code: Select all
<?php } elseif ($_GET['s2member_level_required'] === '1') { ?>


I might be i am wrong but should be this way?

Code: Select all
<?php } elseif { ($_GET['s2member_level_required'] === '1') ?>


Hope that helps

Re: Understanding the code...

PostPosted: August 17th, 2011, 2:25 am
by rwilki
Thanks for this RJ, but it didn't seem to work for me.

Re: Understanding the code...

PostPosted: August 17th, 2011, 3:37 am
by RJGonzalez
I try, hope you get it resolved

Re: Understanding the code...

PostPosted: August 17th, 2011, 4:14 am
by Cristián Lávaque
You start with an elseif, do you have an if before the quoted code? If not, then you should start with an if.

Code: Select all
<?php if ($_GET['s2member_level_req'] == '0') { ?>
By registering now...
<?php } elseif ($_GET['s2member_level_req'] == '1') { ?>
By signing up for Premium Access Pass...
<?php } ?>


I hope that helps. :)

Re: Understanding the code...

PostPosted: August 17th, 2011, 4:49 pm
by rwilki
wow this is tough. i feel like I'm getting closer. when I put this code on my page or in the template for this page, none of the text within the php shows up. So the page is blank.

the "By registering now..." does not appear when seeking level#0 content and "By signing up for Premium Access Pass..." doesn't not appear when seeking level#1 content.

Is there a shortcode for this condition?
Code: Select all
<?php if ($_GET['s2member_seeking'] == '0') { ?>
and this one?
Code: Select all
<?php } elseif ($_GET['s2member_seeking'] == '1') { ?>


The idea is that this is content that appears when people are NOT logged in and they're seeking the designated content...

Re: Understanding the code...

PostPosted: August 17th, 2011, 7:58 pm
by Bruce C
THAT problem is caused by the ===. the '0' and '1' in the single quotes turns the output to a string, which is why it is not working for you. Try taking out the quotes, as I showed you in the PM I sent you, it should work.

Hope that helps!

P.S.
Whenever the current member is NOT redirected from a page, the value defaults to a string of '0', therefore, you HAVE to use the === for the free subscribers, otherwise it will error.

Re: Understanding the code...

PostPosted: August 17th, 2011, 8:25 pm
by rwilki
thanks Ace. Tried every configuration I can think of. Same result. Nothing. So frustrating because I know it's possible and it's probably something simple...

Re: Understanding the code...

PostPosted: August 17th, 2011, 9:04 pm
by Bruce C
s2member_seeking looks like it's the post id. I'm looking at the code somemore, I'll get back to you if I figure it out.

Re: Understanding the code...

PostPosted: August 17th, 2011, 9:13 pm
by rwilki
Thanks Ace. I'm surprised I'm the first person to ask about this. Seems kind of logical to me. Since s2member offers multiple levels of access, how do people know which level to signup for if all the signups fall on one page?

I love the community and plugin. Just wish I could move on...

Re: Understanding the code...

PostPosted: August 17th, 2011, 9:36 pm
by Bruce C
Alright, so I was wrong about the strings...

Here's the solution:

Code: Select all
<?php
if (!isset ($_GET["s2member_level_req"])) {
//do nothing
}
else if ($_GET["s2member_level_req"] === "0")
   {
      echo "You need to be at least a free member to do that.";
   }
else if ($_GET["s2member_level_req"] === "1")
   {
      echo "You need to be level 1";
   }
else {
//do nothing
}
?>


Basically, you have to see if the s2member_level_req is set before you go through the conditionals.

Ace tested and approved!

Re: Understanding the code...

PostPosted: August 17th, 2011, 9:48 pm
by rwilki
ACE!!!!! You are the man! That worked great. The logic in your conditions make sense, I wish I had thought of that.

Sorry but two final questions for you. I'm using "Shortcode Exec PHP" plugin and I had to add the "Exec-PHP" plugin for the most recent code you just posted.

1] Do you think there is a way to use shortcode or to shortcode the php for the condition?
2] More importantly, I was hoping to put a button shortcode inside the echo for people to signup for paid access. I'm guessing that there are restrictions with code inside the echo " ". Do you think I can escape certain code characters or will it just not work?

Thanks SO VERY MUCH for you awesome geniusness!!!
Bob

Re: Understanding the code...

PostPosted: August 17th, 2011, 10:05 pm
by Bruce C
You can escape the php by just adding a ?> whenever you want the php to stop and a <?php whenever it starts again.

Code: Select all
<?php
if (!isset ($_GET["s2member_level_req"]))
   {
?>
<?php
   }
else if ($_GET["s2member_level_req"] === "0")
   {
?>
      You need to be at least a free member to do that.
<?php
   }
else if ($_GET["s2member_level_req"] === "1")
   {
?>
      You need to be level 1
<?php
   }
else
   {
?>
<?php
   }
?>

Re: Understanding the code...

PostPosted: August 17th, 2011, 10:45 pm
by Bruce C
Also, for the Shortcode Execution, I believe that if you just use <? instead of <?php it would work with it? Otherwise, I'm not sure, I've never used that.

Re: Understanding the code...

PostPosted: August 18th, 2011, 3:03 am
by Cristián Lávaque
rwilki wrote:I was hoping to put a button shortcode inside the echo for people to signup for paid access.


You mean something like this?

Code: Select all
<?php if ($_GET['s2member_level_req'] == '0') { ?>

By registering now...

<?php } elseif ($_GET['s2member_level_req'] == '1') { ?>

[s2Member-PayPal-Button ... /]

<?php } ?>