Using Gravity Forms ‘gform_rest_api_capability_delete_forms’ PHP action

The gform_rest_api_capability_delete_forms filter allows you to customize the capability required to delete forms via the Gravity Forms REST API v2.

Usage

add_filter('gform_rest_api_capability_delete_forms', 'your_function_name', 10, 2);

Parameters

  • $capability (string) – The capability required. Defaults to ‘gravityforms_delete_forms’.
  • $request (WP_REST_Request) – Full data about the request.

More information

See Gravity Forms Docs: gform_rest_api_capability_delete_forms

Examples

Change the capability required to delete forms

This example changes the required capability to delete forms via the REST API to ‘my_custom_capability’.

add_filter('gform_rest_api_capability_delete_forms', 'get_delete_forms_capability', 10, 2);

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

Allow users with ‘editor’ role to delete forms

This example allows users with the ‘editor’ role to delete forms via the REST API.

add_filter('gform_rest_api_capability_delete_forms', 'allow_editor_delete_forms', 10, 2);

function allow_editor_delete_forms($capability, $request) {
    return 'edit_others_posts';
}

Restrict form deletion to a specific user

This example allows only a specific user with ID 5 to delete forms via the REST API.

add_filter('gform_rest_api_capability_delete_forms', 'restrict_form_deletion', 10, 2);

function restrict_form_deletion($capability, $request) {
    if (get_current_user_id() == 5) {
        return $capability;
    } else {
        return 'do_not_allow';
    }
}

Allow form deletion only for forms with specific IDs

This example allows form deletion via the REST API only for forms with the IDs 1, 2, and 3.

add_filter('gform_rest_api_capability_delete_forms', 'allow_specific_forms_deletion', 10, 2);

function allow_specific_forms_deletion($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 $capability;
    } else {
        return 'do_not_allow';
    }
}

Disable form deletion via the REST API

This example disables form deletion via the REST API.

add_filter('gform_rest_api_capability_delete_forms', 'disable_form_deletion', 10, 2);

function disable_form_deletion($capability, $request) {
    return 'do_not_allow';
}