The gform_rest_api_capability_put_feeds filter allows you to modify the capability required to update feeds using the Gravity Forms REST API v2.
Usage
add_filter('gform_rest_api_capability_put_feeds', 'your_function_name', 10, 2);
Parameters
- $capability (string): The capability required, defaults to ‘gravityforms_edit_forms’.
- $request (WP_REST_Request): Full data about the request.
More information
See Gravity Forms Docs: gform_rest_api_capability_put_feeds
Examples
Change the required capability to update feeds
Allow users with the ‘my_custom_capability’ capability to update feeds through the REST API v2.
add_filter('gform_rest_api_capability_put_feeds', 'get_rest_api_capability_put_feeds', 10, 2); function get_rest_api_capability_put_feeds($capability, $request) { return 'my_custom_capability'; }
Restrict updating feeds based on user role
Restrict feed updates via REST API to users with an ‘editor’ role.
add_filter('gform_rest_api_capability_put_feeds', 'restrict_feed_update_to_editors', 10, 2); function restrict_feed_update_to_editors($capability, $request) { $user = wp_get_current_user(); if (in_array('editor', $user->roles)) { return $capability; } return 'do_not_allow'; }
Allow feed updates only for specific form IDs
Allow feed updates via REST API only for specific form IDs.
add_filter('gform_rest_api_capability_put_feeds', 'allow_specific_forms_feed_update', 10, 2); function allow_specific_forms_feed_update($capability, $request) { $allowed_form_ids = array(1, 3, 5); $form_id = $request->get_param('form_id'); if (in_array($form_id, $allowed_form_ids)) { return $capability; } return 'do_not_allow'; }
Check custom user meta before allowing feed update
Allow feed updates via REST API only if the user has a specific custom meta value.
add_filter('gform_rest_api_capability_put_feeds', 'check_custom_user_meta_for_feed_update', 10, 2); function check_custom_user_meta_for_feed_update($capability, $request) { $user = wp_get_current_user(); $allow_feed_update = get_user_meta($user->ID, 'allow_feed_update', true); if ('yes' === $allow_feed_update) { return $capability; } return 'do_not_allow'; }
Restrict feed updates based on request data
Restrict feed updates via REST API based on specific request data conditions.
add_filter('gform_rest_api_capability_put_feeds', 'restrict_feed_update_based_on_request_data', 10, 2); function restrict_feed_update_based_on_request_data($capability, $request) { $request_data = $request->get_params(); if (isset($request_data['meta']) && isset($request_data['meta']['custom_field']) && 'some_value' === $request_data['meta']['custom_field']) { return $capability; } return 'do_not_allow'; }