Skip Navigation

[Resolved] Use conditional display (based on user role) in php template

This support ticket is created 4 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+01:00)

This topic contains 3 replies, has 2 voices.

Last updated by Nigel 4 years, 3 months ago.

Assisted by: Nigel.

Author
Posts
#1488555

Tell us what you are trying to do? Hide sections of a page using Access Conditionally Displayed Text

Is there any documentation that you are following? Just the using shortcodes and API in php templates

So I ended up with something like this:-

<?php echo do_shortcode("[toolset_access role='Team Leader' operator='allow']"); ?>Team Leader Only Content Here<?php echo do_shortcode("[/toolset_access]"); ?>

but this does not work.

Can I use Access in php templates to hide sections based on user role? And if so, how?

Many thanks,
D

#1488675

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Hi David

I haven't tried it, but your code is problematic, you need the entire shortcode and content in a single string that is passed to do_shortcode, e.g.

$protected = "[toolset_access role='Team Leader' operator='allow']Team Leader Only Content Here[/toolset_access]";
echo do_shortcode( $protected );

Do you want to try that?

#1488819

Thanks Nigel, I'll give this a go and get back to you.

Quick Question: Can I put line 1 into the functions file and line 2 in my template?

#1488839

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Probably not, unless $protected is in the global scope, though you can enforce that by including global $protected; in both files before using it.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.