Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

87 lines
2.1KB

  1. <?php
  2. /*
  3. * Plugin Name: Australia Local Check
  4. * Plugin URI: https://biukop.com.au/
  5. * 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.
  6. * Version: 1.3.3
  7. * Author: Patrick
  8. * Author URI: https://biukop.com.au/
  9. * Text Domain: Biukop
  10. * Domain Path: /i18n/
  11. * */
  12. namespace Biukop;
  13. require_once (ABSPATH . 'wp-includes/pluggable.php');
  14. class BAU {
  15. private $nonce;
  16. public function __construct(){
  17. add_action('wp_enqueue_scripts', array($this, 'register_js_css'), 99);
  18. $this->ajax_hook('is_admin');
  19. $this->ajax_hook('is_logged_in');
  20. }
  21. private function ajax_hook($code, $admin_only = false)
  22. {
  23. add_action("wp_ajax_$code", array($this,"ajax_" . $code ));
  24. if (!$admin_only) {
  25. add_action("wp_ajax_nopriv_$code", array($this,"ajax_" . $code));
  26. }
  27. }
  28. public function register_js_css()
  29. {
  30. $this->nonce = wp_create_nonce('bau');
  31. $this->register_visitor_js_css();
  32. }
  33. private function register_visitor_js_css()
  34. {
  35. wp_enqueue_style( 'bau', plugins_url('css/bau.css', __FILE__));
  36. wp_enqueue_script('bau', plugins_url('js/bau.js', __FILE__), array('jquery', 'jquery-ui-core'));
  37. wp_localize_script('bau', 'bau', array(
  38. 'nonce' => $this->nonce,
  39. 'ajax_url' => admin_url('admin_ajax.php'),
  40. 'is_admin' => $this->is_user_admin(),
  41. 'is_editor'=> $this->is_user_editor(),
  42. 'is_logged_in' => $this->is_user_logged_in(),
  43. ));
  44. }
  45. public function ajax_is_logged_in() {
  46. echo is_user_logged_in()?'yes':'no';
  47. wp_die();
  48. }
  49. public function ajax_is_admin() {
  50. if( $this->is_user_admin() ){
  51. echo 'yes';
  52. }else{
  53. echo 'no';
  54. }
  55. wp_die();
  56. }
  57. private function is_user_admin() {
  58. if( current_user_can('administrator')) {
  59. return true;
  60. }else{
  61. return false;
  62. }
  63. }
  64. private function is_user_editor() {
  65. if ( current_user_can('editor') ){
  66. return true;
  67. }else{
  68. return false;
  69. }
  70. }
  71. private function is_user_logged_in()
  72. {
  73. return is_user_logged_in();
  74. }
  75. }
  76. $bau = new BAU;
  77. ?>