Home › Forums › Quform WordPress › Allow specific roles to view specific forms and their entries
- This topic has 7 replies, 2 voices, and was last updated 1 year, 8 months ago by
Ally.
- AuthorPosts
- June 30, 2023 at 11:44 am #35695
vickydev
ParticipantHello,
I love your plugin and I really do believe that it’s the best one in the market!
I need however one small customisation, which I am hoping can be implemented with a custom hook of some sort.
I basically need to be able to allow a user role to see specific forms and their entries. The plugin is currently allowing all user roles to see all the forms and interact with them depending on their role permissions, so I was wondering if it’s possible to also have the ability to select which forms (based on their form ID) can be viewed by a specific user role.
Many thanks in advance!
VickyJune 30, 2023 at 11:45 am #35696vickydev
ParticipantLooking forward to your response! Have a great day 🙂
July 3, 2023 at 3:59 pm #35698vickydev
ParticipantHello, could someone help me please?
Many thanks!
July 4, 2023 at 9:43 am #35701Ally
Support StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
July 4, 2023 at 1:08 pm #35705vickydev
ParticipantOkay thank you very much, I will try to write something myself to see if I can manage it with a code snippet for now.. any pointers as to what hook to use to get a formID and the user role would be much appreciated!
Many thanks,
VickyJuly 6, 2023 at 10:05 am #35716Ally
Support StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
July 7, 2023 at 6:29 pm #35721vickydev
ParticipantRight, this is quite helpful, I wrote this but it’s not working however I do think im very close, would you be able to help me correct what’s wrong?
function restrict_quform_entry_access($allcaps, $cap, $args) {
// Check if the capability being checked is related to Quform entry access
if ($cap === ‘quform_view_entries’) {
// Get the form ID from the entry ID
$repository = quform(‘repository’);
$form_id = $repository->getFormIdFromEntryId((int) $_GET[‘id’]);// Define the form IDs you want to restrict access to
$restricted_form_ids = array(“1″,”2″,”4”); // Replace with your desired form IDs// Define the user roles that are forbidden to access the forms
$forbidden_roles = array(‘editor, author’); // Replace with your desired roles// Get the current user’s role
$user = wp_get_current_user();
$user_roles = $user->roles;// Check if the user has any forbidden roles and if the form ID matches any restricted form ID
if (in_array($form_id, $restricted_form_ids) && array_intersect($user_roles, $forbidden_roles)) {
// Deny access to the specific form entry
$allcaps[$cap] = false;
}
}return $allcaps;
}
add_filter(‘user_has_cap’, ‘restrict_quform_entry_access’, 10, 3);Many thanks in advance!
July 12, 2023 at 11:46 am #35733Ally
Support StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
- AuthorPosts
- You must be logged in to reply to this topic.