Using Gravity Forms ‘custom_condition_notifications_capability’ PHP filter

The gform_rest_api_capability_post_entries_notifications filter allows you to modify the capability required to re-send notifications via the Gravity Forms REST API v2.

Usage

add_filter('gform_rest_api_capability_post_entries_notifications', '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_post_entries_notifications

Examples

Change the required capability

In this example, we’ll change the required capability for re-sending notifications to ‘my_custom_capability’.

function change_post_entries_notifications_capability($capability, $request) {
    return 'my_custom_capability';
}
add_filter('gform_rest_api_capability_post_entries_notifications', 'change_post_entries_notifications_capability', 10, 2);

Restrict capability based on user role

This example restricts the ability to re-send notifications only to users with the ‘administrator’ role.

function restrict_notifications_capability($capability, $request) {
    if (current_user_can('administrator')) {
        return 'gravityforms_edit_entries';
    }
    return 'do_not_allow';
}
add_filter('gform_rest_api_capability_post_entries_notifications', 'restrict_notifications_capability', 10, 2);

Allow users with ‘publish_posts’ capability

This example allows users with the ‘publish_posts’ capability to re-send notifications.

function allow_publish_posts_capability($capability, $request) {
    return 'publish_posts';
}
add_filter('gform_rest_api_capability_post_entries_notifications', 'allow_publish_posts_capability', 10, 2);

Restrict capability based on a custom condition

This example restricts the capability to re-send notifications based on a custom condition, such as a specific user ID.

function custom_condition_notifications_capability($capability, $request) {
    $user_id = get_current_user_id();
    if ($user_id === 123) {
        return 'gravityforms_edit_entries';
    }
    return 'do_not_allow';
}
add_filter('gform_rest_api_capability_post_entries_notifications', 'custom_condition_notifications_capability', 10, 2);

Allow all logged-in users

This example allows all logged-in users to re-send notifications.

function allow_all_logged_in_users($capability, $request) {
    if (is_user_logged_in()) {
        return 'gravityforms_edit_entries';
    }
    return 'do_not_allow';
}
add_filter('gform_rest_api_capability_post_entries_notifications', 'allow_all_logged_in_users', 10, 2);