Geo & IP Blocker for WooCommerce WP Registry grade A. No security issues foundWP RegistryNo security issues foundOpen the reportA
Plugin for wordpress and integration with woocommerce
Install
This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.
Install straight from GitHub with WP-CLI:
wp plugin install https://github.com/jrg-code/geo-and-ip-block/archive/refs/heads/main.zipA powerful WordPress plugin to block or allow access to your WooCommerce store based on geographic location and IP addresses.
Features
- Multi-level Blocking: Block by country, region, or specific IP addresses
- CIDR Support: Block entire IP ranges using CIDR notation
- Multiple Geolocation Providers: Support for MaxMind, IP2Location, and IP-API.com
- Smart Caching: Reduces API calls with WordPress Transients (30-minute cache)
- Local Database Support: Optional offline geolocation using MaxMind GeoLite2
- Priority System: Set rule priorities for fine-grained control
- Detailed Logging: Track all blocked access attempts
- CDN Compatible: Detects real IP behind Cloudflare, proxies, and load balancers
Requirements
- PHP >= 7.4
- WordPress >= 5.8
- WooCommerce >= 6.0
Installation
Basic Installation
- Upload the
geo-ip-blockerfolder to/wp-content/plugins/ - Activate the plugin through the 'Plugins' menu in WordPress
- Configure your API keys in the settings
- Add blocking rules as needed
Installation with Local Database (Recommended)
For better performance and unlimited lookups, install the MaxMind GeoIP2 PHP library:
cd wp-content/plugins/geo-ip-blocker
composer install --no-dev
Then configure your MaxMind license key in the settings to enable automatic database updates.
Geolocation Providers
1. MaxMind GeoIP2 (Recommended)
Pros:
- High accuracy
- Local database option (unlimited lookups)
- Commercial support available
Setup:
- Sign up at MaxMind
- Generate a license key
- Enter your Account ID and License Key in plugin settings
- (Optional) Enable local database for offline lookups
API Pricing: Free tier: 1,000 requests/day
2. IP2Location
Pros:
- Good accuracy
- Multiple data points
- Commercial options
Setup:
- Sign up at IP2Location
- Get your API key
- Enter the key in plugin settings
API Pricing: Free tier: 500 queries/day
3. IP-API.com (Fallback)
Pros:
- Completely free
- No API key required
- Good for testing
Cons:
- Rate limited to 45 requests/minute
- Less accurate than paid services
Setup: Enable in plugin settings (no API key required)
Configuration
API Provider Priority
The plugin tries providers in this order:
- Local MaxMind database (if available)
- MaxMind API
- IP2Location API
- IP-API.com (free fallback)
Cache Settings
Location data is cached for 30 minutes by default. You can modify this:
add_filter( 'geo_ip_blocker_cache_expiration', function() {
return 3600; // 1 hour in seconds
});
Local Database Updates
If using the local MaxMind database, it updates automatically every week. Manual update:
$geolocation = geo_ip_blocker_get_geolocation();
$geolocation->update_local_database();
Usage Examples
Get Current Visitor's Location
// Get full location data
$location = geo_ip_blocker_get_current_location();
echo $location['country_code']; // e.g., "US"
echo $location['country_name']; // e.g., "United States"
echo $location['region']; // e.g., "California"
echo $location['city']; // e.g., "San Francisco"
// Get just the country code
$country = geo_ip_blocker_get_current_country(); // "US"
Get Location for Specific IP
$ip_location = geo_ip_blocker_get_ip_location( '8.8.8.8' );
print_r( $ip_location );
Clear Cache
// Clear cache for specific IP
geo_ip_blocker_clear_geo_cache( '8.8.8.8' );
// Clear all location cache
geo_ip_blocker_clear_geo_cache();
IP Detection
The plugin detects visitor IP addresses with support for:
- Cloudflare:
CF-Connecting-IPheader - Nginx Proxy:
X-Real-IPheader - Load Balancers:
X-Forwarded-Forheader - Standard:
REMOTE_ADDR
Custom IP Detection
add_filter( 'geo_ip_blocker_visitor_ip', function( $ip ) {
// Your custom IP detection logic
return $custom_ip;
});
Blocking Rules
Block by Country
// Add rule via database
$database = geo_ip_blocker_get_database();
$database->add_rule([
'rule_type' => 'country',
'value' => 'CN', // China
'action' => 'block',
'priority' => 10
]);
Block by IP Range (CIDR)
$database->add_rule([
'rule_type' => 'ip',
'value' => '192.168.1.0/24',
'action' => 'block',
'priority' => 5
]);
Allow Specific IPs (Whitelist)
$database->add_rule([
'rule_type' => 'ip',
'value' => '1.2.3.4',
'action' => 'allow', // Overrides blocks
'priority' => 1 // Higher priority
]);
Hooks & Filters
Filters
// Modify cache expiration (default: 1800 seconds)
add_filter( 'geo_ip_blocker_cache_expiration', function( $seconds ) {
return 3600; // 1 hour
});
// Modify blocked message
add_filter( 'geo_ip_blocker_blocked_message', function( $message ) {
return 'Custom blocked message';
});
// Custom blocked template
add_filter( 'geo_ip_blocker_blocked_template', function( $template ) {
return get_template_directory() . '/blocked-page.php';
});
// Add custom geolocation provider
add_filter( 'geo_ip_blocker_query_custom_provider', function( $data, $ip, $provider ) {
if ( $provider === 'my_custom_provider' ) {
// Your API call logic
return $location_data;
}
return $data;
}, 10, 3 );
Actions
// Runs weekly to update local database
add_action( 'geo_ip_blocker_update_database', function() {
// Custom database update logic
});
Performance Optimization
Enable Local Database
- Install composer dependencies
- Configure MaxMind license key
- Enable "Use Local Database" in settings
- Plugin will download GeoLite2-City database automatically
Benefits:
- No API rate limits
- Faster lookups
- Works offline
- Free unlimited queries
Cache Strategy
- Location data cached for 30 minutes
- Rate limiting prevents API abuse
- Automatic fallback between providers
Troubleshooting
Location Not Detected
- Check if visitor IP is public (not local/private)
- Verify API keys are correct
- Check provider rate limits
- Review error logs
Enable Debug Logging
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
Check /wp-content/debug.log for geolocation errors.
Clear All Cache
geo_ip_blocker_clear_geo_cache();
Security
- All IP addresses validated with
filter_var() - API responses sanitized
- Rate limiting prevents abuse
- CSRF protection on admin forms
Development
Run Tests
composer install
./vendor/bin/phpunit
Code Standards
Follows WordPress Coding Standards:
./vendor/bin/phpcs --standard=WordPress geo-ip-blocker/
License
GPL v2 or later
Support
- Issues: GitHub Issues
- Documentation: Plugin Wiki
Changelog
1.0.0
- Initial release
- Multiple geolocation provider support
- Local database option
- Smart caching system
- IP detection with CDN support
Releases
8 releases.
These releases are tags only. The author does not attach a packaged zip, so there are no download counts to report.