Skip Navigation

[Resolved] Conditional display is User Role does not contain a specific role

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 1 reply, has 2 voices.

Last updated by Luo Yang 1 year, 10 months ago.

Assisted by: Luo Yang.

Author
Posts
#2595079
Screen Shot 2023-04-17 at 2.59.43 pm.png

Users are assigned the role of Candidate on registration. Then when purchasing certification they are also assigned the role of ApprovedCandidate.
I have a block I want to display IF they are a Candidate but not if the are also an ApprovedCandidate. (there is also another condition it needs to meet, but that part is working fine)

I have tried all the conditional options I could, but nothing seems to give me the results I want.

#2595179
change-permission.jpg

Hello,

The "Current user role" option is using shortcode [wpv-current-user info="role"] as the condition, but it can only retrieve the main role(Candidate) of current user role.

But in your website one same user can have multiple roles(Candidate and ApprovedCandidate), in this case, you can try with a custom permission, see below sandbox website:
Login URL: hidden link

1) Dashboard-> Toolset-> Access Control-> Custom Roles,
hidden link
Find role "Candidate", and click link "Change permissions", add a custom permission "candidate_capability"
Find role "ApprovedCandidate", and click link "Change permissions", add a custom permission "approvedcandidate_capability"
see my screenshot change-permission.jpg

2) Dashboard-> Toolset-> Settings-> Front-end Content
hidden link
in section "Functions inside conditional evaluations", add WordPress built-in function name: current_user_can

3) Setup the condition as below:
hidden link

  ( ( current_user_can(approvedcandidate_capability) ne '1' ) AND ( current_user_can(candidate_capability) eq '1' ) ) 

And test again.

It works fine in above sandbox website.

More helps:
https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/
https://developer.wordpress.org/reference/functions/current_user_can/