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™

Nesting WordPress Shortcodes & Conditionals?

s2Member Plugin. A Membership plugin for WordPress®.

Nesting WordPress Shortcodes & Conditionals?

Postby fcandillo » July 12th, 2011, 11:26 am

I am creating a teaser / blocker for certain pages & posts.

So, I will show some teaser content... and if the viewer has 'Level 1' access, then they will be shown the rest of the content. ** those that don't have access to the [pay] Premium content are shown a "blocker" message.

I understand how to do this with Simple Conditionals. However, want to take it a step further.

We are converting from another membership plugin and we already have shortcode tags in our posts written like the following:

Teaser content...
[pay]
Premium content
[/pay]

So far, using the S2Member plugin... I have figured out to do the following

Teaser content...
[s2If current_user_can(access_s2member_level1)]
Premium content...
[/s2If]
[s2If !current_user_can(access_s2member_level1)]
[blockermessage]
[/s2If]

here is my sandbox page example using the Simple Conditionals: https://museuminsider.co.uk/sandbox/sit ... y-tenders/

I created a [blocker] shortcode by adding to my functions.php -- include shortcode.php.... and then my [blocker] message is pulled from the shortcode.php

So the Question is...
Is is possible to duplicate the same using Simple or Advanced PHP conditionals... So that basically the following occurs:

[pay] = [s2If current_user_can(access_s2member_level1)]
[/pay] = [/s2If] [s2If !current_user_can(access_s2member_level1)] [blockermessage] [/s2If]

Then I don't have to change anything in the thousands of posts we have. ;)
User avatar
fcandillo
Registered User
Registered User
 
Posts: 10
Joined: July 12, 2011

Re: Nesting WordPress Shortcodes & Conditionals?

Postby fcandillo » July 12th, 2011, 4:17 pm

For now... since the Simple Conditionals are working properly, i just used the "Search Regex" plugin to search and replace the [pay] shortcode to = [s2If current_user_can(access_s2member_level1)], etc.

but, i would still be interested in knowing how to shorten the shortcode / simple conditionals.
thanks.
User avatar
fcandillo
Registered User
Registered User
 
Posts: 10
Joined: July 12, 2011

Re: Nesting WordPress Shortcodes & Conditionals?

Postby Cristián Lávaque » July 13th, 2011, 2:17 am

If you know how to create new shortcodes, then you could try defining new ones using the PHP conditionals. WP Admin -> s2Member -> API / Scripting -> Using Advanced Conditionals
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Nesting WordPress Shortcodes & Conditionals?

Postby fcandillo » July 13th, 2011, 7:23 am

Yes, this is what I tried with the PHP conditionals. It looks correct. However, it isn't working...
Code: Select all
function pay1_tag() {
   return '<?php if (current_user_is("s2member_level1")){ ?>';
   }

   add_shortcode('pay1', 'pay1_tag');


function pay2_tag() {
   return '<?php } else if (current_user_is("s2member_level0")){ ?>
                   The blocker message...
               <?php } else { ?>
                  The blocker message...
               <?php } ?> ';
   }

   add_shortcode('pay2', 'pay2_tag');


I have the following written in the post:

Teaser content...
[pay1]
Pay Content.......
[pay2]
User avatar
fcandillo
Registered User
Registered User
 
Posts: 10
Joined: July 12, 2011

Re: Nesting WordPress Shortcodes & Conditionals?

Postby Cristián Lávaque » July 13th, 2011, 4:13 pm

I'm not sure you can have the if statement split into separate shortcodes, it doesn't look like that will work. Try searching Google for shortcode conditionals in WordPress and see if you find info on how to achieve it.
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Nesting WordPress Shortcodes & Conditionals?

Postby fcandillo » July 15th, 2011, 7:11 pm

i was able to combine the S2Member simple conditional shortcodes and my [blockermessage] shortcode using the "Embedder" plugin. worked very simple!
User avatar
fcandillo
Registered User
Registered User
 
Posts: 10
Joined: July 12, 2011

Re: Nesting WordPress Shortcodes & Conditionals?

Postby Cristián Lávaque » July 16th, 2011, 12:27 am

Great! Thanks for the update. :)
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010


Return to s2Member Plugin

Who is online

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

cron