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.

Creating Shortcode "AND/OR" Statements

Home Forums Community Forum Creating Shortcode "AND/OR" Statements

This topic contains 2 replies, has 2 voices. Last updated by  Eduan 3 years, 11 months ago.

Topic Author Topic
Posted: Thursday Jan 17th, 2013 at 9:29 pm #37987
Lee Wallis
Username: lithium

Hey guys,

Basically I’m have content which should be accessible with any of 3 custom capabilities.

For example,

Section 1 > Video 1 – Should be accessible by anyone with “section1” OR “section1_video1” OR “all_sections” custom capabilities.

So currently, my code looks like this:

[s2If current_user_can(access_s2member_ccap_section1)]
Protected content goes here...
[/s2If]

[s2If current_user_can(access_s2member_ccap_section1_video1)]
Protected content goes here... (DUPLICATE)
[/s2If]

[s2If current_user_can(access_s2member_ccap_all_sections)]
Protected content goes here... (DUPLICATE)
[/s2If]

Instead of that, is there a way I can have one conditional line? Like…

[s2If current_user_can(access_s2member_ccap_section1)
or (access_s2member_ccap_section1_video1)
or (access_s2member_ccap_all_sections)]
Protected content goes here...
[/s2If]

If so, what is the correct syntax for shortcode?

Thanks for your help!

Lee

List Of Topic Replies

Viewing 2 replies - 1 through 2 (of 2 total)
Author Replies
Author Replies
Posted: Thursday Jan 17th, 2013 at 9:51 pm #37995
Lee Wallis
Username: lithium

Sorry guys, I’m an idiot!

It already explains exactly how to do this here:

/wp-admin/admin.php?page=ws-plugin–s2member-scripting

And what’s even funnier, is I was very close with my first guess… Here’s how you do it:

[s2If current_user_can(access_s2member_ccap_section1)
or current_user_can(access_s2member_ccap_section1_video1)
or current_user_can(access_s2member_ccap_all_sections)]
Protected content goes here...
[/s2If]

Hope this helps someone else!

Lee

Posted: Friday Jan 18th, 2013 at 9:31 pm #38203
Eduan
Username: Eduan
Moderator

Excellent Lee! Thanks for sharing the solution.

Just an FYI, I recommend you use “OR” instead of “or”, since that’s the way it actually is if you use those words in code. :)

– Eduan

Viewing 2 replies - 1 through 2 (of 2 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.