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0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / includes / admin / class-wc-admin-menus.php
woocommerce / includes / admin Last commit date
helper 4 years ago importers 4 years ago list-tables 4 years ago marketplace-suggestions 4 years ago meta-boxes 4 years ago notes 4 years ago plugin-updates 5 years ago reports 5 years ago settings 4 years ago views 4 years ago class-wc-admin-addons.php 4 years ago class-wc-admin-api-keys-table-list.php 6 years ago class-wc-admin-api-keys.php 6 years ago class-wc-admin-assets.php 4 years ago class-wc-admin-attributes.php 5 years ago class-wc-admin-customize.php 5 years ago class-wc-admin-dashboard-setup.php 4 years ago class-wc-admin-dashboard.php 5 years ago class-wc-admin-duplicate-product.php 5 years ago class-wc-admin-exporters.php 5 years ago class-wc-admin-help.php 5 years ago class-wc-admin-importers.php 5 years ago class-wc-admin-log-table-list.php 5 years ago class-wc-admin-menus.php 4 years ago class-wc-admin-meta-boxes.php 4 years ago class-wc-admin-notices.php 4 years ago class-wc-admin-permalink-settings.php 5 years ago class-wc-admin-pointers.php 5 years ago class-wc-admin-post-types.php 5 years ago class-wc-admin-profile.php 4 years ago class-wc-admin-reports.php 5 years ago class-wc-admin-settings.php 5 years ago class-wc-admin-setup-wizard.php 4 years ago class-wc-admin-status.php 5 years ago class-wc-admin-taxonomies.php 5 years ago class-wc-admin-webhooks-table-list.php 7 years ago class-wc-admin-webhooks.php 5 years ago class-wc-admin.php 4 years ago wc-admin-functions.php 4 years ago wc-meta-box-functions.php 5 years ago
class-wc-admin-menus.php
394 lines
1 <?php
2 /**
3 * Setup menus in WP admin.
4 *
5 * @package WooCommerce\Admin
6 * @version 2.5.0
7 */
8
9 defined( 'ABSPATH' ) || exit;
10
11 if ( class_exists( 'WC_Admin_Menus', false ) ) {
12 return new WC_Admin_Menus();
13 }
14
15 /**
16 * WC_Admin_Menus Class.
17 */
18 class WC_Admin_Menus {
19
20 /**
21 * Hook in tabs.
22 */
23 public function __construct() {
24 // Add menus.
25 add_action( 'admin_menu', array( $this, 'menu_highlight' ) );
26 add_action( 'admin_menu', array( $this, 'menu_order_count' ) );
27 add_action( 'admin_menu', array( $this, 'admin_menu' ), 9 );
28 add_action( 'admin_menu', array( $this, 'reports_menu' ), 20 );
29 add_action( 'admin_menu', array( $this, 'settings_menu' ), 50 );
30 add_action( 'admin_menu', array( $this, 'status_menu' ), 60 );
31
32 if ( apply_filters( 'woocommerce_show_addons_page', true ) ) {
33 add_action( 'admin_menu', array( $this, 'addons_menu' ), 70 );
34 }
35
36 add_filter( 'menu_order', array( $this, 'menu_order' ) );
37 add_filter( 'custom_menu_order', array( $this, 'custom_menu_order' ) );
38 add_filter( 'set-screen-option', array( $this, 'set_screen_option' ), 10, 3 );
39
40 // Add endpoints custom URLs in Appearance > Menus > Pages.
41 add_action( 'admin_head-nav-menus.php', array( $this, 'add_nav_menu_meta_boxes' ) );
42
43 // Admin bar menus.
44 if ( apply_filters( 'woocommerce_show_admin_bar_visit_store', true ) ) {
45 add_action( 'admin_bar_menu', array( $this, 'admin_bar_menus' ), 31 );
46 }
47
48 // Handle saving settings earlier than load-{page} hook to avoid race conditions in conditional menus.
49 add_action( 'wp_loaded', array( $this, 'save_settings' ) );
50 }
51
52 /**
53 * Add menu items.
54 */
55 public function admin_menu() {
56 global $menu;
57
58 $woocommerce_icon = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMDI0IDEwMjQiPjxwYXRoIGZpbGw9IiNhMmFhYjIiIGQ9Ik02MTIuMTkyIDQyNi4zMzZjMC02Ljg5Ni0zLjEzNi01MS42LTI4LTUxLjYtMzcuMzYgMC00Ni43MDQgNzIuMjU2LTQ2LjcwNCA4Mi42MjQgMCAzLjQwOCAzLjE1MiA1OC40OTYgMjguMDMyIDU4LjQ5NiAzNC4xOTItLjAzMiA0Ni42NzItNzIuMjg4IDQ2LjY3Mi04OS41MnptMjAyLjE5MiAwYzAtNi44OTYtMy4xNTItNTEuNi0yOC4wMzItNTEuNi0zNy4yOCAwLTQ2LjYwOCA3Mi4yNTYtNDYuNjA4IDgyLjYyNCAwIDMuNDA4IDMuMDcyIDU4LjQ5NiAyNy45NTIgNTguNDk2IDM0LjE5Mi0uMDMyIDQ2LjY4OC03Mi4yODggNDYuNjg4LTg5LjUyek0xNDEuMjk2Lj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Y0IDIzLjcxMiAxNy4xNjggMTEuNjQ4IDYyLjAzMiAxNi42ODggMTIwLjUxMiAyOS4xNjggMTg1Ljk2OCAxLjg1NiAyLjkyOCAxLjUwNCA3LjAwOCA0LjU2IDEwLjQzMiAzLjE1Mi0xMC4yODggNjYuOTI4LTE2OC43ODQgOTQuOTYtMTY4Ljc4NCAyMi41NDQgMCAzMC40IDQ0LjU5MiAzMy41MzYgNjEuODI0IDYuMjA4IDIwLjY1NiAxMy4wODggNTUuMjE2IDIyLjQxNiA4Mi43NTIgMC0xMy43NzYgMTIuNDgtMjAzLjEyIDY1LjM5Mi0yMDMuMTIgMTguNTkyLjAzMiAyNi43MDQgNi45MjggMjYuNzA0IDI3LjU2OHpNODcwLjMyIDQyMi45MjhjMCA1NS4wODgtMzEuMDg4IDE1NC44OC0xMDIuNjQgMTU0Ljg4LTYuMTkyIDAtMTguNDQ4LTMuNjE2LTI1LjQyNC02LjAxNi0zMi40MzItMTEuMTY4LTUwLjE3Ni00OS42OTYtNTIuMjg4LTY2LjI1NiAwIDAtMy44ODgtMTcuOTItMy44ODgtNDAuODk2czMuODg4LTQ1LjE4NCAzLjg4OC00NS4xODRjMTUuNTUyLTc1LjcyOCA0My40ODgtMTA2LjczNiA5Ni4zODQtMTA2LjczNiA1OS4xMDQtLjAzMiA4My45NjggNTguNTI4IDgzLjk2OCAxMTAuMjA4eiIvPjwvc3ZnPg==';
59
60 if ( current_user_can( 'edit_others_shop_orders' ) ) {
61 $menu[] = array( '', 'read', 'separator-woocommerce', '', 'wp-menu-separator woocommerce' ); // WPCS: override ok.
62 }
63
64 add_menu_page( __( 'WooCommerce', 'woocommerce' ), __( 'WooCommerce', 'woocommerce' ), 'edit_others_shop_orders', 'woocommerce', null, $woocommerce_icon, '55.5' );
65
66 add_submenu_page( 'edit.php?post_type=product', __( 'Attributes', 'woocommerce' ), __( 'Attributes', 'woocommerce' ), 'manage_product_terms', 'product_attributes', array( $this, 'attributes_page' ) );
67 }
68
69 /**
70 * Add menu item.
71 */
72 public function reports_menu() {
73 if ( current_user_can( 'edit_others_shop_orders' ) ) {
74 add_submenu_page( 'woocommerce', __( 'Reports', 'woocommerce' ), __( 'Reports', 'woocommerce' ), 'view_woocommerce_reports', 'wc-reports', array( $this, 'reports_page' ) );
75 } else {
76 add_menu_page( __( 'Sales reports', 'woocommerce' ), __( 'Sales reports', 'woocommerce' ), 'view_woocommerce_reports', 'wc-reports', array( $this, 'reports_page' ), 'dashicons-chart-bar', '55.6' );
77 }
78 }
79
80 /**
81 * Add menu item.
82 */
83 public function settings_menu() {
84 $settings_page = add_submenu_page( 'woocommerce', __( 'WooCommerce settings', 'woocommerce' ), __( 'Settings', 'woocommerce' ), 'manage_woocommerce', 'wc-settings', array( $this, 'settings_page' ) );
85
86 add_action( 'load-' . $settings_page, array( $this, 'settings_page_init' ) );
87 }
88
89 /**
90 * Loads gateways and shipping methods into memory for use within settings.
91 */
92 public function settings_page_init() {
93 WC()->payment_gateways();
94 WC()->shipping();
95
96 // Include settings pages.
97 WC_Admin_Settings::get_settings_pages();
98
99 // Add any posted messages.
100 if ( ! empty( $_GET['wc_error'] ) ) { // WPCS: input var okay, CSRF ok.
101 WC_Admin_Settings::add_error( wp_kses_post( wp_unslash( $_GET['wc_error'] ) ) ); // WPCS: input var okay, CSRF ok.
102 }
103
104 if ( ! empty( $_GET['wc_message'] ) ) { // WPCS: input var okay, CSRF ok.
105 WC_Admin_Settings::add_message( wp_kses_post( wp_unslash( $_GET['wc_message'] ) ) ); // WPCS: input var okay, CSRF ok.
106 }
107
108 do_action( 'woocommerce_settings_page_init' );
109 }
110
111 /**
112 * Handle saving of settings.
113 *
114 * @return void
115 */
116 public function save_settings() {
117 global $current_tab, $current_section;
118
119 // We should only save on the settings page.
120 if ( ! is_admin() || ! isset( $_GET['page'] ) || 'wc-settings' !== $_GET['page'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
121 return;
122 }
123
124 // Include settings pages.
125 WC_Admin_Settings::get_settings_pages();
126
127 // Get current tab/section.
128 $current_tab = empty( $_GET['tab'] ) ? 'general' : sanitize_title( wp_unslash( $_GET['tab'] ) ); // WPCS: input var okay, CSRF ok.
129 $current_section = empty( $_REQUEST['section'] ) ? '' : sanitize_title( wp_unslash( $_REQUEST['section'] ) ); // WPCS: input var okay, CSRF ok.
130
131 // Save settings if data has been posted.
132 if ( '' !== $current_section && apply_filters( "woocommerce_save_settings_{$current_tab}_{$current_section}", ! empty( $_POST['save'] ) ) ) { // WPCS: input var okay, CSRF ok.
133 WC_Admin_Settings::save();
134 } elseif ( '' === $current_section && apply_filters( "woocommerce_save_settings_{$current_tab}", ! empty( $_POST['save'] ) ) ) { // WPCS: input var okay, CSRF ok.
135 WC_Admin_Settings::save();
136 }
137 }
138
139 /**
140 * Add menu item.
141 */
142 public function status_menu() {
143 add_submenu_page( 'woocommerce', __( 'WooCommerce status', 'woocommerce' ), __( 'Status', 'woocommerce' ), 'manage_woocommerce', 'wc-status', array( $this, 'status_page' ) );
144 }
145
146 /**
147 * Addons menu item.
148 */
149 public function addons_menu() {
150 $count_html = WC_Helper_Updater::get_updates_count_html();
151 /* translators: %s: extensions count */
152 $menu_title = sprintf( __( 'Extensions %s', 'woocommerce' ), $count_html );
153 add_submenu_page( 'woocommerce', __( 'WooCommerce extensions', 'woocommerce' ), $menu_title, 'manage_woocommerce', 'wc-addons', array( $this, 'addons_page' ) );
154 }
155
156 /**
157 * Highlights the correct top level admin menu item for post type add screens.
158 */
159 public function menu_highlight() {
160 global $parent_file, $submenu_file, $post_type;
161
162 switch ( $post_type ) {
163 case 'shop_order':
164 case 'shop_coupon':
165 $parent_file = 'woocommerce'; // WPCS: override ok.
166 break;
167 case 'product':
168 $screen = get_current_screen();
169 if ( $screen && taxonomy_is_product_attribute( $screen->taxonomy ) ) {
170 $submenu_file = 'product_attributes'; // WPCS: override ok.
171 $parent_file = 'edit.php?post_type=product'; // WPCS: override ok.
172 }
173 break;
174 }
175 }
176
177 /**
178 * Adds the order processing count to the menu.
179 */
180 public function menu_order_count() {
181 global $submenu;
182
183 if ( isset( $submenu['woocommerce'] ) ) {
184 // Remove 'WooCommerce' sub menu item.
185 unset( $submenu['woocommerce'][0] );
186
187 // Add count if user has access.
188 if ( apply_filters( 'woocommerce_include_processing_order_count_in_menu', true ) && current_user_can( 'edit_others_shop_orders' ) ) {
189 $order_count = apply_filters( 'woocommerce_menu_order_count', wc_processing_order_count() );
190
191 if ( $order_count ) {
192 foreach ( $submenu['woocommerce'] as $key => $menu_item ) {
193 if ( 0 === strpos( $menu_item[0], _x( 'Orders', 'Admin menu name', 'woocommerce' ) ) ) {
194 $submenu['woocommerce'][ $key ][0] .= ' <span class="awaiting-mod update-plugins count-' . esc_attr( $order_count ) . '"><span class="processing-count">' . number_format_i18n( $order_count ) . '</span></span>'; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
195 break;
196 }
197 }
198 }
199 }
200 }
201 }
202
203 /**
204 * Reorder the WC menu items in admin.
205 *
206 * @param int $menu_order Menu order.
207 * @return array
208 */
209 public function menu_order( $menu_order ) {
210 // Initialize our custom order array.
211 $woocommerce_menu_order = array();
212
213 // Get the index of our custom separator.
214 $woocommerce_separator = array_search( 'separator-woocommerce', $menu_order, true );
215
216 // Get index of product menu.
217 $woocommerce_product = array_search( 'edit.php?post_type=product', $menu_order, true );
218
219 // Loop through menu order and do some rearranging.
220 foreach ( $menu_order as $index => $item ) {
221
222 if ( 'woocommerce' === $item ) {
223 $woocommerce_menu_order[] = 'separator-woocommerce';
224 $woocommerce_menu_order[] = $item;
225 $woocommerce_menu_order[] = 'edit.php?post_type=product';
226 unset( $menu_order[ $woocommerce_separator ] );
227 unset( $menu_order[ $woocommerce_product ] );
228 } elseif ( ! in_array( $item, array( 'separator-woocommerce' ), true ) ) {
229 $woocommerce_menu_order[] = $item;
230 }
231 }
232
233 // Return order.
234 return $woocommerce_menu_order;
235 }
236
237 /**
238 * Custom menu order.
239 *
240 * @param bool $enabled Whether custom menu ordering is already enabled.
241 * @return bool
242 */
243 public function custom_menu_order( $enabled ) {
244 return $enabled || current_user_can( 'edit_others_shop_orders' );
245 }
246
247 /**
248 * Validate screen options on update.
249 *
250 * @param bool|int $status Screen option value. Default false to skip.
251 * @param string $option The option name.
252 * @param int $value The number of rows to use.
253 */
254 public function set_screen_option( $status, $option, $value ) {
255 if ( in_array( $option, array( 'woocommerce_keys_per_page', 'woocommerce_webhooks_per_page' ), true ) ) {
256 return $value;
257 }
258
259 return $status;
260 }
261
262 /**
263 * Init the reports page.
264 */
265 public function reports_page() {
266 WC_Admin_Reports::output();
267 }
268
269 /**
270 * Init the settings page.
271 */
272 public function settings_page() {
273 WC_Admin_Settings::output();
274 }
275
276 /**
277 * Init the attributes page.
278 */
279 public function attributes_page() {
280 WC_Admin_Attributes::output();
281 }
282
283 /**
284 * Init the status page.
285 */
286 public function status_page() {
287 WC_Admin_Status::output();
288 }
289
290 /**
291 * Init the addons page.
292 */
293 public function addons_page() {
294 WC_Admin_Addons::output();
295 }
296
297 /**
298 * Add custom nav meta box.
299 *
300 * Adapted from http://www.johnmorrisonline.com/how-to-add-a-fully-functional-custom-meta-box-to-wordpress-navigation-menus/.
301 */
302 public function add_nav_menu_meta_boxes() {
303 add_meta_box( 'woocommerce_endpoints_nav_link', __( 'WooCommerce endpoints', 'woocommerce' ), array( $this, 'nav_menu_links' ), 'nav-menus', 'side', 'low' );
304 }
305
306 /**
307 * Output menu links.
308 */
309 public function nav_menu_links() {
310 // Get items from account menu.
311 $endpoints = wc_get_account_menu_items();
312
313 // Remove dashboard item.
314 if ( isset( $endpoints['dashboard'] ) ) {
315 unset( $endpoints['dashboard'] );
316 }
317
318 // Include missing lost password.
319 $endpoints['lost-password'] = __( 'Lost password', 'woocommerce' );
320
321 $endpoints = apply_filters( 'woocommerce_custom_nav_menu_items', $endpoints );
322
323 ?>
324 <div id="posttype-woocommerce-endpoints" class="posttypediv">
325 <div id="tabs-panel-woocommerce-endpoints" class="tabs-panel tabs-panel-active">
326 <ul id="woocommerce-endpoints-checklist" class="categorychecklist form-no-clear">
327 <?php
328 $i = -1;
329 foreach ( $endpoints as $key => $value ) :
330 ?>
331 <li>
332 <label class="menu-item-title">
333 <input type="checkbox" class="menu-item-checkbox" name="menu-item[<?php echo esc_attr( $i ); ?>][menu-item-object-id]" value="<?php echo esc_attr( $i ); ?>" /> <?php echo esc_html( $value ); ?>
334 </label>
335 <input type="hidden" class="menu-item-type" name="menu-item[<?php echo esc_attr( $i ); ?>][menu-item-type]" value="custom" />
336 <input type="hidden" class="menu-item-title" name="menu-item[<?php echo esc_attr( $i ); ?>][menu-item-title]" value="<?php echo esc_attr( $value ); ?>" />
337 <input type="hidden" class="menu-item-url" name="menu-item[<?php echo esc_attr( $i ); ?>][menu-item-url]" value="<?php echo esc_url( wc_get_account_endpoint_url( $key ) ); ?>" />
338 <input type="hidden" class="menu-item-classes" name="menu-item[<?php echo esc_attr( $i ); ?>][menu-item-classes]" />
339 </li>
340 <?php
341 $i--;
342 endforeach;
343 ?>
344 </ul>
345 </div>
346 <p class="button-controls">
347 <span class="list-controls">
348 <a href="<?php echo esc_url( admin_url( 'nav-menus.php?page-tab=all&selectall=1#posttype-woocommerce-endpoints' ) ); ?>" class="select-all"><?php esc_html_e( 'Select all', 'woocommerce' ); ?></a>
349 </span>
350 <span class="add-to-menu">
351 <button type="submit" class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e( 'Add to menu', 'woocommerce' ); ?>" name="add-post-type-menu-item" id="submit-posttype-woocommerce-endpoints"><?php esc_html_e( 'Add to menu', 'woocommerce' ); ?></button>
352 <span class="spinner"></span>
353 </span>
354 </p>
355 </div>
356 <?php
357 }
358
359 /**
360 * Add the "Visit Store" link in admin bar main menu.
361 *
362 * @since 2.4.0
363 * @param WP_Admin_Bar $wp_admin_bar Admin bar instance.
364 */
365 public function admin_bar_menus( $wp_admin_bar ) {
366 if ( ! is_admin() || ! is_admin_bar_showing() ) {
367 return;
368 }
369
370 // Show only when the user is a member of this site, or they're a super admin.
371 if ( ! is_user_member_of_blog() && ! is_super_admin() ) {
372 return;
373 }
374
375 // Don't display when shop page is the same of the page on front.
376 if ( intval( get_option( 'page_on_front' ) ) === wc_get_page_id( 'shop' ) ) {
377 return;
378 }
379
380 // Add an option to visit the store.
381 $wp_admin_bar->add_node(
382 array(
383 'parent' => 'site-name',
384 'id' => 'view-store',
385 'title' => __( 'Visit Store', 'woocommerce' ),
386 'href' => wc_get_page_permalink( 'shop' ),
387 )
388 );
389 }
390
391 }
392
393 return new WC_Admin_Menus();
394