Automattic\WooCommerce\Admin\Features\Navigation

CoreMenu::add_dashboard_menu_items()publicWC 1.0

Add the dashboard items to the WP menu to create a quick-access flyout menu.

Method of the class: CoreMenu{}

No Hooks.

Return

null. Nothing (null).

Usage

$CoreMenu = new CoreMenu();
$CoreMenu->add_dashboard_menu_items();

CoreMenu::add_dashboard_menu_items() code WC 8.7.0

public function add_dashboard_menu_items() {
	global $submenu, $menu;
	$mapped_items = Menu::get_mapped_menu_items();
	$top_level    = $mapped_items['woocommerce'];

	// phpcs:disable
	if ( ! isset( $submenu['woocommerce'] ) || empty( $top_level ) ) {
		return;
	}

	$menuIds = array(
		'primary',
		'secondary',
		'favorites',
	);

	foreach ( $menuIds as $menuId ) {
		foreach( $top_level[ $menuId ] as $item ) {
			// Skip specific categories.
			if (
				in_array(
					$item['id'],
					array(
						'woocommerce-tools',
					),
					true
				)
			) {
				continue;
			}

			// Use the link from the first item if it's a category.
			if ( ! isset( $item['url'] ) ) {
				$categoryMenuId = $menuId === 'favorites' ? 'plugins' : $menuId;
				$category_items = $mapped_items[ $item['id'] ][ $categoryMenuId ];

				if ( ! empty( $category_items ) ) {
					$first_item = $category_items[0];


					$submenu['woocommerce'][] = array(
						$item['title'],
						$first_item['capability'],
						isset( $first_item['url'] ) ? $first_item['url'] : null,
						$item['title'],
					);
				}

				continue;
			}

			// Show top-level items.
			$submenu['woocommerce'][] = array(
				$item['title'],
				$item['capability'],
				isset( $item['url'] ) ? $item['url'] : null,
				$item['title'],
			);
		}
	}
	// phpcs:enable
}