Using Gravity Forms ‘gform_web_api_capability_get_results’ PHP filter

The gform_web_api_capability_get_results filter allows you to modify the capability required to get form results via the Gravity Forms web API.

Usage

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

Parameters

  • $capability (string): The capability required. Defaults to ‘gravityforms_view_entries’.

More information

See Gravity Forms Docs: gform_web_api_capability_get_results

Examples

Custom capability for getting form results

Change the required capability for getting form results to a custom capability called ‘custom_get_results’.

add_filter('gform_web_api_capability_get_results', 'my_custom_capability_function');
function my_custom_capability_function($capability) {
    return 'custom_get_results';
}

Restrict access to form results for specific user role

Only allow users with the ‘editor’ role to access form results.

add_filter('gform_web_api_capability_get_results', 'editor_capability_function');
function editor_capability_function($capability) {
    return 'edit_others_posts';
}

Grant access to form results for multiple roles

Allow both ‘editor’ and ‘author’ roles to access form results.

add_filter('gform_web_api_capability_get_results', 'multiple_roles_capability_function');
function multiple_roles_capability_function($capability) {
    $user = wp_get_current_user();
    if (in_array('editor', $user->roles) || in_array('author', $user->roles)) {
        return 'gravityforms_view_entries';
    }
    return '';
}

Restrict access to form results based on user ID

Allow only user with ID 5 to access form results.

add_filter('gform_web_api_capability_get_results', 'user_id_capability_function');
function user_id_capability_function($capability) {
    $user = wp_get_current_user();
    if ($user->ID == 5) {
        return 'gravityforms_view_entries';
    }
    return '';
}

Grant access to form results based on custom user meta

Allow users with custom user meta ‘can_view_form_results’ set to ‘yes’ to access form results.

add_filter('gform_web_api_capability_get_results', 'custom_meta_capability_function');
function custom_meta_capability_function($capability) {
    $user = wp_get_current_user();
    if (get_user_meta($user->ID, 'can_view_form_results', true) == 'yes') {
        return 'gravityforms_view_entries';
    }
    return '';
}