Home › Forums › Community Forum › Need help with conditionals
Tagged: conditionals, shortcode
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. 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
Author | Replies |
---|---|
Author | Replies |
Posted: Tuesday Dec 31st, 2013 at 4:27 am #62287 | |
|
|
Try this:
|
|
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? 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 | |
|
|
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:
A subscriber has read-only access to a wordpress site. Or to put it a better way:
s2Member is exactly the same:
So just like in your scenario, the following shortcode would give level 1, 2, 3, and 4 users access to some content:
However, a much better way, which would achieve exactly the same thing, is this:
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. 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 | |
|
|
Hello again Peggy. Just after posting I gave it some more thought and although the “correct” way to do it would be with:
You could also just extend the shortcode you already have with: “OR current_user_is(administrator)]”
|
|
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 :) |
This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.