Completed
Push — master ( f161c3...b7334e )
by Fulvio
18s queued 15s
created
includes/wp-api-menus-v1.php 1 patch
Spacing   +66 added lines, -66 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_JSON_Menus' ) ) :
12
+if ( ! class_exists('WP_JSON_Menus')) :
13 13
 
14 14
 
15 15
 	/**
@@ -30,23 +30,23 @@  discard block
 block discarded – undo
30 30
 		 * @param  array $routes Existing routes
31 31
 		 * @return array Modified routes
32 32
 		 */
33
-		public function register_routes( $routes ) {
33
+		public function register_routes($routes) {
34 34
 
35 35
 			// all registered menus
36 36
 			$routes['/menus'] = array(
37
-				array( array( $this, 'get_menus' ), WP_JSON_Server::READABLE ),
37
+				array(array($this, 'get_menus'), WP_JSON_Server::READABLE),
38 38
 			);
39 39
 			// a specific menu
40 40
 			$routes['/menus/(?P<id>\d+)'] = array(
41
-				array( array( $this, 'get_menu' ), WP_JSON_Server::READABLE ),
41
+				array(array($this, 'get_menu'), WP_JSON_Server::READABLE),
42 42
 			);
43 43
 			// all registered menu locations
44 44
 			$routes['/menu-locations'] = array(
45
-				array( array( $this, 'get_menu_locations' ), WP_JSON_Server::READABLE ),
45
+				array(array($this, 'get_menu_locations'), WP_JSON_Server::READABLE),
46 46
 			);
47 47
 			// menu for given location
48 48
 			$routes['/menu-locations/(?P<location>[a-zA-Z0-9_-]+)'] = array(
49
-				array( array( $this, 'get_menu_location' ), WP_JSON_Server::READABLE ),
49
+				array(array($this, 'get_menu_location'), WP_JSON_Server::READABLE),
50 50
 			);
51 51
 
52 52
 			return $routes;
@@ -61,27 +61,27 @@  discard block
 block discarded – undo
61 61
 		 */
62 62
 		public static function get_menus() {
63 63
 
64
-			$json_url = get_json_url() . '/menus/';
64
+			$json_url = get_json_url().'/menus/';
65 65
 			$wp_menus = wp_get_nav_menus();
66 66
 
67 67
 			$i          = 0;
68 68
 			$json_menus = array();
69 69
 
70
-			foreach ( $wp_menus as $wp_menu ) :
70
+			foreach ($wp_menus as $wp_menu) :
71 71
 
72 72
 				$menu = (array) $wp_menu;
73 73
 
74
-				$json_menus[ $i ]                 = $menu;
75
-				$json_menus[ $i ]['ID']           = $menu['term_id'];
76
-				$json_menus[ $i ]['name']         = $menu['name'];
77
-				$json_menus[ $i ]['slug']         = $menu['slug'];
78
-				$json_menus[ $i ]['description']  = $menu['description'];
79
-				$json_menus[ $i ]['count']        = $menu['count'];
74
+				$json_menus[$i]                 = $menu;
75
+				$json_menus[$i]['ID']           = $menu['term_id'];
76
+				$json_menus[$i]['name']         = $menu['name'];
77
+				$json_menus[$i]['slug']         = $menu['slug'];
78
+				$json_menus[$i]['description']  = $menu['description'];
79
+				$json_menus[$i]['count']        = $menu['count'];
80 80
 
81
-				$json_menus[ $i ]['meta']['links']['collection'] = $json_url;
82
-				$json_menus[ $i ]['meta']['links']['self']       = $json_url . $menu['term_id'];
81
+				$json_menus[$i]['meta']['links']['collection'] = $json_url;
82
+				$json_menus[$i]['meta']['links']['self']       = $json_url.$menu['term_id'];
83 83
 
84
-				$i ++;
84
+				$i++;
85 85
 
86 86
 			endforeach;
87 87
 
@@ -96,33 +96,33 @@  discard block
 block discarded – undo
96 96
 		 * @param  int   $id ID of the menu
97 97
 		 * @return array Menu data
98 98
 		 */
99
-		public function get_menu( $id ) {
99
+		public function get_menu($id) {
100 100
 
101
-			$json_url       = get_json_url() . '/menus/';
102
-			$wp_menu_object = $id ? wp_get_nav_menu_object( $id ) : array();
103
-			$wp_menu_items  = $id ? wp_get_nav_menu_items( $id ) : array();
101
+			$json_url       = get_json_url().'/menus/';
102
+			$wp_menu_object = $id ? wp_get_nav_menu_object($id) : array();
103
+			$wp_menu_items  = $id ? wp_get_nav_menu_items($id) : array();
104 104
 
105 105
 			$json_menu = array();
106 106
 
107
-			if ( $wp_menu_object ) :
107
+			if ($wp_menu_object) :
108 108
 
109 109
 				$menu = (array) $wp_menu_object;
110
-				$json_menu['ID']            = abs( $menu['term_id'] );
110
+				$json_menu['ID']            = abs($menu['term_id']);
111 111
 				$json_menu['name']          = $menu['name'];
112 112
 				$json_menu['slug']          = $menu['slug'];
113 113
 				$json_menu['description']   = $menu['description'];
114
-				$json_menu['count']         = abs( $menu['count'] );
114
+				$json_menu['count']         = abs($menu['count']);
115 115
 
116 116
 				$json_menu_items = array();
117 117
 
118
-				foreach ( $wp_menu_items as $item_object ) {
118
+				foreach ($wp_menu_items as $item_object) {
119 119
 
120
-					$json_menu_items[] = $this->format_menu_item( $item_object );
120
+					$json_menu_items[] = $this->format_menu_item($item_object);
121 121
 				}
122 122
 
123 123
 				$json_menu['items']                       = $json_menu_items;
124 124
 				$json_menu['meta']['links']['collection'] = $json_url;
125
-				$json_menu['meta']['links']['self']       = $json_url . $id;
125
+				$json_menu['meta']['links']['self']       = $json_url.$id;
126 126
 
127 127
 			endif;
128 128
 
@@ -140,22 +140,22 @@  discard block
 block discarded – undo
140 140
 
141 141
 			$locations        = get_nav_menu_locations();
142 142
 			$registered_menus = get_registered_nav_menus();
143
-			$json_url         = get_json_url() . '/menu-locations/';
143
+			$json_url         = get_json_url().'/menu-locations/';
144 144
 			$json_menus       = array();
145 145
 
146
-			if ( $locations && $registered_menus ) :
146
+			if ($locations && $registered_menus) :
147 147
 
148
-				foreach ( $registered_menus as $slug => $label ) :
148
+				foreach ($registered_menus as $slug => $label) :
149 149
 
150 150
 					// Sanity check
151
-					if ( ! isset( $locations[ $slug ] ) ) {
151
+					if ( ! isset($locations[$slug])) {
152 152
 						continue;
153 153
 					}
154 154
 
155
-					$json_menus[ $slug ]['ID']                          = $locations[ $slug ];
156
-					$json_menus[ $slug ]['label']                       = $label;
157
-					$json_menus[ $slug ]['meta']['links']['collection'] = $json_url;
158
-					$json_menus[ $slug ]['meta']['links']['self']       = $json_url . $slug;
155
+					$json_menus[$slug]['ID']                          = $locations[$slug];
156
+					$json_menus[$slug]['label']                       = $label;
157
+					$json_menus[$slug]['meta']['links']['collection'] = $json_url;
158
+					$json_menus[$slug]['meta']['links']['self']       = $json_url.$slug;
159 159
 
160 160
 				endforeach;
161 161
 
@@ -172,29 +172,29 @@  discard block
 block discarded – undo
172 172
 		 * @param  string $location The theme location menu name
173 173
 		 * @return array The menu for the corresponding location
174 174
 		 */
175
-		public function get_menu_location( $location ) {
175
+		public function get_menu_location($location) {
176 176
 
177 177
 			$locations = get_nav_menu_locations();
178 178
 
179
-			if ( ! isset( $locations[ $location ] ) ) {
179
+			if ( ! isset($locations[$location])) {
180 180
 
181 181
 				return array();
182 182
 			}
183 183
 
184
-			$wp_menu = wp_get_nav_menu_object( $locations[ $location ] );
185
-			$menu_items = wp_get_nav_menu_items( $wp_menu->term_id );
184
+			$wp_menu = wp_get_nav_menu_object($locations[$location]);
185
+			$menu_items = wp_get_nav_menu_items($wp_menu->term_id);
186 186
 
187 187
 			$sorted_menu_items = $top_level_menu_items = $menu_items_with_children = array();
188 188
 
189
-			foreach ( (array) $menu_items as $menu_item ) {
189
+			foreach ((array) $menu_items as $menu_item) {
190 190
 
191
-				$sorted_menu_items[ $menu_item->menu_order ] = $menu_item;
191
+				$sorted_menu_items[$menu_item->menu_order] = $menu_item;
192 192
 			}
193 193
 
194
-			foreach ( $sorted_menu_items as $menu_item ) {
194
+			foreach ($sorted_menu_items as $menu_item) {
195 195
 
196
-				if ( (int) $menu_item->menu_item_parent !== 0 ) {
197
-					$menu_items_with_children[ $menu_item->menu_item_parent ] = true;
196
+				if ((int) $menu_item->menu_item_parent !== 0) {
197
+					$menu_items_with_children[$menu_item->menu_item_parent] = true;
198 198
 				} else {
199 199
 					$top_level_menu_items[] = $menu_item;
200 200
 				}
@@ -202,18 +202,18 @@  discard block
 block discarded – undo
202 202
 
203 203
 			$menu = array();
204 204
 
205
-			while ( $sorted_menu_items ) :
205
+			while ($sorted_menu_items) :
206 206
 
207 207
 				$i = 0;
208 208
 
209
-				foreach ( $top_level_menu_items as $top_item ) :
209
+				foreach ($top_level_menu_items as $top_item) :
210 210
 
211
-					$menu[ $i ] = $this->format_menu_item( $top_item, false );
211
+					$menu[$i] = $this->format_menu_item($top_item, false);
212 212
 
213
-					if ( isset( $menu_items_with_children[ $top_item->ID ] ) ) {
214
-						$menu[ $i ]['children'] = $this->get_nav_menu_item_children( $top_item->ID, $menu_items, false );
213
+					if (isset($menu_items_with_children[$top_item->ID])) {
214
+						$menu[$i]['children'] = $this->get_nav_menu_item_children($top_item->ID, $menu_items, false);
215 215
 					} else {
216
-						$menu[ $i ]['children'] = array();
216
+						$menu[$i]['children'] = array();
217 217
 					}
218 218
 
219 219
 					$i++;
@@ -237,21 +237,21 @@  discard block
 block discarded – undo
237 237
 		 * @param  bool    $depth          gives all children or direct children only
238 238
 		 * @return array   returns filtered array of nav_menu_items
239 239
 		 */
240
-		public function get_nav_menu_item_children( $parent_id, $nav_menu_items, $depth = true ) {
240
+		public function get_nav_menu_item_children($parent_id, $nav_menu_items, $depth = true) {
241 241
 
242 242
 			$nav_menu_item_list = array();
243 243
 
244
-			foreach ( (array) $nav_menu_items as $nav_menu_item ) :
244
+			foreach ((array) $nav_menu_items as $nav_menu_item) :
245 245
 
246
-				if ( $nav_menu_item->menu_item_parent == $parent_id ) :
246
+				if ($nav_menu_item->menu_item_parent == $parent_id) :
247 247
 
248
-					$nav_menu_item_list[] = $this->format_menu_item( $nav_menu_item, true, $nav_menu_items );
248
+					$nav_menu_item_list[] = $this->format_menu_item($nav_menu_item, true, $nav_menu_items);
249 249
 
250
-					if ( $depth ) {
250
+					if ($depth) {
251 251
 
252
-						if ( $children = $this->get_nav_menu_item_children( $nav_menu_item->ID, $nav_menu_items ) ) {
252
+						if ($children = $this->get_nav_menu_item_children($nav_menu_item->ID, $nav_menu_items)) {
253 253
 
254
-							$nav_menu_item_list = array_merge( $nav_menu_item_list, $children );
254
+							$nav_menu_item_list = array_merge($nav_menu_item_list, $children);
255 255
 						}
256 256
 					}
257 257
 
@@ -272,34 +272,34 @@  discard block
 block discarded – undo
272 272
 		 * @param   array           $menu       the menu the item belongs to (used when $children is set to true)
273 273
 		 * @return  array   a formatted menu item for JSON
274 274
 		 */
275
-		public function format_menu_item( $menu_item, $children = false, $menu = array() ) {
275
+		public function format_menu_item($menu_item, $children = false, $menu = array()) {
276 276
 
277 277
 			$item = (array) $menu_item;
278 278
 
279 279
 			$menu_item = array(
280
-				'ID'          => abs( $item['ID'] ),
280
+				'ID'          => abs($item['ID']),
281 281
 				'order'       => (int) $item['menu_order'],
282
-				'parent'      => abs( $item['menu_item_parent'] ),
282
+				'parent'      => abs($item['menu_item_parent']),
283 283
 				'title'       => $item['title'],
284 284
 				'url'         => $item['url'],
285 285
 				'attr'        => $item['attr_title'],
286 286
 				'target'      => $item['target'],
287
-				'classes'     => implode( ' ', $item['classes'] ),
287
+				'classes'     => implode(' ', $item['classes']),
288 288
 				'xfn'         => $item['xfn'],
289 289
 				'description' => $item['description'],
290
-				'object_id'   => abs( $item['object_id'] ),
290
+				'object_id'   => abs($item['object_id']),
291 291
 				'object'      => $item['object'],
292 292
                 'object_slug' => get_post($item['object_id'])->post_name,
293 293
 				'type'        => $item['type'],
294 294
 				'type_label'  => $item['type_label'],
295 295
 			);
296 296
 
297
-			if ( $children === true && ! empty( $menu ) ) {
297
+			if ($children === true && ! empty($menu)) {
298 298
 
299
-				$menu_item['children'] = $this->get_nav_menu_item_children( $item['ID'], $menu );
299
+				$menu_item['children'] = $this->get_nav_menu_item_children($item['ID'], $menu);
300 300
 			}
301 301
 
302
-			return apply_filters( 'json_menus_format_menu_item', $menu_item );
302
+			return apply_filters('json_menus_format_menu_item', $menu_item);
303 303
 		}
304 304
 
305 305
 
Please login to merge, or discard this patch.
wp-api-menus.php 1 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
 	 *
@@ -73,10 +73,10 @@  discard block
 block discarded – undo
73 73
 	 * @since 1.4.0
74 74
 	 * @uses _doing_it_wrong()
75 75
 	 */
76
-	function _wp_rest_menus_doing_it_wrong( $function, $route, $replacement ) {
76
+	function _wp_rest_menus_doing_it_wrong($function, $route, $replacement) {
77 77
 		if (
78 78
 			_wp_rest_menus_allow_legacy_menus() ||
79
-			is_wp_version_compatible( '5.9' ) && _wp_rest_menus_allow_legacy_menus()
79
+			is_wp_version_compatible('5.9') && _wp_rest_menus_allow_legacy_menus()
80 80
 		) {
81 81
 			return;
82 82
 		}
@@ -85,16 +85,16 @@  discard block
 block discarded – undo
85 85
 			$function,
86 86
 			sprintf(
87 87
 			/* translators: 1: The REST API route namespace, 2: The plugin version. */
88
-				__( 'The REST API Menu route %1$s is "deprecated". Please use WordPres cores menu route replacement found in WP >= 5.9: %2$s' ),
88
+				__('The REST API Menu route %1$s is "deprecated". Please use WordPres cores menu route replacement found in WP >= 5.9: %2$s'),
89 89
 				sprintf('<code>%1$s%2$s</code>', WP_REST_Menus::get_plugin_namespace(), $route),
90
-				'<code>' . $replacement . '</code>'
90
+				'<code>'.$replacement.'</code>'
91 91
 			),
92 92
 			'1.4.0'
93 93
 		);
94 94
 	}
95 95
 endif;
96 96
 
97
-if ( ! function_exists( '_wp_rest_menus_allow_legacy_menus' ) ) :
97
+if ( ! function_exists('_wp_rest_menus_allow_legacy_menus')) :
98 98
 	/**
99 99
 	 * Allow legacy menus "filter".
100 100
 	 *
@@ -110,6 +110,6 @@  discard block
 block discarded – undo
110 110
 		 *
111 111
 		 * @return bool
112 112
 		 */
113
-		return apply_filters( 'rest_menus_allow_legacy_menus', false ) === true;
113
+		return apply_filters('rest_menus_allow_legacy_menus', false) === true;
114 114
 	}
115 115
 endif;
Please login to merge, or discard this patch.
includes/wp-api-menus-v2.php 1 patch
Spacing   +94 added lines, -94 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
     /**
@@ -50,18 +50,18 @@  discard block
 block discarded – undo
50 50
          */
51 51
         public function register_routes() {
52 52
 
53
-	        $this->register_rest_route( '/menus', array(
53
+	        $this->register_rest_route('/menus', array(
54 54
 		        array(
55 55
 			        'methods'             => WP_REST_Server::READABLE,
56
-			        'callback'            => array( $this, 'get_menus' ),
56
+			        'callback'            => array($this, 'get_menus'),
57 57
 			        'permission_callback' => '__return_true',
58 58
 		        )
59
-	        ) );
59
+	        ));
60 60
 
61
-	        $this->register_rest_route( '/menus/(?P<id>\d+)', array(
61
+	        $this->register_rest_route('/menus/(?P<id>\d+)', array(
62 62
 		        array(
63 63
 			        'methods'             => WP_REST_Server::READABLE,
64
-			        'callback'            => array( $this, 'get_menu' ),
64
+			        'callback'            => array($this, 'get_menu'),
65 65
 			        'permission_callback' => '__return_true',
66 66
 			        'args'                => array(
67 67
 				        'context' => array(
@@ -69,23 +69,23 @@  discard block
 block discarded – undo
69 69
 				        ),
70 70
 			        ),
71 71
 		        )
72
-	        ) );
72
+	        ));
73 73
 
74
-	        $this->register_rest_route( '/menu-locations', array(
74
+	        $this->register_rest_route('/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
 			        'permission_callback' => '__return_true',
79 79
 		        )
80
-	        ) );
80
+	        ));
81 81
 
82
-	        $this->register_rest_route( '/menu-locations/(?P<location>[a-zA-Z0-9_-]+)', array(
82
+	        $this->register_rest_route('/menu-locations/(?P<location>[a-zA-Z0-9_-]+)', array(
83 83
 		        array(
84 84
 			        'methods'             => WP_REST_Server::READABLE,
85
-			        'callback'            => array( $this, 'get_menu_location' ),
85
+			        'callback'            => array($this, 'get_menu_location'),
86 86
 			        'permission_callback' => '__return_true',
87 87
 		        )
88
-	        ) );
88
+	        ));
89 89
         }
90 90
 
91 91
         /**
@@ -95,29 +95,29 @@  discard block
 block discarded – undo
95 95
          * @return array All registered menus
96 96
          */
97 97
         public function get_menus() {
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,37 +128,37 @@  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_plugin_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_plugin_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 160
 
161
-            return apply_filters( 'rest_menus_format_menu', $rest_menu );
161
+            return apply_filters('rest_menus_format_menu', $rest_menu);
162 162
         }
163 163
 
164 164
 
@@ -173,24 +173,24 @@  discard block
 block discarded – undo
173 173
          * @param  $parent
174 174
          * @return array
175 175
          */
176
-        private function nested_menu_items( &$menu_items, $parent = null ) {
176
+        private function nested_menu_items(&$menu_items, $parent = null) {
177 177
 
178 178
             $parents = array();
179 179
             $children = array();
180 180
 
181 181
             // Separate menu_items into parents & children.
182
-            array_map( function( $i ) use ( $parent, &$children, &$parents ){
183
-                if ( $i['id'] != $parent && $i['parent'] == $parent ) {
182
+            array_map(function($i) use ($parent, &$children, &$parents){
183
+                if ($i['id'] != $parent && $i['parent'] == $parent) {
184 184
                     $parents[] = $i;
185 185
                 } else {
186 186
                     $children[] = $i;
187 187
                 }
188
-            }, $menu_items );
188
+            }, $menu_items);
189 189
 
190
-            foreach ( $parents as &$parent ) {
190
+            foreach ($parents as &$parent) {
191 191
 
192
-                if ( $this->has_children( $children, $parent['id'] ) ) {
193
-                    $parent['children'] = $this->nested_menu_items( $children, $parent['id'] );
192
+                if ($this->has_children($children, $parent['id'])) {
193
+                    $parent['children'] = $this->nested_menu_items($children, $parent['id']);
194 194
                 }
195 195
             }
196 196
 
@@ -206,8 +206,8 @@  discard block
 block discarded – undo
206 206
          * @param  int $id
207 207
          * @return array
208 208
          */
209
-        private function has_children( $items, $id ) {
210
-            return array_filter( $items, function( $i ) use ( $id ) {
209
+        private function has_children($items, $id) {
210
+            return array_filter($items, function($i) use ($id) {
211 211
                 return $i['parent'] == $id;
212 212
             } );
213 213
         }
@@ -220,25 +220,25 @@  discard block
 block discarded – undo
220 220
          * @param  $request
221 221
          * @return array All registered menus locations
222 222
          */
223
-        public function get_menu_locations( $request ) {
223
+        public function get_menu_locations($request) {
224 224
             $locations        = get_nav_menu_locations();
225 225
             $registered_menus = get_registered_nav_menus();
226
-	        $rest_url         = get_rest_url() . self::get_plugin_namespace() . '/menu-locations/';
226
+	        $rest_url = get_rest_url().self::get_plugin_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,69 +255,69 @@  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
             $params     = $request->get_params();
260 260
             $location   = $params['location'];
261 261
             $locations  = get_nav_menu_locations();
262 262
 
263
-            if ( empty( $locations[ $location ] ) ) {
263
+            if (empty($locations[$location])) {
264 264
 	            return array();
265 265
             }
266 266
 
267
-            $wp_menu = wp_get_nav_menu_object( $locations[ $location ] );
268
-            $menu_items = wp_get_nav_menu_items( $wp_menu->term_id );
267
+            $wp_menu = wp_get_nav_menu_object($locations[$location]);
268
+            $menu_items = wp_get_nav_menu_items($wp_menu->term_id);
269 269
 
270 270
 			/**
271 271
 			 * wp_get_nav_menu_items() outputs a list that's already sequenced correctly.
272 272
 			 * So the easiest thing to do is to reverse the list and then build our tree
273 273
 			 * from the ground up
274 274
 			 */
275
-			$rev_items = array_reverse ( $menu_items );
275
+			$rev_items = array_reverse($menu_items);
276 276
 			$rev_menu  = array();
277 277
 			$cache     = array();
278 278
 
279
-			foreach ( $rev_items as $item ) :
279
+			foreach ($rev_items as $item) :
280 280
 
281 281
 				$formatted = array(
282
-					'ID'          => abs( $item->ID ),
282
+					'ID'          => abs($item->ID),
283 283
 					'order'       => (int) $item->menu_order,
284
-					'parent'      => abs( $item->menu_item_parent ),
284
+					'parent'      => abs($item->menu_item_parent),
285 285
 					'title'       => $item->title,
286 286
 					'url'         => $item->url,
287 287
 					'attr'        => $item->attr_title,
288 288
 					'target'      => $item->target,
289
-					'classes'     => implode( ' ', $item->classes ),
289
+					'classes'     => implode(' ', $item->classes),
290 290
 					'xfn'         => $item->xfn,
291 291
 					'description' => $item->description,
292
-					'object_id'   => abs( $item->object_id ),
292
+					'object_id'   => abs($item->object_id),
293 293
 					'object'      => $item->object,
294 294
 					'type'        => $item->type,
295 295
 					'type_label'  => $item->type_label,
296 296
 					'children'    => array(),
297 297
 				);
298 298
 
299
-				if ( array_key_exists( $item->ID , $cache ) ) {
300
-					$formatted['children'] = array_reverse( $cache[ $item->ID ] );
299
+				if (array_key_exists($item->ID, $cache)) {
300
+					$formatted['children'] = array_reverse($cache[$item->ID]);
301 301
 				}
302 302
 
303
-            	$formatted = apply_filters( 'rest_menus_format_menu_item', $formatted );
303
+            	$formatted = apply_filters('rest_menus_format_menu_item', $formatted);
304 304
 
305
-				if ( $item->menu_item_parent != 0 ) {
305
+				if ($item->menu_item_parent != 0) {
306 306
 
307
-					if ( array_key_exists( $item->menu_item_parent , $cache ) ) {
308
-						array_push( $cache[ $item->menu_item_parent ], $formatted );
307
+					if (array_key_exists($item->menu_item_parent, $cache)) {
308
+						array_push($cache[$item->menu_item_parent], $formatted);
309 309
 					} else {
310
-						$cache[ $item->menu_item_parent ] = array( $formatted, );
310
+						$cache[$item->menu_item_parent] = array($formatted,);
311 311
 					}
312 312
 
313 313
 				} else {
314 314
 
315
-					array_push( $rev_menu, $formatted );
315
+					array_push($rev_menu, $formatted);
316 316
 				}
317 317
 
318 318
 			endforeach;
319 319
 
320
-			return array_reverse ( $rev_menu );
320
+			return array_reverse($rev_menu);
321 321
         }
322 322
 
323 323
 
@@ -330,19 +330,19 @@  discard block
 block discarded – undo
330 330
          * @param bool  $depth          Gives all children or direct children only
331 331
          * @return array	returns filtered array of nav_menu_items
332 332
          */
333
-        public function get_nav_menu_item_children( $parent_id, $nav_menu_items, $depth = true ) {
333
+        public function get_nav_menu_item_children($parent_id, $nav_menu_items, $depth = true) {
334 334
 
335 335
             $nav_menu_item_list = array();
336 336
 
337
-            foreach ( (array) $nav_menu_items as $nav_menu_item ) :
337
+            foreach ((array) $nav_menu_items as $nav_menu_item) :
338 338
 
339
-                if ( $nav_menu_item->menu_item_parent == $parent_id ) :
339
+                if ($nav_menu_item->menu_item_parent == $parent_id) :
340 340
 
341
-                    $nav_menu_item_list[] = $this->format_menu_item( $nav_menu_item, true, $nav_menu_items );
341
+                    $nav_menu_item_list[] = $this->format_menu_item($nav_menu_item, true, $nav_menu_items);
342 342
 
343
-                    if ( $depth ) {
344
-                        if ( $children = $this->get_nav_menu_item_children( $nav_menu_item->ID, $nav_menu_items ) ) {
345
-                            $nav_menu_item_list = array_merge( $nav_menu_item_list, $children );
343
+                    if ($depth) {
344
+                        if ($children = $this->get_nav_menu_item_children($nav_menu_item->ID, $nav_menu_items)) {
345
+                            $nav_menu_item_list = array_merge($nav_menu_item_list, $children);
346 346
                         }
347 347
                     }
348 348
 
@@ -363,35 +363,35 @@  discard block
 block discarded – undo
363 363
          * @param  array        $menu       The menu the item belongs to (used when $children is set to true)
364 364
          * @return array	a formatted menu item for REST
365 365
          */
366
-        public function format_menu_item( $menu_item, $children = false, $menu = array() ) {
366
+        public function format_menu_item($menu_item, $children = false, $menu = array()) {
367 367
 
368 368
             $item = (array) $menu_item;
369
-            $object_post = get_post( $item['object_id'] );
369
+            $object_post = get_post($item['object_id']);
370 370
 
371 371
 
372 372
             $menu_item = array(
373
-                'id'          => abs( $item['ID'] ),
373
+                'id'          => abs($item['ID']),
374 374
                 'order'       => (int) $item['menu_order'],
375
-                'parent'      => abs( $item['menu_item_parent'] ),
375
+                'parent'      => abs($item['menu_item_parent']),
376 376
                 'title'       => $item['title'],
377 377
                 'url'         => $item['url'],
378 378
                 'attr'        => $item['attr_title'],
379 379
                 'target'      => $item['target'],
380
-                'classes'     => implode( ' ', $item['classes'] ),
380
+                'classes'     => implode(' ', $item['classes']),
381 381
                 'xfn'         => $item['xfn'],
382 382
                 'description' => $item['description'],
383
-                'object_id'   => abs( $item['object_id'] ),
383
+                'object_id'   => abs($item['object_id']),
384 384
                 'object'      => $item['object'],
385
-                'object_slug' => !empty($object_post) ? $object_post->post_name : null,
385
+                'object_slug' => ! empty($object_post) ? $object_post->post_name : null,
386 386
                 'type'        => $item['type'],
387 387
                 'type_label'  => $item['type_label'],
388 388
             );
389 389
 
390
-            if ( $children === true && ! empty( $menu ) ) {
391
-	            $menu_item['children'] = $this->get_nav_menu_item_children( $item['ID'], $menu );
390
+            if ($children === true && ! empty($menu)) {
391
+	            $menu_item['children'] = $this->get_nav_menu_item_children($item['ID'], $menu);
392 392
             }
393 393
 
394
-            return apply_filters( 'rest_menus_format_menu_item', $menu_item );
394
+            return apply_filters('rest_menus_format_menu_item', $menu_item);
395 395
         }
396 396
 
397 397
 	    /**
@@ -401,9 +401,9 @@  discard block
 block discarded – undo
401 401
 	     * @param array  $args      Optional. Either an array of options for the endpoint, or an array of arrays for
402 402
 	     *                          multiple methods. Default empty array.
403 403
 	     */
404
-	    private function register_rest_route( $route, $args = array() ) {
405
-		    _wp_rest_menus_doing_it_wrong( __METHOD__, $route, $this->replacements[ $route ] );
406
-		    register_rest_route( self::get_plugin_namespace(), $route, $args );
404
+	    private function register_rest_route($route, $args = array()) {
405
+		    _wp_rest_menus_doing_it_wrong(__METHOD__, $route, $this->replacements[$route]);
406
+		    register_rest_route(self::get_plugin_namespace(), $route, $args);
407 407
 	    }
408 408
     }
409 409
 
Please login to merge, or discard this patch.