From 3ba0ed86a756914ded4bb5acccf87a38240105d8 Mon Sep 17 00:00:00 2001 From: isvaljek Date: Sat, 3 Jun 2017 09:44:45 +0200 Subject: [PATCH 1/3] Check for object_type before creating object_slug --- includes/wp-api-menus-v2.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/includes/wp-api-menus-v2.php b/includes/wp-api-menus-v2.php index ae7c82e..5ae69d4 100644 --- a/includes/wp-api-menus-v2.php +++ b/includes/wp-api-menus-v2.php @@ -369,6 +369,13 @@ 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'] ), @@ -383,7 +390,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' => $slug, 'type' => $item['type'], 'type_label' => $item['type_label'], ); From 43940fc53d9ce55e37803ce8feba289f29c9bc68 Mon Sep 17 00:00:00 2001 From: isvaljek Date: Sun, 11 Jun 2017 14:56:46 +0200 Subject: [PATCH 2/3] refactor getting object slug into function --- includes/wp-api-menus-v2.php | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/includes/wp-api-menus-v2.php b/includes/wp-api-menus-v2.php index 5ae69d4..ec84f2e 100644 --- a/includes/wp-api-menus-v2.php +++ b/includes/wp-api-menus-v2.php @@ -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'], @@ -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'], ); @@ -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; + } } From 60be1fa032d6bec86d08af154004c3d6d31b69a5 Mon Sep 17 00:00:00 2001 From: isvaljek Date: Mon, 7 Aug 2017 23:31:13 +0200 Subject: [PATCH 3/3] fix for taxonomy slugs --- includes/wp-api-menus-v2.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/wp-api-menus-v2.php b/includes/wp-api-menus-v2.php index ec84f2e..797cc0b 100644 --- a/includes/wp-api-menus-v2.php +++ b/includes/wp-api-menus-v2.php @@ -369,7 +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; - + $menu_item = array( 'id' => abs( $item['ID'] ), 'order' => (int) $item['menu_order'], @@ -383,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' => get_object_slug($item), + 'object_slug' => $this->get_object_slug( $item ), 'type' => $item['type'], 'type_label' => $item['type_label'], ); @@ -394,8 +394,8 @@ 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){ + + private function get_object_slug($item){ $slug = ''; if($item['type'] == 'taxonomy'){