Allow specific roles to view specific forms and their entries

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

This topic is: not resolved
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #35695
    vickydev
    Participant

    Hello,

    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!
    Vicky

    #35696
    vickydev
    Participant

    Looking forward to your response! Have a great day 🙂

    #35698
    vickydev
    Participant

    Hello, could someone help me please?

    Many thanks!

    #35701
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #35705
    vickydev
    Participant

    Okay 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,
    Vicky

    #35716
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #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!

    #35733
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.
Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy