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™

Code "If" or "Switch?"

s2Member Plugin. A Membership plugin for WordPress®.

Code "If" or "Switch?"

Postby KirkWard » October 24th, 2010, 9:55 pm

Would this work?

Code: Select all
<?php
switch (current_user_is($i) {
    case s2member_level4:
      Some premium content for Level 4 Members.
      break;
    case s2member_level3:
      Some premium content for Level 3 Members.
      break;
    case s2member_level2:
      Some premium content for Level 2 Members.
      break;
    case s2member_level1:
      Some premium content for Level 1 Members.
      break;
    case s2member_level0:
      Some content for Free Subscribers.
      break;
    default:
      Some public content.;
} ?>
User avatar
KirkWard
Experienced User
Experienced User
 
Posts: 61
Joined: October 22, 2010

Re: Code "If" or "Switch?"

Postby Jason Caldwell » October 25th, 2010, 2:54 am

Hi Kirk. Thanks for the excellent question.

Please try it like this instead:

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 } ?>
Documented in your Dashboard under: s2Member -> API Scripting -> Advanced Conditionals.

Or, if you really like the switch() function, do it this way:
Code: Select all
<?php
switch 
(ws_plugin__s2member_user_access_level ())
    {
        case 4:
            echo 'Some premium content for Level 4 Members.';
            break;
        case 3:
            echo 'Some premium content for Level 3 Members.';
            break;
        case 2:
            echo 'Some premium content for Level 2 Members.';
            break;
        case 1:
            echo 'Some premium content for Level 1 Members.';
            break;
        case 0:
            echo 'Some content for Free Subscribers.';
            break;
        default:
            echo 'Some public content';
    }
?>


If you'd like to do this without using PHP, here is a Shortcode equivalent:
Code: Select all
[s2If current_user_is(s2member_level4)]
   Some premium content for Level 4 Members.
[/s2If]

[s2If current_user_is(s2member_level3)]
   Some premium content for Level 3 Members.
[/s2If]

[s2If current_user_is(s2member_level2)]
   Some premium content for Level 2 Members.
[/s2If]

[s2If current_user_is(s2member_level1)]
   Some premium content for Level 1 Members.
[/s2If]

[s2If current_user_is(s2member_level0)]
   Some content for Free Subscribers.
[/s2If]

[s2If !current_user_can(access_s2member_level0)]
   Some public content.
[/s2If]
Perfect for the WordPress® Visual Editor.
Documented in your Dashboard, under: s2Member -> API Scripting -> Simple Conditionals
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA

Re: Code "If" or "Switch?"

Postby KirkWard » October 25th, 2010, 10:10 am

Found notes on the shortcode after I posted and plan on using that.

Don't like strings of "if" statements as it's too easy for old brains to get confused. We have enough trouble remembering how to turn our computers on.
User avatar
KirkWard
Experienced User
Experienced User
 
Posts: 61
Joined: October 22, 2010

Re: Code "If" or "Switch?"

Postby KirkWard » October 25th, 2010, 12:11 pm

Hi Jason,

Expanding on your suggested usage above, and what I saw in the video about using advanced conditionals, would this work to allow me to show specific content, such as buttons on the member options page?

Code: Select all
    <?php if (is_user_logged_in && current_user_can ("s2member_level4")){ ?>
        Some premium content for Level 4 Members, but not for members of any other level.

    <?php } else if (is_user_logged_in && current_user_can ("s2member_level3")){ ?>
        Some premium content for Level 3 Members, but not for members of any other level.

    <?php } else if (is_user_logged_in && current_user_can ("s2member_level2")){ ?>
        Some premium content for Level 2 Members, but not for members of any other level.

    <?php } else if (is_user_logged_in && current_user_can ("s2member_level1")){ ?>
        Some premium content for Level 1 Members, but not for members of any other level.

    <?php } else if (is_user_logged_in && current_user_can ("s2member_level0")){ ?>
        Some content for Free Subscribers, but not for members of any other level.

    <?php } else { ?>
        Some public content, not for members of any other level.
    <?php } ?>
User avatar
KirkWard
Experienced User
Experienced User
 
Posts: 61
Joined: October 22, 2010

Re: Code "If" or "Switch?"

Postby KirkWard » October 25th, 2010, 6:28 pm

edit: Cancel responding to this ... I was using a script other than EXEC-php. I thought the "Raw HTML" script worked the same way. It didn't.

Thanks anyway.

I'm leaving the message intact, because I put it here and didn't want to delete what was up.

***************************************

Jason,

I copied your code from above and wrapped my "home" page in the public content. Then I logged out and went ot my home page. The content was not displayed. Did I miss something?

What I used ...
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 { ?>
        Content from my home page went here.
    <?php } ?>
User avatar
KirkWard
Experienced User
Experienced User
 
Posts: 61
Joined: October 22, 2010

Re: Code "If" or "Switch?"

Postby Jason Caldwell » October 25th, 2010, 11:17 pm

Awesome. Thanks for reporting back on this.
~ Much appreciated.
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA


Return to s2Member Plugin

Who is online

Users browsing this forum: Google [Bot] and 1 guest

cron