Last active
December 30, 2020 14:51
-
-
Save mannieschumpert/7188426 to your computer and use it in GitHub Desktop.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
}); |
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
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.