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