# Use the Comment Blocklist for Gravity Forms

> Sends Gravity Forms entries to spam when they contain any word, IP address or email from WordPress's Disallowed Comment Keys list, so one blocklist covers comments and forms.

- Type: PHP
- Runs: Run everywhere
- Category: [Forms](https://wpide.com/library/category/forms/)
- Tags: gravity-forms, spam, blocklist
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/gf-disallowed-keys-spam/

## Code

```php
add_filter( 'gform_entry_is_spam', function ( $is_spam, $form, $entry ) {
    if ( $is_spam ) {
        return $is_spam;
    }

    $keys = trim( (string) get_option( 'disallowed_keys' ) );
    if ( '' === $keys ) {
        return false;
    }

    $text = (string) rgar( $entry, 'ip' ) . ' ' . (string) rgar( $entry, 'user_agent' );
    foreach ( $form['fields'] as $field ) {
        $text .= ' ' . (string) $field->get_value_export( $entry );
    }

    foreach ( preg_split( '/\R/', $keys ) as $word ) {
        $word = trim( $word );
        if ( '' !== $word && false !== stripos( $text, $word ) ) {
            return true;
        }
    }

    return false;
}, 10, 3 );
```

## Notes

Manage the list under Settings > Discussion > Disallowed Comment Keys, one entry per line.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Use the Comment Blocklist for Gravity Forms" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
