Page 1 of 1

API/Scripting

PostPosted: August 21st, 2011, 12:50 pm
by buck415
Hi. I'm having a little trouble with the API/Scripting examples.

I have installed and activated the EXEC-php plugin.

Logged in as Administrator, I created a test page with Level 3 access, and pasted the following:

Code: Select all
<?php if (current_user_is("s2member_level4")){ ?>
    Some premium content for Level 4 Members.
<?php } else if (current_user_is("s2member_level3")){ ?>
    Some premium content for Level 3 Members.
<?php } else if (current_user_is("s2member_level2")){ ?>
    Some premium content for Level 2 Members.
<?php } else if (current_user_is("s2member_level1")){ ?>
    Some premium content for Level 1 Members.
<?php } else if (current_user_is("s2member_level0")){ ?>
    Some content for Free Subscribers.
<?php } else { ?>
    Some public content.
<?php } ?>


When I view the page, I only see the text "Some public content," which is not what I expected to see. If I am logged in as Administrator, won't I see the text for each level?

Here's what I want to accomplish:

A Level 1 user visits a page and sees content assigned to that level.
A Level 2 user visits that same page and sees content assigned to Level 2, and Level 1.
A Level 3 user visits that same page ans sees content assigned to Level 3, and Levels 1 & 2.

Thanks

Re: API/Scripting

PostPosted: August 21st, 2011, 4:48 pm
by Bruce C
Try using the current_user_can() function instead.

Re: API/Scripting

PostPosted: August 21st, 2011, 8:08 pm
by buck415
Good suggestion, thank you.

I replaced current_user_is with current_user_can and this time when viewing the page as Admin, I received the text "Some premium content for Level 4 Members".

Based on that result, I can simply duplicate content within each if/else if command for each respective level and that will accomplish what I need, however, is there a simpler way using the code that would use an "if and" rather than an "else if" (I'm not a programmer)?

Thanks

Re: API/Scripting

PostPosted: August 22nd, 2011, 2:03 pm
by Bruce C
The simplest way to do it would be to use the shortcode format for the conditionals.

Check out Dashboard -> s2Member -> API/Scripting -> Simple/Shortcode Conditionals