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.

using shortcodes in widgets

Home Forums Community Forum using shortcodes in widgets

This topic contains 8 replies, has 3 voices. Last updated by  Raam Dev 4 years, 6 months ago.

Topic Author Topic
Posted: Tuesday Jun 26th, 2012 at 7:58 am #17526

I am trying to use the s2member shortcodes in the text widget.
Like:

[s2If get_user_field("taal_language_sprache")="NL"]
echo "Nederlands menu";
[/s2if]

or

[s2Get user_field("taal_language_sprache") /]

or

<?php
if (get_user_field("taal_language_sprache")="NL")
{
echo "Nederlands menu";
}
?>

Nothing seems to work.
How can I make these codes work. I hear all over the web that PHP is simple to use.
So far it feels like a brick wall to me…
This is fairly simple so it seems, but then this appears to be a misleading assumption.

List Of Topic Replies

Viewing 8 replies - 1 through 8 (of 8 total)
Author Replies
Author Replies
Posted: Tuesday Jun 26th, 2012 at 1:50 pm #17564
Eduan
Username: Eduan
Moderator

Hello Boudewijn,

Try adding a = to it, so it’s == instead of just one.

Hope this helps. :)

Posted: Tuesday Jun 26th, 2012 at 4:18 pm #17575

Tried that already. Doesn’t work either.
If only things could work as promised, >sigh< …

Posted: Wednesday Jun 27th, 2012 at 6:45 am #17640
Raam Dev
Username: Raam
Staff Member

Hi Boudewijn,

I just tried this on my test site and it’s working fine.

Could you try the following and then check if the text shows up when you view the site while you’re logged in?

[s2If !is_user_logged_in()]
    Content for anyone that is logged in, regardless of their Membership Level.
[/s2If]

If that doesn’t work either, then I suspect you have something else going on. There could be another plugin installed that’s causing a conflict with the parsing. You might want to use something like the Plugin Organizer plugin to disable all plugins on a specific page and then try viewing that page and seeing if the widget works. If it does, then you should try re-enabling each of the plugins until you find the conflicting one.

Also, Eduan was correct: In the PHP example you gave, you should be using == (comparison operator) not = (assignment operator).

Posted: Wednesday Jun 27th, 2012 at 12:11 pm #17660

well, FYI. The == did not work, neither did your code… So I have to look at other plug-ins to see what happens.
I suppose you tested it in a widget did you?
Oh boy, this is gonna be a long night…
Tx for the hint anyways

Posted: Thursday Jun 28th, 2012 at 1:44 am #17724

this is what I tested today.
First I used Raam’s code, BTW Raam, I changed the !is_user_logged_in() to is_user_logged_in() so I could see the text if I was logged in.
That works fine. with all widgets in place.

Then I add the following

Testing the language
[s2If get_user_field("taal_language_sprache")=="NL"]
Nederlands
[/s2If]

it actually causes the whole widget to disappear.
Something worse happened as well. I cannot even log in to my own website. I contacted the helpdesk of my isp already, hoping they can stop some weird process that apparently blocks the server.

Posted: Friday Jun 29th, 2012 at 3:00 am #17823
Raam Dev
Username: Raam
Staff Member

Hi Boudewijn,

I suspect your inability to login to the website is only a coincidence; I cannot think of any reason playing with this code would cause that to happen.

With regards to the code itself, I suspect you may be running into a limitation of the [s2If] [/s2If] shortcode (a conditional shortcode that was created by s2Member with a very basic feature set).

To test this theory, coud you try using the following PHP snippet in your Text Widget (if you’re not running the Exec-PHP Plugin, please install it):

<?php
$lang = get_user_field ("taal_language_sprache");
if($lang == "NL") { 
	echo 'Nederlands';
} else {
	echo 'Language: ' . $lang;
}
?>
Posted: Friday Jun 29th, 2012 at 10:12 am #17856

To Thou My Lord I bow deep. exec-php is the magic wand here. It works wonderful!
Thanks so much!

before I forget, it so seemed that the dreaded ISP did some maintenance at the time I was testing. Thus making the site unavailable. Duuuhhh… (OMG, I feel stupid!)

BL

Posted: Saturday Jun 30th, 2012 at 5:42 am #17925
Raam Dev
Username: Raam
Staff Member

Glad to help, Boudewijn. :) I thought that access problem might be a coincidence!

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