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