|
- <?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;
- ?>
|