Automattic\WooCommerce\Admin\Features\Navigation

Menu::get_mapped_menu_items()public staticWC 1.0

Gets the menu item data mapped by category and menu ID.

Method of the class: Menu{}

No Hooks.

Return

Array.

Usage

$result = Menu::get_mapped_menu_items();

Menu::get_mapped_menu_items() code WC 8.7.0

public static function get_mapped_menu_items() {
	$menu_items   = self::get_items();
	$mapped_items = array();

	// Sort the items by order and title.
	$order     = array_column( $menu_items, 'order' );
	$title     = array_column( $menu_items, 'title' );
	array_multisort( $order, SORT_ASC, $title, SORT_ASC, $menu_items );

	foreach ( $menu_items as $id => $menu_item ) {
		$category_id = $menu_item[ 'parent' ];
		$menu_id     = $menu_item[ 'menuId' ];
		if ( ! isset( $mapped_items[ $category_id ] ) ) {
			$mapped_items[ $category_id ] = array();
			foreach ( self::MENU_IDS as $available_menu_id ) {
				$mapped_items[ $category_id ][ $available_menu_id ] = array();
			}
		}

		// Incorrect menu ID.
		if ( ! isset( $mapped_items[ $category_id ][ $menu_id ] ) ) {
			continue;
		}

		// Remove the item if the user cannot access it.
		if ( isset( $menu_item[ 'capability' ] ) && ! current_user_can( $menu_item[ 'capability' ] ) ) {
			continue;
		}

		$mapped_items[ $category_id ][ $menu_id ][] = $menu_item;
	}

	return $mapped_items;
}