The gform_rest_api_capability_put_entries filter allows you to change the capability required to update entries via the Gravity Forms REST API v2.
Usage
add_filter('gform_rest_api_capability_put_entries', 'your_function_name', 10, 2);
Parameters
- $capability (string): The capability required, defaults to ‘gravityforms_edit_entries’.
- $request (WP_REST_Request): Full data about the request.
More information
See Gravity Forms Docs: gform_rest_api_capability_put_entries
Examples
Custom capability for updating entries
Change the required capability for updating entries to ‘my_custom_capability’.
add_filter('gform_rest_api_capability_put_entries', 'get_put_entries_capability', 10, 2); function get_put_entries_capability($capability, $request) { return 'my_custom_capability'; }
Allow users with ‘edit_posts’ capability to update entries
Allow users with the ‘edit_posts’ capability to update entries via the REST API v2.
add_filter('gform_rest_api_capability_put_entries', 'allow_edit_posts_capability', 10, 2); function allow_edit_posts_capability($capability, $request) { return 'edit_posts'; }
Allow specific user role to update entries
Allow only users with the ‘editor’ role to update entries via the REST API v2.
add_filter('gform_rest_api_capability_put_entries', 'allow_editor_role', 10, 2); function allow_editor_role($capability, $request) { $user = wp_get_current_user(); if (in_array('editor', (array) $user->roles)) { return 'gravityforms_edit_entries'; } return 'do_not_allow'; }
Allow specific user ID to update entries
Allow only a user with a specific user ID to update entries via the REST API v2.
add_filter('gform_rest_api_capability_put_entries', 'allow_specific_user', 10, 2); function allow_specific_user($capability, $request) { $allowed_user_id = 5; // Change this to the allowed user ID $current_user_id = get_current_user_id(); if ($current_user_id === $allowed_user_id) { return 'gravityforms_edit_entries'; } return 'do_not_allow'; }
Allow entry updates only if a certain condition is met
Allow entry updates via the REST API v2 only if a custom condition is met (e.g., form ID is greater than 10).
add_filter('gform_rest_api_capability_put_entries', 'allow_conditionally', 10, 2); function allow_conditionally($capability, $request) { $form_id = $request->get_param('form_id'); if ($form_id > 10) { return 'gravityforms_edit_entries'; } return 'do_not_allow'; }