Filter view by current user role

By: David TABARY | Asked: 12/21/2022
ForumsCategory: General questionsFilter view by current user role
David TABARY asked 1 year ago
Hi, I'm searching for a way to dynamically filter a view by the current user role. Any idea of how to achieve that ?
1 Answers
Victor Font answered 1 year ago
You need to create custom code for the frm_where_filter hook. If you follow this example, https://formidableforms.com/knowledgebase/frm_where_filter/#kb-stop-user-id-filter-for-admins, instead of using current_user_can(), use one of the role specific WordPress functions: https://developer.wordpress.org/?s=user+role. YOu can also write your own shortcode to retrieve a user role and use the shortcode directly in the view builder filter.
David TABARY replied 1 year ago

Thank you Victor for your help!

Victor Font replied 1 year ago

Here's a little more. I remembered this morning that I have this public snippet to validate against a field against a user role. You can adapt this for your view filter code.
https://formidable-masterminds.com/conditionally-require-fields-by-user-role/

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right