Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save badabingbreda/9ef5f21b42c9d2d3d5de43cda5919d2f to your computer and use it in GitHub Desktop.
Save badabingbreda/9ef5f21b42c9d2d3d5de43cda5919d2f to your computer and use it in GitHub Desktop.
Toolbox Example - Conditional Filter GeoIP Detection
<?php
add_action( 'toolbox_add_conditional_options' , 'add_geo_detect', 10, 1 );
function add_geo_detect() {
toolboxExtender::add_conditional_option(
// filter name
'geo_detect',
// option key and title
array('key'=> 'geo_check' , 'title' => __('Geo Check', 'textdomain') ),
// fields that are part of this options settings.
// No toggling of subfields or forms
array(
'query_parameter' => array(
'type' => 'text',
'label' => __( 'isoCode to check for', 'textdomain' ),
'default' => 'US',
),
)
);
add_filter( 'geo_detect' , 'check_geo_location' , 10, 3 );
function check_geo_location ( $is_visible, $param , $node ) {
$record = geoip_detect2_get_info_from_current_ip();
if ( $record->country->isoCode !== strtoupper($param['query_parameter']) ) return false;
return $is_visible;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment