Using Gravity Forms ‘gform_web_api_capability_get_forms’ PHP filter

The gform_web_api_capability_get_forms filter allows you to modify the capability required to access form details via the Gravity Forms web API.

Usage

add_filter('gform_web_api_capability_get_forms', 'change_capability_get_forms');
function change_capability_get_forms($capability) {
    // your custom code here
    return $capability;
}

Parameters

  • $capability (string): The capability required to access form details. Defaults to ‘gravityforms_edit_forms’.

More information

See Gravity Forms Docs: gform_web_api_capability_get_forms

Examples

Change the required capability for getting form details

Change the required capability to ‘manage_options’ instead of the default ‘gravityforms_edit_forms’.

add_filter('gform_web_api_capability_get_forms', 'change_capability_get_forms_to_manage_options');
function change_capability_get_forms_to_manage_options($capability) {
    return 'manage_options';
}

Use a custom capability

Use a custom capability named ‘my_custom_capability’ to access form details.

add_filter('gform_web_api_capability_get_forms', 'change_capability_get_forms_to_custom_capability');
function change_capability_get_forms_to_custom_capability($capability) {
    return 'my_custom_capability';
}

Grant capability to a specific user role

Allow only users with the ‘editor’ role to access form details.

add_filter('gform_web_api_capability_get_forms', 'grant_capability_get_forms_to_editors');
function grant_capability_get_forms_to_editors($capability) {
    if (current_user_can('editor')) {
        return $capability;
    }
    return false;
}

Restrict capability based on user ID

Allow only a specific user (with user ID 5) to access form details.

add_filter('gform_web_api_capability_get_forms', 'grant_capability_get_forms_to_specific_user');
function grant_capability_get_forms_to_specific_user($capability) {
    $user_id = get_current_user_id();
    if ($user_id == 5) {
        return $capability;
    }
    return false;
}

Add additional capability check

Require an additional capability, ‘publish_pages’, to access form details.

add_filter('gform_web_api_capability_get_forms', 'add_additional_capability_get_forms');
function add_additional_capability_get_forms($capability) {
    if (current_user_can('publish_pages')) {
        return $capability;
    }
    return false;
}