wp-includes/nav-menu.php

Navigation Menu functions

package
WordPress
since
3.0.0
subpackage
Nav_Menus

Functions

function _is_valid_nav_menu_item( $item ) : bool
Returns if a menu item is valid. Bug #13958
Parameters
Name Type Description
$item
Returns
Type Description
bool
Details
access
private
since
3.2.0
function _sort_nav_menu_items( object $a, object $b ) : int
Sort menu items by the desired key.
Parameters
Name Type Description
$a object The first object to compare
$b object The second object to compare
Returns
Type Description
int
Details
access
private
since
3.0.0
function _wp_auto_add_pages_to_menu( string $new_status, string $old_status, object $post ) : void
Automatically add newly published page objects to menus with that as an option.
Parameters
Name Type Description
$new_status string The new status of the post object.
$old_status string The old status of the post object.
$post object The post object being transitioned from one status to another.
Details
access
private
since
3.0.0
function _wp_delete_post_menu_item( int $object_id = 0 ) :
Callback for handling a menu item when its original object is deleted.
Parameters
Name Type Description
$object_id int The ID of the original object being trashed.
Details
access
private
since
3.0.0
function _wp_delete_tax_menu_item( int $object_id = 0 ) :
Callback for handling a menu item when its original object is deleted.
Parameters
Name Type Description
$object_id int The ID of the original object being trashed.
Details
access
private
since
3.0.0
function get_nav_menu_locations( ) : array
Returns an array with the registered navigation menu locations and the menu assigned to it
Returns
Type Description
array
Details
since
3.0.0
function get_registered_nav_menus( ) : array
Returns an array of all registered navigation menus in a theme
Returns
Type Description
array
Details
since
3.0.0
function has_nav_menu( string $location ) : bool
Whether a registered nav menu location has a menu assigned to it.
Parameters
Name Type Description
$location string Menu location identifier.
Returns
Type Description
bool
Details
since
3.0.0
function is_nav_menu( int|string $menu ) : bool
Check if the given ID is a navigation menu.

Returns true if it is; false otherwise.

Parameters
Name Type Description
$menu int|string

The menu to check (id, slug, or name)

Returns
Type Description
bool
Details
since
3.0.0
function is_nav_menu_item( int $menu_item_id = 0 ) : bool
Determine whether the given ID is a nav menu item.
Parameters
Name Type Description
$menu_item_id int The ID of the potential nav menu item.
Returns
Type Description
bool
Details
since
3.0.0
function register_nav_menu( string $location, string $description ) :
Register a navigation menu for a theme.
Parameters
Name Type Description
$location string Menu location identifier, like a slug.
$description string Menu location descriptive text.
Details
since
3.0.0
function register_nav_menus( array $locations = array ) :
Register navigation menus for a theme.
Parameters
Name Type Description
$locations array

Associative array of menu location identifiers (like a slug) and descriptive text.

Details
since
3.0.0
function unregister_nav_menu( array $location ) : bool
Unregisters a navigation menu for a theme.
Parameters
Name Type Description
$location array the menu location identifier
Returns
Type Description
bool
function wp_create_nav_menu( string $menu_name ) : mixed
Create a Navigation Menu.
Parameters
Name Type Description
$menu_name string Menu Name
Returns
Type Description
mixed
Details
since
3.0.0
function wp_delete_nav_menu( string $menu ) : mixed
Delete a Navigation Menu.
Parameters
Name Type Description
$menu string name|id|slug
Returns
Type Description
mixed
Details
since
3.0.0
function wp_get_associated_nav_menu_items( int $object_id = 0, string $object_type = post_type ) : array
Get the menu items associated with a particular object.
Parameters
Name Type Description
$object_id int The ID of the original object.
$object_type string

The type of object, such as "taxonomy" or "post_type."

Returns
Type Description
array
Details
since
3.0.0
function wp_get_nav_menu_items( string $menu, string $args = array ) : mixed
Returns all menu items of a navigation menu.
Parameters
Name Type Description
$menu string menu name, id, or slug
$args string
Returns
Type Description
mixed
Details
since
3.0.0
function wp_get_nav_menu_object( string $menu ) : mixed
Returns a navigation menu object.
Parameters
Name Type Description
$menu string Menu id, slug or name
Returns
Type Description
mixed
Details
since
3.0.0
uses
\get_term
uses
\get_term_by
function wp_get_nav_menus( array $args = array ) : array
Returns all navigation menu objects.
Parameters
Name Type Description
$args array

Array of arguments passed on to get_terms().

Returns
Type Description
array
Details
since
3.0.0
function wp_setup_nav_menu_item( object $menu_item ) : object
Decorates a menu item object with the shared navigation menu item properties.

Properties: - db_id: The DB ID of this item as a nav_menu_item object, if it exists (0 if it doesn't exist). - object_id: The DB ID of the original object this menu item represents, e.g. ID for posts and term_id for categories. - type: The family of objects originally represented, such as "post_type" or "taxonomy." - object: The type of object originally represented, such as "category," "post", or "attachment." - type_label: The singular label used to describe this type of menu item. - post_parent: The DB ID of the original object's parent object, if any (0 otherwise). - menu_item_parent: The DB ID of the nav_menu_item that is this item's menu parent, if any. 0 otherwise. - url: The URL to which this menu item points. - title: The title of this menu item. - target: The target attribute of the link element for this menu item. - attr_title: The title attribute of the link element for this menu item. - classes: The array of class attribute values for the link element of this menu item. - xfn: The XFN relationship expressed in the link of this menu item. - description: The description of this menu item.

Parameters
Name Type Description
$menu_item object The menu item to modify.
Returns
Type Description
object
Details
since
3.0.0
function wp_update_nav_menu_item( int $menu_id = 0, int $menu_item_db_id = 0, array $menu_item_data = array ) : int
Save the properties of a menu item or create a new one.
Parameters
Name Type Description
$menu_id int

The ID of the menu. Required. If "0", makes the menu item a draft orphan.

$menu_item_db_id int

The ID of the menu item. If "0", creates a new menu item.

$menu_item_data array

The menu item's data.

Returns
Type Description
int
Details
since
3.0.0
function wp_update_nav_menu_object( int $menu_id = 0, array $menu_data = array ) : int|\error
Save the properties of a menu or create a new menu with those properties.
Parameters
Name Type Description
$menu_id int

The ID of the menu or "0" to create a new menu.

$menu_data array The array of menu data.
Returns
Type Description
int\error
Details
since
3.0.0
Documentation was generated by DocBlox 0.13.0.