PHP Class WP_JSON_Menus

Since: 1.0.0
Show file Open project: nekojira/wp-api-menus

Public Methods

Method Description
format_menu_item ( object | array $menu_item, boolean $children = false, array $menu = [] ) : array Format a menu item for JSON API consumption.
get_menu ( integer $id ) : array Get a menu.
get_menu_location ( string $location ) : array Get menu for location.
get_menu_locations ( ) : array Get menu locations.
get_menus ( ) : array Get menus.
get_nav_menu_item_children ( integer $parent_id, array $nav_menu_items, boolean $depth = true ) : array Returns all child nav_menu_items under a specific parent.
register_routes ( array $routes ) : array Register menu routes for WP API.

Method Details

format_menu_item() public method

Format a menu item for JSON API consumption.
Since: 1.1.0
public format_menu_item ( object | array $menu_item, boolean $children = false, array $menu = [] ) : array
$menu_item object | array the menu item
$children boolean get menu item children (default false)
$menu array the menu the item belongs to (used when $children is set to true)
return array a formatted menu item for JSON

get_menu() public method

Get a menu.
Since: 1.0.0
public get_menu ( integer $id ) : array
$id integer ID of the menu
return array Menu data

get_menu_location() public method

Get menu for location.
Since: 1.0.0
public get_menu_location ( string $location ) : array
$location string The theme location menu name
return array The menu for the corresponding location

get_menu_locations() public static method

Get menu locations.
Since: 1.0.0
public static get_menu_locations ( ) : array
return array All registered menus locations

get_menus() public static method

Get menus.
Since: 1.0.0
public static get_menus ( ) : array
return array All registered menus

get_nav_menu_item_children() public method

Returns all child nav_menu_items under a specific parent.
Since: 1.1.0
public get_nav_menu_item_children ( integer $parent_id, array $nav_menu_items, boolean $depth = true ) : array
$parent_id integer the parent nav_menu_item ID
$nav_menu_items array navigation menu items
$depth boolean gives all children or direct children only
return array returns filtered array of nav_menu_items

register_routes() public method

Register menu routes for WP API.
Since: 1.0.0
public register_routes ( array $routes ) : array
$routes array Existing routes
return array Modified routes