gform_field_container

gform_field_container

DescriptionUsageParametersExamplePlacementSource CodeSince

Description
This filter can be used to modify the markup, the li, used for the field container.
Usage
The base filter which would run for all forms and all fields would be used like so:
1add_filter( 'gform_field_container', 'your_function_name', 10, 6 );
To target a specific form append the form id to the hook name. (format: gform_field_container_FORMID)
1add_filter( 'gform_field_container_10', 'your_function_name', 10, 6 );
To target a specific field append both the form id and the field id to the hook name. (format: gform_field_container_FORMID_FIELDID)
1add_filter( 'gform_field_container_10_3', 'your_function_name', 10, 6 );

Parameters

$field_container string
The field container markup. The placeholder {FIELD_CONTENT} indicates where the markup for the field content should be located.

$field Field Object
The field currently being processed.

$form Form Object
The Form currently being processed.

$css_class string
The CSS classes to be assigned to the li element.

$style string
An empty string as of 1.9.4.4. Was previously used to hold the conditional logic display style.

$field_content string
The markup for the field content (label, description, and inputs etc) which will replace the {FIELD_CONTENT} placeholder.

Example
1234add_filter( 'gform_field_container', 'my_field_container', 10, 6 );function my_field_container( $field_container, $field, $form, $css_class, $style, $field_content ) {    return '

  • {FIELD_CONTENT}
  • ';}
    Placement
    This code should be placed in the functions.php file of your active theme.
    Source Code
    1gf_apply_filters( 'gform_field_container', array( $form['id'], $field->id ), $field_container, $field, $form, $css_class, $style, $field_content );
    This filter is located in GFFormDisplay::get_field() in form_display.php
    Since
    This filter was added in Gravity Forms 1.8.9.

    gform_field_added

    gform_field_added

    DescriptionUsageParametersExamplesSource Code

    Description
    The 「gform_field_added」 JavaScript filter in Gravity Forms fires after a form field is added, either in the Form Editor or programmatically.
    Usage
    12345678

    Parameters

    event Event Object
    Default JS event object.

    form Form Object
    The current form object.

    field Field Object
    The current field object.

    Examples
    This example uses the gform_admin_pre_render filter to load the hook. A message is displayed when the form id is 44 and new fields are added.
    1234567891011121314add_action( 'gform_admin_pre_render', 'pre_render_function' );function pre_render_function( $form ) {    ?>        

    gform_entry_ids_automatic_deletion

    gform_entry_ids_automatic_deletion

    DescriptionUsageParametersExamplesPlacementSinceSource Code

    Description
    Allows the array of entry IDs to be modified before automatically deleting entries according to the personal data retention policy.
    Usage
    add_filter( 'gform_entry_ids_automatic_deletion', 'your_function_name', 10, 1 );

    Parameters

    $entry_ids array
    The array of entry IDs to delete.

    Examples
    add_filter( 'gform_entry_ids_automatic_deletion', 'save_entries', 10, 1 );
    function save_entries( $entry_ids ){
    $delete_ids = array();
    foreach ( $entry_ids as $entry_id )
    {
    $entry = GFFormsModel::get_entry( $entry_id );
    //save entries for form id 74 that are not in the trash
    if ( ! $entry['form_id'] == 74 || $entry['status'] == 'trash' ){
    $delete_ids[] = $entry_id;
    GFCommon::log_debug( 'Deleting entry ' . $entry['id'] );
    }
    else{
    GFCommon::log_debug( 'Not deleting entry ' . $entry['id'] );
    }
    }
    return $delete_ids;
    }

    Placement
    This code should be placed in the functions.php file of your active theme.
    Since
    This filter was added in Gravity Forms version 2.4.
    Source Code
    This filter is located in GF_Personal_Data::cron_task() in includes/class-personal-data.php.

    gform_entry_pre_update

    gform_entry_pre_update

    DescriptionUsageParametersExamplePlacementSinceSource Code

    Description
    Filters the entry before it is updated by an add-on or the API.
    When editing entries in the admin, this filter is only used when updating payment information.
    Usage
    add_filter( 'gform_entry_pre_update', 'your_function_name', 10, 2 );

    Parameters

    $entry Entry Object
    The current entry.

    $original_entry Entry Object
    The original entry, before changes.

    Example
    add_filter( 'gform_entry_pre_update', 'change_entry', 10, 2 );
    function change_entry( $entry, $original_entry ){
    if ( rgar( $entry, '1.3' ) == 'Rocketgenius' || rgar( $entry, '1.6' ) == 'Rocketgenius') {
    $entry['2'] = '[email protected]';
    }
    return $entry;
    }

    Placement
    This code should be placed in the functions.php file of your active theme.
    Since
    This filter was added in Gravity Forms version 1.8.8.
    Source Code
    This filter is located in GFAPI::update_entry() in includes/api.php and
    GF_Forms_Model_Legacy::update_entry() in includes/legacy/forms_model_legacy.php.

    gform_entry_meta_conditional_logic_confirmations

    gform_entry_meta_conditional_logic_confirmations

    DescriptionUsageParametersExamplesPlacementSource Code

    Description
    Enables the entry meta conditional logic filters to be modified on the confirmation edit page.
    Usage
    add_filter( 'gform_entry_meta_conditional_logic_confirmations', 'conditional_logic_filters', 10, 3 );

    Parameters

    $entry_meta array
    The entry meta.

    $form array
    The form object.

    $notification_id string
    The notification id.

    Examples
    This example removes certain entry meta filters depending on the form settings.
    add_filter( 'gform_entry_meta_conditional_logic_confirmations', 'conditional_logic_filters', 10, 3 );
    function conditional_logic_filters( $filters, $form, $id ) {
    $quiz_fields = GFAPI::get_fields_by_type( $form, array( 'quiz' ) );
    if ( empty( $quiz_fields ) )
    return $filters;

    switch ( self::get_form_setting( $form, 'grading' ) ) {
    case "letter" :
    if ( false === isset ( $form['gquizDisplayConfirmationLetter'] ) || $form['gquizDisplayConfirmationLetter'] )
    unset( $filters['gquiz_is_pass'] );
    break;
    case "passfail" :
    if ( false === isset ( $form['gquizDisplayConfirmationPassFail'] ) || $form['gquizDisplayConfirmationPassFail'] )
    unset( $filters['gquiz_grade'] );
    break;
    default:
    unset( $filters['gquiz_grade'] );
    unset( $filters['gquiz_is_pass'] );
    }

    return $filters;
    }

    Placement
    This code should be placed in the functions.php file of your active theme.
    Source Code
    This action hook is located in GFFormSettings::confirmations_edit_page() in form_settings.php.

    gform_entry_info

    gform_entry_info

    DescriptionUsageParametersExamplesSource Code

    Description
    Use this hook to add custom entry information to the Info area on the Entry detail page.
    Usage
    add_action( 'gform_entry_info', 'my_entry_info', 10, 2 );

    Parameters

    $form_id string
    The ID of the form from which the entry was submitted.

    $entry Entry Object
    The current entry.

    Examples
    This very basic example will output 「Hello」 in the Info panel on the Entry Detail view.
    add_action( 'gform_entry_info', 'my_entry_info', 10, 2 );
    function my_entry_info( $form_id, $entry ) {
    echo 'Hello';
    }

    Source Code
    This filter is located in GFEntryDetail::lead_detail_page() in entry_detail.php.

    gform_export_entries_forms

    gform_export_entries_forms

    DescriptionUsageParametersExamplesPlacementSinceSource Code

    Description
    The 「gform_export_entries_forms」 filter in Gravity Forms allows the forms displayed on the Export Entries page to be filtered.
    Usage
    1add_filter( 'gform_export_entries_forms', 'your_function_name', 10, 1 );

    Parameters

    $forms array
    The complete list of forms.

    Examples
    123456add_filter( 'gform_export_entries_forms', 'filter_forms', 10, 1 );function filter_forms( $forms ){    //remove half of the forms    $forms = array_slice( $forms, 0, round( count( $forms ) / 2 ) );    return $forms;}
    Placement
    This code should be placed in the functions.php file of your active theme.
    Since
    This filter was added in Gravity Forms version 2.4.6.16.
    Source Code
    This filter is located in GFExport::export_lead_page() in export.php.

    gform_entry_detail_title

    gform_entry_detail_title

    DescriptionUsageParametersExampleSource Code

    Description
    The 「gform_entry_detail_title」 filter in Gravity Forms allows the title displayed on the entry detail page to be modified.
    Usage
    add_filter( 'gform_entry_detail_title', 'my_function_call' );

    Parameters

    $title string
    The title used.

    $form array
    The form object.

    $entry array
    The entry object

    Example
    add_filter( 'gform_entry_detail_title', function( $title, $form, $entry ) {
    return 'Your new title for entry #' . $entry['id'];
    }, 10, 3 );

    Source Code
    This filter is located in entry_detail.php.

    gform_entry_meta_conditional_logic_notifications

    gform_entry_meta_conditional_logic_notifications

    DescriptionUsageParametersExamplesPlacementSource Code

    Description
    Enables the entry meta conditional logic filters to be modified on the notification edit page.
    Usage
    1add_filter( 'gform_entry_meta_conditional_logic_notifications', 'conditional_logic_filters', 10, 3 );
    Parameters

    $filters array
    The array of filters

    $form Form Object
    The form object

    Examples
    This example removes certain entry meta filters depending on the form settings.
    1234567891011121314151617181920212223add_filter( 'gform_entry_meta_conditional_logic_confirmations', 'conditional_logic_filters', 10, 3 );function conditional_logic_filters($filters, $form, $id) {    $quiz_fields = GFAPI::get_fields_by_type( $form, array( 'quiz' ) );    if (empty($quiz_fields))        return $filters;     switch ( self::get_form_setting( $form, 'grading' ) ) {        case "letter" :            if ( false === isset( $form['gquizDisplayConfirmationLetter'] ) || $form['gquizDisplayConfirmationLetter'] )                unset( $filters['gquiz_is_pass'] );            break;        case "passfail" :            if ( false === isset( $form['gquizDisplayConfirmationPassFail'] ) || $form['gquizDisplayConfirmationPassFail'] )                unset( $filters['gquiz_grade'] );            break;        default:            unset( $filters['gquiz_grade'] );            unset( $filters['gquiz_is_pass'] );    }     return $filters; }
    Placement
    This code should be placed in the functions.php file of your active theme.
    Source Code
    This action hook is located in GFNotification::notification_edit_page() in notification.php

    gform_entry_is_spam

    gform_entry_is_spam

    DescriptionUsageParametersExamplesBasic UsageIntegrate with OOPSpam Anti-SpamIntegrate with PlinoIntegrate with ZeroBounceCheck field values for URLsIP Rate LimitCheck Name Field ValuesIntegrate with ipapi.coIntegrate with iplocate.ioMark as Not Spam for administratorsIntegrate with Komprehend Abusive Content ClassifierIntegrate with PurgoMalum profanity filterIntegrate with Moderation APIIntegrate with Detect Language APIPlacementSource Code

    Description

    The gform_entry_is_spam filter is used to mark entries as spam during form submission.

    Notifications and add-on feeds will NOT be processed for submissions which are marked as spam.

    As the submission completes the default 「Thanks for contacting us! We will get in touch with you shortly.」 message will be displayed instead of the forms configured confirmation. The gform_confirmation filter can be used to change the message.

    Usage

    The following would apply to all forms.

    add_filter( 'gform_entry_is_spam', 'your_function_name', 10, 3 );

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

    add_filter( 'gform_entry_is_spam_6', 'your_function_name' );

    Parameters

    $is_spam bool
    Indicates if the entry is to be marked as spam.

    $form Form Object
    The form currently being processed.

    $entry Entry Object
    The entry being evaluated.

    Examples

    Basic Usage

    add_filter( 'gform_entry_is_spam', 'it_is_all_spam', 10, 3 );
    function it_is_all_spam( $is_spam, $form, $entry ) {
    return true;
    }

    Integrate with OOPSpam Anti-Spam

    This example shows how a field value can be checked by the OOPSpam Anti-Spam plugin.

    add_filter( 'gform_entry_is_spam', 'filter_gform_entry_is_spam_oopspam', 11, 3 );
    function filter_gform_entry_is_spam_oopspam( $is_spam, $form, $entry ) {
    if ( $is_spam || ! function_exists( 'oopspamantispam_call_OOPSpam' ) ) {
    return $is_spam;
    }

    $field_id = '1'; // The ID of the field containing the value to be checked.
    $message = rgar( $entry, $field_id );
    $ip = rgars( $form, 'personalData/preventIP' ) ? GFFormsModel::get_ip() : rgar( $entry, 'ip' );
    $is_spam = ! oopspamantispam_call_OOPSpam( $message, $ip );
    GFCommon::log_debug( __METHOD__ . '(): ' . json_encode( $is_spam ) );

    return $is_spam;
    }

    Integrate with Plino

    This example shows how a field value can be checked by the Plino spam filtering system.

    add_filter( 'gform_entry_is_spam', 'filter_gform_entry_is_spam_plino', 11, 3 );
    function filter_gform_entry_is_spam_plino( $is_spam, $form, $entry ) {
    if ( $is_spam ) {
    return $is_spam;
    }

    $field_id = '1'; // The ID of the field containing the value to be checked.
    $text = rgar( $entry, $field_id );

    $args = array(
    'headers' => array(
    'Content-Type' => 'application/json',
    ),
    'body' => json_encode( array(
    'email_text' => $text,
    ) ),
    );

    $response = wp_remote_post( 'https://plino.herokuapp.com/api/v1/classify/', $args );

    if ( ! is_wp_error( $response ) && wp_remote_retrieve_response_code( $response ) === 200 ) {
    $response_body = wp_remote_retrieve_body( $response );
    GFCommon::log_debug( __METHOD__ . '(): ' . print_r( $response_body, true ) );

    return rgar( json_decode( $response_body, true ), 'email_class' ) === 'spam';
    }

    return false;
    }

    Integrate with ZeroBounce

    This example shows how a field value can be checked by the ZeroBounce Email Validation API.

    add_filter( 'gform_entry_is_spam', 'filter_gform_entry_is_spam_zerobounce', 11, 3 );
    function filter_gform_entry_is_spam_zerobounce( $is_spam, $form, $entry ) {
    if ( $is_spam ) {
    return $is_spam;
    }

    $field_id = '1'; // The ID of the field containing the email address to be checked.
    $email = rgar( $entry, $field_id );

    if ( GFCommon::is_invalid_or_empty_email( $email ) ) {
    return true;
    }

    $ip = rgars( $form, 'personalData/preventIP' ) ? GFFormsModel::get_ip() : rgar( $entry, 'ip' );

    $request_url = add_query_arg(
    array(
    'email' => $email,
    'ip_address' => $ip,
    'api_key' => 'your_api_key_here',
    ),
    'https://api.zerobounce.net/v2/validate'
    );

    $response = wp_remote_get( $request_url );

    if ( ! is_wp_error( $response ) && wp_remote_retrieve_response_code( $response ) === 200 ) {
    $response_body = wp_remote_retrieve_body( $response );
    GFCommon::log_debug( __METHOD__ . '(): ' . print_r( $response_body, true ) );

    return rgar( json_decode( $response_body, true ), 'status' ) !== 'valid';
    }

    return false;
    }

    Check field values for URLs

    This example shows how you can mark a submission as spam if a field value contains a URL. It checks only fields of the following types: Hidden, Single Line Text, Paragraph.

    add_filter( 'gform_entry_is_spam', 'filter_gform_entry_is_spam_urls', 11, 3 );
    function filter_gform_entry_is_spam_urls( $is_spam, $form, $entry ) {
    if ( $is_spam ) {
    return $is_spam;
    }

    $field_types_to_check = array(
    'hidden',
    'text',
    'textarea',
    );

    foreach ( $form['fields'] as $field ) {
    // Skipping fields which are administrative or the wrong type.
    if ( $field->is_administrative() || ! in_array( $field->get_input_type(), $field_types_to_check ) ) {
    continue;
    }

    // Skipping fields which don't have a value.
    $value = $field->get_value_export( $entry );
    if ( empty( $value ) ) {
    continue;
    }

    // If value contains a URL mark submission as spam.
    if ( preg_match( '~(https?|ftp)://S+~', $value ) ) {
    return true;
    }
    }

    return false;
    }

    IP Rate Limit

    This example shows how you can mark a submission as spam if the IP address is the source of multiple submissions.

    add_filter( 'gform_entry_is_spam', 'filter_gform_entry_is_spam_ip_rate_limit', 11, 3 );
    function filter_gform_entry_is_spam_ip_rate_limit( $is_spam, $form, $entry ) {
    if ( $is_spam ) {
    return $is_spam;
    }

    $ip_address = empty( $entry['ip'] ) ? GFFormsModel::get_ip() : $entry['ip'];

    if ( ! filter_var( $ip_address, FILTER_VALIDATE_IP ) ) {
    return true;
    }

    $key = wp_hash( __FUNCTION__ . $ip_address );
    $count = (int) get_transient( $key );

    if ( $count >= 2 ) {
    return true;
    }

    $count ++;
    set_transient( $key, $count, HOUR_IN_SECONDS );

    return false;
    }

    Check Name Field Values

    This example shows how you can mark a submission as spam if the first and last name inputs contain the same value.

    add_filter( 'gform_entry_is_spam', 'filter_gform_entry_is_spam_name_values', 11, 3 );
    function filter_gform_entry_is_spam_name_values( $is_spam, $form, $entry ) {
    if ( $is_spam ) {
    return $is_spam;
    }

    foreach ( $form['fields'] as $field ) {
    // Skipping fields which are administrative or the wrong type.
    if ( $field->is_administrative() || $field->get_input_type() !== 'name' || $field->nameFormat === 'simple' ) {
    continue;
    }

    $first_name = rgar( $entry, $field->id . '.3' );
    $last_name = rgar( $entry, $field->id . '.6' );

    if ( ! empty( $first_name ) && ! empty( $last_name ) && $first_name === $last_name ) {
    return true;
    }
    }

    return false;
    }

    Integrate with ipapi.co

    This example shows how the ipapi.co service can be used to get the country code for the IP address of the form submitter enabling you to mark submissions as spam if they originate from specified countries.

    add_filter( 'gform_entry_is_spam', 'filter_gform_entry_is_spam_ipapi_country', 11, 3 );
    function filter_gform_entry_is_spam_ipapi_country( $is_spam, $form, $entry ) {
    if ( $is_spam ) {
    return $is_spam;
    }

    $ip_address = empty( $entry['ip'] ) ? GFFormsModel::get_ip() : $entry['ip'];
    if ( ! filter_var( $ip_address, FILTER_VALIDATE_IP ) ) {
    return true;
    }

    $response = wp_remote_get( sprintf( 'https://ipapi.co/%s/country/', $ip_address ) );
    if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) !== 200 ) {
    return false;
    }

    $response_country_code = trim( wp_remote_retrieve_body( $response ) );
    if ( empty( $response_country_code ) ) {
    return false;
    }

    // The two letter ISO 3166-1 alpha-2 country codes.
    $country_codes = array( 'CN', 'RU' );

    return in_array( $response_country_code, $country_codes );
    }

    Integrate with iplocate.io

    This example shows how the iplocate.io service can be used to get the country code for the IP address of the form submitter enabling you to mark submissions as spam if they originate from specified countries.

    add_filter( 'gform_entry_is_spam', 'filter_gform_entry_is_spam_iplocate_country', 11, 3 );
    function filter_gform_entry_is_spam_iplocate_country( $is_spam, $form, $entry ) {
    if ( $is_spam ) {
    return $is_spam;
    }

    $ip_address = empty( $entry['ip'] ) ? GFFormsModel::get_ip() : $entry['ip'];
    if ( ! filter_var( $ip_address, FILTER_VALIDATE_IP ) ) {
    return true;
    }

    $response = wp_remote_get( 'https://www.iplocate.io/api/lookup/' . $ip_address );
    if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) !== 200 ) {
    return false;
    }

    $response_body = json_decode( wp_remote_retrieve_body( $response ), true );
    if ( empty( $response_body['country_code'] ) ) {
    return false;
    }

    // The two letter ISO 3166-1 alpha-2 country codes.
    $country_codes = array( 'CN', 'RU' );

    return in_array( $response_body['country_code'], $country_codes );
    }

    Mark as Not Spam for administrators

    This example shows how prevent entries being marked as spam for logged in users with the 『administrator』 role.

    add_filter( 'gform_entry_is_spam', 'gf_admin_is_not_spam', 10, 3 );
    function gf_admin_is_not_spam( $is_spam, $form, $entry ) {
    if ( $is_spam && current_user_can( 'administrator' ) ) {
    // Always not spam for users with administrator role.
    $is_spam = false;
    GFCommon::log_debug( __METHOD__ . '(): Entry marked as not spam for administrator role.' );
    }

    return $is_spam;
    }

    Integrate with Komprehend Abusive Content Classifier

    This example shows how you can use the Komprehend Abusive Content Classifier (ParallelDots Abuse API) to mark submissions as spam if Text or Paragraph field values are abusive or offensive.

    add_filter( 'gform_entry_is_spam', 'filter_gform_entry_is_spam_komprehend', 11, 3 );
    function filter_gform_entry_is_spam_komprehend( $is_spam, $form, $entry ) {
    if ( $is_spam ) {
    return $is_spam;
    }

    $field_types_to_check = array(
    'text',
    'textarea',
    );

    $text_to_check = array();

    foreach ( $form['fields'] as $field ) {
    // Skipping fields which are administrative or the wrong type.
    if ( $field->is_administrative() || ! in_array( $field->get_input_type(), $field_types_to_check ) ) {
    continue;
    }

    // Skipping fields which don't have a value.
    $value = $field->get_value_export( $entry );
    if ( empty( $value ) ) {
    continue;
    }

    $text_to_check[] = $value;
    }

    if ( empty( $text_to_check ) ) {
    return false;
    }

    $response = wp_remote_post( 'https://apis.paralleldots.com/v4/abuse_batch', array(
    'body' => array(
    'text' => json_encode( $text_to_check ),
    'api_key' => 'your_api_key_here',
    ),
    ) );

    if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) !== 200 ) {
    GFCommon::log_debug( __METHOD__ . '(): $response => ' . print_r( $response, true ) );

    return false;
    }

    $results = rgar( json_decode( wp_remote_retrieve_body( $response ), true ), 'abuse' );

    if ( empty( $results ) || ! is_array( $results ) ) {
    GFCommon::log_debug( __METHOD__ . '(): $response => ' . print_r( $response, true ) );

    return false;
    }

    // Add the checked text to the results.
    foreach ( $text_to_check as $key => $text ) {
    if ( ! isset( $results[ $key ] ) ) {
    continue;
    }
    $results[ $key ]['text'] = $text;
    }

    // Define the thresholds the scores will be compared with.
    $abuse_threshold = 0.75;
    $hate_threshold = 0.75;

    foreach ( $results as $result ) {
    // Mark entry as spam if scores are equal to or greater than the thresholds.
    if ( rgar( $result, 'abusive', 0 ) >= $abuse_threshold || rgar( $result, 'hate_speech', 0 ) >= $hate_threshold ) {
    GFCommon::log_debug( __METHOD__ . '(): $results => ' . print_r( $results, true ) );

    return true;
    }
    }

    return false;
    }

    Integrate with PurgoMalum profanity filter

    This example shows how you can use the PurgoMalum profanity filter to mark submissions as spam if Text or Paragraph field values contain words found on the PurgoMalum profanity list.

    add_filter( 'gform_entry_is_spam', 'filter_gform_entry_is_spam_purgomalum', 11, 3 );
    function filter_gform_entry_is_spam_purgomalum( $is_spam, $form, $entry ) {
    if ( $is_spam ) {
    return $is_spam;
    }

    $field_types_to_check = array(
    'text',
    'textarea',
    );

    $text_to_check = array();

    foreach ( $form['fields'] as $field ) {
    // Skipping fields which are administrative or the wrong type.
    if ( $field->is_administrative() || ! in_array( $field->get_input_type(), $field_types_to_check ) ) {
    continue;
    }

    // Skipping fields which don't have a value.
    $value = $field->get_value_export( $entry );
    if ( empty( $value ) ) {
    continue;
    }

    $text_to_check[] = $value;
    }

    if ( empty( $text_to_check ) ) {
    return false;
    }

    $args = array(
    'text' => urlencode( implode( "rn", $text_to_check ) ),
    );

    $response = wp_remote_get( add_query_arg( $args, 'https://www.purgomalum.com/service/containsprofanity' ) );

    if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) !== 200 ) {
    GFCommon::log_debug( __METHOD__ . '(): $response => ' . print_r( $response, true ) );

    return false;
    }

    return wp_remote_retrieve_body( $response ) === 'true';
    }

    Integrate with Moderation API

    This example shows how you can use the Moderation API Toxicity Analyzer to mark submissions as spam if Text or Paragraph field values contain profanity, swearing, racism, threats etc.

    add_filter( 'gform_entry_is_spam', 'filter_gform_entry_is_spam_moderationapi', 11, 3 );
    function filter_gform_entry_is_spam_moderationapi( $is_spam, $form, $entry ) {
    if ( $is_spam ) {
    return $is_spam;
    }

    $field_types_to_check = array(
    'text',
    'textarea',
    );

    $text_to_check = array();

    foreach ( $form['fields'] as $field ) {
    // Skipping fields which are administrative or the wrong type.
    if ( $field->is_administrative() || ! in_array( $field->get_input_type(), $field_types_to_check ) ) {
    continue;
    }

    // Skipping fields which don't have a value.
    $value = $field->get_value_export( $entry );
    if ( empty( $value ) ) {
    continue;
    }

    $text_to_check[] = $value;
    }

    if ( empty( $text_to_check ) ) {
    return false;
    }

    $response = wp_remote_post( 'https://moderationapi.com/api/v1/moderation/text', array(
    'headers' => array(
    'Authorization' => 'Bearer your_api_key_here',
    'Content-Type' => 'application/json',
    ),
    'body' => json_encode( array( 'value' => implode( "rn", $text_to_check ) ) ),
    ) );

    if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) !== 200 ) {
    GFCommon::log_debug( __METHOD__ . '(): $response => ' . print_r( $response, true ) );

    return false;
    }

    $body = json_decode( wp_remote_retrieve_body( $response ), true );
    GFCommon::log_debug( __METHOD__ . '(): $body => ' . print_r( $body, true ) );

    if ( empty( $body['toxicity'] ) || rgar( $body['toxicity'], 'label' ) === 'NEUTRAL' || empty( $body['toxicity']['label_scores'] ) ) {
    return false;
    }

    // Define the thresholds the scores will be compared with; range from 0 (not spam) to 1 (definitely spam).
    $thresholds = array(
    'TOXICITY' => 0.75,
    'PROFANITY' => 0.75,
    'DISCRIMINATION' => 0.75,
    );

    foreach ( $thresholds as $key => $threshold ) {
    // Mark entry as spam if score is equal to or greater than the threshold.
    if ( rgar( $body['toxicity']['label_scores'], $key ) >= $threshold ) {
    return true;
    }
    }

    return false;
    }

    Integrate with Detect Language API

    This example shows how you can use the Detect Language API to mark submissions as spam if Text or Paragraph field values aren』t the specified language, in this case English.

    add_filter( 'gform_entry_is_spam', 'filter_gform_entry_is_spam_detectlanguage', 11, 3 );
    function filter_gform_entry_is_spam_detectlanguage( $is_spam, $form, $entry ) {
    if ( $is_spam ) {
    return $is_spam;
    }

    $field_types_to_check = array(
    'text',
    'textarea',
    );

    $text_to_check = array();

    foreach ( $form['fields'] as $field ) {
    // Skipping fields which are administrative or the wrong type.
    if ( $field->is_administrative() || ! in_array( $field->get_input_type(), $field_types_to_check ) ) {
    continue;
    }

    // Skipping fields which don't have a value.
    $value = $field->get_value_export( $entry );
    if ( empty( $value ) ) {
    continue;
    }

    $text_to_check[] = $value;
    }

    if ( empty( $text_to_check ) ) {
    return false;
    }

    $response = wp_remote_post( 'https://ws.detectlanguage.com/0.2/detect', array(
    'headers' => array(
    'Authorization' => 'Bearer your_api_key_here',
    'Content-Type' => 'application/json',
    ),
    'body' => json_encode( array( 'q' => $text_to_check ) ),
    ) );

    if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) !== 200 ) {
    GFCommon::log_debug( __METHOD__ . '(): $response => ' . print_r( $response, true ) );

    return false;
    }

    $body = json_decode( wp_remote_retrieve_body( $response ), true );
    GFCommon::log_debug( __METHOD__ . '(): $body => ' . print_r( $body, true ) );

    if ( empty( $body['data'] ) || empty( $body['data']['detections'] ) || ! is_array( $body['data']['detections'] ) ) {
    return false;
    }

    foreach ( $body['data']['detections'] as $detections ) {
    foreach ( $detections as $detection ) {
    // Not spam if language is English.
    if ( rgar( $detection, 'language' ) === 'en' && rgar( $detection, 'isReliable' ) ) {
    return false;
    }
    }
    }

    return true;
    }

    Placement

    This code should be placed in the functions.php file of your active theme or a custom functions plugin.

    Source Code

    As of Gravity Forms 2.4.17 this filter is located in GFCommon::is_spam_entry() in common.php. It was previously located in GFFormDisplay::handle_submission() in form_display.php.