timesheet source code
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

107 lines
3.2KB

  1. <?php
  2. /**
  3. * Plugin Name: Acare Advanced Office
  4. * Plugin URI: http://biukop.com.au/acaresydney/timesheets
  5. * Description: Advanced Office system, timesheet, Payroll for AcareSydney
  6. * Version: 2.1
  7. * Author: Biukop Intelligence
  8. * Author URI: http://biukop.com.au/
  9. */
  10. namespace Biukop;
  11. require_once(dirname(__FILE__) . '/autoload.php');
  12. require_once (ABSPATH . 'wp-includes/pluggable.php');
  13. class AcareOffice{
  14. private $nonce; //for ajax verification
  15. private $pages = array('time-sheets', 'user-list');
  16. private $acaresydney_userid = 0;
  17. private $xero ;
  18. public function __construct() {
  19. add_action('init', array($this, 'class_loader'));
  20. add_action('wp', array($this, 'check_auth'));
  21. add_action('wp_enqueue_scripts', array($this, 'register_js_css'), 99);
  22. add_filter('show_admin_bar', '__return_false');
  23. add_shortcode( 'ts-sync-users', array($this, 'sync_users'));
  24. }
  25. /**
  26. * Autoload the custom theme classes
  27. */
  28. public function class_loader()
  29. {
  30. // Create a new instance of the autoloader
  31. $loader = new \Psr4AutoloaderClass();
  32. // Register this instance
  33. $loader->register();
  34. // Add our namespace and the folder it maps to
  35. $loader->addNamespace('\XeroPHP', dirname(__FILE__) . '/xero-php-master/src/XeroPHP');
  36. $loader->addNamespace('\Biukop', dirname(__FILE__) . '/' );
  37. $this->xero = new Xero();
  38. }
  39. //
  40. //
  41. ///check auth
  42. public function check_auth(){
  43. global $pagename;
  44. //echo $pagename;
  45. }
  46. ///
  47. // enqueue / register css /js
  48. //
  49. public function register_js_css() {
  50. $this->nonce = wp_create_nonce('acaresydney');
  51. $this->acaresydney_userid = get_query_var( 'acaresydney_userid' ) ;
  52. $this->register_bts_js();
  53. $this->register_timesheet_js_css();
  54. }
  55. private function register_bts_js()
  56. {
  57. wp_enqueue_style( 'bts', plugins_url('css/ts.css', __FILE__));
  58. wp_enqueue_script('bts', plugins_url('js/ts.js', __FILE__), array('jquery', 'jquery-ui-core'));
  59. wp_localize_script( 'bts', 'bts1', array(
  60. 'ajax_url' => admin_url( 'admin-ajax.php' ),
  61. 'nonce' => $this->nonce, // It is common practice to comma after
  62. 'display_name' => wp_get_current_user()->display_name,
  63. 'anonymous' => !is_user_logged_in(),
  64. 'me'=> get_current_user_id(),
  65. 'userid'=> $this->acaresydney_userid,
  66. ) );
  67. }
  68. private function register_timesheet_js_css(){
  69. global $pagename;
  70. if ($pagename != 'time-sheets'){
  71. return;
  72. }
  73. wp_enqueue_style( 'bts_ts', plugins_url('css/bts_timesheet.css', __FILE__));
  74. wp_enqueue_script( 'bts_ts', plugins_url('js/bts_timesheet.js', __FILE__), array( 'jquery' , 'bts' ));
  75. }
  76. public function sync_user_cli($args = array(), $assoc_args = array()){
  77. $this->cli = true;
  78. echo "running sync user from command line;\n";
  79. $this->xero->sync_users();
  80. return;
  81. }
  82. }
  83. $bb = new AcareOffice();
  84. if ( defined( 'WP_CLI' ) && WP_CLI ) {
  85. \WP_CLI::add_command( 'sync_users', array($bb, 'sync_user_cli'));
  86. }