11<?php
22/*
33Plugin Name: WP-REST-API V2 Menus
4- Version: 0.7.3
4+ Version: 0.7.6
55Description: Adding menus endpoints on WP REST API v2
66Author: Claudio La Barbera
77Author URI: https://thebatclaud.io
@@ -146,10 +146,10 @@ function wp_api_v2_menus_get_menu_items( $id ) {
146146 $ slug = basename ( get_permalink ($ item ->object_id ) );
147147 $ item ->slug = $ slug ;
148148 if (isset ($ item ->thumbnail_id ) && $ item ->thumbnail_id ) {
149- $ item ->thumbnailSrc = wp_get_attachment_image_url ($ item ->thumbnail_id , 'post-thumbnail ' );
149+ $ item ->thumbnail_src = wp_get_attachment_image_url (intval ( $ item ->thumbnail_id ) , 'post-thumbnail ' );
150150 }
151151 } else if ($ item ->type == 'taxonomy ' ) {
152- $ cat = get_category ($ item ->object_id );
152+ $ cat = get_term ($ item ->object_id );
153153 $ item ->slug = $ cat ->slug ;
154154 } else if ($ item ->type == 'post_type_archive ' ) {
155155 $ post_type_data = get_post_type_object ($ item ->object );
@@ -160,6 +160,10 @@ function wp_api_v2_menus_get_menu_items( $id ) {
160160 }
161161
162162 if ( $ item ->menu_item_parent ) {
163+ if (isset ($ item ->thumbnail_id ) && $ item ->thumbnail_id ) {
164+ $ item ->thumbnail_src = wp_get_attachment_image_url (intval ($ item ->thumbnail_id ), 'post-thumbnail ' );
165+ }
166+
163167 array_push ( $ child_items , $ item );
164168 unset( $ menu_items [ $ key ] );
165169 }
@@ -237,4 +241,4 @@ function wp_api_v2_menus_get_menu_data( $data ) {
237241 'methods ' => 'GET ' ,
238242 'callback ' => 'wp_api_v2_menu_get_all_locations ' ,
239243 ) );
240- } );
244+ } );
0 commit comments