Last active
May 20, 2018 08:09
-
-
Save badabingbreda/9ef5f21b42c9d2d3d5de43cda5919d2f to your computer and use it in GitHub Desktop.
Toolbox Example - Conditional Filter GeoIP Detection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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