The gform_rest_api_capability_post_entries_notifications filter in Gravity Forms sets the capability required to re-send notifications via the REST API v2.
Usage
Here’s an example of how to use this filter:
add_filter( 'gform_rest_api_capability_post_entries_notifications', 'your_function_name', 10, 2 ); function your_function_name($capability, $request) { // your custom code here return $capability; }
Parameters
- $capability (string) – The capability required. It defaults to ‘gravityforms_edit_entries’.
- $request (WP_REST_Request) – Full data about the request.
More information
Refer to the Gravity Forms Docs: gform_rest_api_capability_post_entries_notifications
This filter was implemented in Gravity Forms 2.4. Its source code can be found in GF_REST_Entry_Notifications_Controller::create_item_permissions_check
in includes/webapi/v2/includes/controllers/class-controller-entry-notifications.php
.
Examples
Example 1 – Modifying the capability
In this example, we modify the default capability to a custom one:
add_filter( 'gform_rest_api_capability_post_entries_notifications', 'modify_capability', 10, 2 ); function modify_capability($capability, $request) { return 'my_custom_capability'; }
Example 2 – Conditional capability
In this example, we set the capability based on a condition in the request:
add_filter( 'gform_rest_api_capability_post_entries_notifications', 'conditional_capability', 10, 2 ); function conditional_capability($capability, $request) { if($request['some_condition']) return 'conditional_capability'; else return $capability; }
Example 3 – User role based capability
This example sets the capability based on the user’s role:
add_filter( 'gform_rest_api_capability_post_entries_notifications', 'role_based_capability', 10, 2 ); function role_based_capability($capability, $request) { $user = wp_get_current_user(); if(in_array('administrator', $user->roles)) return 'admin_capability'; else return $capability; }
Example 4 – Logging the request
In this example, we log the request data:
add_filter( 'gform_rest_api_capability_post_entries_notifications', 'log_request', 10, 2 ); function log_request($capability, $request) { error_log(print_r($request, true)); return $capability; }
Example 5 – Combining capabilities
This example combines multiple capabilities:
add_filter( 'gform_rest_api_capability_post_entries_notifications', 'combine_capabilities', 10, 2 ); function combine_capabilities($capability, $request) { return $capability . ', my_custom_capability'; }