Guest User

Untitled

a guest
May 25th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. <?php
  2.  
  3. add_action( 'toolbox_add_conditional_options' , 'add_geo_detect', 10, 1 );
  4.  
  5. function add_geo_detect() {
  6. toolboxExtender::add_conditional_option(
  7. // filter name
  8. 'geo_detect',
  9. // option key and title
  10. array('key'=> 'geo_check' , 'title' => __('Geo Check', 'textdomain') ),
  11. // fields that are part of this options settings.
  12. // No toggling of subfields or forms
  13. array(
  14. 'query_parameter' => array(
  15. 'type' => 'text',
  16. 'label' => __( 'isoCode to check for', 'textdomain' ),
  17. 'default' => 'US',
  18. ),
  19. )
  20. );
  21.  
  22. add_filter( 'geo_detect' , 'check_geo_location' , 10, 3 );
  23.  
  24. function check_geo_location ( $is_visible, $param , $node ) {
  25. $record = geoip_detect2_get_info_from_current_ip();
  26. if ( $record->country->isoCode !== strtoupper($param['query_parameter']) ) return false;
  27. return $is_visible;
  28. }
  29.  
  30. }
Add Comment
Please, Sign In to add comment