WooCommerce Code Reference

Menu

Contains logic for the WooCommerce Navigation menu.

Table of Contents

CALLBACK  = 2
Array index of menu callback.
CAPABILITY  = 1
Array index of menu capability.
CSS_CLASSES  = 4
Array index of menu CSS class string.
MENU_IDS  = array('primary', 'favorites', 'plugins', 'secondary')
Array of usable menu IDs.
SLUG  = 3
Array index of menu callback.
$callbacks  : array<string|int, mixed>
Registered callbacks or URLs with migration boolean as key value pairs.
$categories  : array<string|int, mixed>
Store categories with menu item IDs.
$instance  : Menu
Class instance.
$menu_items  : array<string|int, mixed>
Store menu items.
add_core_items()  : mixed
Add core menu items.
add_item_and_taxonomy()  : mixed
Add an item or taxonomy.
add_plugin_category()  : mixed
Adds a plugin category.
add_plugin_item()  : mixed
Adds a plugin item.
add_setting_item()  : mixed
Adds a plugin setting item.
enqueue_data()  : array<string|int, mixed>
Add the menu to the page output.
get_callback_url()  : string
Convert a WordPress menu callback to a URL.
get_callbacks()  : array<string|int, mixed>
Get registered callbacks.
get_category_items()  : array<string|int, mixed>
Get registered menu items.
get_item_menu_id()  : string
Get an item's menu ID from its parent.
get_items()  : array<string|int, mixed>
Get registered menu items.
get_mapped_menu_items()  : array<string|int, mixed>
Gets the menu item data mapped by category and menu ID.
get_parent_key()  : string|null
Get the parent key if one exists.
get_post_type_items()  : array<string|int, mixed>
Get menu item templates for a given post type.
get_taxonomy_items()  : array<string|int, mixed>
Get menu item templates for a given taxonomy.
has_callback()  : bool
Check if a menu item's callback is registered in the menu.
hide_wp_menu_item()  : mixed
Add a callback to identify and hide pages in the WP menu.
init()  : mixed
Init.
instance()  : mixed
Get class instance.
migrate_core_child_items()  : array<string|int, mixed>
Migrate any remaining WooCommerce child items.
migrate_menu_items()  : mixed
Hides all WP admin menus items and adds screen IDs to check for new items.
add_category()  : mixed
Adds a top level menu item to the navigation.
add_item()  : mixed
Adds a child menu item to the navigation.

Constants

Properties

$callbacks

Registered callbacks or URLs with migration boolean as key value pairs.

protected static array<string|int, mixed> $callbacks = array()

Methods

add_item_and_taxonomy()

Add an item or taxonomy.

public add_item_and_taxonomy(array<string|int, mixed> $menu_item) : mixed
Parameters
$menu_item : array<string|int, mixed>

Menu item.

Return values
mixed

add_plugin_category()

Adds a plugin category.

public static add_plugin_category(array<string|int, mixed> $args) : mixed
Parameters
$args : array<string|int, mixed>

Array containing the necessary arguments. $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. 'migrate' => (bool) Whether or not to hide the item in the wp admin menu. 'order' => (int) Menu item order. ).

Return values
mixed

add_plugin_item()

Adds a plugin item.

public static add_plugin_item(array<string|int, mixed> $args) : mixed
Parameters
$args : array<string|int, mixed>

Array containing the necessary arguments. $args = array( 'id' => (string) The unique ID of the menu item. Required. 'title' => (string) Title of the menu item. Required. 'parent' => (string) Parent menu item ID. 'capability' => (string) Capability to view this menu item. 'url' => (string) URL or callback to be used. Required. 'migrate' => (bool) Whether or not to hide the item in the wp admin menu. 'order' => (int) Menu item order. 'matchExpression' => (string) A regular expression used to identify if the menu item is active. ).

Return values
mixed

add_setting_item()

Adds a plugin setting item.

