Hooks

Docs Hooks Pro · PHP hooks

modal_kit_pro_country_sources

filter

Pro

PHP

Add, reorder or remove the request headers Pro reads the visitor’s country from for the country rule.

Lists the country lookups: Cloudflare, Vercel, CloudFront, Fastly and host GeoIP (WP Engine, WordPress VIP, Pantheon, MaxMind’s server module). Each names the $_SERVER keys to read and the request header a page cache should vary on. They appear under Look up with in a modal’s Country panel, after Automatic, which uses the first one found in this order.

Runs whenever Pro looks up a country, when it sends the Vary header, and when the block editor loads.

Parameters

Parameter

Description

$sources

array

Sources by id (cloudflare, vercel, cloudfront, fastly, host). Each is an array with label (shown in the editor), keys (the $_SERVER keys to read, in order) and header (the request header’s name).

Returns

array The sources, in the order Automatic checks them. Every entry needs all three keys.

Examples

Read your own proxy’s header

Your proxy or load balancer adds X-Geo-Country: GB to each request, replacing any value the visitor sent. PHP sees it as HTTP_X_GEO_COUNTRY.

PHP

add_filter( 'modal_kit_pro_country_sources', function ( $sources ) {
  $sources['my-edge'] = array(
    'label'  => __( 'Our edge proxy (X-Geo-Country)', 'my-plugin' ),
    'keys'   => array( 'HTTP_X_GEO_COUNTRY' ),
    'header' => 'X-Geo-Country',
  );

  return $sources;
} );

Keep only the header your host sets

Automatic trusts the first header it finds. On a host that doesn’t set one of them, a visitor can send it and choose the country they see. Behind Cloudflare, keep only Cloudflare’s.

PHP

add_filter( 'modal_kit_pro_country_sources', function ( $sources ) {
  return array_intersect_key( $sources, array( 'cloudflare' => true ) );
} );

Good to know

Header values are cleaned and upper-cased, and must be two letters; anything else counts as unknown.

A modal saved with a source that’s no longer listed checks every remaining source, like Automatic.

When a published modal has a country rule, responses send Vary on its source’s header. For Automatic, only the headers present in that request are named.

Applied in modal-kit-pro/includes/Audience.php.

Need a hook that isn’t here?