# Block IP Addresses From Gravity Forms

> Stops Gravity Forms submissions from IP addresses or ranges you list and marks them as spam, without blocking those visitors from reading the site.

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

## Code

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

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

    $ip = (string) rgar( $entry, 'ip' );

    foreach ( $wpide_gf_blocked_ips as $blocked ) {
        $prefix = in_array( substr( $blocked, -1 ), array( '.', ':' ), true );
        if ( $ip === $blocked || ( $prefix && 0 === strpos( $ip, $blocked ) ) ) {
            return true;
        }
    }

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

## Notes

Use exact addresses or prefixes ending in a dot or colon (198.51.100.) for ranges.

## How to use it

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