Skip to content

Commit

Permalink
refactor getting object slug into function
Browse files Browse the repository at this point in the history
  • Loading branch information
nine-2-five committed Jun 11, 2017
1 parent 3ba0ed8 commit 43940fc
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions includes/wp-api-menus-v2.php
Expand Up @@ -369,14 +369,7 @@ public function get_nav_menu_item_children( $parent_id, $nav_menu_items, $depth
public function format_menu_item( $menu_item, $children = false, $menu = array() ) {

$item = (array) $menu_item;

if($item['type'] == 'taxonomy'){
$slug = get_term( $item['object_id'] )->slug;
}
else {
$slug = get_post( $item['object_id'] )->post_name;
}


$menu_item = array(
'id' => abs( $item['ID'] ),
'order' => (int) $item['menu_order'],
Expand All @@ -390,7 +383,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' => $slug,
'object_slug' => get_object_slug($item),
'type' => $item['type'],
'type_label' => $item['type_label'],
);
Expand All @@ -401,7 +394,19 @@ public function format_menu_item( $menu_item, $children = false, $menu = array()

return apply_filters( 'rest_menus_format_menu_item', $menu_item );
}


private function get_object_slug($item){
$slug = '';

if($item['type'] == 'taxonomy'){
$slug = get_term( $item['object_id'] )->slug;
}
else {
$slug = get_post( $item['object_id'] )->post_name;
}

return $slug;
}

}

Expand Down

0 comments on commit 43940fc

Please sign in to comment.