The gform_web_api_capability_put_forms Gravity Forms PHP filter allows you to modify the capability required to update forms via the web API.
Usage
add_filter('gform_web_api_capability_put_forms', 'my_custom_function');
function my_custom_function($capability) {
// your custom code here
return $capability;
}
Parameters
- $capability (string) – The capability required. Defaults to ‘gravityforms_create_form’.
More information
See Gravity Forms Docs: gform_web_api_capability_put_forms
Examples
Change capability to a custom one
Modify the required capability to update forms via the web API to a custom one called ‘my_custom_capability’.
add_filter('gform_web_api_capability_put_forms', 'change_capability_to_custom');
function change_capability_to_custom($capability) {
return 'my_custom_capability';
}
Allow editors to update forms via the web API
Allow users with the ‘edit_others_posts’ capability (editors and administrators) to update forms via the web API.
add_filter('gform_web_api_capability_put_forms', 'allow_editors_update_forms');
function allow_editors_update_forms($capability) {
return 'edit_others_posts';
}
Restrict form updates via the web API to administrators only
Restrict form updates via the web API to users with the ‘manage_options’ capability (administrators).
add_filter('gform_web_api_capability_put_forms', 'restrict_updates_to_admins');
function restrict_updates_to_admins($capability) {
return 'manage_options';
}
Disable form updates via the web API
Disable form updates via the web API by setting the required capability to a non-existent one.
add_filter('gform_web_api_capability_put_forms', 'disable_form_updates');
function disable_form_updates($capability) {
return 'non_existent_capability';
}
Change capability based on user ID
Allow a specific user (e.g., user ID 5) to update forms via the web API, even if they don’t have the default capability.
add_filter('gform_web_api_capability_put_forms', 'allow_specific_user_update_forms');
function allow_specific_user_update_forms($capability) {
$current_user = wp_get_current_user();
if ($current_user->ID == 5) {
return 'read'; // or any other capability the user has
}
return $capability;
}