Using Gravity Forms ‘gform_akismet_enabled’ PHP action

The gform_akismet_enabled Gravity Forms PHP filter allows you to enable or disable the default Akismet integration either globally or on a per-form basis.

Usage

To use the filter, add the following code:

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

To limit the scope of your function to a specific form, append the form id to the end of the hook name (format: gform_akismet_enabled_FORMID):

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

Parameters

  • $is_enabled (bool): Defaults to true; return false to disable Akismet.
  • $form_id (int): The ID of the form being processed. Since 2.4.18.5.

More information

See Gravity Forms Docs: gform_akismet_enabled

Examples

Disable Akismet Globally

This example will globally disable Akismet integration with Gravity Forms:

add_filter('gform_akismet_enabled', '__return_false');

Disable Akismet for a Specific Form Only

This example will disable Akismet integration with Gravity Forms only for form id 1:

add_filter('gform_akismet_enabled_1', '__return_false');

Using One Function with Multiple Forms

This example disables Akismet for forms with ids 1, 3, and 5:

add_filter('gform_akismet_enabled', function($is_enabled, $form_id) {
    if (in_array($form_id, array(1, 3, 5))) {
        $is_enabled = false;
    }
    return $is_enabled;
}, 10, 2);

Placement

This code should be placed in the functions.php file of your active theme.

Source Code

This filter is located in GFCommon::akismet_enabled() in common.php.