# Use the Comment Blocklist for WPForms

> Blocks WPForms submissions that contain any word, IP address or email from WordPress's Disallowed Comment Keys list, so one blocklist protects comments and forms.

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

## Code

```php
add_filter( 'wpforms_process_honeypot', function ( $honeypot, $fields, $entry ) {
    $keys = trim( (string) get_option( 'disallowed_keys' ) );

    if ( $honeypot || '' === $keys ) {
        return $honeypot;
    }

    $text = isset( $_SERVER['REMOTE_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : '';
    foreach ( (array) ( isset( $entry['fields'] ) ? $entry['fields'] : array() ) as $value ) {
        $text .= ' ' . ( is_array( $value ) ? implode( ' ', $value ) : (string) $value );
    }

    foreach ( preg_split( '/\R/', $keys ) as $word ) {
        $word = trim( $word );
        if ( '' !== $word && false !== stripos( $text, $word ) ) {
            return 'Your submission could not be accepted.';
        }
    }

    return $honeypot;
}, 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 WPForms" 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/
