Skip Navigation

[Resolved] How can I restrict View to only users of a certain role

This thread is resolved. Here is a description of the problem and solution.

Problem:

Is it possible to create a custom shortcode to get the current user "role" and compare that to a string?
Eg. [get_logged_in_user_role] == "administrator"

Solution:

It is possible with Toolset Access plugin, for example:

https://toolset.com/forums/topic/how-can-i-restrict-view-to-only-users-of-a-certain-role/#post-2055089

Relevant Documentation:

This support ticket is created 2 years, 11 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 4 replies, has 2 voices.

Last updated by PaulS4783 2 years, 11 months ago.

Assisted by: Luo Yang.

Author
Posts
#2054839

I can see that it is possible to create conditional output.
https://toolset.com/documentation/legacy-features/views-plugin/conditional-html-output-in-views/

I can see that it is also possible to create a custom shortcode and evaluate the output against a string.
hidden link

Is it possible to create a custom shortcode to get the current user "role" and compare that to a string?
Eg. [get_logged_in_user_role] == "administrator"

Can you suggest how to write the shortcode which will be evaluated against?

#2054999

Hello,

It is possible with Toolset Access plugin, for example:

[toolset_access role="Administrator" operator="allow"]
Here display something for administrator only
[/toolset_access]
#2055075

Yes, in fact I already tried that.
It works, but it adds superfluous <p> tags to the layout, and generally messes things up.
So I though conditional tags which check for "administrator" role via a short code might work better.

#2055089

Please try to modify it as below, and test again:
[toolset_access role="Administrator" operator="allow" raw="true"]
Here display something for administrator only
[/toolset_access]

The attribute raw="true" should be able to avoid the problem you mentioned above.

#2057309

My issue is resolved now. Thank you!
You can close the ticket.

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