Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions includes/wp-api-menus-v2.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,6 @@ public function get_nav_menu_item_children( $parent_id, $nav_menu_items, $depth
return $nav_menu_item_list;
}


/**
* Format a menu item for REST API consumption.
*
Expand All @@ -370,6 +369,21 @@ public function format_menu_item( $menu_item, $children = false, $menu = array()

$item = (array) $menu_item;

//categories, tags, etc ...
if($item['type'] === 'taxonomy')
{
$object_slug = get_term($item['object_id'], $item['object'])->slug;
}
//archive
else if($item['type'] === 'post_type_archive'){
$object_slug = get_post_type_object( $item['object'] )->rewrite['slug'];
}
else{
// post_type, page, etc ...
$object_slug = get_post( $item['object_id'] )->post_name;
}


$menu_item = array(
'id' => abs( $item['ID'] ),
'order' => (int) $item['menu_order'],
Expand All @@ -383,7 +397,7 @@ public function format_menu_item( $menu_item, $children = false, $menu = array()
'description' => $item['description'],
'object_id' => abs( $item['object_id'] ),
'object' => $item['object'],
'object_slug' => get_post( $item['object_id'] )->post_name,
'object_slug' => $object_slug,
'type' => $item['type'],
'type_label' => $item['type_label'],
);
Expand All @@ -395,6 +409,8 @@ public function format_menu_item( $menu_item, $children = false, $menu = array()
return apply_filters( 'rest_menus_format_menu_item', $menu_item );
}




}

Expand Down