latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Need help with conditionals

Home Forums Community Forum Need help with conditionals

This topic contains 14 replies, has 2 voices. Last updated by  Glyn Davidson 3 years ago.

Topic Author Topic
Posted: Monday Dec 30th, 2013 at 7:53 pm #62260
[s2If current_user_is(s2member_level4) OR current_user_is(s2member_level1) OR current_user_is(s2member_level0)] OR current_user_is(s2member_level10) [/s2If]

I have only Pages to protect. Each course is a different level and on its own page.

Level 4= You should only have access to Level 4 course.
Level 0=access to all
Level 1=access to all
Level 10=access to all

Is my conditional code correct? And if so, where does it go? I pasted it at the top of the Level 4 course, but a test customer accessed everything (not from my log-in but theirs).

Thanks for any help.

List Of Topic Replies

Viewing 14 replies - 1 through 14 (of 14 total)
Author Replies
Author Replies
Posted: Tuesday Dec 31st, 2013 at 4:27 am #62287

Try this:

[s2If current_user_is(s2member_level4)]
   Level 4 course goes here
[/s2If]

[s2If current_user_is(s2member_level1) OR current_user_is(s2member_level0) OR current_user_is(s2member_level10)]
   All courses go here
[/s2If]
Posted: Tuesday Dec 31st, 2013 at 2:25 pm #62304

Thanks Glyn. I’m so confused with all this. Please see my notes in parenthesis.

