Reply To: Allow specific roles to view specific forms and their entries

Home Forums Quform WordPress Allow specific roles to view specific forms and their entries Reply To: Allow specific roles to view specific forms and their entries

#35721
vickydev
Participant

Right, 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!

Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy