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.

Shortcode Conditionals Not Working?

Home Forums Community Forum Shortcode Conditionals Not Working?

This topic contains 7 replies, has 3 voices. Last updated by  Cristián Lávaque 4 years, 9 months ago.

Topic Author Topic
Posted: Tuesday Mar 20th, 2012 at 6:40 pm #8656
Randy King
Username: RandyKing

I had a fairly complex page with conditionals, divs, and php code – it all worked.

Then I added a section of a nested conditional set ([_s2If] … [/_s2If]) and the items in the conditionals did not work.

Finally, I just deleted the entire page and replaced it with this (verbatim)…
==========================================
[s2If current_user_is(s2member_level4)]
STUFF HERE 4
[/s2If]
[s2If current_user_is(s2member_level3)]
STUFF HERE 3
[/s2If]
[s2If current_user_is(s2member_level2)]
STUFF HERE 2
[/s2If]
[s2If current_user_is(s2member_level1)]
STUFF HERE 1
[/s2If]
[s2If current_user_is(s2member_level0)]
STUFF HERE 0
[/s2If]
==========================================

None of the “STUFF HERE x” lines are displaying; however, there appears to be one blank line being output for each conditional I have. If I remove all but one conditional, only one blank line is displayed. But it IS blank!

What’s going on here? Is it the case that there is some browser-side or server-side code or engine that has gotten trashed or put into some weird state? I’ve tried clearing the browser side by clearing browser cache and re-starting – even re-booting the whole system. Nothing – it appears broken.

What the heck am I missing here?

List Of Topic Replies

Viewing 7 replies - 1 through 7 (of 7 total)
Author Replies
Author Replies
Posted: Tuesday Mar 20th, 2012 at 10:33 pm #8676
Eduan
Username: Eduan
Moderator

Hello Randy, thanks for your inquiry.

Are you trying to look at the content at the correct level? In other words, are you looking at the content as a member level 2 for example?

Posted: Wednesday Mar 21st, 2012 at 2:18 am #8695

Hi Randy.

I think I know what you’re talking about. Let’s say that WordPress shortcode parsing is not perfect. I suggest that for complex conditions, or several of them, you use actual PHP code.

Using echoes or goint in and out of PHP, you should be able to control the whitespace problem. And the conditional nesting won’t be an issue either.

In your example, you could use a series of [hilite mono]if[/hilite]s and [hilite mono]elseif[/hilite]s or even a [hilite mono]switch[/hilite].

[hilite path]Dashboard -› s2Member® -› API / Scripting -› Advanced PHP Conditionals[/hilite]
[hilite path]Dashboard -› s2Member® -› API / Scripting -› PHP/API Constants[/hilite]

I hope that helps. :)

Posted: Wednesday Mar 21st, 2012 at 8:25 am #8719
Randy King
Username: RandyKing

Cristián, thanks, and I actually found another solution that I’ll list here for completeness.

I wanted to display a specific image based on the level of the user. My original logic in shortcodes was:

If (user is logged in)
      some happy content here
      If (user is level 4)
          display level 4 picture
      Endif
      If (user is level 3)
          display level 3 picture
      Endif
      .... etc
Endif

So now what I am doing, which works perfectly and is much cleaner (note the img tag)…

[s2If is_user_logged_in()]
	blah blah blah...

	Your membership entitles you to "[s2Get constant="S2MEMBER_CURRENT_USER_ACCESS_LABEL" /]" benefits.

	<img src='[blogurl]images/member-level-[s2Get constant="S2MEMBER_CURRENT_USER_ACCESS_LEVEL" /]-collage.png' title='[s2Get constant="S2MEMBER_CURRENT_USER_FIRST_NAME" /], you are a [s2Get constant="S2MEMBER_CURRENT_USER_ACCESS_LABEL" /]!' \>

<h2><a href="<?php echo wp_logout_url('my-account'); ?>" title="Logout">Click Here to log out and secure your account</a>
[/s2If]

All this requires is that my individual images appear as …/member-level-X-collage.png, where X is the member level number.

Posted: Wednesday Mar 21st, 2012 at 9:23 am #8725
Eduan
Username: Eduan
Moderator

Thanks for the follow-up.

That certainly is cleaner Randy. If you come across trouble with shortcode conditionals, I suggest you try what Cristián said, use PHP conditionals, which you can find under Dashboard -› s2Member® -› API / Scripting -› Advanced PHP Conditionals.

Thanks for updating us, and I’m glad I was able to help. :)

Posted: Wednesday Mar 21st, 2012 at 9:30 am #8727
Randy King
Username: RandyKing

Thanks, Eduán. I like the simplicity of the shortcodes, but certainly can code up the php stuff when need be!

Posted: Wednesday Mar 21st, 2012 at 10:16 am #8733
Eduan
Username: Eduan
Moderator

:)

Posted: Friday Mar 23rd, 2012 at 4:41 pm #8950

All this requires is that my individual images appear as …/member-level-X-collage.png, where X is the member level number.

Lovely. I agree, that’s what I’d have done too.

Glad you solved it. :)

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