Skip Navigation

[Résolu] How can I restrict View to only users of a certain role

Ce fil est résolu. Voici une description du problème et la solution proposée.

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 Il y a 3 années et 6 mois. 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.

Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.

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)

Ce sujet contient 4 réponses, a 2 voix.

Dernière mise à jour par PaulS4783 Il y a 3 années et 6 mois.

Assisté par: Luo Yang.

Auteur
Publications
#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.
lien caché

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.