[s2If current_user_is(s2member_level4)] (am I putting this code at the top of the page that has the Level 4 content?
Level 4 course goes here
[/s2If] (then at the bottom of the page, I put this ending?

[s2If current_user_is(s2member_level1) OR current_user_is(s2member_level0) OR current_user_is(s2member_level10)]
All courses go here (each of my courses represents a level and are different pages with its own Level #)
[/s2If]
Posted: Tuesday Dec 31st, 2013 at 2:42 pm #62306

[s2If current_user_is(s2member_level4)] (am I putting this code at the top of the page that has the Level 4 content?
Level 4 course goes here
[/s2If] (then at the bottom of the page, I put this ending?

Yep :)

Then do the same again for each of your other levels/pages. Get that working first and then I’ll tell you how you can improve upon it.

Posted: Tuesday Dec 31st, 2013 at 4:33 pm #62311

Yes! Glyn I got that working on the individual pages. When you click to go to a page you don’t have access to, you see my header and a blank page. Wish it could say something…”If you would like to purchase access to this content, please click here.”

I’m ready to take your next baby steps. Bring it on!

Posted: Tuesday Dec 31st, 2013 at 5:52 pm #62330

Glad you got it working Peggy.

Now add this to the bottom of your level 4 page:

[s2If current_user_is_not(s2member_level4)]
If you would like to purchase access to this content, please click here.
[/s2If]
Posted: Tuesday Dec 31st, 2013 at 6:35 pm #62332

Done! Thanks.

As admin, I can’t see the content from the browser.

Levels 1 and 10 (VIP access), and 0 (my faculty) should be able to see all courses.

Posted: Tuesday Dec 31st, 2013 at 8:15 pm #62334

Here’s what I put at the top of each page, changing the first Level #. Thanks so much for your help!

[s2If current_user_is(s2member_level4) OR current_user_is(s2member_level1) OR current_user_is(s2member_level0) OR current_user_is(s2member_level10)]
Posted: Wednesday Jan 1st, 2014 at 6:28 am #62335

Hi Peggy

Forgive me if I’m wrong, but as far as I can tell, you haven’t yet quite understood something that is fundamental to s2member.

Just like with WordPress default roles, roles in s2Member are incremental.

The default roles in WordPress are:

  • Subscriber
  • Contributor
  • Author
  • Editor
  • Administrator
  • Super Admin

A subscriber has read-only access to a wordpress site.
An author has read access to the site, and can create posts and pages.
An editor can read the site, create posts and pages, and make changes to other people peoples posts/pages.
An Admin, well you know…

Or to put it a better way:

  • A subscriber only has the subscribe capability.
  • A contributor can contribute and subscribe.
  • An author can author, contribute and subscribe.
  • An editor can edit, author, contribute and subscribe.
  • An admin can administrate, edit, author, contribute, and subscribe.
  • A super admin can rule the world.

s2Member is exactly the same:

  • A level 0 user can only do level 0 stuff.
  • A level 1 user can do level 1 stuff and level 0 stuff.
  • A level 2 user can do level 2, level 1 and level 0 stuff.
  • A level 3 user can do level 3, level 2, level 1, and level 0 stuff.
  • A level 4 user can do level 4, level 3, level 2, level 1, and level 0 stuff.

So just like in your scenario, the following shortcode would give level 1, 2, 3, and 4 users access to some content:

[s2If current_user_is(s2member_level1) OR current_user_is(s2member_level2) OR current_user_is(s2member_level3) OR current_user_is(s2member_level4)]
	Some protected content would go here
[/s2If]

However, a much better way, which would achieve exactly the same thing, is this:

[s2If current_user_can(access_s2member_level1)]
	Some protected content would go here
[/s2If]

In this statement, your checking if the current user can access level 1. Yes, level 1, 2, 3 and 4 users can access level 1, and so can admin :)

Recommend you get to grips with all of the following before you go any further.
http://codex.wordpress.org/Roles_and_Capabilities
http://www.s2member.com/kb/roles-caps/
Dashboard -> s2Member -> API / Scripting -> Membership Levels / Labels
Dashboard -> s2Member -> API / Scripting -> Simple / Shortcode Conditionals

P.S. I have a sneaky suspicion that actually, as far s2member is concerned, all of your users will be level 1 and you should be using custom capabilities instead. Suggest you do a batabase backup before going any further.

Posted: Wednesday Jan 1st, 2014 at 6:39 am #62337

Here’s what I put at the top of each page, changing the first Level #. Thanks so much for your help!
[s2If current_user_is(s2member_level4) OR current_user_is(s2member_level1) OR current_user_is(s2member_level0) OR current_user_is(s2member_level10)]

Hello again Peggy. Just after posting I gave it some more thought and although the “correct” way to do it would be with:

[s2If current_user_can(access_s2member_level1)]
	Some protected content would go here
[/s2If]

You could also just extend the shortcode you already have with: “OR current_user_is(administrator)]”
So that you end up with a conditional that looks like this:

[s2If current_user_is(s2member_level4) OR current_user_is(s2member_level1) OR current_user_is(s2member_level0) OR current_user_is(s2member_level10) OR current_user_is(administrator)]
   All courses go here
[/s2If]
Posted: Wednesday Jan 1st, 2014 at 3:37 pm #62348

When non-authorized folks click on a tutorial, I want them to see a message. At the bottom of my page, I put

[s2If current_user_is_not(s2member_level4)] OR current_user_is_not(s2member_level1) OR current_user_is_not(s2member_level0) OR current_user_is_not(s2member_level10) OR current_user_is_not(administrator)]12 Fast Ways to Answer Email in Outlook If you would like to purchase access to this course content, please CLICK HERE. One-time payment for lifetime access. Please refer to the TRAINING tab for course descriptions.
[/s2If]

I need Levels 4, 1, 0, 10, and administrator to NOT see this message. But it’s not working. Please advise. Thanks.

Posted: Wednesday Jan 1st, 2014 at 4:26 pm #62349

Replace ‘OR’ with ‘AND’ :D

Posted: Wednesday Jan 1st, 2014 at 5:42 pm #62355

OK. Got it. I think I’m clicking over here now. Happy New Year and thanks so very much!

Posted: Wednesday Jan 1st, 2014 at 5:53 pm #62356

Glyn, I’m just now seeing your comments on Roles. I was understanding all that on the WordPress side. Been using WP for years, but had to figure out s2Member on my own with Forum and Tech Support’s help. Definitely nobody’s programmer.

This is the code I ended up with, and it looks like it’s working with my test member (who purchased Level 4 course) the way I want it to. He could only access Level 4 and receives the message when clicking to other lessons. As the Administrator, I can now View Page and Preview Changes from the Dashboard.

[s2If current_user_is_not(s2member_level4) AND current_user_is_not(s2member_level1) AND current_user_is_not(s2member_level0) AND current_user_is_not(s2member_level10) AND current_user_is_not(administrator)]12 Fast Ways to Answer Email in Outlook If you would like to purchase access to this course content, please CLICK HERE. One-time payment for lifetime access. Please refer to the TRAINING tab for course descriptions.
[/s2If]

Thanks so much!

Posted: Wednesday Jan 1st, 2014 at 6:20 pm #62359

Glad you got it working. Happy new year :)

Viewing 14 replies - 1 through 14 (of 14 total)

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.