Completed
Push — master ( b54d32...a2d0a6 )
by
unknown
37s
created
includes/wp-api-menus-v2.php 1 patch
Indentation   +339 added lines, -339 removed lines patch added patch discarded remove patch
@@ -6,273 +6,273 @@  discard block
 block discarded – undo
6 6
  */
7 7
 
8 8
 if ( ! defined( 'ABSPATH' ) ) {
9
-    exit; // Exit if accessed directly
9
+	exit; // Exit if accessed directly
10 10
 }
11 11
 
12 12
 if ( ! class_exists( 'WP_REST_Menus' ) ) :
13 13
 
14 14
 
15
-    /**
16
-     * WP REST Menus class.
17
-     *
18
-     * WP API Menus support for WP API v2.
19
-     *
20
-     * @package WP_API_Menus
21
-     * @since 1.2.0
22
-     */
23
-    class WP_REST_Menus {
24
-
25
-
26
-	    /**
27
-	     * Get WP API namespace.
28
-	     *
29
-	     * @since 1.2.0
30
-	     * @return string
31
-	     */
32
-        public static function get_api_namespace() {
33
-            return 'wp/v2';
34
-        }
35
-
36
-
37
-	    /**
38
-	     * Get WP API Menus namespace.
39
-	     *
40
-	     * @since 1.2.1
41
-	     * @return string
42
-	     */
43
-	    public static function get_plugin_namespace() {
44
-		    return 'wp-api-menus/v2';
45
-	    }
46
-
47
-
48
-        /**
49
-         * Register menu routes for WP API v2.
50
-         *
51
-         * @since  1.2.0
52
-         */
53
-        public function register_routes() {
54
-
55
-            register_rest_route( self::get_plugin_namespace(), '/menus', array(
56
-                array(
57
-                    'methods'  => WP_REST_Server::READABLE,
58
-                    'callback' => array( $this, 'get_menus' ),
59
-                    'permission_callback' => '__return_true',
60
-                )
61
-            ) );
62
-
63
-            register_rest_route( self::get_plugin_namespace(), '/menus/(?P<id>\d+)', array(
64
-                array(
65
-                    'methods'  => WP_REST_Server::READABLE,
66
-                    'callback' => array( $this, 'get_menu' ),
67
-                    'permission_callback' => '__return_true',
68
-                    'args'     => array(
69
-                        'context' => array(
70
-                        'default' => 'view',
71
-                        ),
72
-                    ),
73
-                )
74
-            ) );
75
-
76
-            register_rest_route( self::get_plugin_namespace(), '/menu-locations', array(
77
-                array(
78
-                    'methods'  => WP_REST_Server::READABLE,
79
-                    'callback' => array( $this, 'get_menu_locations' ),
80
-                    'permission_callback' => '__return_true',
81
-                )
82
-            ) );
83
-
84
-            register_rest_route( self::get_plugin_namespace(), '/menu-locations/(?P<location>[a-zA-Z0-9_-]+)', array(
85
-                array(
86
-                    'methods'  => WP_REST_Server::READABLE,
87
-                    'callback' => array( $this, 'get_menu_location' ),
88
-                    'permission_callback' => '__return_true',
89
-                )
90
-            ) );
91
-        }
92
-
93
-
94
-        /**
95
-         * Get menus.
96
-         *
97
-         * @since  1.2.0
98
-         * @return array All registered menus
99
-         */
100
-        public static function get_menus() {
101
-
102
-            $rest_url = trailingslashit( get_rest_url() . self::get_plugin_namespace() . '/menus/' );
103
-            $wp_menus = wp_get_nav_menus();
104
-
105
-            $i = 0;
106
-            $rest_menus = array();
107
-            foreach ( $wp_menus as $wp_menu ) :
108
-
109
-                $menu = (array) $wp_menu;
110
-
111
-                $rest_menus[ $i ]                = $menu;
112
-                $rest_menus[ $i ]['ID']          = $menu['term_id'];
113
-                $rest_menus[ $i ]['name']        = $menu['name'];
114
-                $rest_menus[ $i ]['slug']        = $menu['slug'];
115
-                $rest_menus[ $i ]['description'] = $menu['description'];
116
-                $rest_menus[ $i ]['count']       = $menu['count'];
117
-
118
-                $rest_menus[ $i ]['meta']['links']['collection'] = $rest_url;
119
-                $rest_menus[ $i ]['meta']['links']['self']       = $rest_url . $menu['term_id'];
120
-
121
-                $i ++;
122
-            endforeach;
123
-
124
-            return apply_filters( 'rest_menus_format_menus', $rest_menus );
125
-        }
126
-
127
-
128
-        /**
129
-         * Get a menu.
130
-         *
131
-         * @since  1.2.0
132
-         * @param  $request
133
-         * @return array Menu data
134
-         */
135
-        public function get_menu( $request ) {
136
-
137
-            $id             = (int) $request['id'];
138
-            $rest_url       = get_rest_url() . self::get_plugin_namespace() . '/menus/';
139
-            $wp_menu_object = $id ? wp_get_nav_menu_object( $id ) : array();
140
-            $wp_menu_items  = $id ? wp_get_nav_menu_items( $id ) : array();
141
-
142
-            $rest_menu = array();
143
-
144
-            if ( $wp_menu_object ) :
145
-
146
-                $menu = (array) $wp_menu_object;
147
-                $rest_menu['ID']          = abs( $menu['term_id'] );
148
-                $rest_menu['name']        = $menu['name'];
149
-                $rest_menu['slug']        = $menu['slug'];
150
-                $rest_menu['description'] = $menu['description'];
151
-                $rest_menu['count']       = abs( $menu['count'] );
152
-
153
-                $rest_menu_items = array();
154
-                foreach ( $wp_menu_items as $item_object ) {
155
-	                $rest_menu_items[] = $this->format_menu_item( $item_object );
156
-                }
157
-
158
-                $rest_menu_items = $this->nested_menu_items($rest_menu_items, 0);
159
-
160
-                $rest_menu['items']                       = $rest_menu_items;
161
-                $rest_menu['meta']['links']['collection'] = $rest_url;
162
-                $rest_menu['meta']['links']['self']       = $rest_url . $id;
163
-
164
-            endif;
165
-
166
-            return apply_filters( 'rest_menus_format_menu', $rest_menu );
167
-        }
168
-
169
-
170
-        /**
171
-         * Handle nested menu items.
172
-         *
173
-         * Given a flat array of menu items, split them into parent/child items
174
-         * and recurse over them to return children nested in their parent.
175
-         *
176
-         * @since  1.2.0
177
-         * @param  $menu_items
178
-         * @param  $parent
179
-         * @return array
180
-         */
181
-        private function nested_menu_items( &$menu_items, $parent = null ) {
182
-
183
-            $parents = array();
184
-            $children = array();
185
-
186
-            // Separate menu_items into parents & children.
187
-            array_map( function( $i ) use ( $parent, &$children, &$parents ){
188
-                if ( $i['id'] != $parent && $i['parent'] == $parent ) {
189
-                    $parents[] = $i;
190
-                } else {
191
-                    $children[] = $i;
192
-                }
193
-            }, $menu_items );
194
-
195
-            foreach ( $parents as &$parent ) {
196
-
197
-                if ( $this->has_children( $children, $parent['id'] ) ) {
198
-                    $parent['children'] = $this->nested_menu_items( $children, $parent['id'] );
199
-                }
200
-            }
201
-
202
-            return $parents;
203
-        }
204
-
205
-
206
-        /**
207
-         * Check if a collection of menu items contains an item that is the parent id of 'id'.
208
-         *
209
-         * @since  1.2.0
210
-         * @param  array $items
211
-         * @param  int $id
212
-         * @return array
213
-         */
214
-        private function has_children( $items, $id ) {
215
-            return array_filter( $items, function( $i ) use ( $id ) {
216
-                return $i['parent'] == $id;
217
-            } );
218
-        }
219
-
220
-
221
-        /**
222
-         * Get menu locations.
223
-         *
224
-         * @since 1.2.0
225
-         * @param  $request
226
-         * @return array All registered menus locations
227
-         */
228
-        public static function get_menu_locations( $request ) {
229
-
230
-            $locations        = get_nav_menu_locations();
231
-            $registered_menus = get_registered_nav_menus();
232
-	        $rest_url         = get_rest_url() . self::get_plugin_namespace() . '/menu-locations/';
233
-            $rest_menus       = array();
234
-
235
-            if ( $locations && $registered_menus ) :
236
-
237
-                foreach ( $registered_menus as $slug => $label ) :
238
-
239
-	                // Sanity check
240
-	                if ( ! isset( $locations[ $slug ] ) ) {
241
-		                continue;
242
-	                }
243
-
244
-	                $rest_menus[ $slug ]['ID']                          = $locations[ $slug ];
245
-                    $rest_menus[ $slug ]['label']                       = $label;
246
-                    $rest_menus[ $slug ]['meta']['links']['collection'] = $rest_url;
247
-                    $rest_menus[ $slug ]['meta']['links']['self']       = $rest_url . $slug;
248
-
249
-                endforeach;
250
-
251
-            endif;
252
-
253
-            return $rest_menus;
254
-        }
255
-
256
-
257
-        /**
258
-         * Get menu for location.
259
-         *
260
-         * @since 1.2.0
261
-         * @param  $request
262
-         * @return array The menu for the corresponding location
263
-         */
264
-        public function get_menu_location( $request ) {
265
-
266
-            $params     = $request->get_params();
267
-            $location   = $params['location'];
268
-            $locations  = get_nav_menu_locations();
269
-
270
-            if ( empty( $locations[ $location ] ) ) {
271
-	            return array();
272
-            }
273
-
274
-            $wp_menu = wp_get_nav_menu_object( $locations[ $location ] );
275
-            $menu_items = wp_get_nav_menu_items( $wp_menu->term_id );
15
+	/**
16
+	 * WP REST Menus class.
17
+	 *
18
+	 * WP API Menus support for WP API v2.
19
+	 *
20
+	 * @package WP_API_Menus
21
+	 * @since 1.2.0
22
+	 */
23
+	class WP_REST_Menus {
24
+
25
+
26
+		/**
27
+		 * Get WP API namespace.
28
+		 *
29
+		 * @since 1.2.0
30
+		 * @return string
31
+		 */
32
+		public static function get_api_namespace() {
33
+			return 'wp/v2';
34
+		}
35
+
36
+
37
+		/**
38
+		 * Get WP API Menus namespace.
39
+		 *
40
+		 * @since 1.2.1
41
+		 * @return string
42
+		 */
43
+		public static function get_plugin_namespace() {
44
+			return 'wp-api-menus/v2';
45
+		}
46
+
47
+
48
+		/**
49
+		 * Register menu routes for WP API v2.
50
+		 *
51
+		 * @since  1.2.0
52
+		 */
53
+		public function register_routes() {
54
+
55
+			register_rest_route( self::get_plugin_namespace(), '/menus', array(
56
+				array(
57
+					'methods'  => WP_REST_Server::READABLE,
58
+					'callback' => array( $this, 'get_menus' ),
59
+					'permission_callback' => '__return_true',
60
+				)
61
+			) );
62
+
63
+			register_rest_route( self::get_plugin_namespace(), '/menus/(?P<id>\d+)', array(
64
+				array(
65
+					'methods'  => WP_REST_Server::READABLE,
66
+					'callback' => array( $this, 'get_menu' ),
67
+					'permission_callback' => '__return_true',
68
+					'args'     => array(
69
+						'context' => array(
70
+						'default' => 'view',
71
+						),
72
+					),
73
+				)
74
+			) );
75
+
76
+			register_rest_route( self::get_plugin_namespace(), '/menu-locations', array(
77
+				array(
78
+					'methods'  => WP_REST_Server::READABLE,
79
+					'callback' => array( $this, 'get_menu_locations' ),
80
+					'permission_callback' => '__return_true',
81
+				)
82
+			) );
83
+
84
+			register_rest_route( self::get_plugin_namespace(), '/menu-locations/(?P<location>[a-zA-Z0-9_-]+)', array(
85
+				array(
86
+					'methods'  => WP_REST_Server::READABLE,
87
+					'callback' => array( $this, 'get_menu_location' ),
88
+					'permission_callback' => '__return_true',
89
+				)
90
+			) );
91
+		}
92
+
93
+
94
+		/**
95
+		 * Get menus.
96
+		 *
97
+		 * @since  1.2.0
98
+		 * @return array All registered menus
99
+		 */
100
+		public static function get_menus() {
101
+
102
+			$rest_url = trailingslashit( get_rest_url() . self::get_plugin_namespace() . '/menus/' );
103
+			$wp_menus = wp_get_nav_menus();
104
+
105
+			$i = 0;
106
+			$rest_menus = array();
107
+			foreach ( $wp_menus as $wp_menu ) :
108
+
109
+				$menu = (array) $wp_menu;
110
+
111
+				$rest_menus[ $i ]                = $menu;
112
+				$rest_menus[ $i ]['ID']          = $menu['term_id'];
113
+				$rest_menus[ $i ]['name']        = $menu['name'];
114
+				$rest_menus[ $i ]['slug']        = $menu['slug'];
115
+				$rest_menus[ $i ]['description'] = $menu['description'];
116
+				$rest_menus[ $i ]['count']       = $menu['count'];
117
+
118
+				$rest_menus[ $i ]['meta']['links']['collection'] = $rest_url;
119
+				$rest_menus[ $i ]['meta']['links']['self']       = $rest_url . $menu['term_id'];
120
+
121
+				$i ++;
122
+			endforeach;
123
+
124
+			return apply_filters( 'rest_menus_format_menus', $rest_menus );
125
+		}
126
+
127
+
128
+		/**
129
+		 * Get a menu.
130
+		 *
131
+		 * @since  1.2.0
132
+		 * @param  $request
133
+		 * @return array Menu data
134
+		 */
135
+		public function get_menu( $request ) {
136
+
137
+			$id             = (int) $request['id'];
138
+			$rest_url       = get_rest_url() . self::get_plugin_namespace() . '/menus/';
139
+			$wp_menu_object = $id ? wp_get_nav_menu_object( $id ) : array();
140
+			$wp_menu_items  = $id ? wp_get_nav_menu_items( $id ) : array();
141
+
142
+			$rest_menu = array();
143
+
144
+			if ( $wp_menu_object ) :
145
+
146
+				$menu = (array) $wp_menu_object;
147
+				$rest_menu['ID']          = abs( $menu['term_id'] );
148
+				$rest_menu['name']        = $menu['name'];
149
+				$rest_menu['slug']        = $menu['slug'];
150
+				$rest_menu['description'] = $menu['description'];
151
+				$rest_menu['count']       = abs( $menu['count'] );
152
+
153
+				$rest_menu_items = array();
154
+				foreach ( $wp_menu_items as $item_object ) {
155
+					$rest_menu_items[] = $this->format_menu_item( $item_object );
156
+				}
157
+
158
+				$rest_menu_items = $this->nested_menu_items($rest_menu_items, 0);
159
+
160
+				$rest_menu['items']                       = $rest_menu_items;
161
+				$rest_menu['meta']['links']['collection'] = $rest_url;
162
+				$rest_menu['meta']['links']['self']       = $rest_url . $id;
163
+
164
+			endif;
165
+
166
+			return apply_filters( 'rest_menus_format_menu', $rest_menu );
167
+		}
168
+
169
+
170
+		/**
171
+		 * Handle nested menu items.
172
+		 *
173
+		 * Given a flat array of menu items, split them into parent/child items
174
+		 * and recurse over them to return children nested in their parent.
175
+		 *
176
+		 * @since  1.2.0
177
+		 * @param  $menu_items
178
+		 * @param  $parent
179
+		 * @return array
180
+		 */
181
+		private function nested_menu_items( &$menu_items, $parent = null ) {
182
+
183
+			$parents = array();
184
+			$children = array();
185
+
186
+			// Separate menu_items into parents & children.
187
+			array_map( function( $i ) use ( $parent, &$children, &$parents ){
188
+				if ( $i['id'] != $parent && $i['parent'] == $parent ) {
189
+					$parents[] = $i;
190
+				} else {
191
+					$children[] = $i;
192
+				}
193
+			}, $menu_items );
194
+
195
+			foreach ( $parents as &$parent ) {
196
+
197
+				if ( $this->has_children( $children, $parent['id'] ) ) {
198
+					$parent['children'] = $this->nested_menu_items( $children, $parent['id'] );
199
+				}
200
+			}
201
+
202
+			return $parents;
203
+		}
204
+
205
+
206
+		/**
207
+		 * Check if a collection of menu items contains an item that is the parent id of 'id'.
208
+		 *
209
+		 * @since  1.2.0
210
+		 * @param  array $items
211
+		 * @param  int $id
212
+		 * @return array
213
+		 */
214
+		private function has_children( $items, $id ) {
215
+			return array_filter( $items, function( $i ) use ( $id ) {
216
+				return $i['parent'] == $id;
217
+			} );
218
+		}
219
+
220
+
221
+		/**
222
+		 * Get menu locations.
223
+		 *
224
+		 * @since 1.2.0
225
+		 * @param  $request
226
+		 * @return array All registered menus locations
227
+		 */
228
+		public static function get_menu_locations( $request ) {
229
+
230
+			$locations        = get_nav_menu_locations();
231
+			$registered_menus = get_registered_nav_menus();
232
+			$rest_url         = get_rest_url() . self::get_plugin_namespace() . '/menu-locations/';
233
+			$rest_menus       = array();
234
+
235
+			if ( $locations && $registered_menus ) :
236
+
237
+				foreach ( $registered_menus as $slug => $label ) :
238
+
239
+					// Sanity check
240
+					if ( ! isset( $locations[ $slug ] ) ) {
241
+						continue;
242
+					}
243
+
244
+					$rest_menus[ $slug ]['ID']                          = $locations[ $slug ];
245
+					$rest_menus[ $slug ]['label']                       = $label;
246
+					$rest_menus[ $slug ]['meta']['links']['collection'] = $rest_url;
247
+					$rest_menus[ $slug ]['meta']['links']['self']       = $rest_url . $slug;
248
+
249
+				endforeach;
250
+
251
+			endif;
252
+
253
+			return $rest_menus;
254
+		}
255
+
256
+
257
+		/**
258
+		 * Get menu for location.
259
+		 *
260
+		 * @since 1.2.0
261
+		 * @param  $request
262
+		 * @return array The menu for the corresponding location
263
+		 */
264
+		public function get_menu_location( $request ) {
265
+
266
+			$params     = $request->get_params();
267
+			$location   = $params['location'];
268
+			$locations  = get_nav_menu_locations();
269
+
270
+			if ( empty( $locations[ $location ] ) ) {
271
+				return array();
272
+			}
273
+
274
+			$wp_menu = wp_get_nav_menu_object( $locations[ $location ] );
275
+			$menu_items = wp_get_nav_menu_items( $wp_menu->term_id );
276 276
 
277 277
 			/**
278 278
 			 * wp_get_nav_menu_items() outputs a list that's already sequenced correctly.
@@ -307,7 +307,7 @@  discard block
 block discarded – undo
307 307
 					$formatted['children'] = array_reverse( $cache[ $item->ID ] );
308 308
 				}
309 309
 
310
-            	$formatted = apply_filters( 'rest_menus_format_menu_item', $formatted );
310
+				$formatted = apply_filters( 'rest_menus_format_menu_item', $formatted );
311 311
 
312 312
 				if ( $item->menu_item_parent != 0 ) {
313 313
 
@@ -325,82 +325,82 @@  discard block
 block discarded – undo
325 325
 			endforeach;
326 326
 
327 327
 			return array_reverse ( $rev_menu );
328
-        }
329
-
330
-
331
-        /**
332
-         * Returns all child nav_menu_items under a specific parent.
333
-         *
334
-         * @since   1.2.0
335
-         * @param int   $parent_id      The parent nav_menu_item ID
336
-         * @param array $nav_menu_items Navigation menu items
337
-         * @param bool  $depth          Gives all children or direct children only
338
-         * @return array	returns filtered array of nav_menu_items
339
-         */
340
-        public function get_nav_menu_item_children( $parent_id, $nav_menu_items, $depth = true ) {
341
-
342
-            $nav_menu_item_list = array();
343
-
344
-            foreach ( (array) $nav_menu_items as $nav_menu_item ) :
345
-
346
-                if ( $nav_menu_item->menu_item_parent == $parent_id ) :
347
-
348
-                    $nav_menu_item_list[] = $this->format_menu_item( $nav_menu_item, true, $nav_menu_items );
349
-
350
-                    if ( $depth ) {
351
-                        if ( $children = $this->get_nav_menu_item_children( $nav_menu_item->ID, $nav_menu_items ) ) {
352
-                            $nav_menu_item_list = array_merge( $nav_menu_item_list, $children );
353
-                        }
354
-                    }
355
-
356
-                endif;
357
-
358
-            endforeach;
359
-
360
-            return $nav_menu_item_list;
361
-        }
362
-
363
-
364
-        /**
365
-         * Format a menu item for REST API consumption.
366
-         *
367
-         * @since  1.2.0
368
-         * @param  object|array $menu_item  The menu item
369
-         * @param  bool         $children   Get menu item children (default false)
370
-         * @param  array        $menu       The menu the item belongs to (used when $children is set to true)
371
-         * @return array	a formatted menu item for REST
372
-         */
373
-        public function format_menu_item( $menu_item, $children = false, $menu = array() ) {
374
-
375
-            $item = (array) $menu_item;
376
-
377
-            $menu_item = array(
378
-                'id'          => abs( $item['ID'] ),
379
-                'order'       => (int) $item['menu_order'],
380
-                'parent'      => abs( $item['menu_item_parent'] ),
381
-                'title'       => $item['title'],
382
-                'url'         => $item['url'],
383
-                'attr'        => $item['attr_title'],
384
-                'target'      => $item['target'],
385
-                'classes'     => implode( ' ', $item['classes'] ),
386
-                'xfn'         => $item['xfn'],
387
-                'description' => $item['description'],
388
-                'object_id'   => abs( $item['object_id'] ),
389
-                'object'      => $item['object'],
390
-                'object_slug' => get_post( $item['object_id'] )->post_name,
391
-                'type'        => $item['type'],
392
-                'type_label'  => $item['type_label'],
393
-            );
394
-
395
-            if ( $children === true && ! empty( $menu ) ) {
396
-	            $menu_item['children'] = $this->get_nav_menu_item_children( $item['ID'], $menu );
397
-            }
398
-
399
-            return apply_filters( 'rest_menus_format_menu_item', $menu_item );
400
-        }
401
-
402
-
403
-    }
328
+		}
329
+
330
+
331
+		/**
332
+		 * Returns all child nav_menu_items under a specific parent.
333
+		 *
334
+		 * @since   1.2.0
335
+		 * @param int   $parent_id      The parent nav_menu_item ID
336
+		 * @param array $nav_menu_items Navigation menu items
337
+		 * @param bool  $depth          Gives all children or direct children only
338
+		 * @return array	returns filtered array of nav_menu_items
339
+		 */
340
+		public function get_nav_menu_item_children( $parent_id, $nav_menu_items, $depth = true ) {
341
+
342
+			$nav_menu_item_list = array();
343
+
344
+			foreach ( (array) $nav_menu_items as $nav_menu_item ) :
345
+
346
+				if ( $nav_menu_item->menu_item_parent == $parent_id ) :
347
+
348
+					$nav_menu_item_list[] = $this->format_menu_item( $nav_menu_item, true, $nav_menu_items );
349
+
350
+					if ( $depth ) {
351
+						if ( $children = $this->get_nav_menu_item_children( $nav_menu_item->ID, $nav_menu_items ) ) {
352
+							$nav_menu_item_list = array_merge( $nav_menu_item_list, $children );
353
+						}
354
+					}
355
+
356
+				endif;
357
+
358
+			endforeach;
359
+
360
+			return $nav_menu_item_list;
361
+		}
362
+
363
+
364
+		/**
365
+		 * Format a menu item for REST API consumption.
366
+		 *
367
+		 * @since  1.2.0
368
+		 * @param  object|array $menu_item  The menu item
369
+		 * @param  bool         $children   Get menu item children (default false)
370
+		 * @param  array        $menu       The menu the item belongs to (used when $children is set to true)
371
+		 * @return array	a formatted menu item for REST
372
+		 */
373
+		public function format_menu_item( $menu_item, $children = false, $menu = array() ) {
374
+
375
+			$item = (array) $menu_item;
376
+
377
+			$menu_item = array(
378
+				'id'          => abs( $item['ID'] ),
379
+				'order'       => (int) $item['menu_order'],
380
+				'parent'      => abs( $item['menu_item_parent'] ),
381
+				'title'       => $item['title'],
382
+				'url'         => $item['url'],
383
+				'attr'        => $item['attr_title'],
384
+				'target'      => $item['target'],
385
+				'classes'     => implode( ' ', $item['classes'] ),
386
+				'xfn'         => $item['xfn'],
387
+				'description' => $item['description'],
388
+				'object_id'   => abs( $item['object_id'] ),
389
+				'object'      => $item['object'],
390
+				'object_slug' => get_post( $item['object_id'] )->post_name,
391
+				'type'        => $item['type'],
392
+				'type_label'  => $item['type_label'],
393
+			);
394
+
395
+			if ( $children === true && ! empty( $menu ) ) {
396
+				$menu_item['children'] = $this->get_nav_menu_item_children( $item['ID'], $menu );
397
+			}
398
+
399
+			return apply_filters( 'rest_menus_format_menu_item', $menu_item );
400
+		}
401
+
402
+
403
+	}
404 404
 
405 405
 
406 406
 endif;
Please login to merge, or discard this patch.