Completed
Pull Request — master (#53)
by
unknown
02:00
created
includes/wp-api-menus-v2.php 2 patches
Indentation   +362 added lines, -362 removed lines patch added patch discarded remove patch
@@ -6,267 +6,267 @@  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
-                )
60
-            ) );
61
-
62
-            register_rest_route( self::get_plugin_namespace(), '/menus/(?P<id>\d+)', array(
63
-                array(
64
-                    'methods'  => WP_REST_Server::READABLE,
65
-                    'callback' => array( $this, 'get_menu' ),
66
-                    'args'     => array(
67
-                        'context' => array(
68
-                        'default' => 'view',
69
-                        ),
70
-                    ),
71
-                )
72
-            ) );
73
-
74
-            register_rest_route( self::get_plugin_namespace(), '/menu-locations', array(
75
-                array(
76
-                    'methods'  => WP_REST_Server::READABLE,
77
-                    'callback' => array( $this, 'get_menu_locations' ),
78
-                )
79
-            ) );
80
-
81
-            register_rest_route( self::get_plugin_namespace(), '/menu-locations/(?P<location>[a-zA-Z0-9_-]+)', array(
82
-                array(
83
-                    'methods'  => WP_REST_Server::READABLE,
84
-                    'callback' => array( $this, 'get_menu_location' ),
85
-                )
86
-            ) );
87
-        }
88
-
89
-
90
-        /**
91
-         * Get menus.
92
-         *
93
-         * @since  1.2.0
94
-         * @return array All registered menus
95
-         */
96
-        public static function get_menus() {
97
-
98
-            $rest_url = trailingslashit( get_rest_url() . self::get_plugin_namespace() . '/menus/' );
99
-            $wp_menus = wp_get_nav_menus();
100
-
101
-            $i = 0;
102
-            $rest_menus = array();
103
-            foreach ( $wp_menus as $wp_menu ) :
104
-
105
-                $menu = (array) $wp_menu;
106
-
107
-                $rest_menus[ $i ]                = $menu;
108
-                $rest_menus[ $i ]['ID']          = $menu['term_id'];
109
-                $rest_menus[ $i ]['name']        = $menu['name'];
110
-                $rest_menus[ $i ]['slug']        = $menu['slug'];
111
-                $rest_menus[ $i ]['description'] = $menu['description'];
112
-                $rest_menus[ $i ]['count']       = $menu['count'];
113
-
114
-                $rest_menus[ $i ]['meta']['links']['collection'] = $rest_url;
115
-                $rest_menus[ $i ]['meta']['links']['self']       = $rest_url . $menu['term_id'];
116
-
117
-                $i ++;
118
-            endforeach;
119
-
120
-            return apply_filters( 'rest_menus_format_menus', $rest_menus );
121
-        }
122
-
123
-
124
-        /**
125
-         * Get a menu.
126
-         *
127
-         * @since  1.2.0
128
-         * @param  $request
129
-         * @return array Menu data
130
-         */
131
-        public function get_menu( $request ) {
132
-            $id             = (int) $request['id'];
133
-            $rest_url       = get_rest_url() . self::get_api_namespace() . '/menus/';
134
-            $wp_menu_object = $id ? wp_get_nav_menu_object( $id ) : array();
135
-            $wp_menu_items  = $id ? wp_get_nav_menu_items( $id ) : array();
136
-
137
-            $rest_menu = array();
138
-
139
-            if ( $wp_menu_object ) :
140
-
141
-                $menu = (array) $wp_menu_object;
142
-                $rest_menu['ID']          = abs( $menu['term_id'] );
143
-                $rest_menu['name']        = $menu['name'];
144
-                $rest_menu['slug']        = $menu['slug'];
145
-                $rest_menu['description'] = $menu['description'];
146
-                $rest_menu['count']       = abs( $menu['count'] );
147
-
148
-                $rest_menu_items = array();
149
-                foreach ( $wp_menu_items as $item_object ) {
150
-	                $rest_menu_items[] = $this->format_menu_item( $item_object );
151
-                }
152
-
153
-                $rest_menu_items = $this->nested_menu_items($rest_menu_items, 0);
154
-
155
-                $rest_menu['items']                       = $rest_menu_items;
156
-                $rest_menu['meta']['links']['collection'] = $rest_url;
157
-                $rest_menu['meta']['links']['self']       = $rest_url . $id;
158
-
159
-            endif;
160
-            return apply_filters( 'rest_menus_format_menu', $rest_menu );
161
-        }
162
-
163
-
164
-        /**
165
-         * Handle nested menu items.
166
-         *
167
-         * Given a flat array of menu items, split them into parent/child items
168
-         * and recurse over them to return children nested in their parent.
169
-         *
170
-         * @since  1.2.0
171
-         * @param  $menu_items
172
-         * @param  $parent
173
-         * @return array
174
-         */
175
-        private function nested_menu_items( &$menu_items, $parent = null ) {
176
-
177
-            $parents = array();
178
-            $children = array();
179
-
180
-            // Separate menu_items into parents & children.
181
-            array_map( function( $i ) use ( $parent, &$children, &$parents ){
182
-                if ( $i['id'] != $parent && $i['parent'] == $parent ) {
183
-                    $parents[] = $i;
184
-                } else {
185
-                    $children[] = $i;
186
-                }
187
-            }, $menu_items );
188
-
189
-            foreach ( $parents as &$parent ) {
190
-
191
-                if ( $this->has_children( $children, $parent['id'] ) ) {
192
-                    $parent['children'] = $this->nested_menu_items( $children, $parent['id'] );
193
-                }
194
-            }
195
-
196
-            return $parents;
197
-        }
198
-
199
-
200
-        /**
201
-         * Check if a collection of menu items contains an item that is the parent id of 'id'.
202
-         *
203
-         * @since  1.2.0
204
-         * @param  array $items
205
-         * @param  int $id
206
-         * @return array
207
-         */
208
-        private function has_children( $items, $id ) {
209
-            return array_filter( $items, function( $i ) use ( $id ) {
210
-                return $i['parent'] == $id;
211
-            } );
212
-        }
213
-
214
-
215
-        /**
216
-         * Get menu locations.
217
-         *
218
-         * @since 1.2.0
219
-         * @param  $request
220
-         * @return array All registered menus locations
221
-         */
222
-        public static function get_menu_locations( $request ) {
223
-
224
-            $locations        = get_nav_menu_locations();
225
-            $registered_menus = get_registered_nav_menus();
226
-	        $rest_url         = get_rest_url() . self::get_api_namespace() . '/menu-locations/';
227
-            $rest_menus       = array();
228
-
229
-            if ( $locations && $registered_menus ) :
230
-
231
-                foreach ( $registered_menus as $slug => $label ) :
232
-
233
-	                // Sanity check
234
-	                if ( ! isset( $locations[ $slug ] ) ) {
235
-		                continue;
236
-	                }
237
-
238
-	                $rest_menus[ $slug ]['ID']                          = $locations[ $slug ];
239
-                    $rest_menus[ $slug ]['label']                       = $label;
240
-                    $rest_menus[ $slug ]['meta']['links']['collection'] = $rest_url;
241
-                    $rest_menus[ $slug ]['meta']['links']['self']       = $rest_url . $slug;
242
-
243
-                endforeach;
244
-
245
-            endif;
246
-
247
-            return $rest_menus;
248
-        }
249
-
250
-
251
-        /**
252
-         * Get menu for location.
253
-         *
254
-         * @since 1.2.0
255
-         * @param  $request
256
-         * @return array The menu for the corresponding location
257
-         */
258
-        public function get_menu_location( $request ) {
259
-
260
-            $params     = $request->get_params();
261
-            $location   = $params['location'];
262
-            $locations  = get_nav_menu_locations();
263
-
264
-            if ( ! isset( $locations[ $location ] ) ) {
265
-	            return array();
266
-            }
267
-
268
-            $wp_menu = wp_get_nav_menu_object( $locations[ $location ] );
269
-            $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
+				)
60
+			) );
61
+
62
+			register_rest_route( self::get_plugin_namespace(), '/menus/(?P<id>\d+)', array(
63
+				array(
64
+					'methods'  => WP_REST_Server::READABLE,
65
+					'callback' => array( $this, 'get_menu' ),
66
+					'args'     => array(
67
+						'context' => array(
68
+						'default' => 'view',
69
+						),
70
+					),
71
+				)
72
+			) );
73
+
74
+			register_rest_route( self::get_plugin_namespace(), '/menu-locations', array(
75
+				array(
76
+					'methods'  => WP_REST_Server::READABLE,
77
+					'callback' => array( $this, 'get_menu_locations' ),
78
+				)
79
+			) );
80
+
81
+			register_rest_route( self::get_plugin_namespace(), '/menu-locations/(?P<location>[a-zA-Z0-9_-]+)', array(
82
+				array(
83
+					'methods'  => WP_REST_Server::READABLE,
84
+					'callback' => array( $this, 'get_menu_location' ),
85
+				)
86
+			) );
87
+		}
88
+
89
+
90
+		/**
91
+		 * Get menus.
92
+		 *
93
+		 * @since  1.2.0
94
+		 * @return array All registered menus
95
+		 */
96
+		public static function get_menus() {
97
+
98
+			$rest_url = trailingslashit( get_rest_url() . self::get_plugin_namespace() . '/menus/' );
99
+			$wp_menus = wp_get_nav_menus();
100
+
101
+			$i = 0;
102
+			$rest_menus = array();
103
+			foreach ( $wp_menus as $wp_menu ) :
104
+
105
+				$menu = (array) $wp_menu;
106
+
107
+				$rest_menus[ $i ]                = $menu;
108
+				$rest_menus[ $i ]['ID']          = $menu['term_id'];
109
+				$rest_menus[ $i ]['name']        = $menu['name'];
110
+				$rest_menus[ $i ]['slug']        = $menu['slug'];
111
+				$rest_menus[ $i ]['description'] = $menu['description'];
112
+				$rest_menus[ $i ]['count']       = $menu['count'];
113
+
114
+				$rest_menus[ $i ]['meta']['links']['collection'] = $rest_url;
115
+				$rest_menus[ $i ]['meta']['links']['self']       = $rest_url . $menu['term_id'];
116
+
117
+				$i ++;
118
+			endforeach;
119
+
120
+			return apply_filters( 'rest_menus_format_menus', $rest_menus );
121
+		}
122
+
123
+
124
+		/**
125
+		 * Get a menu.
126
+		 *
127
+		 * @since  1.2.0
128
+		 * @param  $request
129
+		 * @return array Menu data
130
+		 */
131
+		public function get_menu( $request ) {
132
+			$id             = (int) $request['id'];
133
+			$rest_url       = get_rest_url() . self::get_api_namespace() . '/menus/';
134
+			$wp_menu_object = $id ? wp_get_nav_menu_object( $id ) : array();
135
+			$wp_menu_items  = $id ? wp_get_nav_menu_items( $id ) : array();
136
+
137
+			$rest_menu = array();
138
+
139
+			if ( $wp_menu_object ) :
140
+
141
+				$menu = (array) $wp_menu_object;
142
+				$rest_menu['ID']          = abs( $menu['term_id'] );
143
+				$rest_menu['name']        = $menu['name'];
144
+				$rest_menu['slug']        = $menu['slug'];
145
+				$rest_menu['description'] = $menu['description'];
146
+				$rest_menu['count']       = abs( $menu['count'] );
147
+
148
+				$rest_menu_items = array();
149
+				foreach ( $wp_menu_items as $item_object ) {
150
+					$rest_menu_items[] = $this->format_menu_item( $item_object );
151
+				}
152
+
153
+				$rest_menu_items = $this->nested_menu_items($rest_menu_items, 0);
154
+
155
+				$rest_menu['items']                       = $rest_menu_items;
156
+				$rest_menu['meta']['links']['collection'] = $rest_url;
157
+				$rest_menu['meta']['links']['self']       = $rest_url . $id;
158
+
159
+			endif;
160
+			return apply_filters( 'rest_menus_format_menu', $rest_menu );
161
+		}
162
+
163
+
164
+		/**
165
+		 * Handle nested menu items.
166
+		 *
167
+		 * Given a flat array of menu items, split them into parent/child items
168
+		 * and recurse over them to return children nested in their parent.
169
+		 *
170
+		 * @since  1.2.0
171
+		 * @param  $menu_items
172
+		 * @param  $parent
173
+		 * @return array
174
+		 */
175
+		private function nested_menu_items( &$menu_items, $parent = null ) {
176
+
177
+			$parents = array();
178
+			$children = array();
179
+
180
+			// Separate menu_items into parents & children.
181
+			array_map( function( $i ) use ( $parent, &$children, &$parents ){
182
+				if ( $i['id'] != $parent && $i['parent'] == $parent ) {
183
+					$parents[] = $i;
184
+				} else {
185
+					$children[] = $i;
186
+				}
187
+			}, $menu_items );
188
+
189
+			foreach ( $parents as &$parent ) {
190
+
191
+				if ( $this->has_children( $children, $parent['id'] ) ) {
192
+					$parent['children'] = $this->nested_menu_items( $children, $parent['id'] );
193
+				}
194
+			}
195
+
196
+			return $parents;
197
+		}
198
+
199
+
200
+		/**
201
+		 * Check if a collection of menu items contains an item that is the parent id of 'id'.
202
+		 *
203
+		 * @since  1.2.0
204
+		 * @param  array $items
205
+		 * @param  int $id
206
+		 * @return array
207
+		 */
208
+		private function has_children( $items, $id ) {
209
+			return array_filter( $items, function( $i ) use ( $id ) {
210
+				return $i['parent'] == $id;
211
+			} );
212
+		}
213
+
214
+
215
+		/**
216
+		 * Get menu locations.
217
+		 *
218
+		 * @since 1.2.0
219
+		 * @param  $request
220
+		 * @return array All registered menus locations
221
+		 */
222
+		public static function get_menu_locations( $request ) {
223
+
224
+			$locations        = get_nav_menu_locations();
225
+			$registered_menus = get_registered_nav_menus();
226
+			$rest_url         = get_rest_url() . self::get_api_namespace() . '/menu-locations/';
227
+			$rest_menus       = array();
228
+
229
+			if ( $locations && $registered_menus ) :
230
+
231
+				foreach ( $registered_menus as $slug => $label ) :
232
+
233
+					// Sanity check
234
+					if ( ! isset( $locations[ $slug ] ) ) {
235
+						continue;
236
+					}
237
+
238
+					$rest_menus[ $slug ]['ID']                          = $locations[ $slug ];
239
+					$rest_menus[ $slug ]['label']                       = $label;
240
+					$rest_menus[ $slug ]['meta']['links']['collection'] = $rest_url;
241
+					$rest_menus[ $slug ]['meta']['links']['self']       = $rest_url . $slug;
242
+
243
+				endforeach;
244
+
245
+			endif;
246
+
247
+			return $rest_menus;
248
+		}
249
+
250
+
251
+		/**
252
+		 * Get menu for location.
253
+		 *
254
+		 * @since 1.2.0
255
+		 * @param  $request
256
+		 * @return array The menu for the corresponding location
257
+		 */
258
+		public function get_menu_location( $request ) {
259
+
260
+			$params     = $request->get_params();
261
+			$location   = $params['location'];
262
+			$locations  = get_nav_menu_locations();
263
+
264
+			if ( ! isset( $locations[ $location ] ) ) {
265
+				return array();
266
+			}
267
+
268
+			$wp_menu = wp_get_nav_menu_object( $locations[ $location ] );
269
+			$menu_items = wp_get_nav_menu_items( $wp_menu->term_id );
270 270
 
271 271
 			/**
272 272
 			 * wp_get_nav_menu_items() outputs a list that's already sequenced correctly.
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
 					$formatted['children'] = array_reverse( $cache[ $item->ID ] );
302 302
 				}
303 303
 
304
-              	$formatted = apply_filters( 'rest_menus_format_menu_item', $formatted );
304
+			  	$formatted = apply_filters( 'rest_menus_format_menu_item', $formatted );
305 305
 
306 306
 				if ( $item->menu_item_parent != 0 ) {
307 307
 
@@ -319,112 +319,112 @@  discard block
 block discarded – undo
319 319
 			endforeach;
320 320
 
321 321
 			return array_reverse ( $rev_menu );
322
-        }
323
-
324
-
325
-        /**
326
-         * Returns all child nav_menu_items under a specific parent.
327
-         *
328
-         * @since   1.2.0
329
-         * @param int   $parent_id      The parent nav_menu_item ID
330
-         * @param array $nav_menu_items Navigation menu items
331
-         * @param bool  $depth          Gives all children or direct children only
332
-         * @return array	returns filtered array of nav_menu_items
333
-         */
334
-        public function get_nav_menu_item_children( $parent_id, $nav_menu_items, $depth = true ) {
335
-
336
-            $nav_menu_item_list = array();
337
-
338
-            foreach ( (array) $nav_menu_items as $nav_menu_item ) :
339
-
340
-                if ( $nav_menu_item->menu_item_parent == $parent_id ) :
341
-
342
-                    $nav_menu_item_list[] = $this->format_menu_item( $nav_menu_item, true, $nav_menu_items );
343
-
344
-                    if ( $depth ) {
345
-                        if ( $children = $this->get_nav_menu_item_children( $nav_menu_item->ID, $nav_menu_items ) ) {
346
-                            $nav_menu_item_list = array_merge( $nav_menu_item_list, $children );
347
-                        }
348
-                    }
349
-
350
-                endif;
351
-
352
-            endforeach;
353
-
354
-            return $nav_menu_item_list;
355
-        }
356
-
357
-
358
-        /**
359
-         * Format a menu item for REST API consumption.
360
-         *
361
-         * @since  1.2.0
362
-         * @param  object|array $menu_item  The menu item
363
-         * @param  bool         $children   Get menu item children (default false)
364
-         * @param  array        $menu       The menu the item belongs to (used when $children is set to true)
365
-         * @return array	a formatted menu item for REST
366
-         */
367
-        public function format_menu_item( $menu_item, $children = false, $menu = array() ) {
368
-            $item = (array) $menu_item;
369
-            $object_slug=null;
370
-            $rest_path = '';
371
-            switch($item['type']){
372
-                case 'post_type_archive': //archive.
373
-                    $post_type_data = get_post_type_object( $item['object'] );
374
-                    $object = empty($post_type_data->rest_base) ? $item['object'] : $post_type_data->rest_base;
375
-                    $object_slug = $post_type_data->rewrite['slug'];
376
-
377
-                    $rest_path = rest_url( '/wp/v2/'.$object.'/');
378
-                    break;
379
-                case 'taxonomy'://taxonomy term.
380
-                    $term = get_term_by( 'id', $item['object_id'], $item['object']);
381
-                    $object_slug = $term->slug;
382
-                    $taxonomy = get_taxonomy( $item['object']);
383
-                    $object =  ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name;
322
+		}
323
+
324
+
325
+		/**
326
+		 * Returns all child nav_menu_items under a specific parent.
327
+		 *
328
+		 * @since   1.2.0
329
+		 * @param int   $parent_id      The parent nav_menu_item ID
330
+		 * @param array $nav_menu_items Navigation menu items
331
+		 * @param bool  $depth          Gives all children or direct children only
332
+		 * @return array	returns filtered array of nav_menu_items
333
+		 */
334
+		public function get_nav_menu_item_children( $parent_id, $nav_menu_items, $depth = true ) {
335
+
336
+			$nav_menu_item_list = array();
337
+
338
+			foreach ( (array) $nav_menu_items as $nav_menu_item ) :
339
+
340
+				if ( $nav_menu_item->menu_item_parent == $parent_id ) :
341
+
342
+					$nav_menu_item_list[] = $this->format_menu_item( $nav_menu_item, true, $nav_menu_items );
343
+
344
+					if ( $depth ) {
345
+						if ( $children = $this->get_nav_menu_item_children( $nav_menu_item->ID, $nav_menu_items ) ) {
346
+							$nav_menu_item_list = array_merge( $nav_menu_item_list, $children );
347
+						}
348
+					}
349
+
350
+				endif;
351
+
352
+			endforeach;
353
+
354
+			return $nav_menu_item_list;
355
+		}
356
+
357
+
358
+		/**
359
+		 * Format a menu item for REST API consumption.
360
+		 *
361
+		 * @since  1.2.0
362
+		 * @param  object|array $menu_item  The menu item
363
+		 * @param  bool         $children   Get menu item children (default false)
364
+		 * @param  array        $menu       The menu the item belongs to (used when $children is set to true)
365
+		 * @return array	a formatted menu item for REST
366
+		 */
367
+		public function format_menu_item( $menu_item, $children = false, $menu = array() ) {
368
+			$item = (array) $menu_item;
369
+			$object_slug=null;
370
+			$rest_path = '';
371
+			switch($item['type']){
372
+				case 'post_type_archive': //archive.
373
+					$post_type_data = get_post_type_object( $item['object'] );
374
+					$object = empty($post_type_data->rest_base) ? $item['object'] : $post_type_data->rest_base;
375
+					$object_slug = $post_type_data->rewrite['slug'];
376
+
377
+					$rest_path = rest_url( '/wp/v2/'.$object.'/');
378
+					break;
379
+				case 'taxonomy'://taxonomy term.
380
+					$term = get_term_by( 'id', $item['object_id'], $item['object']);
381
+					$object_slug = $term->slug;
382
+					$taxonomy = get_taxonomy( $item['object']);
383
+					$object =  ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name;
384 384
                     
385
-                    $rest_path = rest_url( '/wp/v2/'.$object.'/'.$item['object_id']);
386
-                    break;
387
-                case 'post_type':
388
-                    $post_type_data = get_post_type_object( $item['object'] );
389
-                    $object = empty($post_type_data->rest_base) ? $item['object'] : $post_type_data->rest_base;
390
-                    $object_slug = get_post( $item['object_id'] )->post_name;
391
-
392
-                    $rest_path = rest_url( '/wp/v2/'.$object.'/'.$item['object_id']);
393
-                    break;
394
-                default: //try with the object and id.
395
-                    $rest_path = rest_url( '/wp/v2/'.$item['object'].'/'.$item['object_id']);
396
-                    break;
397
-            }
398
-            //get_rest_url( int $blog_id = null, string $path = '/', string $scheme = 'rest' )
399
-
400
-            $menu_item = array(
401
-                'id'          => abs( $item['ID'] ),
402
-                'order'       => (int) $item['menu_order'],
403
-                'parent'      => abs( $item['menu_item_parent'] ),
404
-                'title'       => $item['title'],
405
-                'url'         => $item['url'],
406
-                'attr'        => $item['attr_title'],
407
-                'target'      => $item['target'],
408
-                'classes'     => implode( ' ', $item['classes'] ),
409
-                'xfn'         => $item['xfn'],
410
-                'description' => $item['description'],
411
-                'object_id'   => abs( $item['object_id'] ),
412
-                'object'      => $item['object'],
413
-                'object_slug' => $object_slug,
414
-                'type'        => $item['type'],
415
-                'type_label'  => $item['type_label'],
416
-                '_links'      => array('self'=>$rest_path)
417
-            );
418
-
419
-            if ( $children === true && ! empty( $menu ) ) {
420
-	            $menu_item['children'] = $this->get_nav_menu_item_children( $item['ID'], $menu );
421
-            }
422
-
423
-            return apply_filters( 'rest_menus_format_menu_item', $menu_item );
424
-        }
425
-
426
-
427
-    }
385
+					$rest_path = rest_url( '/wp/v2/'.$object.'/'.$item['object_id']);
386
+					break;
387
+				case 'post_type':
388
+					$post_type_data = get_post_type_object( $item['object'] );
389
+					$object = empty($post_type_data->rest_base) ? $item['object'] : $post_type_data->rest_base;
390
+					$object_slug = get_post( $item['object_id'] )->post_name;
391
+
392
+					$rest_path = rest_url( '/wp/v2/'.$object.'/'.$item['object_id']);
393
+					break;
394
+				default: //try with the object and id.
395
+					$rest_path = rest_url( '/wp/v2/'.$item['object'].'/'.$item['object_id']);
396
+					break;
397
+			}
398
+			//get_rest_url( int $blog_id = null, string $path = '/', string $scheme = 'rest' )
399
+
400
+			$menu_item = array(
401
+				'id'          => abs( $item['ID'] ),
402
+				'order'       => (int) $item['menu_order'],
403
+				'parent'      => abs( $item['menu_item_parent'] ),
404
+				'title'       => $item['title'],
405
+				'url'         => $item['url'],
406
+				'attr'        => $item['attr_title'],
407
+				'target'      => $item['target'],
408
+				'classes'     => implode( ' ', $item['classes'] ),
409
+				'xfn'         => $item['xfn'],
410
+				'description' => $item['description'],
411
+				'object_id'   => abs( $item['object_id'] ),
412
+				'object'      => $item['object'],
413
+				'object_slug' => $object_slug,
414
+				'type'        => $item['type'],
415
+				'type_label'  => $item['type_label'],
416
+				'_links'      => array('self'=>$rest_path)
417
+			);
418
+
419
+			if ( $children === true && ! empty( $menu ) ) {
420
+				$menu_item['children'] = $this->get_nav_menu_item_children( $item['ID'], $menu );
421
+			}
422
+
423
+			return apply_filters( 'rest_menus_format_menu_item', $menu_item );
424
+		}
425
+
426
+
427
+	}
428 428
 
