IMPORTANT: This plugin uses external third-party services (ipwho.is and ipapi.co) to determine visitor location. Please review the “External Services” section below for details on data transmission and privacy.
Smart Country Blocker is a powerful WordPress plugin that allows you to restrict access to your website based on visitor location. Block unwanted traffic from specific countries on both frontend pages and backend admin areas.
Key Features:
CRITICAL: If you use a caching plugin (WP Rocket, W3 Total Cache, WP Super Cache, LiteSpeed Cache, etc.), cached pages may bypass country blocking. Follow these configuration steps:
WP Rocket should work automatically as the plugin sets the DONOTCACHEPAGE constant. However, for best results:
/(.*)* (if you want complete blocking to bypass cache)WP Super Cache should work automatically as the plugin sets no-cache headers. To verify:
If using Cloudflare:
yoursite.com/*Always test blocking functionality:
Click Clear All Logs button to remove all historical block records. This cannot be undone.
This plugin relies on third-party GeoIP services to determine visitor location based on their IP address. These services are essential for the plugin’s core functionality.
What it does: Provides IP geolocation data to identify the visitor’s country.
When data is sent: Every time a new visitor accesses your website from an IP address not cached in the last hour. The plugin sends the visitor’s IP address to ipwho.is API.
Data transmitted: Only the visitor’s IP address is sent to the API. No personal information, cookies, or user data is transmitted.
Caching: Results are cached for 1 hour per IP address to minimize API calls and improve performance.
Service provider: ipwho.is is a free IP geolocation service.
Website: https://ipwho.is/
API Documentation: https://ipwho.is/
Terms of Service: https://ipwho.is/ (see website footer for terms)
Privacy Policy: https://ipwho.is/ (see website footer for privacy policy)
What it does: An alternative IP geolocation service you can use instead of ipwho.is. Requires a free API key.
When data is sent: When configured as the primary service, the visitor’s IP address is sent to findip.net on each uncached lookup.
Data transmitted: Only the visitor’s IP address is sent to the API. No personal information, cookies, or user data is transmitted.
Service provider: findip.net is an IP geolocation service using GeoNames / MaxMind data.
API key: A free account and API token are required. Sign up at https://findip.net/ and enter the token in Country Blocker > API Settings.
Website: https://findip.net/
API Documentation: https://findip.net/
Terms of Service: https://findip.net/ (see website for current terms of service)
Privacy Policy: https://findip.net/ (see website for privacy policy information)
Note: By using findip.net, you agree to their terms of service and privacy policy as outlined on their website.
What it does: Acts as a backup geolocation service if the primary service (ipwho.is or findip.net) fails or is unavailable.
When data is sent: Only when the primary service fails to respond or returns an error. The plugin automatically tries ipapi.co as a fallback.
Data transmitted: Only the visitor’s IP address is sent to the API. No personal information, cookies, or user data is transmitted.
Service provider: ipapi.co is a free IP geolocation service with rate limits (30,000 requests/month for free tier).
Terms of Service: https://ipapi.co/terms/
Privacy Policy: https://ipapi.co/privacy/
API Documentation: https://ipapi.co/api/
If you operate in regions with strict privacy laws (GDPR, CCPA, etc.), please be aware:
– IP addresses may be considered personal data under some regulations.
– Consider adding a privacy notice informing users that their IP addresses may be processed for access control.
– The plugin logs blocked access attempts (IP + country + timestamp) in your WordPress database for security purposes.
The plugin creates wp_country_blocker_logs table with the following structure:
– id (Primary Key)
– ip_address (VARCHAR 45)
– country_code (VARCHAR 2)
– country_name (VARCHAR 100)
– blocked_url (TEXT)
– user_agent (TEXT)
– access_type (VARCHAR 20) – ‘frontend’ or ‘backend’
– blocked_at (DATETIME)
plugins_loaded (priority -999999) – Early blocking executionadmin_menu – Register admin pagesadmin_notices – Show cache configuration noticeImportant Note About Unprefixed Constants:
This plugin defines industry-standard cache bypass constants that are intentionally unprefixed and cannot be changed. These constants have been the de-facto standard in the WordPress caching ecosystem for over 15 years and are recognized by virtually all caching plugins and CDN services.
Why these constants MUST remain unprefixed:
These constants are NOT WordPress core constants. They are industry standards established by the caching plugin ecosystem. WP Rocket, LiteSpeed Cache, W3 Total Cache, WP Super Cache, and dozens of other caching/CDN plugins specifically check for these exact constant names.
Prefixing these constants (e.g., changing DONOTCACHEPAGE to WPCB_DONOTCACHEPAGE) would break compatibility with all major caching plugins, rendering the blocking functionality useless on cached sites.
Constants used for cache bypass (when blocking visitors):
DONOTCACHEPAGE – Prevents page caching (WP Rocket, LiteSpeed Cache, W3 Total Cache, WP Super Cache)DONOTCACHEDB – Prevents database query caching (W3 Total Cache)DONOTMINIFY – Prevents JS/CSS minification (Autoptimize, WP Rocket, Fast Velocity Minify)DONOTCDN – Prevents CDN URL rewriting (CDN Enabler, W3 Total Cache CDN module)DONOTCACHEOBJECT – Prevents object caching (LiteSpeed Cache, W3 Total Cache)These constants are set ONLY when a visitor is being blocked (403 response), not globally. They signal to caching plugins: “Do not cache this specific request.”
References:
– WP Rocket Documentation: https://docs.wp-rocket.me/article/61-disable-page-caching
– LiteSpeed Cache Documentation: https://docs.litespeedtech.com/lscache/lscwp/cache/#do-not-cache-constants
This is an accepted exception to WordPress naming conventions and is properly documented in the code with phpcs ignore comments.
For support, bug reports, or feature requests, please contact the developer.
This plugin logs IP addresses and country information for security purposes. Ensure compliance with GDPR/privacy laws in your jurisdiction. Consider adding a privacy notice to inform users that their IP addresses may be logged if they attempt to access from blocked countries.