0

I understand that Caldera Forms was sunset a while ago, but that there is a version still available for CiviCRM, which I am using.

On WordPress, I have some CiviCRM users that I want to also be able to access the Caldera Forms plugin/admin page, but this would require giving them the manage_options capability which would then allow them access to ALL plugins, which I do not want.

How can I grant them access to Caldera Forms plugin only, without having access to other plugins?

1 Answer 1

1

We can use the caldera forms caldera_forms_manage_cap hook to grant access to specific users without giving them access to any other plugins.

In order for this solution to work, you will need to install two addtional plugins:

MEMBERS PLUGIN

Once Members is installed and activated, go to the Members SETTINGS page and check the Multiple User Roles box "Allow users to be assigned more than a single role."

Go to Members ADD NEW ROLE and create a new role called "Caldera Forms Access". This new role should only have 1 capability granted which is READ, and it should show the role as "caldera_forms_access".

Now add a new Custom Capability to the role called "caldera_forms_manage_options" and make sure GRANT is checked and then save the role.

The saved role should show as "caldera_forms_access" and say that it has 2 Granted capabilities.

CODE SNIPPETS PLUGIN

Once Code Snippets is installed and activated, ADD NEW snippet called Caldera Forms Access and copy and paste the following:

///////////////////////////////////////////////////////////////////////////////
/*** Grant access to Caldera Forms plugin options/admin page by Jeff Sherk ***/
///////////////////////////////////////////////////////////////////////////////
// CF requires manage_options capability in order to access the options/admin page.
// This code will allow users that do not have manage_options capability to access it.
// (1) From the MEMBERS plugin, go to Add New Role and create a role (should have 1 capability of READ=grant) and call the new role "caldera_forms_access".
// (2) Edit this new role and add a custom capability called "caldera_forms_manage_options" (grant must be checked).
// (3) Assign the role to the user you want to have access.
add_filter( 'caldera_forms_manage_cap', function( $cap, $context ) {
    if ( $cap == "manage_options" && is_user_logged_in() ) { // A request to CF that requires manage_options was made.
        $user = wp_get_current_user();
        $roles = (array)$user->roles;
        if ( in_array("caldera_forms_access", $roles) ) { // Does user have the custom role we created that they need to get access?
            $cap = "caldera_forms_manage_options"; // Change the capability to the custom one we added in the custom role.
        } else {
            // If they do not have the custom role, then do nothing. Users that already have the manage_options capability will still be able to access the plugin as before.
        }
    }
    return $cap;
}, 10, 2 );

Make sure to SAVE and ACTIVATE the snippet.

GRANT ACCESS

Now go to any users profile that needs access, under their User Roles section of their profile you can check the Caldera Forms Access box, and save the change, and they should be good to go!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.