429 429
 
430 430
 endif;
Please login to merge, or discard this patch.
Spacing   +101 added lines, -101 removed lines patch added patch discarded remove patch
@@ -5,11 +5,11 @@  discard block
 block discarded – undo
5 5
  * @package WP_API_Menus
6 6
  */
7 7
 
8
-if ( ! defined( 'ABSPATH' ) ) {
8
+if ( ! defined('ABSPATH')) {
9 9
     exit; // Exit if accessed directly
10 10
 }
11 11
 
12
-if ( ! class_exists( 'WP_REST_Menus' ) ) :
12
+if ( ! class_exists('WP_REST_Menus')) :
13 13
 
14 14
 
15 15
     /**
@@ -52,38 +52,38 @@  discard block
 block discarded – undo
52 52
          */
53 53
         public function register_routes() {
54 54
 
55
-            register_rest_route( self::get_plugin_namespace(), '/menus', array(
55
+            register_rest_route(self::get_plugin_namespace(), '/menus', array(
56 56
                 array(
57 57
                     'methods'  => WP_REST_Server::READABLE,
58
-                    'callback' => array( $this, 'get_menus' ),
58
+                    'callback' => array($this, 'get_menus'),
59 59
                 )
60
-            ) );
60
+            ));
61 61
 
62
-            register_rest_route( self::get_plugin_namespace(), '/menus/(?P<id>\d+)', array(
62
+            register_rest_route(self::get_plugin_namespace(), '/menus/(?P<id>\d+)', array(
63 63
                 array(
64 64
                     'methods'  => WP_REST_Server::READABLE,
65
-                    'callback' => array( $this, 'get_menu' ),
65
+                    'callback' => array($this, 'get_menu'),
66 66
                     'args'     => array(
67 67
                         'context' => array(
68 68
                         'default' => 'view',
69 69
                         ),
70 70
                     ),
71 71
                 )
72
-            ) );
72
+            ));
73 73
 
74
-            register_rest_route( self::get_plugin_namespace(), '/menu-locations', array(
74
+            register_rest_route(self::get_plugin_namespace(), '/menu-locations', array(
75 75
                 array(
76 76
                     'methods'  => WP_REST_Server::READABLE,
77
-                    'callback' => array( $this, 'get_menu_locations' ),
77
+                    'callback' => array($this, 'get_menu_locations'),
78 78
                 )
79
-            ) );
79
+            ));
80 80
 
81
-            register_rest_route( self::get_plugin_namespace(), '/menu-locations/(?P<location>[a-zA-Z0-9_-]+)', array(
81
+            register_rest_route(self::get_plugin_namespace(), '/menu-locations/(?P<location>[a-zA-Z0-9_-]+)', array(
82 82
                 array(
83 83
                     'methods'  => WP_REST_Server::READABLE,
84
-                    'callback' => array( $this, 'get_menu_location' ),
84
+                    'callback' => array($this, 'get_menu_location'),
85 85
                 )
86
-            ) );
86
+            ));
87 87
         }
88 88
 
89 89
 
@@ -95,29 +95,29 @@  discard block
 block discarded – undo
95 95
          */
96 96
         public static function get_menus() {
97 97
 
98
-            $rest_url = trailingslashit( get_rest_url() . self::get_plugin_namespace() . '/menus/' );
98
+            $rest_url = trailingslashit(get_rest_url().self::get_plugin_namespace().'/menus/');
99 99
             $wp_menus = wp_get_nav_menus();
100 100
 
101 101
             $i = 0;
102 102
             $rest_menus = array();
103
-            foreach ( $wp_menus as $wp_menu ) :
103
+            foreach ($wp_menus as $wp_menu) :
104 104
 
105 105
                 $menu = (array) $wp_menu;
106 106
 
107
-                $rest_menus[ $i ]                = $menu;
108
-                $rest_menus[ $i ]['ID']          = $menu['term_id'];
109
-                $rest_menus[ $i ]['name']        = $menu['name'];
110
-                $rest_menus[ $i ]['slug']        = $menu['slug'];
111
-                $rest_menus[ $i ]['description'] = $menu['description'];
112
-                $rest_menus[ $i ]['count']       = $menu['count'];
107
+                $rest_menus[$i]                = $menu;
108
+                $rest_menus[$i]['ID']          = $menu['term_id'];
109
+                $rest_menus[$i]['name']        = $menu['name'];
110
+                $rest_menus[$i]['slug']        = $menu['slug'];
111
+                $rest_menus[$i]['description'] = $menu['description'];
112
+                $rest_menus[$i]['count']       = $menu['count'];
113 113
 
114
-                $rest_menus[ $i ]['meta']['links']['collection'] = $rest_url;
115
-                $rest_menus[ $i ]['meta']['links']['self']       = $rest_url . $menu['term_id'];
114
+                $rest_menus[$i]['meta']['links']['collection'] = $rest_url;
115
+                $rest_menus[$i]['meta']['links']['self']       = $rest_url.$menu['term_id'];
116 116
 
117
-                $i ++;
117
+                $i++;
118 118
             endforeach;
119 119
 
120
-            return apply_filters( 'rest_menus_format_menus', $rest_menus );
120
+            return apply_filters('rest_menus_format_menus', $rest_menus);
121 121
         }
122 122
 
123 123
 
@@ -128,36 +128,36 @@  discard block
 block discarded – undo
128 128
          * @param  $request
129 129
          * @return array Menu data
130 130
          */
131
-        public function get_menu( $request ) {
131
+        public function get_menu($request) {
132 132
             $id             = (int) $request['id'];
133
-            $rest_url       = get_rest_url() . self::get_api_namespace() . '/menus/';
134
-            $wp_menu_object = $id ? wp_get_nav_menu_object( $id ) : array();
135
-            $wp_menu_items  = $id ? wp_get_nav_menu_items( $id ) : array();
133
+            $rest_url       = get_rest_url().self::get_api_namespace().'/menus/';
134
+            $wp_menu_object = $id ? wp_get_nav_menu_object($id) : array();
135
+            $wp_menu_items  = $id ? wp_get_nav_menu_items($id) : array();
136 136
 
137 137
             $rest_menu = array();
138 138
 
139
-            if ( $wp_menu_object ) :
139
+            if ($wp_menu_object) :
140 140
 
141 141
                 $menu = (array) $wp_menu_object;
142
-                $rest_menu['ID']          = abs( $menu['term_id'] );
142
+                $rest_menu['ID']          = abs($menu['term_id']);
143 143
                 $rest_menu['name']        = $menu['name'];
144 144
                 $rest_menu['slug']        = $menu['slug'];
145 145
                 $rest_menu['description'] = $menu['description'];
146
-                $rest_menu['count']       = abs( $menu['count'] );
146
+                $rest_menu['count']       = abs($menu['count']);
147 147
 
148 148
                 $rest_menu_items = array();
149
-                foreach ( $wp_menu_items as $item_object ) {
150
-	                $rest_menu_items[] = $this->format_menu_item( $item_object );
149
+                foreach ($wp_menu_items as $item_object) {
150
+	                $rest_menu_items[] = $this->format_menu_item($item_object);
151 151
                 }
152 152
 
153 153
                 $rest_menu_items = $this->nested_menu_items($rest_menu_items, 0);
154 154
 
155 155
                 $rest_menu['items']                       = $rest_menu_items;
156 156
                 $rest_menu['meta']['links']['collection'] = $rest_url;
157
-                $rest_menu['meta']['links']['self']       = $rest_url . $id;
157
+                $rest_menu['meta']['links']['self']       = $rest_url.$id;
158 158
 
159 159
             endif;
160
-            return apply_filters( 'rest_menus_format_menu', $rest_menu );
160
+            return apply_filters('rest_menus_format_menu', $rest_menu);
161 161
         }
162 162
 
163 163
 
@@ -172,24 +172,24 @@  discard block
 block discarded – undo
172 172
          * @param  $parent
173 173
          * @return array
174 174
          */
175
-        private function nested_menu_items( &$menu_items, $parent = null ) {
175
+        private function nested_menu_items(&$menu_items, $parent = null) {
176 176
 
177 177
             $parents = array();
178 178
             $children = array();
179 179
 
180 180
             // Separate menu_items into parents & children.
181
-            array_map( function( $i ) use ( $parent, &$children, &$parents ){
182
-                if ( $i['id'] != $parent && $i['parent'] == $parent ) {
181
+            array_map(function($i) use ($parent, &$children, &$parents){
182
+                if ($i['id'] != $parent && $i['parent'] == $parent) {
183 183
                     $parents[] = $i;
184 184
                 } else {
185 185
                     $children[] = $i;
186 186
                 }
187
-            }, $menu_items );
187
+            }, $menu_items);
188 188
 
189
-            foreach ( $parents as &$parent ) {
189
+            foreach ($parents as &$parent) {
190 190
 
191
-                if ( $this->has_children( $children, $parent['id'] ) ) {
192
-                    $parent['children'] = $this->nested_menu_items( $children, $parent['id'] );
191
+                if ($this->has_children($children, $parent['id'])) {
192
+                    $parent['children'] = $this->nested_menu_items($children, $parent['id']);
193 193
                 }
194 194
             }
195 195
 
@@ -205,8 +205,8 @@  discard block
 block discarded – undo
205 205
          * @param  int $id
206 206
          * @return array
207 207
          */
208
-        private function has_children( $items, $id ) {
209
-            return array_filter( $items, function( $i ) use ( $id ) {
208
+        private function has_children($items, $id) {
209
+            return array_filter($items, function($i) use ($id) {
210 210
                 return $i['parent'] == $id;
211 211
             } );
212 212
         }
@@ -219,26 +219,26 @@  discard block
 block discarded – undo
219 219
          * @param  $request
220 220
          * @return array All registered menus locations
221 221
          */
222
-        public static function get_menu_locations( $request ) {
222
+        public static function get_menu_locations($request) {
223 223
 
224 224
             $locations        = get_nav_menu_locations();
225 225
             $registered_menus = get_registered_nav_menus();
226
-	        $rest_url         = get_rest_url() . self::get_api_namespace() . '/menu-locations/';
226
+	        $rest_url = get_rest_url().self::get_api_namespace().'/menu-locations/';
227 227
             $rest_menus       = array();
228 228
 
229
-            if ( $locations && $registered_menus ) :
229
+            if ($locations && $registered_menus) :
230 230
 
231
-                foreach ( $registered_menus as $slug => $label ) :
231
+                foreach ($registered_menus as $slug => $label) :
232 232
 
233 233
 	                // Sanity check
234
-	                if ( ! isset( $locations[ $slug ] ) ) {
234
+	                if ( ! isset($locations[$slug])) {
235 235
 		                continue;
236 236
 	                }
237 237
 
238
-	                $rest_menus[ $slug ]['ID']                          = $locations[ $slug ];
239
-                    $rest_menus[ $slug ]['label']                       = $label;
240
-                    $rest_menus[ $slug ]['meta']['links']['collection'] = $rest_url;
241
-                    $rest_menus[ $slug ]['meta']['links']['self']       = $rest_url . $slug;
238
+	                $rest_menus[$slug]['ID'] = $locations[$slug];
239
+                    $rest_menus[$slug]['label']                       = $label;
240
+                    $rest_menus[$slug]['meta']['links']['collection'] = $rest_url;
241
+                    $rest_menus[$slug]['meta']['links']['self']       = $rest_url.$slug;
242 242
 
243 243
                 endforeach;
244 244
 
@@ -255,70 +255,70 @@  discard block
 block discarded – undo
255 255
          * @param  $request
256 256
          * @return array The menu for the corresponding location
257 257
          */
258
-        public function get_menu_location( $request ) {
258
+        public function get_menu_location($request) {
259 259
 
260 260
             $params     = $request->get_params();
261 261
             $location   = $params['location'];
262 262
             $locations  = get_nav_menu_locations();
263 263
 
264
-            if ( ! isset( $locations[ $location ] ) ) {
264
+            if ( ! isset($locations[$location])) {
265 265
 	            return array();
266 266
             }
267 267
 
268
-            $wp_menu = wp_get_nav_menu_object( $locations[ $location ] );
269
-            $menu_items = wp_get_nav_menu_items( $wp_menu->term_id );
268
+            $wp_menu = wp_get_nav_menu_object($locations[$location]);
269
+            $menu_items = wp_get_nav_menu_items($wp_menu->term_id);
270 270
 
271 271
 			/**
272 272
 			 * wp_get_nav_menu_items() outputs a list that's already sequenced correctly.
273 273
 			 * So the easiest thing to do is to reverse the list and then build our tree
274 274
 			 * from the ground up
275 275
 			 */
276
-			$rev_items = array_reverse ( $menu_items );
276
+			$rev_items = array_reverse($menu_items);
277 277
 			$rev_menu  = array();
278 278
 			$cache     = array();
279 279
 
280
-			foreach ( $rev_items as $item ) :
280
+			foreach ($rev_items as $item) :
281 281
 
282 282
 				$formatted = array(
283
-					'ID'          => abs( $item->ID ),
283
+					'ID'          => abs($item->ID),
284 284
 					'order'       => (int) $item->menu_order,
285
-					'parent'      => abs( $item->menu_item_parent ),
285
+					'parent'      => abs($item->menu_item_parent),
286 286
 					'title'       => $item->title,
287 287
 					'url'         => $item->url,
288 288
 					'attr'        => $item->attr_title,
289 289
 					'target'      => $item->target,
290
-					'classes'     => implode( ' ', $item->classes ),
290
+					'classes'     => implode(' ', $item->classes),
291 291
 					'xfn'         => $item->xfn,
292 292
 					'description' => $item->description,
293
-					'object_id'   => abs( $item->object_id ),
293
+					'object_id'   => abs($item->object_id),
294 294
 					'object'      => $item->object,
295 295
 					'type'        => $item->type,
296 296
 					'type_label'  => $item->type_label,
297 297
 					'children'    => array(),
298 298
 				);
299 299
 
300
-				if ( array_key_exists( $item->ID , $cache ) ) {
301
-					$formatted['children'] = array_reverse( $cache[ $item->ID ] );
300
+				if (array_key_exists($item->ID, $cache)) {
301
+					$formatted['children'] = array_reverse($cache[$item->ID]);
302 302
 				}
303 303
 
304
-              	$formatted = apply_filters( 'rest_menus_format_menu_item', $formatted );
304
+              	$formatted = apply_filters('rest_menus_format_menu_item', $formatted);
305 305
 
306
-				if ( $item->menu_item_parent != 0 ) {
306
+				if ($item->menu_item_parent != 0) {
307 307
 
308
-					if ( array_key_exists( $item->menu_item_parent , $cache ) ) {
309
-						array_push( $cache[ $item->menu_item_parent ], $formatted );
308
+					if (array_key_exists($item->menu_item_parent, $cache)) {
309
+						array_push($cache[$item->menu_item_parent], $formatted);
310 310
 					} else {
311
-						$cache[ $item->menu_item_parent ] = array( $formatted, );
311
+						$cache[$item->menu_item_parent] = array($formatted,);
312 312
 					}
313 313
 
314 314
 				} else {
315 315
 
316
-					array_push( $rev_menu, $formatted );
316
+					array_push($rev_menu, $formatted);
317 317
 				}
318 318
 
319 319
 			endforeach;
320 320
 
321
-			return array_reverse ( $rev_menu );
321
+			return array_reverse($rev_menu);
322 322
         }
323 323
 
324 324
 
@@ -331,19 +331,19 @@  discard block
 block discarded – undo
331 331
          * @param bool  $depth          Gives all children or direct children only
332 332
          * @return array	returns filtered array of nav_menu_items
333 333
          */
334
-        public function get_nav_menu_item_children( $parent_id, $nav_menu_items, $depth = true ) {
334
+        public function get_nav_menu_item_children($parent_id, $nav_menu_items, $depth = true) {
335 335
 
336 336
             $nav_menu_item_list = array();
337 337
 
338
-            foreach ( (array) $nav_menu_items as $nav_menu_item ) :
338
+            foreach ((array) $nav_menu_items as $nav_menu_item) :
339 339
 
340
-                if ( $nav_menu_item->menu_item_parent == $parent_id ) :
340
+                if ($nav_menu_item->menu_item_parent == $parent_id) :
341 341
 
342
-                    $nav_menu_item_list[] = $this->format_menu_item( $nav_menu_item, true, $nav_menu_items );
342
+                    $nav_menu_item_list[] = $this->format_menu_item($nav_menu_item, true, $nav_menu_items);
343 343
 
344
-                    if ( $depth ) {
345
-                        if ( $children = $this->get_nav_menu_item_children( $nav_menu_item->ID, $nav_menu_items ) ) {
346
-                            $nav_menu_item_list = array_merge( $nav_menu_item_list, $children );
344
+                    if ($depth) {
345
+                        if ($children = $this->get_nav_menu_item_children($nav_menu_item->ID, $nav_menu_items)) {
346
+                            $nav_menu_item_list = array_merge($nav_menu_item_list, $children);
347 347
                         }
348 348
                     }
349 349
 
@@ -364,51 +364,51 @@  discard block
 block discarded – undo
364 364
          * @param  array        $menu       The menu the item belongs to (used when $children is set to true)
365 365
          * @return array	a formatted menu item for REST
366 366
          */
367
-        public function format_menu_item( $menu_item, $children = false, $menu = array() ) {
367
+        public function format_menu_item($menu_item, $children = false, $menu = array()) {
368 368
             $item = (array) $menu_item;
369
-            $object_slug=null;
369
+            $object_slug = null;
370 370
             $rest_path = '';
371
-            switch($item['type']){
371
+            switch ($item['type']) {
372 372
                 case 'post_type_archive': //archive.
373
-                    $post_type_data = get_post_type_object( $item['object'] );
373
+                    $post_type_data = get_post_type_object($item['object']);
374 374
                     $object = empty($post_type_data->rest_base) ? $item['object'] : $post_type_data->rest_base;
375 375
                     $object_slug = $post_type_data->rewrite['slug'];
376 376
 
377
-                    $rest_path = rest_url( '/wp/v2/'.$object.'/');
377
+                    $rest_path = rest_url('/wp/v2/'.$object.'/');
378 378
                     break;
379 379
                 case 'taxonomy'://taxonomy term.
380
-                    $term = get_term_by( 'id', $item['object_id'], $item['object']);
380
+                    $term = get_term_by('id', $item['object_id'], $item['object']);
381 381
                     $object_slug = $term->slug;
382
-                    $taxonomy = get_taxonomy( $item['object']);
383
-                    $object =  ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name;
382
+                    $taxonomy = get_taxonomy($item['object']);
383
+                    $object = ! empty($taxonomy->rest_base) ? $taxonomy->rest_base : $taxonomy->name;
384 384
                     
385
-                    $rest_path = rest_url( '/wp/v2/'.$object.'/'.$item['object_id']);
385
+                    $rest_path = rest_url('/wp/v2/'.$object.'/'.$item['object_id']);
386 386
                     break;
387 387
                 case 'post_type':
388
-                    $post_type_data = get_post_type_object( $item['object'] );
388
+                    $post_type_data = get_post_type_object($item['object']);
389 389
                     $object = empty($post_type_data->rest_base) ? $item['object'] : $post_type_data->rest_base;
390
-                    $object_slug = get_post( $item['object_id'] )->post_name;
390
+                    $object_slug = get_post($item['object_id'])->post_name;
391 391
 
392
-                    $rest_path = rest_url( '/wp/v2/'.$object.'/'.$item['object_id']);
392
+                    $rest_path = rest_url('/wp/v2/'.$object.'/'.$item['object_id']);
393 393
                     break;
394 394
                 default: //try with the object and id.
395
-                    $rest_path = rest_url( '/wp/v2/'.$item['object'].'/'.$item['object_id']);
395
+                    $rest_path = rest_url('/wp/v2/'.$item['object'].'/'.$item['object_id']);
396 396
                     break;
397 397
             }
398 398
             //get_rest_url( int $blog_id = null, string $path = '/', string $scheme = 'rest' )
399 399
 
400 400
             $menu_item = array(
401
-                'id'          => abs( $item['ID'] ),
401
+                'id'          => abs($item['ID']),
402 402
                 'order'       => (int) $item['menu_order'],
403
-                'parent'      => abs( $item['menu_item_parent'] ),
403
+                'parent'      => abs($item['menu_item_parent']),
404 404
                 'title'       => $item['title'],
405 405
                 'url'         => $item['url'],
406 406
                 'attr'        => $item['attr_title'],
407 407
                 'target'      => $item['target'],
408
-                'classes'     => implode( ' ', $item['classes'] ),
408
+                'classes'     => implode(' ', $item['classes']),
409 409
                 'xfn'         => $item['xfn'],
410 410
                 'description' => $item['description'],
411
-                'object_id'   => abs( $item['object_id'] ),
411
+                'object_id'   => abs($item['object_id']),
412 412
                 'object'      => $item['object'],
413 413
                 'object_slug' => $object_slug,
414 414
                 'type'        => $item['type'],
@@ -416,11 +416,11 @@  discard block
 block discarded – undo
416 416
                 '_links'      => array('self'=>$rest_path)
417 417
             );
418 418
 
419
-            if ( $children === true && ! empty( $menu ) ) {
420
-	            $menu_item['children'] = $this->get_nav_menu_item_children( $item['ID'], $menu );
419
+            if ($children === true && ! empty($menu)) {
420
+	            $menu_item['children'] = $this->get_nav_menu_item_children($item['ID'], $menu);
421 421
             }
422 422
 
423
-            return apply_filters( 'rest_menus_format_menu_item', $menu_item );
423
+            return apply_filters('rest_menus_format_menu_item', $menu_item);
424 424
         }
425 425
 
426 426
 
Please login to merge, or discard this patch.