The gform_rest_api_capability_put_forms filter allows you to modify the capability required to update forms via the REST API v2 in Gravity Forms.
Usage
add_filter('gform_rest_api_capability_put_forms', 'your_function_name', 10, 2);
Parameters
$capability
(string): The capability required. Defaults to ‘gravityforms_create_form’.$request
(WP_REST_Request): Full data about the request.
More information
See Gravity Forms Docs: gform_rest_api_capability_put_forms
Examples
Change capability to a custom capability
This example changes the required capability to ‘my_custom_capability’:
add_filter('gform_rest_api_capability_put_forms', 'get_put_forms_capability', 10, 2); function get_put_forms_capability($capability, $request) { return 'my_custom_capability'; }
Restrict capability based on user role
This example restricts the capability to users with the ‘editor’ role:
add_filter('gform_rest_api_capability_put_forms', 'restrict_capability_to_editor', 10, 2); function restrict_capability_to_editor($capability, $request) { return current_user_can('editor') ? $capability : ''; }
Allow only admin to update forms
This example restricts the capability to users with the ‘administrator’ role:
add_filter('gform_rest_api_capability_put_forms', 'allow_only_admin', 10, 2); function allow_only_admin($capability, $request) { return current_user_can('administrator') ? $capability : ''; }
Change capability based on a specific form ID
This example changes the capability for a specific form with ID ‘123’:
add_filter('gform_rest_api_capability_put_forms', 'change_capability_for_form', 10, 2); function change_capability_for_form($capability, $request) { $form_id = $request->get_param('id'); return ($form_id == '123') ? 'my_custom_capability' : $capability; }
Disable capability for specific forms
This example disables the capability for forms with IDs ‘456’ and ‘789’:
add_filter('gform_rest_api_capability_put_forms', 'disable_capability_for_forms', 10, 2); function disable_capability_for_forms($capability, $request) { $form_id = $request->get_param('id'); return (in_array($form_id, array('456', '789'))) ? '' : $capability; }