collecting medal for hitxy members
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

116 lignes
3.4KB

  1. <?php
  2. /*
  3. Plugin Name: Collecting Medal for membmers
  4. Plugin URI: https://biukop.com.au/
  5. Description: A backend for collecting memorial medal for HITxy Medal for 100 anuversary
  6. Text Domain: member
  7. Author: Patrick
  8. Twitter: @lawipac
  9. Author URI: https://lawipac.com/
  10. Version: 1.0.1
  11. License: GPL
  12. Copyright: All rights reserved.
  13. */
  14. namespace Member;
  15. //require_once(dirname(__FILE__) . '/autoload.php');
  16. require_once (ABSPATH . 'wp-includes/pluggable.php');
  17. class Member{
  18. private $token = "";
  19. private $nonce = "";
  20. public function __construct() {
  21. add_action('wp_enqueue_scripts', array($this, 'register_js_css'), 99);
  22. add_shortcode( 'mm_workspace', array($this, 'shortcode_workspace'));
  23. add_shortcode( 'mm_token', array($this, 'shortcode_token'));
  24. // hook add_rewrite_rules function into rewrite_rules_array
  25. add_filter('rewrite_rules_array', array($this,'my_add_rewrite_rules'));
  26. // hook add_query_vars function into query_vars
  27. add_filter('query_vars', array($this,'add_query_vars'));
  28. //
  29. $this->ajax_hook('list_users');
  30. }
  31. private function ajax_hook($code, $admin_only = false)
  32. {
  33. add_action("wp_ajax_$code", array($this,"ajax_$code" ));
  34. if (!$admin_only) {
  35. add_action("wp_ajax_nopriv_$code", array($this,"ajax_$code"));
  36. }
  37. }
  38. public function shortcode_workspace($attrs) {
  39. if ($this->token != "" )
  40. return "";
  41. $str = file_get_contents(plugin_dir_path(__FILE__) . "/html/workspace.html");
  42. $css = file_get_contents(plugin_dir_path(__FILE__) . "/css/workspace.css");
  43. return $css . "\n" . $str;
  44. }
  45. public function shortcode_token($attrs) {
  46. $login = get_query_var( 'token' );
  47. return "<h1 id='test'> $login </h1>";
  48. }
  49. //for customer profile and broker trans
  50. public function my_add_rewrite_rules($aRules) {
  51. $aNewRules = array(
  52. 'medal/([^/]+)/?$' => 'index.php?pagename=medal&token=$matches[1]',
  53. );
  54. $aRules = $aNewRules + $aRules;
  55. return $aRules;
  56. }
  57. //
  58. //query var
  59. public function add_query_vars($aVars) {
  60. $aVars[] = "token"; // represents the receiption of this medal
  61. return $aVars;
  62. }
  63. public function register_js_css() {
  64. $this->nonce = wp_create_nonce('medal');
  65. $this->token = get_query_var( 'token' );
  66. $this->register_medal_js();
  67. }
  68. private function register_medal_js()
  69. {
  70. //wp_enqueue_style( 'mm', plugins_url('css/workspace.css', __FILE__));
  71. wp_enqueue_script('mm', plugins_url('js/workspace.js', __FILE__), array('jquery', 'jquery-ui-core'));
  72. wp_localize_script( 'mm', 'mm', array(
  73. 'ajax_url' => admin_url( 'admin-ajax.php' ),
  74. 'nonce' => $this->nonce, // It is common practice to comma after
  75. 'display_name' => wp_get_current_user()->display_name,
  76. 'anonymous' => !is_user_logged_in(),
  77. ) );
  78. }
  79. function ajax_list_users()
  80. {
  81. check_ajax_referer('medal');
  82. $client = $_POST['client'];
  83. $url = $_POST["action"];
  84. $response = array(
  85. 'status' => 'success',
  86. 'users' => [
  87. 1,2,3,4,5,6,7
  88. ],
  89. 'id' => $client,
  90. 'url' => $url,
  91. );
  92. wp_send_json($response);
  93. }
  94. }
  95. $mm = new Member();