The gform_rest_api_capability_delete_feeds filter allows you to modify the capability required to delete feeds via the REST API v2 in Gravity Forms.
Usage
add_filter('gform_rest_api_capability_delete_feeds', 'your_function_name', 10, 2);
Parameters
- $capability (string): The capability required to delete feeds. Defaults to ‘gravityforms_edit_forms’.
- $request (WP_REST_Request): Full data about the request.
More information
See Gravity Forms Docs: gform_rest_api_capability_delete_feeds
Examples
Change required capability to delete feeds
Change the required capability to ‘manage_options’ for deleting feeds via REST API.
add_filter('gform_rest_api_capability_delete_feeds', 'change_capability_delete_feeds', 10, 2); function change_capability_delete_feeds($capability, $request) { return 'manage_options'; }
Allow specific user role to delete feeds
Allow users with the ‘editor’ role to delete feeds via REST API.
add_filter('gform_rest_api_capability_delete_feeds', 'allow_editor_delete_feeds', 10, 2); function allow_editor_delete_feeds($capability, $request) { if (current_user_can('editor')) { return 'gravityforms_edit_forms'; } return $capability; }
Prevent feed deletion for a specific form
Prevent feed deletion for a specific form (e.g., form ID 5) via REST API.
add_filter('gform_rest_api_capability_delete_feeds', 'prevent_feed_deletion_specific_form', 10, 2); function prevent_feed_deletion_specific_form($capability, $request) { $feed_id = $request->get_param('feed_id'); $feed = GFAPI::get_feed($feed_id); if ($feed['form_id'] == 5) { return 'do_not_allow'; } return $capability; }
Allow only admins to delete feeds
Allow only users with the ‘administrator’ role to delete feeds via REST API.
add_filter('gform_rest_api_capability_delete_feeds', 'allow_only_admin_delete_feeds', 10, 2); function allow_only_admin_delete_feeds($capability, $request) { if (current_user_can('administrator')) { return 'gravityforms_edit_forms'; } return 'do_not_allow'; }
Restrict feed deletion based on user ID
Allow only a specific user (e.g., user ID 3) to delete feeds via REST API.
add_filter('gform_rest_api_capability_delete_feeds', 'restrict_feed_deletion_by_user', 10, 2); function restrict_feed_deletion_by_user($capability, $request) { $current_user_id = get_current_user_id(); if ($current_user_id == 3) { return 'gravityforms_edit_forms'; } return 'do_not_allow'; }