| 开发者 | honeill |
|---|---|
| 更新时间 | 2026年11月15日 04:41 |
| PHP版本: | 7.4 及以上 |
| WordPress版本: | 7.1 |
| 版权: | GPLv2 or later |
| 版权网址: | 版权信息 |
GB) from their IP address using MaxMind's GeoLite2 database, and exposes it through a single WordPress filter so your theme or plugin can use it with no hard dependency.
The GeoLite2 database is not bundled — MaxMind's licence does not allow redistribution. Instead you enter your own free MaxMind account ID and licence key once on the settings screen. The plugin then:
wp-content/uploads (so it survives plugin updates),$country = apply_filters( 'honeill_visitor_country_detection_country_code', '' );
Returns a two-letter country code, or an empty string when it can't be determined (local IP, missing database, etc.) — your code decides the fallback. Results are cached per IP, so it's cheap to call on every request.
Prefer REST? GET /wp-json/honeill-visitor-country-detection/v1/country returns { "country": "GB" } for the caller.
This product includes GeoLite2 Data created by MaxMind, available from https://www.maxmind.com. This plugin is an independent project and is not affiliated with, endorsed, or sponsored by MaxMind, Inc. GeoIP and GeoLite2 are trademarks of MaxMind, Inc.
honeill-visitor-country-detection folder to /wp-content/plugins/, or install the ZIP via Plugins → Add New → Upload Plugin.wp-config.php to keep them out of the database:
define( 'HONEILL_VISITOR_COUNTRY_DETECTION_ACCOUNT_ID', '123456' );
define( 'HONEILL_VISITOR_COUNTRY_DETECTION_LICENSE_KEY', 'your-key' );Yes. You use your own licence key to download your own copy of the database — nothing is redistributed, which is what MaxMind's licence restricts. Attribution to MaxMind is included as required.
In a folder inside wp-content/uploads/ named honeill-visitor-country-detection- plus a random suffix, in a file that also has a random name. It is kept out of the plugin folder so plugin updates don't wipe it. The random names mean the licensed file has no guessable web address on any server — even one that lists folder contents; on Apache an .htaccess file blocks direct access as well. Sites upgrading from an earlier version have their folder and file renamed automatically.
It ships with the lighter GeoLite2-Country database. City is a small change (the edition id and filename) but needs more disk space and exposes additional fields.
Yes. The plugin reads the connection's real address and only trusts X-Forwarded-For entries added by proxies it can vouch for: your host's own private-network proxy and Cloudflare's published IP ranges. Visitors coming through Cloudflare get Cloudflare's own country header. If you use another CDN or load balancer with public IPs, add its ranges with the honeill_visitor_country_detection_trusted_proxies filter (an array of CIDR strings, e.g. '203.0.113.0/24'), or replace the detected IP entirely with the honeill_visitor_country_detection_client_ip filter.
Not by sending headers. X-Forwarded-For entries a visitor adds themselves are ignored, and Cloudflare's country header is only believed when the request really came from Cloudflare. A visitor can still change their apparent country with a VPN, as with any IP-based lookup — so use the country for content, never for access control.
Most often an incorrect account ID or licence key (MaxMind returns 401/403), or the PHP zlib extension is missing (needed to unpack the download). The settings screen's status table shows both, along with the reason for the last failed update — including automatic weekly ones. A failed download never replaces a working database.
.htaccess (nginx), even where folder listings are switched on. Existing installs are moved automatically.X-Forwarded-For entry was used, which a visitor could set to anything.honeill_visitor_country_detection_trusted_proxies and honeill_visitor_country_detection_client_ip filters.HONEILL_VISITOR_COUNTRY_DETECTION_ACCOUNT_ID constant.X-Forwarded-For entries (Azure App Service, IIS ARR) are understood.honeill-visitor-country-detection). No functional changes; filter, REST namespace, options, and constant names now use the new prefix.honeill_visitor_country_detection_country_code filter, licence-key-based download, weekly auto-update, and a settings screen.