Skip to content

Commit 7ca6e25

Browse files
Merge pull request #28 from Fifciu/feat/#24-thumbnail_src
Thumbnail src for childs items
2 parents 2adc152 + bcd1001 commit 7ca6e25

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

wp-rest-api-v2-menus.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/*
33
Plugin Name: WP-REST-API V2 Menus
4-
Version: 0.7.5
4+
Version: 0.7.6
55
Description: Adding menus endpoints on WP REST API v2
66
Author: Claudio La Barbera
77
Author URI: https://thebatclaud.io
@@ -145,9 +145,6 @@ function wp_api_v2_menus_get_menu_items( $id ) {
145145
// add slug to menu items
146146
$slug = basename( get_permalink($item->object_id) );
147147
$item->slug = $slug;
148-
if (isset($item->thumbnail_id) && $item->thumbnail_id) {
149-
$item->thumbnailSrc = wp_get_attachment_image_url($item->thumbnail_id, 'post-thumbnail');
150-
}
151148
} else if($item->type == 'taxonomy') {
152149
$cat = get_term($item->object_id);
153150
$item->slug = $cat->slug;
@@ -159,10 +156,18 @@ function wp_api_v2_menus_get_menu_items( $id ) {
159156
}
160157
}
161158

159+
if (isset($item->thumbnail_id) && $item->thumbnail_id) {
160+
$item->thumbnail_src = wp_get_attachment_image_url(intval($item->thumbnail_id), 'post-thumbnail');
161+
}
162+
if (isset($item->thumbnail_hover_id) && $item->thumbnail_hover_id) {
163+
$item->thumbnail_hover_src = wp_get_attachment_image_url(intval($item->thumbnail_hover_id), 'post-thumbnail');
164+
}
165+
162166
if ( $item->menu_item_parent ) {
163167
array_push( $child_items, $item );
164168
unset( $menu_items[ $key ] );
165169
}
170+
166171
}
167172

168173
// push child items into their parent item in the original object
@@ -237,4 +242,4 @@ function wp_api_v2_menus_get_menu_data( $data ) {
237242
'methods' => 'GET',
238243
'callback' => 'wp_api_v2_menu_get_all_locations',
239244
) );
240-
} );
245+
} );

0 commit comments

Comments
 (0)