WC_Domination_Admin

Plugin admin class.

Defined (1)

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

/includes/admin/class-wc-domination-admin.php  
  1. class WC_Domination_Admin { 
  2.  
  3. /** 
  4. * Initialize the plugin admin. 
  5. */ 
  6. public function __construct() { 
  7. // Menus. 
  8. add_action( 'admin_menu', array( $this, 'admin_menu' ), 999 ); 
  9. add_action( 'menu_order', array( $this, 'menu_order' ), 999 ); 
  10.  
  11. // WooCommerce Post types arguments. 
  12. add_filter( 'woocommerce_register_post_type_shop_order', array( $this, 'custom_post_type_shop_order' ) ); 
  13. add_filter( 'woocommerce_register_post_type_shop_coupon', array( $this, 'custom_post_type_shop_coupon' ) ); 
  14.  
  15. // Screen ids. 
  16. add_filter( 'woocommerce_reports_screen_ids', array( $this, 'custom_screen_ids' ) ); 
  17. add_filter( 'woocommerce_screen_ids', array( $this, 'custom_screen_ids' ) ); 
  18.  
  19. // Menu highlight. 
  20. add_action( 'admin_head', array( $this, 'menu_highlight' ), 999 ); 
  21.  
  22. /** 
  23. * Remove menu items. 
  24. */ 
  25. public function admin_menu() { 
  26. global $menu; 
  27.  
  28. if ( class_exists( 'WC_Admin_Menus' ) ) { 
  29. $wc_admin_menus = new WC_Admin_Menus; 
  30. $menu[] = array( '', 'read', 'separator-wc-domination1', '', 'wp-not-current-submenu wp-menu-separator' ); 
  31. $menu[] = array( '', 'read', 'separator-wc-domination2', '', 'wp-not-current-submenu wp-menu-separator' ); 
  32.  
  33. // Add custom orders menu. 
  34. $orders_menu_name = _x( 'Orders', 'Admin menu name', 'woocommerce-domination' ); 
  35. if ( $order_count = wc_processing_order_count() ) { 
  36. $orders_menu_name .= ' <span class="awaiting-mod update-plugins count-' . $order_count . '"><span class="processing-count">' . number_format_i18n( $order_count ) . '</span></span>'; 
  37. add_menu_page( $orders_menu_name, $orders_menu_name, 'manage_woocommerce', 'edit.php?post_type=shop_order', '', 'dashicons-list-view' ); 
  38.  
  39. // Change wc-reports location. 
  40. remove_submenu_page( 'woocommerce', 'wc-reports' ); 
  41. add_menu_page( __( 'Reports', 'woocommerce-domination' ), __( 'Reports', 'woocommerce-domination' ) , 'view_woocommerce_reports', 'wc-reports', array( $wc_admin_menus, 'reports_page' ), 'dashicons-chart-area' ); 
  42.  
  43. // Add customers menu. 
  44. add_menu_page( __( 'Customers', 'woocommerce-domination' ), __( 'Customers', 'woocommerce-domination' ), 'manage_woocommerce', 'wc-customers-list', array( $this, 'customers_list_page' ), 'dashicons-groups' ); 
  45.  
  46. /** 
  47. * Custom WooCommerce screen ids. 
  48. * @param array $ids Default screen ids. 
  49. * @return array Added new screen ids. 
  50. */ 
  51. public function custom_screen_ids( $ids ) { 
  52. $ids[] = 'toplevel_page_wc-reports'; 
  53. $ids[] = 'toplevel_page_wc-customers-list'; 
  54.  
  55. return $ids; 
  56.  
  57. /** 
  58. * Custom shop order arguments. 
  59. * @param array $args Post type arguments. 
  60. * @return array Fixed show_in_menu item. 
  61. */ 
  62. public function custom_post_type_shop_order( $args ) { 
  63. $args['show_in_menu'] = false; 
  64.  
  65. return $args; 
  66.  
  67. /** 
  68. * Custom shop coupon arguments. 
  69. * @param array $args Post type arguments. 
  70. * @return array Fixed show_in_menu item. 
  71. */ 
  72. public function custom_post_type_shop_coupon( $args ) { 
  73. $args['show_in_menu'] = true; 
  74. $args['menu_icon'] = 'dashicons-tag'; 
  75.  
  76. return $args; 
  77.  
  78. /** 
  79. * Fixed shop order highlight. 
  80. */ 
  81. public function menu_highlight() { 
  82. global $parent_file, $submenu_file, $post_type; 
  83.  
  84. if ( isset( $post_type ) ) { 
  85. if ( in_array( $post_type, array( 'shop_order', 'shop_coupon' ) ) ) { 
  86. $submenu_file = 'edit.php?post_type=' . esc_attr( $post_type ); 
  87. $parent_file = 'edit.php?post_type=' . esc_attr( $post_type ); 
  88.  
  89. /** 
  90. * Menu order. 
  91. * @param array $menu_order Current menu order. 
  92. * @return array New menu order. 
  93. */ 
  94. public function menu_order( $menu_order ) { 
  95. global $submenu; 
  96.  
  97. // Fix WooCommerce submenus order. 
  98. $submenu_items = array(); 
  99. $woocommerce_order = 2; 
  100. $wc_23 = version_compare( WC_VERSION, '2.3', '>=' ); 
  101.  
  102. if ( isset( $submenu['woocommerce'] ) ) { 
  103. foreach ( $submenu['woocommerce'] as $key => $items ) { 
  104. if ( $wc_23 ) { 
  105. if ( in_array( 'wc-settings', $items ) ) { 
  106. $submenu_items[1] = $items; 
  107. } elseif ( in_array( 'woocommerce', $items ) ) { 
  108. $submenu_items[0] = $items; 
  109. } else { 
  110. $submenu_items[ $woocommerce_order ] = $items; 
  111. } else { 
  112. if ( in_array( 'wc-settings', $items ) ) { 
  113. $submenu_items[0] = $items; 
  114. } elseif ( in_array( 'woocommerce', $items ) ) { 
  115. continue; 
  116. } else { 
  117. $submenu_items[ $woocommerce_order ] = $items; 
  118.  
  119. $woocommerce_order++; 
  120.  
  121. // Fix the array order. 
  122. ksort( $submenu_items ); 
  123. $submenu['woocommerce'] = array_values( $submenu_items ); 
  124.  
  125. // Custom menu items order. 
  126. $menu_order = array( 
  127. 2 => 'index.php',  
  128. 4 => 'separator1',  
  129. 6 => 'edit.php?post_type=shop_order',  
  130. 8 => 'wc-reports',  
  131. 10 => 'wc-customers-list',  
  132. 12 => 'separator-wc-domination1',  
  133. 14 => 'edit.php?post_type=product',  
  134. 16 => 'edit.php?post_type=shop_coupon',  
  135. 18 => 'separator-wc-domination2',  
  136. 20 => 'edit.php?post_type=page',  
  137. 22 => 'upload.php',  
  138. 24 => 'edit.php',  
  139. 26 => 'edit-comments.php',  
  140. 56 => 'separator-woocommerce',  
  141. 58 => 'woocommerce',  
  142. 59 => 'separator2',  
  143. ); 
  144.  
  145. return $menu_order; 
  146.  
  147. /** 
  148. * Customers list page. 
  149. * @return string 
  150. */ 
  151. public function customers_list_page() { 
  152. include_once WC()->plugin_path() . '/includes/admin/reports/class-wc-report-customer-list.php'; 
  153.  
  154. $report = new WC_Report_Customer_List(); 
  155.  
  156. echo '<div class="wrap">'; 
  157. echo '<h2>' . __( 'Customers', 'woocommerce-domination' ) . '</h2>'; 
  158.  
  159. $report->output_report(); 
  160. echo '</div>';