The gform_rest_api_capability_post_feeds Gravity Forms PHP filter allows you to modify the capability required to create feeds via the REST API v2.
Usage
add_filter('gform_rest_api_capability_post_feeds', 'your_function_name', 10, 2);
Parameters
- $capability (string): The required capability. Defaults to ‘gravityforms_edit_forms’.
- $request (WP_REST_Request): Full data about the request.
More information
See Gravity Forms Docs: gform_rest_api_capability_post_feeds
Examples
Change the required capability
This example changes the required capability to ‘my_custom_capability’.
add_filter('gform_rest_api_capability_post_feeds', 'get_rest_api_capability_post_feeds', 10, 2); function get_rest_api_capability_post_feeds($capability, $request) { return 'my_custom_capability'; }
Allow users with ‘manage_options’ capability to create feeds
This example allows users with the ‘manage_options’ capability to create feeds via the REST API.
add_filter('gform_rest_api_capability_post_feeds', 'allow_manage_options_capability', 10, 2); function allow_manage_options_capability($capability, $request) { return 'manage_options'; }
Require ‘edit_posts’ capability for a specific form ID
This example requires the ‘edit_posts’ capability for users to create feeds for a specific form with ID 5.
add_filter('gform_rest_api_capability_post_feeds', 'require_edit_posts_capability_for_form', 10, 2); function require_edit_posts_capability_for_form($capability, $request) { $form_id = $request->get_param('form_id'); if ($form_id == 5) { return 'edit_posts'; } return $capability; }
Require different capabilities based on form ID
This example changes the required capability based on the form ID.
add_filter('gform_rest_api_capability_post_feeds', 'require_capability_based_on_form_id', 10, 2); function require_capability_based_on_form_id($capability, $request) { $form_id = $request->get_param('form_id'); if ($form_id == 1) { return 'edit_posts'; } elseif ($form_id == 2) { return 'manage_options'; } return $capability; }
Allow all users to create feeds
This example allows all users to create feeds via the REST API by returning ‘read’ as the required capability.
add_filter('gform_rest_api_capability_post_feeds', 'allow_all_users_to_create_feeds', 10, 2); function allow_all_users_to_create_feeds($capability, $request) { return 'read'; }