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rc.2 3.1.0 6.2.1 3.1.1 6.2.2 3.1.2 6.2.3 3.2.0 6.3.0 3.2.1 6.3.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 2 months ago importers 1 year ago list-tables 1 month ago marketplace-suggestions 11 months ago meta-boxes 1 month ago notes 2 months ago plugin-updates 2 years ago reports 3 months ago settings 6 days ago views 1 month ago class-wc-admin-addons.php 9 months ago class-wc-admin-api-keys-table-list.php 2 years ago class-wc-admin-api-keys.php 11 months ago class-wc-admin-assets.php 1 month ago class-wc-admin-attributes.php 1 month ago class-wc-admin-brands.php 4 months ago class-wc-admin-customize.php 5 years ago class-wc-admin-dashboard-setup.php 1 month ago class-wc-admin-dashboard.php 4 months ago class-wc-admin-duplicate-product.php 5 months ago class-wc-admin-exporters.php 1 year ago class-wc-admin-help.php 2 years ago class-wc-admin-importers.php 11 months ago class-wc-admin-log-table-list.php 4 months ago class-wc-admin-marketplace-promotions.php 4 months ago class-wc-admin-menus.php 1 month ago class-wc-admin-meta-boxes.php 1 month ago class-wc-admin-notices.php 1 month ago class-wc-admin-permalink-settings.php 5 years ago class-wc-admin-pointers.php 3 years ago class-wc-admin-post-types.php 1 year ago class-wc-admin-profile.php 1 year ago class-wc-admin-reports.php 4 months ago class-wc-admin-settings.php 3 months ago class-wc-admin-setup-wizard.php 1 month ago class-wc-admin-status.php 1 year ago class-wc-admin-taxonomies.php 1 month ago class-wc-admin-upload-downloadable-product.php 2 years ago class-wc-admin-webhooks-table-list.php 1 month ago class-wc-admin-webhooks.php 1 month ago class-wc-admin.php 3 months ago wc-admin-functions.php 7 months ago wc-meta-box-functions.php 1 year ago woocommerce-legacy-reports.php 1 year ago
class-wc-admin-menus.php
597 lines
1 <?php
2 /**
3 * Setup menus in WP admin.
4 *
5 * @package WooCommerce\Admin
6 * @version 2.5.0
7 */
8
9 use Automattic\WooCommerce\Internal\Admin\Marketplace;
10 use Automattic\WooCommerce\Internal\Admin\Orders\COTRedirectionController;
11 use Automattic\WooCommerce\Internal\Admin\Orders\PageController as Custom_Orders_PageController;
12 use Automattic\WooCommerce\Internal\Admin\Logging\PageController as LoggingPageController;
13 use Automattic\WooCommerce\Internal\Admin\Logging\FileV2\{ FileListTable, SearchListTable };
14 use Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController;
15 use Automattic\WooCommerce\Utilities\FeaturesUtil;
16
17 defined( 'ABSPATH' ) || exit;
18
19 if ( class_exists( 'WC_Admin_Menus', false ) ) {
20 return new WC_Admin_Menus();
21 }
22
23 /**
24 * WC_Admin_Menus Class.
25 */
26 class WC_Admin_Menus {
27
28 /**
29 * The CSS classes used to hide the submenu items in navigation.
30 *
31 * @var string
32 */
33 const HIDE_CSS_CLASS = 'hide-if-js';
34
35 /**
36 * Hook in tabs.
37 */
38 public function __construct() {
39 // Add menus.
40 add_action( 'admin_menu', array( $this, 'menu_highlight' ) );
41 add_action( 'admin_menu', array( $this, 'menu_order_count' ) );
42 add_action( 'admin_menu', array( $this, 'maybe_add_new_product_management_experience' ) );
43 add_action( 'admin_menu', array( $this, 'admin_menu' ), 9 );
44 add_action( 'admin_menu', array( $this, 'orders_menu' ), 9 );
45 add_action( 'admin_menu', array( $this, 'reports_menu' ), 20 );
46 add_action( 'admin_menu', array( $this, 'settings_menu' ), 50 );
47 add_action( 'admin_menu', array( $this, 'status_menu' ), 60 );
48
49 /**
50 * Controls whether we add a submenu item for the WooCommerce Addons page.
51 * Woo Express uses this filter.
52 *
53 * @since 8.2.1
54 *
55 * @param bool $show_addons_page If the addons page should be included.
56 */
57 if ( apply_filters( 'woocommerce_show_addons_page', true ) ) {
58 $container = wc_get_container();
59 $container->get( Marketplace::class );
60
61 add_action( 'admin_menu', array( $this, 'addons_my_subscriptions' ), 70 );
62 }
63
64 add_filter( 'menu_order', array( $this, 'menu_order' ) );
65 add_filter( 'custom_menu_order', array( $this, 'custom_menu_order' ) );
66 add_filter( 'set-screen-option', array( $this, 'set_screen_option' ), 10, 3 );
67
68 // Add endpoints custom URLs in Appearance > Menus > Pages.
69 add_action( 'admin_head-nav-menus.php', array( $this, 'add_nav_menu_meta_boxes' ) );
70
71 // Admin bar menus.
72 if ( apply_filters( 'woocommerce_show_admin_bar_visit_store', true ) ) {
73 add_action( 'admin_bar_menu', array( $this, 'admin_bar_menus' ), 31 );
74 }
75
76 // Handle saving settings earlier than load-{page} hook to avoid race conditions in conditional menus.
77 add_action( 'wp_loaded', array( $this, 'save_settings' ) );
78 }
79
80 /**
81 * Add menu items.
82 *
83 * @return void
84 */
85 public function admin_menu() {
86 global $menu, $admin_page_hooks;
87
88 $woocommerce_icon = 'data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgdmlld0JveD0iMCAwIDg1LjkgNDcuNiI+CjxwYXRoIGZpbGw9IiNhMmFhYjIiIGQ9Ik03Ny40LDAuMWMtNC4zLDAtNy4xLDEuNC05LjYsNi4xTDU2LjQsMjcuN1Y4LjZjMC01LjctMi43LTguNS03LjctOC41cy03LjEsMS43LTkuNiw2LjVMMjguMywyNy43VjguOAoJYzAtNi4xLTIuNS04LjctOC42LTguN0g3LjNDMi42LDAuMSwwLDIuMywwLDYuM3MyLjUsNi40LDcuMSw2LjRoNS4xdjI0LjFjMCw2LjgsNC42LDEwLjgsMTEuMiwxMC44UzMzLDQ1LDM2LjMsMzguOWw3LjItMTMuNXYxMS40CgljMCw2LjcsNC40LDEwLjgsMTEuMSwxMC44czkuMi0yLjMsMTMtOC43bDE2LjYtMjhjMy42LTYuMSwxLjEtMTAuOC02LjktMTAuOEM3Ny4zLDAuMSw3Ny4zLDAuMSw3Ny40LDAuMXoiLz4KPC9zdmc+Cg==';
89
90 if ( self::can_view_woocommerce_menu_item() ) {
91 $menu[] = array( '', 'read', 'separator-woocommerce', '', 'wp-menu-separator woocommerce' ); // WPCS: override ok.
92 }
93
94 add_menu_page( __( 'WooCommerce', 'woocommerce' ), __( 'WooCommerce', 'woocommerce' ), 'edit_others_shop_orders', 'woocommerce', null, $woocommerce_icon, '55.5' );
95
96 // Work around https://github.com/woocommerce/woocommerce/issues/35677 (and related https://core.trac.wordpress.org/ticket/18857).
97 // Translating the menu item breaks screen IDs and page hooks, so we force the hookname to be untranslated.
98 $admin_page_hooks['woocommerce'] = 'woocommerce'; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
99
100 add_submenu_page( 'edit.php?post_type=product', __( 'Attributes', 'woocommerce' ), __( 'Attributes', 'woocommerce' ), 'manage_product_terms', 'product_attributes', array( $this, 'attributes_page' ) );
101 }
102
103 /**
104 * Add menu item.
105 *
106 * @return void
107 */
108 public function reports_menu() {
109 if ( self::can_view_woocommerce_menu_item() ) {
110 add_submenu_page( 'woocommerce', __( 'Reports', 'woocommerce' ), __( 'Reports', 'woocommerce' ), 'view_woocommerce_reports', 'wc-reports', array( $this, 'reports_page' ) );
111 } else {
112 add_menu_page( __( 'Sales reports', 'woocommerce' ), __( 'Sales reports', 'woocommerce' ), 'view_woocommerce_reports', 'wc-reports', array( $this, 'reports_page' ), 'dashicons-chart-bar', '55.6' );
113 }
114 }
115
116 /**
117 * Add menu item.
118 *
119 * @return void
120 */
121 public function settings_menu() {
122 $settings_page = add_submenu_page(
123 'woocommerce',
124 __( 'WooCommerce settings', 'woocommerce' ),
125 __( 'Settings', 'woocommerce' ),
126 'manage_woocommerce',
127 'wc-settings',
128 array( $this, 'settings_page' )
129 );
130
131 add_action( 'load-' . $settings_page, array( $this, 'settings_page_init' ) );
132 }
133
134 /**
135 * Check if the user can access the top-level WooCommerce item.
136 *
137 * @return bool
138 */
139 public static function can_view_woocommerce_menu_item() {
140 return current_user_can( 'edit_others_shop_orders' );
141 }
142
143 /**
144 * Loads gateways and shipping methods into memory for use within settings.
145 *
146 * @return void
147 */
148 public function settings_page_init() {
149 WC()->payment_gateways();
150 WC()->shipping();
151
152 // Include settings pages.
153 WC_Admin_Settings::get_settings_pages();
154
155 // Add any posted messages.
156 if ( ! empty( $_GET['wc_error'] ) ) { // WPCS: input var okay, CSRF ok.
157 WC_Admin_Settings::add_error( wp_kses_post( wp_unslash( $_GET['wc_error'] ) ) ); // WPCS: input var okay, CSRF ok.
158 }
159
160 if ( ! empty( $_GET['wc_message'] ) ) { // WPCS: input var okay, CSRF ok.
161 WC_Admin_Settings::add_message( wp_kses_post( wp_unslash( $_GET['wc_message'] ) ) ); // WPCS: input var okay, CSRF ok.
162 }
163
164 do_action( 'woocommerce_settings_page_init' );
165 }
166
167 /**
168 * Handle saving of settings.
169 *
170 * @return void
171 */
172 public function save_settings() {
173 global $current_tab, $current_section;
174
175 // We should only save on the settings page.
176 if ( ! is_wc_admin_settings_page() ) {
177 return;
178 }
179
180 // Include settings pages.
181 WC_Admin_Settings::get_settings_pages();
182
183 // Get current tab/section.
184 $current_tab = empty( $_GET['tab'] ) ? 'general' : sanitize_title( wp_unslash( $_GET['tab'] ) ); // WPCS: input var okay, CSRF ok.
185 $current_section = empty( $_REQUEST['section'] ) ? '' : sanitize_title( wp_unslash( $_REQUEST['section'] ) ); // WPCS: input var okay, CSRF ok.
186
187 // Save settings if data has been posted.
188 if ( '' !== $current_section && apply_filters( "woocommerce_save_settings_{$current_tab}_{$current_section}", ! empty( $_POST['save'] ) ) ) { // WPCS: input var okay, CSRF ok.
189 WC_Admin_Settings::save();
190 } elseif ( '' === $current_section && apply_filters( "woocommerce_save_settings_{$current_tab}", ! empty( $_POST['save'] ) ) ) { // WPCS: input var okay, CSRF ok.
191 WC_Admin_Settings::save();
192 }
193 }
194
195 /**
196 * Add menu item.
197 *
198 * @return void
199 */
200 public function status_menu() {
201 $status_page = add_submenu_page( 'woocommerce', __( 'WooCommerce status', 'woocommerce' ), __( 'Status', 'woocommerce' ), 'manage_woocommerce', 'wc-status', array( $this, 'status_page' ) );
202
203 add_action(
204 'load-' . $status_page,
205 function () {
206 if ( 'logs' === filter_input( INPUT_GET, 'tab' ) ) {
207 // Initialize the logging page controller early so that it can hook into things.
208 wc_get_container()->get( LoggingPageController::class );
209 }
210 },
211 1
212 );
213 }
214
215 /**
216 * Addons menu item.
217 *
218 * @deprecated 10.5.0 The marketplace feature is now always enabled. Use the Extensions menu instead.
219 *
220 * @return void
221 */
222 public function addons_menu() {
223 wc_deprecated_function( __METHOD__, '10.5.0' );
224
225 $count_html = WC_Helper_Updater::get_updates_count_html();
226 /* translators: %s: extensions count */
227 $menu_title = sprintf( __( 'Extensions %s', 'woocommerce' ), $count_html );
228 add_submenu_page( 'woocommerce', __( 'WooCommerce extensions', 'woocommerce' ), $menu_title, 'manage_woocommerce', 'wc-addons', array( $this, 'addons_page' ) );
229 }
230
231 /**
232 * Registers the wc-addons page within the WooCommerce menu.
233 * Temporary measure till we convert the whole page to React.
234 *
235 * @return void
236 */
237 public function addons_my_subscriptions() {
238 add_submenu_page( 'woocommerce', __( 'WooCommerce extensions', 'woocommerce' ), null, 'manage_woocommerce', 'wc-addons', array( $this, 'addons_page' ) );
239 // Temporarily hide the submenu item we've just added.
240 $this->hide_submenu_page( 'woocommerce', 'wc-addons' );
241 }
242
243 /**
244 * Highlights the correct top level admin menu item for post type add screens.
245 *
246 * @return void
247 */
248 public function menu_highlight() {
249 global $parent_file, $submenu_file, $post_type;
250
251 switch ( $post_type ) {
252 case 'shop_order':
253 case 'shop_coupon':
254 $parent_file = 'woocommerce'; // WPCS: override ok.
255 break;
256 case 'product':
257 $screen = get_current_screen();
258 if ( $screen && taxonomy_is_product_attribute( $screen->taxonomy ) ) {
259 $submenu_file = 'product_attributes'; // WPCS: override ok.
260 $parent_file = 'edit.php?post_type=product'; // WPCS: override ok.
261 }
262 break;
263 }
264 }
265
266 /**
267 * Adds the order processing count to the menu.
268 *
269 * @return void
270 */
271 public function menu_order_count() {
272 global $submenu;
273
274 if ( isset( $submenu['woocommerce'] ) ) {
275 // Remove 'WooCommerce' sub menu item.
276 unset( $submenu['woocommerce'][0] );
277
278 // Add count if user has access.
279 if ( apply_filters( 'woocommerce_include_processing_order_count_in_menu', true ) && current_user_can( 'edit_others_shop_orders' ) ) {
280 $order_count = apply_filters( 'woocommerce_menu_order_count', wc_processing_order_count() );
281
282 if ( $order_count ) {
283 foreach ( $submenu['woocommerce'] as $key => $menu_item ) {
284 if ( 0 === strpos( $menu_item[0], _x( 'Orders', 'Admin menu name', 'woocommerce' ) ) ) {
285 $submenu['woocommerce'][ $key ][0] .= ' <span class="menu-counter count-' . esc_attr( $order_count ) . '"><span class="processing-count">' . number_format_i18n( $order_count ) . '</span></span>'; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
286 break;
287 }
288 }
289 }
290 }
291 }
292 }
293
294 /**
295 * Reorder the WC menu items in admin.
296 *
297 * @param int $menu_order Menu order.
298 * @return array
299 */
300 public function menu_order( $menu_order ) {
301 // Initialize our custom order array.
302 $woocommerce_menu_order = array();
303
304 // Get the index of our custom separator.
305 $woocommerce_separator = array_search( 'separator-woocommerce', $menu_order, true );
306
307 // Get index of product menu.
308 $woocommerce_product = array_search( 'edit.php?post_type=product', $menu_order, true );
309
310 // Loop through menu order and do some rearranging.
311 foreach ( $menu_order as $index => $item ) {
312
313 if ( 'woocommerce' === $item ) {
314 $woocommerce_menu_order[] = 'separator-woocommerce';
315 $woocommerce_menu_order[] = $item;
316 $woocommerce_menu_order[] = 'edit.php?post_type=product';
317 unset( $menu_order[ $woocommerce_separator ] );
318 unset( $menu_order[ $woocommerce_product ] );
319 } elseif ( ! in_array( $item, array( 'separator-woocommerce' ), true ) ) {
320 $woocommerce_menu_order[] = $item;
321 }
322 }
323
324 // Return order.
325 return $woocommerce_menu_order;
326 }
327
328 /**
329 * Custom menu order.
330 *
331 * @param bool $enabled Whether custom menu ordering is already enabled.
332 * @return bool
333 */
334 public function custom_menu_order( $enabled ) {
335 return $enabled || self::can_view_woocommerce_menu_item();
336 }
337
338 /**
339 * Validate screen options on update.
340 *
341 * @param bool|int $status Screen option value. Default false to skip.
342 * @param string $option The option name.
343 * @param int $value The number of rows to use.
344 * @return bool|int
345 */
346 public function set_screen_option( $status, $option, $value ) {
347 $screen_options = array(
348 'woocommerce_keys_per_page',
349 'woocommerce_webhooks_per_page',
350 FileListTable::PER_PAGE_USER_OPTION_KEY,
351 SearchListTable::PER_PAGE_USER_OPTION_KEY,
352 WC_Admin_Log_Table_List::PER_PAGE_USER_OPTION_KEY,
353 );
354
355 if ( in_array( $option, $screen_options, true ) ) {
356 return $value;
357 }
358
359 return $status;
360 }
361
362 /**
363 * Init the reports page.
364 *
365 * @return void
366 */
367 public function reports_page() {
368 WC_Admin_Reports::output();
369 }
370
371 /**
372 * Init the settings page.
373 *
374 * @return void
375 */
376 public function settings_page() {
377 WC_Admin_Settings::output();
378 }
379
380 /**
381 * Init the attributes page.
382 *
383 * @return void
384 */
385 public function attributes_page() {
386 WC_Admin_Attributes::output();
387 }
388
389 /**
390 * Init the status page.
391 *
392 * @return void
393 */
394 public function status_page() {
395 WC_Admin_Status::output();
396 }
397
398 /**
399 * Init the addons page.
400 *
401 * @return void
402 */
403 public function addons_page() {
404 WC_Admin_Addons::handle_legacy_marketplace_redirects();
405 }
406
407 /**
408 * Link to the order admin list table from the main WooCommerce menu.
409 *
410 * @return void
411 */
412 public function orders_menu(): void {
413 if ( wc_get_container()->get( CustomOrdersTableController::class )->custom_orders_table_usage_is_enabled() ) {
414 wc_get_container()->get( Custom_Orders_PageController::class )->setup();
415 } else {
416 wc_get_container()->get( COTRedirectionController::class )->setup();
417 }
418 }
419
420 /**
421 * Add custom nav meta box.
422 *
423 * Adapted from http://www.johnmorrisonline.com/how-to-add-a-fully-functional-custom-meta-box-to-wordpress-navigation-menus/.
424 *
425 * @return void
426 */
427 public function add_nav_menu_meta_boxes() {
428 add_meta_box( 'woocommerce_endpoints_nav_link', __( 'WooCommerce endpoints', 'woocommerce' ), array( $this, 'nav_menu_links' ), 'nav-menus', 'side', 'low' );
429 }
430
431 /**
432 * Output menu links.
433 *
434 * @return void
435 */
436 public function nav_menu_links() {
437 // Get items from account menu.
438 $endpoints = wc_get_account_menu_items();
439
440 // Remove dashboard item.
441 if ( isset( $endpoints['dashboard'] ) ) {
442 unset( $endpoints['dashboard'] );
443 }
444
445 // Include missing lost password endpoint, if set in WooCommerce > Settings > Advanced > Account endpoints.
446 if ( ! empty( get_option( 'woocommerce_myaccount_lost_password_endpoint' ) ) ) {
447 $endpoints['lost-password'] = __( 'Lost password', 'woocommerce' );
448 }
449
450 $endpoints = apply_filters( 'woocommerce_custom_nav_menu_items', $endpoints );
451
452 ?>
453 <div id="posttype-woocommerce-endpoints" class="posttypediv">
454 <div id="tabs-panel-woocommerce-endpoints" class="tabs-panel tabs-panel-active">
455 <ul id="woocommerce-endpoints-checklist" class="categorychecklist form-no-clear">
456 <?php
457 $i = -1;
458 foreach ( $endpoints as $key => $value ) :
459 ?>
460 <li>
461 <label class="menu-item-title">
462 <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 ); ?>
463 </label>
464 <input type="hidden" class="menu-item-type" name="menu-item[<?php echo esc_attr( $i ); ?>][menu-item-type]" value="custom" />
465 <input type="hidden" class="menu-item-title" name="menu-item[<?php echo esc_attr( $i ); ?>][menu-item-title]" value="<?php echo esc_attr( $value ); ?>" />
466 <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 ) ); ?>" />
467 <input type="hidden" class="menu-item-classes" name="menu-item[<?php echo esc_attr( $i ); ?>][menu-item-classes]" />
468 </li>
469 <?php
470 --$i;
471 endforeach;
472 ?>
473 </ul>
474 </div>
475 <p class="button-controls" data-items-type="posttype-woocommerce-endpoints">
476 <span class="list-controls">
477 <label>
478 <input type="checkbox" class="select-all" />
479 <?php esc_html_e( 'Select all', 'woocommerce' ); ?>
480 </label>
481 </span>
482 <span class="add-to-menu">
483 <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>
484 <span class="spinner"></span>
485 </span>
486 </p>
487 </div>
488 <?php
489 }
490
491 /**
492 * Add the "Visit Store" link in admin bar main menu.
493 *
494 * @since 2.4.0
495 * @param WP_Admin_Bar $wp_admin_bar Admin bar instance.
496 * @return void
497 */
498 public function admin_bar_menus( $wp_admin_bar ) {
499 if ( ! is_admin() || ! is_admin_bar_showing() ) {
500 return;
501 }
502
503 // Show only when the user is a member of this site, or they're a super admin.
504 if ( ! is_user_member_of_blog() && ! is_super_admin() ) {
505 return;
506 }
507
508 // Don't display when shop page is the same of the page on front.
509 if ( intval( get_option( 'page_on_front' ) ) === wc_get_page_id( 'shop' ) ) {
510 return;
511 }
512
513 // Add an option to visit the store.
514 $wp_admin_bar->add_node(
515 array(
516 'parent' => 'site-name',
517 'id' => 'view-store',
518 'title' => __( 'Visit Store', 'woocommerce' ),
519 'href' => wc_get_page_permalink( 'shop' ),
520 )
521 );
522 }
523
524 /**
525 * Maybe add new management product experience.
526 *
527 * @return void
528 */
529 public function maybe_add_new_product_management_experience() {
530 if ( FeaturesUtil::feature_is_enabled( 'product_block_editor' ) ) {
531 global $submenu;
532 if ( isset( $submenu['edit.php?post_type=product'][10] ) ) {
533 // Disable phpcs since we need to override submenu classes.
534 // Note that `phpcs:ignore WordPress.Variables.GlobalVariables.OverrideProhibited` does not work to disable this check.
535 // phpcs:disable
536 $submenu['edit.php?post_type=product'][10][2] = 'admin.php?page=wc-admin&path=/add-product';
537 // phps:enableWordPress.Variables.GlobalVariables.OverrideProhibited
538 }
539 }
540 }
541
542 /**
543 * Hide the submenu page based on slug and return the item that was hidden.
544 *
545 * Borrowed from Jetpack's Base_Admin_Menu class.
546 *
547 * Instead of actually removing the submenu item, a safer approach is to hide it and filter it in the API response.
548 * In this manner we'll avoid breaking third-party plugins depending on items that no longer exist.
549 *
550 * A false|array value is returned to be consistent with remove_submenu_page() function
551 *
552 * @param string $menu_slug The parent menu slug.
553 * @param string $submenu_slug The submenu slug that should be hidden.
554 * @return false|array
555 */
556 public function hide_submenu_page( $menu_slug, $submenu_slug ) {
557 global $submenu;
558
559 if ( ! isset( $submenu[ $menu_slug ] ) ) {
560 return false;
561 }
562
563 foreach ( $submenu[ $menu_slug ] as $i => $item ) {
564 if ( $submenu_slug !== $item[2] ) {
565 continue;
566 }
567
568 $this->hide_submenu_element( $i, $menu_slug, $item );
569
570 return $item;
571 }
572
573 return false;
574 }
575
576 /**
577 * Apply the hide-if-js CSS class to a submenu item.
578 *
579 * Borrowed from Jetpack's Base_Admin_Menu class.
580 *
581 * @param int $index The position of a submenu item in the submenu array.
582 * @param string $parent_slug The parent slug.
583 * @param array $item The submenu item.
584 * @return void
585 */
586 public function hide_submenu_element( $index, $parent_slug, $item ) {
587 global $submenu;
588
589 $css_classes = empty( $item[4] ) ? self::HIDE_CSS_CLASS : $item[4] . ' ' . self::HIDE_CSS_CLASS;
590
591 // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
592 $submenu [ $parent_slug ][ $index ][4] = $css_classes;
593 }
594 }
595
596 return new WC_Admin_Menus();
597