WC_POS_Admin_Menu

WP Admin Menu Class.

Defined (1)

The class is defined in the following location(s).

/includes/admin/class-wc-pos-menu.php  
  1. class WC_POS_Admin_Menu { 
  2.  
  3. /** @vars string Unique menu identifier */ 
  4. private $toplevel_screen_id; 
  5.  
  6. /** 
  7. * Constructor 
  8. */ 
  9. public function __construct() { 
  10. add_action( 'admin_menu', array( $this, 'admin_menu' ) ); 
  11. add_filter( 'menu_order', array( $this, 'menu_order' ), 9, 1 ); 
  12.  
  13. /** 
  14. * Add POS to admin menu 
  15. */ 
  16. public function admin_menu() { 
  17. if(!current_user_can('manage_woocommerce_pos')) { 
  18. return; 
  19.  
  20. $this->toplevel_screen_id = add_menu_page( 
  21. __( 'POS', 'woocommerce-pos' ),  
  22. __( 'POS', 'woocommerce-pos' ),  
  23. 'manage_woocommerce_pos',  
  24. WC_POS_PLUGIN_NAME,  
  25. array( $this, 'display_upgrade_page' ),  
  26. 'data:image/svg+xml;base64, PHN2<BASE64_ENCODED>' 
  27. ); 
  28.  
  29. add_submenu_page( 
  30. WC_POS_PLUGIN_NAME,  
  31. __( 'View POS', 'woocommerce-pos' ),  
  32. __( 'View POS', 'woocommerce-pos' ),  
  33. 'manage_woocommerce_pos',  
  34. null 
  35. ); 
  36.  
  37. // adjust submenu 
  38. global $submenu; 
  39. $pos_submenu = &$submenu[WC_POS_PLUGIN_NAME]; 
  40. $pos_submenu[0][0] = __( 'Upgrade to Pro', 'woocommerce-pos' ); 
  41. $pos_submenu[1][2] = wc_pos_url(); 
  42.  
  43. /** 
  44. * @param $menu_order 
  45. * @return mixed 
  46. */ 
  47. public function menu_order( $menu_order ) { 
  48. $woo = array_search( 'woocommerce', $menu_order ); 
  49. $pos = array_search( WC_POS_PLUGIN_NAME, $menu_order ); 
  50.  
  51. if( $woo !== false && $pos !== false) { 
  52. // rearrange menu 
  53. unset( $menu_order[$pos] ); 
  54. array_splice( $menu_order, ++$woo, 0, WC_POS_PLUGIN_NAME ); 
  55.  
  56. // rearrange submenu 
  57. global $submenu; 
  58. $pos_submenu = &$submenu[WC_POS_PLUGIN_NAME]; 
  59. $pos_submenu[500] = $pos_submenu[1]; 
  60. unset( $pos_submenu[1] ); 
  61. }; 
  62.  
  63. return $menu_order; 
  64.  
  65. /** 
  66. * Render the upgrade page. 
  67. */ 
  68. public function display_upgrade_page() { 
  69.  
  70. // Check for transient, if none, grab remote HTML file 
  71. if ( false === ( $upgrade = get_transient( 'remote_pro_page' ) ) ) { 
  72. // Get remote HTML file 
  73. $response = wp_remote_get( 'http://woopos.com.au/pro/?wp-admin=woocommerce-pos' ); 
  74. // Check for error 
  75. if ( is_wp_error( $response ) ) { 
  76. return; 
  77. // Parse remote HTML file 
  78. $upgrade = wp_remote_retrieve_body( $response ); 
  79. // Check for error 
  80. if ( is_wp_error( $upgrade ) ) { 
  81. return; 
  82. // Store remote HTML file in transient, expire after 24 hours 
  83. set_transient( 'remote_pro_page', $upgrade, 24 * HOUR_IN_SECONDS ); 
  84. include_once 'views/upgrade.php'; 
  85.