Automattic\WooCommerce\Admin\Features\Navigation

Menu::add_category()private staticWC 1.0

Adds a top level menu item to the navigation.

Method of the class: Menu{}

No Hooks.

Return

null. Nothing (null).

Usage

$result = Menu::add_category( $args );
$args(array) (required)
Array containing the necessary arguments.
php $args = array( 'id' => (string) The unique ID of the menu item. Required. 'title' => (string) Title of the menu item. Required. 'url' => (string) URL or callback to be used. Required. 'order' => (int) Menu item order. 'migrate' => (bool) Whether or not to hide the item in the wp admin menu. 'menuId' => (string) The ID of the menu to add the category to. ).

Menu::add_category() code WC 8.7.0

private static function add_category( $args ) {
	if ( ! isset( $args['id'] ) || isset( self::$menu_items[ $args['id'] ] ) ) {
		return;
	}

	$defaults           = array(
		'id'         => '',
		'title'      => '',
		'order'      => 100,
		'migrate'    => true,
		'menuId'     => 'primary',
		'isCategory' => true,
	);
	$menu_item          = wp_parse_args( $args, $defaults );
	$menu_item['title'] = wp_strip_all_tags( wp_specialchars_decode( $menu_item['title'] ) );
	unset( $menu_item['url'] );
	unset( $menu_item['capability'] );

	if ( ! isset( $menu_item['parent'] ) ) {
		$menu_item['parent']          = 'woocommerce';
		$menu_item['backButtonLabel'] = __(
			'WooCommerce Home',
			'woocommerce'
		);
	}

	self::$menu_items[ $menu_item['id'] ]       = $menu_item;
	self::$categories[ $menu_item['id'] ]       = array();
	self::$categories[ $menu_item['parent'] ][] = $menu_item['id'];

	if ( isset( $args['url'] ) ) {
		self::$callbacks[ $args['url'] ] = $menu_item['migrate'];
	}
}