From 128b67990c10310b930c7131ac779ed2ef880bc3 Mon Sep 17 00:00:00 2001 From: supertraderfx server Date: Thu, 28 Nov 2019 21:01:27 +1100 Subject: [PATCH] add quick redirect --- au.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/au.php b/au.php index fb15f44..cfde0ba 100644 --- a/au.php +++ b/au.php @@ -19,6 +19,38 @@ class BAU { add_action('wp_enqueue_scripts', array($this, 'register_js_css'), 99); $this->ajax_hook('is_admin'); $this->ajax_hook('is_logged_in'); + add_action('wp', array($this, 'check_au')); + } + + public function check_au() + { + $ip = \geoip_detect2_get_client_ip(); + $ipinfo = \geoip_detect2_get_info_from_current_ip(); + if ($this->is_au($ipinfo)){ + if (!$this->is_user_admin()) { + if($this->is_url_wp_admin()){ + //wp-admin, we stay + }else{ + wp_redirect("https://supertraderfx.com.au/", 307); + } + } + } + } + + + private function is_au ($ipinfo) + { + return $ipinfo->country->isoCode == "AU"; + } + + private function is_url_wp_admin() + { + $url = $_SERVER['REQUEST_URI']; + if ($url == "/wp-admin/"){ + return true; + }else{ + return false; + } } private function ajax_hook($code, $admin_only = false)