The gform_akismet_fields Gravity Forms PHP filter allows you to specify the fields that are sent to the Akismet anti-spam service.
Usage
add_filter('gform_akismet_fields', 'set_akismet_fields', 10, 4);
To target a specific form, add the form id after the hook name:
add_filter('gform_akismet_fields_6', 'set_akismet_fields', 10, 4);
Parameters
$akismet_fields(array) – The data to be sent to Akismet in a specific format.$form(Form Object) – The form which created the entry.$entry(Entry Object) – The entry being processed.$action(string) – The action triggering the Akismet request:submit,spam, orham. Since version 2.4.18.5.
More information
See Gravity Forms Docs: gform_akismet_fields
Examples
Override the comment_content
Override the value in the “comment_content” Akismet field so that it is pulled from another field (field ID: 1).
add_filter('gform_akismet_fields', 'set_akismet_fields', 10, 3);
function set_akismet_fields($akismet_fields, $form, $entry) {
$akismet_fields['comment_content'] = rgar($entry, '1');
return $akismet_fields;
}
Provide the IP address
Pass the IP address to Akismet when it has been removed from the entry using the gform_ip_address filter.
add_filter('gform_akismet_fields', 'set_akismet_fields', 10, 3);
function set_akismet_fields($akismet_fields, $form, $entry) {
remove_filter('gform_ip_address', '__return_empty_string');
$ip = GFFormsModel::get_ip();
$akismet_fields['comment_author_IP'] = $ip;
$akismet_fields['user_ip'] = preg_replace('/[^0-9., ]/', '', $ip);
return $akismet_fields;
}
Note: This code should be placed in the functions.php file of your active theme.