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™

API/Scripting

s2Member Plugin. A Membership plugin for WordPress®.

API/Scripting

Postby buck415 » August 21st, 2011, 12:50 pm

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
System: Current versions of WordPress Multi Site / BuddyPress / BuddyPress ScholarPress Courseware / s2Member Pro
User avatar
buck415
Registered User
Registered User
 
Posts: 41
Joined: May 19, 2011
Location: New York, NY & San Francisco, CA

Re: API/Scripting

Postby Bruce C » August 21st, 2011, 4:48 pm

Try using the current_user_can() function instead.
~Bruce ( a.k.a. Ace )

If you're interested in a Professional Installation, or Custom Coding Job, you can send your request here.

Proud Supporter of:
The Zeitgeist Movement
and Occupy Everything
User avatar
Bruce C
Experienced User
Experienced User
 
Posts: 337
Joined: July 20, 2011

Re: API/Scripting

Postby buck415 » August 21st, 2011, 8:08 pm

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
System: Current versions of WordPress Multi Site / BuddyPress / BuddyPress ScholarPress Courseware / s2Member Pro
User avatar
buck415
Registered User
Registered User
 
Posts: 41
Joined: May 19, 2011
Location: New York, NY & San Francisco, CA

Re: API/Scripting

Postby Bruce C » August 22nd, 2011, 2:03 pm

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
~Bruce ( a.k.a. Ace )

If you're interested in a Professional Installation, or Custom Coding Job, you can send your request here.

Proud Supporter of:
The Zeitgeist Movement
and Occupy Everything
User avatar
Bruce C
Experienced User
Experienced User
 
Posts: 337
Joined: July 20, 2011


Return to s2Member Plugin

Who is online

Users browsing this forum: No registered users and 2 guests

cron