Page 1 of 1

MOP Variable Help

PostPosted: April 5th, 2011, 4:37 pm
by dev9833
Hi

First off, big thanks for all the work you've put into developing and support s2 member. Much appreciated.

I'm trying to do something pretty straightforward... I'd like to add a conditional statement to my Member Options page that basically says, if the user has arrived at the Member options page because they are not logged in, echo "you've come to this page because you are not logged in or need to become a member" followed by the rest of the page's content.

Another way to say that is, if the page has been denied, tell the user why, then give them the member options page beneath that explanation.

At this point, I only have one level of membership - paid. I don't have any level 0s, just level 1s.

I tried using
Code: Select all
<?php if($_GET["s2member_level_req"]){ ?><p>The page you were trying to view is protected. Please become a member.</p><?php } ?>
but this didn't seem to work for me .

Do I need to declare a variable first? I'm doing all of this in my template by the way, not using shortcodes or in the HTML editor using php-exec.

You help is appreciated.

Thanks.

Re: MOP Variable Help

PostPosted: April 5th, 2011, 10:20 pm
by Cristián Lávaque
Hi!

OK, so you only have protected content set to Level 1, and that's the only level your members would have?

Then you don't need to check anything, you already know that if they were sent to the Membership Options Page it's because they tried to view Level 1 content and they weren't in a Level 1 account (either don't have it or weren't logged in).

Since you know why they were sent there, there's nothing to figure out and you can simply give the message you see fit. You don't need to check what the required Level is, you know it's 1.

Does that help or are you trying to achieve something I missed? :)

Re: MOP Variable Help

PostPosted: April 5th, 2011, 10:32 pm
by dev9833
But this page is also a general page that talks about my product. I don't want to say "You've accessed this page because you are not a member" if a user has navigated to the page directly. That would be silly. Make sense?

In other words, I *only* want this message to show if they have been redirected to the member options page because they tried to access protected content.

Re: MOP Variable Help

PostPosted: April 5th, 2011, 10:46 pm
by Cristián Lávaque
Yeah, I get that perfectly and I think you're right about it.

Since this is the default page s2Member will send people to because of lack of access, I suggest you just use it for that.

To talk about your product or service you can create another page that isn't tied to this behaviour of s2Member. ;)

Re: MOP Variable Help

PostPosted: April 5th, 2011, 10:50 pm
by dev9833
Hmmmm....but the content is going to be exactly the same.

All I want to know is...

How can I use MOP variables to create the if statement that I outlined in my first post?

IF the user was redirected to the MOP because they were denied access, THEN display X.

Re: MOP Variable Help

PostPosted: April 6th, 2011, 12:27 am
by Cristián Lávaque
Oh ok, I think I now understood what you want. Sorry I didn't get it before.

If you see the MOP Vars documentation WP Admin -> s2Member -> API / Scripting -> Membership Options Page / Variables, you'll notice that one variable is always passed:

`s2member_seeking` is always passed in; it is never excluded.


So you can check for that variable in the $_GET array and if it's there, you know the person got redirected to the Membership Options Page.

The your condition could go like this:

Code: Select all
<?php
if 
(isset($_GET['s2member_seeking']))
    echo '<p>The page you were trying to view is protected. Please become a member.</p>';
?>


I hope that helps you. :)

Re: MOP Variable Help

PostPosted: April 6th, 2011, 1:35 am
by dev9833
Spot on.

Thanks for sticking with me Cristian. You've made my night!

PS This seems like it could be a useful and widely used example that could be included in the MOP vars docs....

Re: MOP Variable Help

PostPosted: April 6th, 2011, 2:48 am
by Cristián Lávaque
Thank you for reporting back. I'm glad I could help! :)

I'll mention your suggestion to Jason, seems like a good idea to document it as an example. In the meantime it'll be available to those who search the forums.

Re: MOP Variable Help

PostPosted: April 7th, 2011, 4:28 pm
by Jason Caldwell
Thanks guys.

@TODO: Add a few simplified examples for MOP Vars to built-in documentation for s2Member.

Re: MOP Variable Help

PostPosted: August 16th, 2011, 1:43 pm
by rwilki
Man, this would be great! Jason, a few examples of MOP variables would be great. I'm not even sure where they go? I understand the code but not the application of where it needs to be...

Re: MOP Variable Help

PostPosted: January 16th, 2012, 5:26 pm
by TotalWeb
So you can check for that variable in the $_GET array and if it's there, you know the person got redirected to the Membership Options Page.


I kind of thought of this solution already, but that will require editing the theme, which I want to avoid. Is it possible to use a shortcode for that? Or, I guess that question is "Does such shortcode exist?". That would most definitely help make it much easier and cleaner way to implement.

Thanks!