Home / Admin / Block IP Addresses From Completing Your Form
Duplicate Snippet

Embed Snippet on Your Site

Block IP Addresses From Completing Your Form

Using this snippet will allow you to add specific IP Addresses from completing your forms.

100+
Code Preview
php
<?php
/**
 * Block form submissions based on IP address
 *
 * @link   https://wpforms.com/developers/how-to-block-ip-addresses-from-completing-your-form/
 * 
 * For support, please visit: https://www.facebook.com/groups/wpformsvip
 */
function wpf_ip_block( $fields, $entry, $form_data ) {
      
    // Get the current users IP address
    $ip_address = wpforms_get_ip();
    // Enter all IP addresses here, separated by a comma
    $blocked_ips = array(
        '129.222.6.90',
        '127.0.0.1',
    );
      
    // Check if the current user IP address is a blocked IP
    if ( in_array( $ip_address, $blocked_ips ) ) {
		
        // Block form submission and print error
        wpforms()->process->errors[ $form_data[ 'id' ] ] [ 'footer' ] = esc_html__( 'Your IP address has been blocked. Please contact the site administrator for further assistance.', 'text-domain' );
    }
}
add_action( 'wpforms_process', 'wpf_ip_block', 10, 3 );

Comments

Add a Comment