Published on
Dec 26, 2024
Updated on
Jan 14, 2025
Share

Country-specific IP access control with WPMasterToolKit

The module Disallow Countries IP from WPMasterToolKit allows you to restrict or authorize access to your WordPress site based on users' country of origin. This feature can be useful for security reasons, to limit traffic to certain countries, or to block regions where your services are not available.

In this article, we'll explore this module, its advantages, its use and the technical choices that make it unique.

Which plugin can replace the Disallow Countries IP module?

This module can replace plugins such as :

  • IP Geo Block
  • Wordfence (for geographical restrictions)
  • Country IP Specific Redirect
    These tools often specialize in geographic restrictions, but can be cumbersome and load unnecessary functionality. With WPMasterToolKit, only the activated module is loaded, optimizing performance.
Discover the module : Block access to sensitive WP files

Key features of the Disallow Countries IP module

1. Blocking or authorizing countries

The module allows you to choose from a list of authorized or prohibited countries:

  • If enabled, only users in selected countries will be able to access the site.
  • If disabled, all countries will have access except those specifically listed.

2. Automatic update of the GeoIP database

The module uses MaxMind's GeoLite2 database to identify countries based on IP addresses. This database is updated automatically every month, to guarantee the accuracy of the information.

3. Flexibility and customization

Administrators can easily configure settings from a dedicated menu in the WordPress dashboard. Thanks to an intuitive interface, you can :

  • Add or remove countries from the list.
  • Enable or disable IP access controls.

4. Exception handling

Some requests are automatically exempted to avoid malfunctions:

  • Legitimate bots like Googlebot.
  • Internal AJAX calls or WordPress cron jobs.
  • Facebook and Twitter previews.

5. Customized error interface

In the event of a block, a 403 (access denied) error page is displayed. The messages on this page can be customized using a WordPress filter:

apply_filters( 'wpmastertoolkit/disallow_countries_ip/error_page', $texts );

How to use this module

  1. Module activation
    Go to the WPMasterToolKit interface and activate the module Disallow Countries IP.
  2. Country settings
    • Go to menu Disallow Countries IP in the WPMasterToolKit parameters.
    • Select the countries to be blocked or authorized from a drop-down list.
    • Activate or deactivate the feature as required.
  3. Saving parameters
    Once you have set the restrictions, click on Save changes to apply settings.
  4. Automatic update
    The plugin automatically updates the GeoLite2 database. It checks for updates on the first Tuesday of each month.
Discover the module : Forbid directory listing

Why did we opt for this technical approach?

1. Performance and modularity

This module only loads the resources required when the module is activated, reducing memory footprint and improving loading times.

2. Using GeoLite2

The GeoLite2 database offers reliable IP recognition and is regularly updated. Using the GeoIp2\Database\Readerwe can easily extract geographic information.

3. Parameter caching

Module settings are stored in the WordPress database via the update_option(). This avoids unnecessary repetitive calls.

4. Proxy compatibility

The module incorporates checks to detect users behind proxies such as Cloudflare or Sucuri, guaranteeing accurate IP recognition.

Documentation of the module's custom filters Disallow Countries IP

The module Disallow Countries IP WPMasterToolKit offers several custom filters that allow you to tailor its behavior to your specific needs. Here's a quick guide to two key filters:

1. wpmastertoolkit/disallow_countries_ip/error_page

This filter lets you customize the error page displayed to visitors blocked by the module. By default, an HTTP 403 error page is generated with a standard title and message. With this filter, you can modify the content to reflect your own style or message.

Example of use:

add_filter( 'wpmastertoolkit/disallow_countries_ip/error_page', function( $texts ) {
    $texts['title'] = __( 'Access denied', 'my-theme' );
    $texts['message'] = __( 'Your country cannot access this site at this time.', 'my-theme' );
    return $texts;
});
  • Parameter : $texts is an array containing two keys :
    • title Page title (default : Forbidden Access).
    • message the message displayed (default : You do not have permission to access this page).
  • Expected result The error page will be displayed with the customized title and message.

2. wpmastertoolkit/disallow_countries_ip/cloudflare_networks

This filter lets you modify or add Cloudflare IP address ranges that will be used to detect users' real IPs when a site uses Cloudflare as a proxy. By default, the module uses a predefined list of Cloudflare IP ranges.

Example of use:

add_filter( 'wpmastertoolkit/disallow_countries_ip/cloudflare_networks', function( $networks ) {
    $networks[] = '203.0.113.0/24';
    return $networks;
});
  • Parameter : $networks is an array containing a list of IP address ranges in CIDR format.
  • Expected result The added IP range will be used to identify users behind Cloudflare.

These filters offer considerable flexibility when it comes to adapting the module to your needs. Disallow Countries IP to your needs. Whether it's customizing the user experience or adjusting the management of proxies, these hooks simplify the process of integrating with your WordPress site.

3. wpmastertoolkit/disallow_countries_ip/securi_networks

The hook wpmastertoolkit/disallow_countries_ip/securi_networks allows you to add or modify the IP address ranges used to detect users' real IPs when a site uses the firewall Sucuri as a proxy or CDN. By default, the module includes a predefined list of IP ranges known to Sucuri.

Example of use:

add_filter( 'wpmastertoolkit/disallow_countries_ip/securi_networks', function( $networks ) {
    $networks[] = '192.0.2.0/24'; // Example of IP range
    return $networks;
});

Explanation of parameters :

  • $networks This is a table containing the IP address ranges used by the Sucuri firewall in the format CIDR (example: 192.88.134.0/23).
  • Return expected The updated table should include all the IP address ranges you wish to consider as legitimate Sucuri proxies.
Pro
from
2.50$
/Month
14
Days
Money-back guarantee
risk-free at 100 %!

Conclusion

The module Disallow Countries IP module from WPMasterToolKit offers a simple, effective solution for controlling access to your site based on users' geographical origin. Replacing several complex plugins with a lightweight, modular solution, this module is in line with WPMasterToolKit's philosophy of performance and efficiency.

If you're looking for a fast, secure and easy-to-manage solution to restrict or authorize access to your site, this module is the ideal tool. Take advantage of the customization and flexibility it offers today.

Category
Security
Version
≤ 2.0.0
Type
Pro
More than 18 reviews
+1000
Installations
104
Modules
Pro
from
30.00$
/Year