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.
Opens WPIDE on
Code
$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 add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.