Kaynağa Gözat

added automatic detection of AU country, redirect only when non-admin is visitingw

master
supertraderfx server 6 yıl önce
işleme
f80523f8b4
3 değiştirilmiş dosya ile 102 ekleme ve 0 silme
  1. +86
    -0
      au.php
  2. +4
    -0
      css/bau.css
  3. +12
    -0
      js/bau.js

+ 86
- 0
au.php Dosyayı Görüntüle

@@ -0,0 +1,86 @@
<?php
/*
* Plugin Name: Australia Local Check
* Plugin URI: https://biukop.com.au/
* Description: Redirect to Australia Website if detecting a visitor is from Australia, but not doing so if the admin is logged in. This is a customized plugin developed for superforex only.
* Version: 1.3.3
* Author: Patrick
* Author URI: https://biukop.com.au/
* Text Domain: Biukop
* Domain Path: /i18n/
* */

namespace Biukop;
require_once (ABSPATH . 'wp-includes/pluggable.php');

class BAU {
private $nonce;
public function __construct(){
add_action('wp_enqueue_scripts', array($this, 'register_js_css'), 99);
$this->ajax_hook('is_admin');
$this->ajax_hook('is_logged_in');
}

private function ajax_hook($code, $admin_only = false)
{
add_action("wp_ajax_$code", array($this,"ajax_" . $code ));
if (!$admin_only) {
add_action("wp_ajax_nopriv_$code", array($this,"ajax_" . $code));
}
}

public function register_js_css()
{
$this->nonce = wp_create_nonce('bau');
$this->register_visitor_js_css();
}
private function register_visitor_js_css()
{
wp_enqueue_style( 'bau', plugins_url('css/bau.css', __FILE__));
wp_enqueue_script('bau', plugins_url('js/bau.js', __FILE__), array('jquery', 'jquery-ui-core'));
wp_localize_script('bau', 'bau', array(
'nonce' => $this->nonce,
'ajax_url' => admin_url('admin_ajax.php'),
'is_admin' => $this->is_user_admin(),
'is_editor'=> $this->is_user_editor(),
'is_logged_in' => $this->is_user_logged_in(),
));
}

public function ajax_is_logged_in() {
echo is_user_logged_in()?'yes':'no';
wp_die();
}

public function ajax_is_admin() {
if( $this->is_user_admin() ){
echo 'yes';
}else{
echo 'no';
}
wp_die();
}

private function is_user_admin() {
if( current_user_can('administrator')) {
return true;
}else{
return false;
}
}
private function is_user_editor() {
if ( current_user_can('editor') ){
return true;
}else{
return false;
}
}
private function is_user_logged_in()
{
return is_user_logged_in();
}
}
$bau = new BAU;
?>

+ 4
- 0
css/bau.css Dosyayı Görüntüle

@@ -0,0 +1,4 @@
/*
* place holder for AU redirect
*
*/

+ 12
- 0
js/bau.js Dosyayı Görüntüle

@@ -0,0 +1,12 @@
//check to see if this is from AU IP
//if yes, silently redirect to AU site
function check_au(){
var is_au = jQuery('body').hasClass('geoip-country-AU') != null;
var is_wp_admin = window.location.href.indexOf('/wp-admin/') >=0;
if (is_au) {
if (!bau.is_admin ){
window.location='https://supertraderfx.com.au/';
}
}
}
setInterval(check_au,800);

Yükleniyor…
İptal
Kaydet