collecting medal for hitxy members
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

87 lines
2.7KB

  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. public function shortcode_workspace($attrs) {
  30. if ($this->token != "" )
  31. return "";
  32. $str = file_get_contents(plugin_dir_path(__FILE__) . "/html/workspace.html");
  33. $css = file_get_contents(plugin_dir_path(__FILE__) . "/css/workspace.css");
  34. return $css . "\n" . $str;
  35. }
  36. public function shortcode_token($attrs) {
  37. $login = get_query_var( 'token' );
  38. return "<h1 id='test'> $login </h1>";
  39. }
  40. //for customer profile and broker trans
  41. public function my_add_rewrite_rules($aRules) {
  42. $aNewRules = array(
  43. 'medal/([^/]+)/?$' => 'index.php?pagename=medal&token=$matches[1]',
  44. );
  45. $aRules = $aNewRules + $aRules;
  46. return $aRules;
  47. }
  48. //
  49. //query var
  50. public function add_query_vars($aVars) {
  51. $aVars[] = "token"; // represents the receiption of this medal
  52. return $aVars;
  53. }
  54. public function register_js_css() {
  55. $this->nonce = wp_create_nonce('medal');
  56. $this->token = get_query_var( 'token' );
  57. $this->register_medal_js();
  58. }
  59. private function register_medal_js()
  60. {
  61. //wp_enqueue_style( 'mm', plugins_url('css/workspace.css', __FILE__));
  62. wp_enqueue_script('mm', plugins_url('js/token.js', __FILE__), array('jquery', 'jquery-ui-core'));
  63. wp_localize_script( 'mm', 'mm', array(
  64. 'ajax_url' => admin_url( 'admin-ajax.php' ),
  65. 'nonce' => $this->nonce, // It is common practice to comma after
  66. 'display_name' => wp_get_current_user()->display_name,
  67. 'anonymous' => !is_user_logged_in(),
  68. ) );
  69. }
  70. }
  71. $mm = new Member();