# Block IP Addresses From WPForms

> Rejects WPForms submissions from IP addresses or ranges you list, such as a persistent spammer, while they can still read the site.

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

## Code

```php
$wpide_wpf_blocked_ips = array( '203.0.113.7', '198.51.100.' );

add_filter( 'wpforms_process_honeypot', function ( $honeypot ) use ( $wpide_wpf_blocked_ips ) {
    if ( $honeypot ) {
        return $honeypot;
    }

    $ip = isset( $_SERVER['REMOTE_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : '';

    foreach ( $wpide_wpf_blocked_ips as $blocked ) {
        $prefix = in_array( substr( $blocked, -1 ), array( '.', ':' ), true );
        if ( $ip === $blocked || ( $prefix && 0 === strpos( $ip, $blocked ) ) ) {
            return 'Submissions from your network are not accepted.';
        }
    }

    return $honeypot;
} );
```

## Notes

Use exact addresses, or prefixes ending in a dot or colon for ranges.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Block IP Addresses From 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/
