The gform_web_api_capability_post_entries filter allows you to change the capability required to create entries via the web API.
Usage
add_filter('gform_web_api_capability_post_entries', 'change_post_entries_capability'); function change_post_entries_capability($capability) { // Your custom code here return $capability; }
Parameters
- $capability (string): The capability required. Defaults to ‘gravityforms_edit_entries’.
More information
See Gravity Forms Docs: gform_web_api_capability_post_entries
Examples
Change capability to ‘manage_options’
Allow users with the ‘manage_options’ capability to create entries via the web API.
add_filter('gform_web_api_capability_post_entries', 'allow_manage_options_capability'); function allow_manage_options_capability($capability) { return 'manage_options'; }
Set a custom capability
Create a custom capability and use it to control access to the web API.
add_filter('gform_web_api_capability_post_entries', 'set_custom_capability'); function set_custom_capability($capability) { return 'my_custom_capability'; }
Allow multiple capabilities
Allow users with either ‘gravityforms_edit_entries’ or ‘edit_others_posts’ capabilities to create entries via the web API.
add_filter('gform_web_api_capability_post_entries', 'allow_multiple_capabilities'); function allow_multiple_capabilities($capability) { return array('gravityforms_edit_entries', 'edit_others_posts'); }
Restrict access based on user role
Allow only users with the ‘editor’ role to create entries via the web API.
add_filter('gform_web_api_capability_post_entries', 'restrict_access_to_editors'); function restrict_access_to_editors($capability) { $user = wp_get_current_user(); if (in_array('editor', $user->roles)) { return 'gravityforms_edit_entries'; } return ''; }
Restrict access to specific user
Allow only a specific user (by user ID) to create entries via the web API.
add_filter('gform_web_api_capability_post_entries', 'restrict_access_to_specific_user'); function restrict_access_to_specific_user($capability) { $user = wp_get_current_user(); if ($user->ID == 123) { // Replace 123 with the user ID you want to grant access return 'gravityforms_edit_entries'; } return ''; }