1 <?php
2 3 4 5 6 7 8 9
10
11 if ( ! defined( 'ABSPATH' ) ) exit;
12
13 if ( ! class_exists( 'WC_Admin_Menus' ) ) :
14
15 16 17
18 class {
19
20 21 22
23 public function __construct() {
24
25 add_action( 'admin_menu', array( $this, 'admin_menu' ), 9 );
26 add_action( 'admin_menu', array( $this, 'reports_menu' ), 20 );
27 add_action( 'admin_menu', array( $this, 'settings_menu' ), 50 );
28 add_action( 'admin_menu', array( $this, 'status_menu' ), 60 );
29
30 if ( apply_filters( 'woocommerce_show_addons_page', true ) ) {
31 add_action( 'admin_menu', array( $this, 'addons_menu' ), 70 );
32 }
33
34 add_action( 'admin_head', array( $this, 'menu_highlight' ) );
35 add_filter( 'menu_order', array( $this, 'menu_order' ) );
36 add_filter( 'custom_menu_order', array( $this, 'custom_menu_order' ) );
37 }
38
39 40 41
42 public function () {
43 global $menu, $woocommerce;
44
45 if ( current_user_can( 'manage_woocommerce' ) )
46 $menu[] = array( '', 'read', 'separator-woocommerce', '', 'wp-menu-separator woocommerce' );
47
48 $main_page = add_menu_page( __( 'WooCommerce', 'woocommerce' ), __( 'WooCommerce', 'woocommerce' ), 'manage_woocommerce', 'woocommerce' , array( $this, 'settings_page' ), null, '55.5' );
49
50 add_submenu_page( 'edit.php?post_type=product', __( 'Attributes', 'woocommerce' ), __( 'Attributes', 'woocommerce' ), 'manage_product_terms', 'product_attributes', array( $this, 'attributes_page' ) );
51 }
52
53 54 55
56 public function () {
57 add_submenu_page( 'woocommerce', __( 'Reports', 'woocommerce' ), __( 'Reports', 'woocommerce' ) , 'view_woocommerce_reports', 'wc-reports', array( $this, 'reports_page' ) );
58 }
59
60 61 62
63 public function () {
64 $settings_page = add_submenu_page( 'woocommerce', __( 'WooCommerce Settings', 'woocommerce' ), __( 'Settings', 'woocommerce' ) , 'manage_woocommerce', 'wc-settings', array( $this, 'settings_page' ) );
65
66 add_action( 'load-' . $settings_page, array( $this, 'settings_page_init' ) );
67 }
68
69 70 71
72 public function settings_page_init() {
73 WC()->payment_gateways();
74 WC()->shipping();
75 }
76
77 78 79
80 public function () {
81 add_submenu_page( 'woocommerce', __( 'WooCommerce Status', 'woocommerce' ), __( 'System Status', 'woocommerce' ) , 'manage_woocommerce', 'wc-status', array( $this, 'status_page' ) );
82 register_setting( 'woocommerce_status_settings_fields', 'woocommerce_status_options' );
83 }
84
85 86 87
88 public function () {
89 add_submenu_page( 'woocommerce', __( 'WooCommerce Add-ons/Extensions', 'woocommerce' ), __( 'Add-ons', 'woocommerce' ) , 'manage_woocommerce', 'wc-addons', array( $this, 'addons_page' ) );
90 }
91
92 93 94 95 96 97
98 public function () {
99 global $menu, $submenu, $parent_file, $submenu_file, $self, $post_type, $taxonomy;
100
101 $to_highlight_types = array( 'shop_order', 'shop_coupon' );
102
103 if ( isset( $post_type ) ) {
104 if ( in_array( $post_type, $to_highlight_types ) ) {
105 $submenu_file = 'edit.php?post_type=' . esc_attr( $post_type );
106 $parent_file = 'woocommerce';
107 }
108
109 if ( 'product' == $post_type ) {
110 $screen = get_current_screen();
111
112 if ( $screen->base == 'edit-tags' && taxonomy_is_product_attribute( $taxonomy ) ) {
113 $submenu_file = 'product_attributes';
114 $parent_file = 'edit.php?post_type=' . esc_attr( $post_type );
115 }
116 }
117 }
118
119 if ( isset( $submenu['woocommerce'] ) && isset( $submenu['woocommerce'][1] ) ) {
120 $submenu['woocommerce'][0] = $submenu['woocommerce'][1];
121 unset( $submenu['woocommerce'][1] );
122 }
123
124
125 if ( ! current_user_can( 'manage_woocommerce' ) ) {
126 foreach ( $menu as $key => $menu_item ) {
127 if ( strpos( $menu_item[0], _x('Orders', 'Admin menu name', 'woocommerce') ) === 0 ) {
128
129 $menu_name = _x('Orders', 'Admin menu name', 'woocommerce');
130 $menu_name_count = '';
131 if ( $order_count = wc_processing_order_count() ) {
132 $menu_name_count = " <span class='awaiting-mod update-plugins count-$order_count'><span class='processing-count'>" . number_format_i18n( $order_count ) . "</span></span>" ;
133 }
134
135 $menu[$key][0] = $menu_name . $menu_name_count;
136 $submenu['edit.php?post_type=shop_order'][5][0] = $menu_name;
137 break;
138 }
139 }
140 }
141 }
142
143 144 145 146 147 148
149 public function ( $menu_order ) {
150
151 $woocommerce_menu_order = array();
152
153
154 $woocommerce_separator = array_search( 'separator-woocommerce', $menu_order );
155
156
157 $woocommerce_product = array_search( 'edit.php?post_type=product', $menu_order );
158
159
160 foreach ( $menu_order as $index => $item ) :
161
162 if ( ( ( 'woocommerce' ) == $item ) ) :
163 $woocommerce_menu_order[] = 'separator-woocommerce';
164 $woocommerce_menu_order[] = $item;
165 $woocommerce_menu_order[] = 'edit.php?post_type=product';
166 unset( $menu_order[$woocommerce_separator] );
167 unset( $menu_order[$woocommerce_product] );
168 elseif ( !in_array( $item, array( 'separator-woocommerce' ) ) ) :
169 $woocommerce_menu_order[] = $item;
170 endif;
171
172 endforeach;
173
174
175 return $woocommerce_menu_order;
176 }
177
178 179 180 181
182 public function () {
183 if ( ! current_user_can( 'manage_woocommerce' ) )
184 return false;
185 return true;
186 }
187
188 189 190
191 public function reports_page() {
192 include_once( 'class-wc-admin-reports.php' );
193 WC_Admin_Reports::output();
194 }
195
196 197 198
199 public function settings_page() {
200 include_once( 'class-wc-admin-settings.php' );
201 WC_Admin_Settings::output();
202 }
203
204 205 206
207 public function attributes_page() {
208 $page = include( 'class-wc-admin-attributes.php' );
209 $page->output();
210 }
211
212 213 214
215 public function status_page() {
216 $page = include( 'class-wc-admin-status.php' );
217 $page->output();
218 }
219
220 221 222
223 public function addons_page() {
224 $page = include( 'class-wc-admin-addons.php' );
225 $page->output();
226 }
227 }
228
229 endif;
230
231 return new WC_Admin_Menus();