Using Gravity Forms ‘gform_rest_api_capability_post_entries’ PHP action

The gform_rest_api_capability_post_entries filter allows you to modify the capability required to create entries via the Gravity Forms REST API v2.

Usage

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

Examples

Change the required capability to a custom capability

This example changes the required capability to ‘my_custom_capability’ for creating entries via the REST API v2.

add_filter('gform_rest_api_capability_post_entries', 'get_post_entries_capability', 10, 2);

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

Allow users with a specific role to create entries via the REST API

This example allows users with the ‘editor’ role to create entries via the REST API v2.

add_filter('gform_rest_api_capability_post_entries', 'allow_editor_post_entries', 10, 2);

function allow_editor_post_entries($capability, $request) {
    return 'edit_posts';
}

Allow users with a custom capability to create entries

This example allows users with the ‘create_custom_entries’ capability to create entries via the REST API v2.

add_filter('gform_rest_api_capability_post_entries', 'allow_custom_capability_post_entries', 10, 2);

function allow_custom_capability_post_entries($capability, $request) {
    return 'create_custom_entries';
}

Check the user role and allow specific users to create entries

This example allows only administrators and editors to create entries via the REST API v2.

add_filter('gform_rest_api_capability_post_entries', 'allow_specific_roles_post_entries', 10, 2);

function allow_specific_roles_post_entries($capability, $request) {
    $user = wp_get_current_user();

    if (in_array('administrator', $user->roles) || in_array('editor', $user->roles)) {
        return 'gravityforms_edit_entries';
    }

    return '';
}

Allow users with a specific email domain to create entries

This example allows users with an email address from the ‘example.com’ domain to create entries via the REST API v2.

add_filter('gform_rest_api_capability_post_entries', 'allow_email_domain_post_entries', 10, 2);

function allow_email_domain_post_entries($capability, $request) {
    $user = wp_get_current_user();
    $email_domain = substr(strrchr($user->user_email, "@"), 1);

    if ($email_domain === 'example.com') {
        return 'gravityforms_edit_entries';
    }

    return '';
}