Using Gravity Forms ‘gform_rest_api_capability_get_feeds’ PHP filter

The gform_rest_api_capability_get_feeds filter in Gravity Forms PHP allows you to modify the capability required to get feeds via the REST API v2.

Usage

add_filter('gform_rest_api_capability_get_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_get_feeds

Examples

Change capability required to get feeds

In this example, we change the required capability to get feeds via the REST API to ‘my_custom_capability’.

add_filter('gform_rest_api_capability_get_feeds', 'get_rest_api_capability_get_feeds', 10, 2);

function get_rest_api_capability_get_feeds($capability, $request) {
    return 'my_custom_capability';
}

Require ‘manage_options’ capability

In this example, we change the required capability to ‘manage_options’, so only administrators can get feeds via the REST API.

add_filter('gform_rest_api_capability_get_feeds', 'require_manage_options_capability', 10, 2);

function require_manage_options_capability($capability, $request) {
    return 'manage_options';
}

Check if the user has a specific role

In this example, we change the required capability based on the user role, so only users with the ‘editor’ role can get feeds via the REST API.

add_filter('gform_rest_api_capability_get_feeds', 'check_user_role_capability', 10, 2);

function check_user_role_capability($capability, $request) {
    $user = wp_get_current_user();
    if (in_array('editor', $user->roles)) {
        return 'gravityforms_edit_forms';
    }
    return 'do_not_allow';
}

Allow getting feeds for specific forms only

In this example, we allow users to get feeds only for specific form IDs via the REST API.

add_filter('gform_rest_api_capability_get_feeds', 'allow_specific_forms_only', 10, 2);

function allow_specific_forms_only($capability, $request) {
    $allowed_form_ids = array(1, 2, 3);
    $form_id = $request->get_param('form_id');

    if (in_array($form_id, $allowed_form_ids)) {
        return 'gravityforms_edit_forms';
    }
    return 'do_not_allow';
}

Change capability based on user ID

In this example, we allow only specific user IDs to get feeds via the REST API.

add_filter('gform_rest_api_capability_get_feeds', 'allow_specific_users_only', 10, 2);

function allow_specific_users_only($capability, $request) {
    $allowed_user_ids = array(1, 2, 3);
    $user = wp_get_current_user();

    if (in_array($user->ID, $allowed_user_ids)) {
        return 'gravityforms_edit_forms';
    }
    return 'do_not_allow';
}