Skip to content

Instantly share code, notes, and snippets.

@Shelob9
Last active October 18, 2020 19:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shelob9/60538a46cdb02381570718522f2e85e6 to your computer and use it in GitHub Desktop.
Save Shelob9/60538a46cdb02381570718522f2e85e6 to your computer and use it in GitHub Desktop.
Examples of how to change the capabilities for what kind of user can use Caldera Forms admin via the caldera_forms_manage_cap filter SEE: https://calderaforms.com/doc/caldera_forms_manage_cap/
<?php
/**
Allow users with the editor role to use the Caldera Forms admin screen
*/
add_filter( 'caldera_forms_manage_cap', function( $cap, $context ) {
if( 'admin' == $context ) {
return 'edit_pages';
}
return $cap;
}, 10, 2 );
<?php
add_filter( 'caldera_forms_manage_cap', function() {
return 'delete_posts';
}, 51 );
<?php
/**
Change capability for editting Caldera Forms entires
*/
add_filter( 'caldera_forms_manage_cap', function( $cap, $context ) {
if( 'edit-entry' == $context ) {
//choose a capability of the role you wish to allow
return 'create_posts';
}
return $cap;
}, 10, 2 );
/**
Change capability for deleting Caldera Forms entires
*/
add_filter( 'caldera_forms_manage_cap', function( $cap, $context ) {
if( 'edit-entry' == $context ) {
//choose a capability of the role you wish to allow
return 'edit_pages';
}
return $cap;
}, 10, 2 );
@Aetles
Copy link

Aetles commented Feb 2, 2018

As far as I know there is no capability called create_posts and the example in caldera_forms_manage_cap1.php above does not work.

If you want to use a capability for the editor role I suggest edit_pages instead, like this:

/**
Allow users with the editor role to use the Caldera Forms admin screen
*/
add_filter( 'caldera_forms_manage_cap', function( $cap, $context ) {
	if( 'admin' == $context ) {
		return 'edit_pages';
	}
	return $cap;
}, 10, 2 );

@filnug
Copy link

filnug commented Jun 5, 2020

Allowing editor to create news forms seems not working.

The following code are working only to edit existing forms. But creating a new form is impossible for an editor.

Any ideas ?

/**
Allow users with the editor role to edit the Caldera Forms `
*/
add_filter( 'caldera_forms_manage_cap', function( $cap, $context ) {
	if( 'admin' == $context ) {
		return 'create_posts';
	}
	return $cap;
}, 10, 2 );

/**
Allow users with the editor role to use the Caldera Forms admin screen
*/
add_filter( 'caldera_forms_manage_cap', function( $cap, $context ) {
	if( 'admin' == $context ) {
		return 'edit_pages';
	}
	return $cap;
}, 10, 2 );

@Quigley-Brendan
Copy link

I have the same code, it was working for allowing a custom role (With the same privileges as an editor) to view the Caldera Entries. Not it shows the little number saying x entries, but doesn't show the entires themselves?

@filnug
Copy link

filnug commented Jun 9, 2020

Maybe an editor cannot create a new form, but only view Caldera form entries...
Is there a solution to allow an editor to create an new form ?

@flofigit
Copy link

flofigit commented Sep 11, 2020

Hi,
any news on that? What to do extactly to allow editors to create and clone forms? Would be great if anybody can help.
No luck with the following code in functions.php:

add_filter('caldera_forms_manage_cap', 'my_caldera_caps', 10, 3);
    function my_caldera_caps($cap, $context, $form) {
        $cap = 'manage_caldera_forms';
        return $cap;
    }
/**
    Change capability for editting Caldera Forms entires
     */
    add_filter( 'caldera_forms_manage_cap', function( $cap, $context ) {
        if( 'edit-entry' == $context ) {
            //choose a capability of the role you wish to allow
            return 'create_posts';
        }
 
        return $cap;
    }, 10, 2 );
 
    /**
    Change capability for deleting Caldera Forms entires
     */
    add_filter( 'caldera_forms_manage_cap', function( $cap, $context ) {
        if( 'edit-entry' == $context ) {
            //choose a capability of the role you wish to allow
            return 'edit_pages';
        }
 
        return $cap;
    }, 10, 2 );

@camilolunacom
Copy link

Any luck with this? I haven't been able to resolve this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment