The gform_web_api_capability_get_entries Gravity Forms PHP filter allows you to modify the capability required to get entries via the web API.
Usage
add_filter('gform_web_api_capability_get_entries', 'my_custom_capability_function'); function my_custom_capability_function($capability) { // Your custom code here return $capability; }
Parameters
- $capability (string): The capability required, defaults to ‘gravityforms_view_entries’.
More information
See Gravity Forms Docs: gform_web_api_capability_get_entries
Examples
Change capability required to ‘manage_options’
Allow only users with ‘manage_options’ capability to get entries via the web API.
add_filter('gform_web_api_capability_get_entries', 'change_capability_to_manage_options'); function change_capability_to_manage_options($capability) { return 'manage_options'; }
Allow users with ‘edit_posts’ capability
Allow users with the ‘edit_posts’ capability to get entries via the web API.
add_filter('gform_web_api_capability_get_entries', 'allow_edit_posts_capability'); function allow_edit_posts_capability($capability) { return 'edit_posts'; }
Restrict access to a custom capability
Restrict access to a custom capability called ‘view_gf_entries’.
add_filter('gform_web_api_capability_get_entries', 'restrict_to_custom_capability'); function restrict_to_custom_capability($capability) { return 'view_gf_entries'; }
Check for multiple capabilities
Allow users with ‘edit_posts’ or ‘edit_pages’ capabilities to get entries via the web API.
add_filter('gform_web_api_capability_get_entries', 'check_multiple_capabilities'); function check_multiple_capabilities($capability) { if (current_user_can('edit_posts') || current_user_can('edit_pages')) { return $capability; } else { return 'do_not_allow'; } }
Restrict access based on user role
Allow only users with the ‘editor’ role to get entries via the web API.
add_filter('gform_web_api_capability_get_entries', 'restrict_to_editor_role'); function restrict_to_editor_role($capability) { $user = wp_get_current_user(); if (in_array('editor', (array) $user->roles)) { return $capability; } else { return 'do_not_allow'; } }