| 开发者 | honeill |
|---|---|
| 更新时间 | 2026年7月5日 14:50 |
| PHP版本: | 7.4 及以上 |
| WordPress版本: | 7.0 |
| 版权: | 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 license does not allow redistribution. Instead you enter your own free MaxMind license 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 with define( 'HONEILL_VISITOR_COUNTRY_DETECTION_LICENSE_KEY', 'your-key' ); to keep it out of the database.Yes. You use your own license key to download your own copy of the database — nothing is redistributed, which is what MaxMind's license restricts. Attribution to MaxMind is included as required.
In wp-content/uploads/honeill-visitor-country-detection/. It is kept out of the plugin folder so plugin updates don't wipe it. The plugin also drops an .htaccess to block direct web access on Apache.
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 — it reads the left-most public IP from X-Forwarded-For, falling back to REMOTE_ADDR.
Most often an incorrect license key (MaxMind returns 401/403), or the PHP Phar extension is disabled (needed to unpack the download). The settings screen shows both.
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, license-key-based download, weekly auto-update, and a settings screen.