public static add_setting_item(array<string|int, mixed> $args) : mixed
Parameters
$args : array<string|int, mixed>

Array containing the necessary arguments. $args = array( 'id' => (string) The unique ID of the menu item. Required. 'title' => (string) Title of the menu item. Required. 'capability' => (string) Capability to view this menu item. 'url' => (string) URL or callback to be used. Required. 'migrate' => (bool) Whether or not to hide the item in the wp admin menu. ).

Return values
mixed

enqueue_data()

Add the menu to the page output.

public enqueue_data(array<string|int, mixed> $menu) : array<string|int, mixed>
Parameters
$menu : array<string|int, mixed>

Menu items.

Return values
array<string|int, mixed>

get_callback_url()

Convert a WordPress menu callback to a URL.

public static get_callback_url(string $callback) : string
Parameters
$callback : string

Menu callback.

Return values
string

get_category_items()

Get registered menu items.

public static get_category_items(mixed $category) : array<string|int, mixed>
Parameters
$category : mixed
Return values
array<string|int, mixed>

get_item_menu_id()

Get an item's menu ID from its parent.

public static get_item_menu_id(array<string|int, mixed> $item) : string
Parameters
$item : array<string|int, mixed>

Item args.

Return values
string

get_mapped_menu_items()

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

public static get_mapped_menu_items() : array<string|int, mixed>
Return values
array<string|int, mixed>

get_parent_key()

Get the parent key if one exists.

public static get_parent_key(string $callback) : string|null
Parameters
$callback : string

Callback or URL.

Return values
string|null

get_post_type_items()

Get menu item templates for a given post type.

public static get_post_type_items(string $post_type[, array<string|int, mixed> $menu_args = array() ]) : array<string|int, mixed>
Parameters
$post_type : string

Post type to add.

$menu_args : array<string|int, mixed> = array()

Arguments merged with the returned menu items.

Return values
array<string|int, mixed>

get_taxonomy_items()

Get menu item templates for a given taxonomy.

public static get_taxonomy_items(string $taxonomy[, array<string|int, mixed> $menu_args = array() ]) : array<string|int, mixed>
Parameters
$taxonomy : string

Taxonomy to add.

$menu_args : array<string|int, mixed> = array()

Arguments merged with the returned menu items.

Return values
array<string|int, mixed>

has_callback()

Check if a menu item's callback is registered in the menu.

public static has_callback(array<string|int, mixed> $menu_item) : bool
Parameters
$menu_item : array<string|int, mixed>

Menu item args.

Return values
bool

hide_wp_menu_item()

Add a callback to identify and hide pages in the WP menu.

public static hide_wp_menu_item(mixed $callback) : mixed
Parameters
$callback : mixed
Return values
mixed

migrate_core_child_items()

Migrate any remaining WooCommerce child items.

public migrate_core_child_items(array<string|int, mixed> $menu) : array<string|int, mixed>
Parameters
$menu : array<string|int, mixed>

Menu items.

Return values
array<string|int, mixed>

migrate_menu_items()

Hides all WP admin menus items and adds screen IDs to check for new items.

public static migrate_menu_items() : mixed
Return values
mixed

add_category()

Adds a top level menu item to the navigation.

private static add_category(array<string|int, mixed> $args) : mixed
Parameters
$args : array<string|int, mixed>

Array containing the necessary arguments. $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. ).

Return values
mixed

add_item()

Adds a child menu item to the navigation.

private static add_item(array<string|int, mixed> $args) : mixed
Parameters
$args : array<string|int, mixed>

Array containing the necessary arguments. $args = array( 'id' => (string) The unique ID of the menu item. Required. 'title' => (string) Title of the menu item. Required. 'parent' => (string) Parent menu item ID. 'capability' => (string) Capability to view this menu item. '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 item to. 'matchExpression' => (string) A regular expression used to identify if the menu item is active. ).

Return values
mixed