PHP Class WP_REST_Menus

Since: 1.0.0
Exibir arquivo Open project: nekojira/wp-api-menus Class Usage Examples

Public Methods

Method Description
format_menu_item ( object | array $menu_item, boolean $children = false, array $menu = [] ) : array Format a menu item for REST API consumption.
get_api_namespace ( ) : string Get WP API namespace.
get_menu ( $request ) : array Get a menu.
get_menu_location ( $request ) : array Get menu for location.
get_menu_locations ( $request ) : 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.
get_plugin_namespace ( ) : string Get WP API Menus namespace.
register_routes ( ) Register menu routes for WP API v2.

Private Methods

Method Description
has_children ( array $items, integer $id ) : array Check if a collection of menu items contains an item that is the parent id of 'id'.
nested_menu_items ( &$menu_items, $parent = null ) : array Handle nested menu items.

Method Details

format_menu_item() public method

Format a menu item for REST API consumption.
Since: 1.2.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 REST

get_api_namespace() public static method

Get WP API namespace.
Since: 1.2.0
public static get_api_namespace ( ) : string
return string

get_menu() public method

Get a menu.
Since: 1.2.0
public get_menu ( $request ) : array
$request
return array Menu data

get_menu_location() public method

Get menu for location.
Since: 1.2.0
public get_menu_location ( $request ) : array
$request
return array The menu for the corresponding location

get_menu_locations() public static method

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

get_menus() public static method

Get menus.
Since: 1.2.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.2.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

get_plugin_namespace() public static method

Get WP API Menus namespace.
Since: 1.2.1
public static get_plugin_namespace ( ) : string
return string

register_routes() public method

Register menu routes for WP API v2.
Since: 1.2.0
public register_routes ( )