Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
When using Gravity Forms on a client project, you might want the client to be able to view and manipulate form entries, without giving them administrator access. The user_has_cap filter allows us to add capabilities without changing the role in the database. This gist allows users with the editor role to view and manipulate form entries.
<?php
/**
* Add Gravity Forms capabilities
*/
add_filter('user_has_cap',
function( $caps ){
if (! empty( $caps['edit_pages'] ) ) { // user has edit capabilities
$caps['gravityforms_delete_entries'] = true;
$caps['gravityforms_edit_entries'] = true;
$caps['gravityforms_edit_entry_notes'] = true;
$caps['gravityforms_view_entries'] = true;
$caps['gravityforms_view_entry_notes'] = true;
}
return $caps;
});
@tfrommen

I suppose the code should read if ( ... ) { ... }, right? There are some curly braces missing, otherwise you would grant the first capability (i.e., delete_entries) only if the user already has edit capabilities, however, all the other caps are always granted.
I just forked the gist and corrected this, and also refactored the logic a bit.

@mannieschumpert
Owner

Huh, I missed this comment. You're totally right, I'm not sure how I missed that.

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