Hooks
modal_kit_pro_country
filter
Pro
PHP
Supply the visitor’s country for Pro’s country rule from your own lookup. Return a two-letter code, or an empty string when unknown.
Runs while a page is built, once for each modal on it with a country rule (the Country panel set to Only in these countries or Everywhere except these countries). Pro first reads the country from the request headers listed in modal_kit_pro_country_sources; this filter gets that result and can replace it.
Only the decision is printed in the page (show, don’t show, or unknown), never the country or the address. When the code is empty, the modal’s If unknown setting applies.
Parameters
Parameter
Description
$code
string
The ISO 3166-1 two-letter code in upper case, or an empty string when no header gave one. Cloudflare’s XX (no data) and T1 (Tor) arrive as empty.
$lookup
string
The modal’s Look up with setting: auto, or a source id such as cloudflare.
Returns
string The code. It’s upper-cased, and anything that isn’t two letters counts as unknown.
Examples
Fall back to WooCommerce’s geolocation
When no CDN header gave a country, ask WooCommerce, which uses its MaxMind database when that integration is set up. The last argument, false, stops it calling outside geolocation services, which would also cache the visitor’s address in a transient.
add_filter( 'modal_kit_pro_country', function ( $code ) {
static $found = null;
if ( '' !== $code || ! class_exists( 'WC_Geolocation' ) ) {
return $code;
}
if ( null === $found ) {
// Local lookups only: no outside API, nothing stored.
$geo = WC_Geolocation::geolocate_ip( '', false, false );
$found = (string) ( $geo['country'] ?? '' );
}
return $found;
} );
Try a country rule as an editor
Add ?my_country=DE to a page while logged in to see what visitors from Germany get. Page caches usually skip logged-in users, so nobody else is served that copy.
add_filter( 'modal_kit_pro_country', function ( $code ) {
if ( ! current_user_can( 'edit_posts' ) || empty( $_GET['my_country'] ) ) {
return $code;
}
return strtoupper( sanitize_key( wp_unslash( $_GET['my_country'] ) ) );
} );
Good to know
Never store or log the visitor’s address in a lookup, and don’t cache a service’s answer under it.
Pro sends Vary on the header of the source a modal uses, so a page cache that honours it keeps one copy per country. A lookup in this filter has no header to vary on: exclude pages with a country rule from the page cache.
On a static export, whatever this returns for the exporter’s own request is printed for every visitor. Return an empty string there so If unknown applies.
Applied in modal-kit-pro/includes/Audience.php.