@@ -5,11 +5,11 @@ discard block |
||
| 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,27 +30,27 @@ discard block |
||
| 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 | // a specific menu rendered in html |
| 44 | 44 | $routes['/menu-html/(?P<id>[a-zA-Z0-9_-]+)'] = array( |
| 45 | - array( array( $this, 'get_menu_html' ), WP_JSON_Server::READABLE ), |
|
| 45 | + array(array($this, 'get_menu_html'), WP_JSON_Server::READABLE), |
|
| 46 | 46 | ); |
| 47 | 47 | // all registered menu locations |
| 48 | 48 | $routes['/menu-locations'] = array( |
| 49 | - array( array( $this, 'get_menu_locations' ), WP_JSON_Server::READABLE ), |
|
| 49 | + array(array($this, 'get_menu_locations'), WP_JSON_Server::READABLE), |
|
| 50 | 50 | ); |
| 51 | 51 | // menu for given location |
| 52 | 52 | $routes['/menu-locations/(?P<location>[a-zA-Z0-9_-]+)'] = array( |
| 53 | - array( array( $this, 'get_menu_location' ), WP_JSON_Server::READABLE ), |
|
| 53 | + array(array($this, 'get_menu_location'), WP_JSON_Server::READABLE), |
|
| 54 | 54 | ); |
| 55 | 55 | |
| 56 | 56 | return $routes; |
@@ -65,28 +65,28 @@ discard block |
||
| 65 | 65 | */ |
| 66 | 66 | public static function get_menus() { |
| 67 | 67 | |
| 68 | - $json_url = get_json_url() . '/menus/'; |
|
| 68 | + $json_url = get_json_url().'/menus/'; |
|
| 69 | 69 | $json_url_base = get_json_url(); |
| 70 | 70 | $wp_menus = wp_get_nav_menus(); |
| 71 | 71 | |
| 72 | 72 | $i = 0; |
| 73 | 73 | $json_menus = array(); |
| 74 | - foreach ( $wp_menus as $wp_menu ) : |
|
| 74 | + foreach ($wp_menus as $wp_menu) : |
|
| 75 | 75 | |
| 76 | 76 | $menu = (array) $wp_menu; |
| 77 | 77 | |
| 78 | - $json_menus[ $i ] = $menu; |
|
| 79 | - $json_menus[ $i ]['ID'] = $menu['term_id']; |
|
| 80 | - $json_menus[ $i ]['name'] = $menu['name']; |
|
| 81 | - $json_menus[ $i ]['slug'] = $menu['slug']; |
|
| 82 | - $json_menus[ $i ]['description'] = $menu['description']; |
|
| 83 | - $json_menus[ $i ]['count'] = $menu['count']; |
|
| 78 | + $json_menus[$i] = $menu; |
|
| 79 | + $json_menus[$i]['ID'] = $menu['term_id']; |
|
| 80 | + $json_menus[$i]['name'] = $menu['name']; |
|
| 81 | + $json_menus[$i]['slug'] = $menu['slug']; |
|
| 82 | + $json_menus[$i]['description'] = $menu['description']; |
|
| 83 | + $json_menus[$i]['count'] = $menu['count']; |
|
| 84 | 84 | |
| 85 | - $json_menus[ $i ]['meta']['links']['collection'] = $json_url; |
|
| 86 | - $json_menus[ $i ]['meta']['links']['self'] = $json_url . $menu['term_id']; |
|
| 87 | - $json_menus[ $i ]['meta']['links']['self'] = $json_url_base . '/menu-html/' . $menu['term_id']; |
|
| 85 | + $json_menus[$i]['meta']['links']['collection'] = $json_url; |
|
| 86 | + $json_menus[$i]['meta']['links']['self'] = $json_url.$menu['term_id']; |
|
| 87 | + $json_menus[$i]['meta']['links']['self'] = $json_url_base.'/menu-html/'.$menu['term_id']; |
|
| 88 | 88 | |
| 89 | - $i ++; |
|
| 89 | + $i++; |
|
| 90 | 90 | endforeach; |
| 91 | 91 | |
| 92 | 92 | return $json_menus; |
@@ -100,31 +100,31 @@ discard block |
||
| 100 | 100 | * @param int $id ID of the menu |
| 101 | 101 | * @return array Menu data |
| 102 | 102 | */ |
| 103 | - public function get_menu( $id ) { |
|
| 103 | + public function get_menu($id) { |
|
| 104 | 104 | |
| 105 | - $json_url = get_json_url() . '/menus/'; |
|
| 106 | - $wp_menu_object = $id ? wp_get_nav_menu_object( $id ) : array(); |
|
| 107 | - $wp_menu_items = $id ? wp_get_nav_menu_items( $id ) : array(); |
|
| 105 | + $json_url = get_json_url().'/menus/'; |
|
| 106 | + $wp_menu_object = $id ? wp_get_nav_menu_object($id) : array(); |
|
| 107 | + $wp_menu_items = $id ? wp_get_nav_menu_items($id) : array(); |
|
| 108 | 108 | |
| 109 | 109 | $json_menu = array(); |
| 110 | 110 | |
| 111 | - if ( $wp_menu_object ) : |
|
| 111 | + if ($wp_menu_object) : |
|
| 112 | 112 | |
| 113 | 113 | $menu = (array) $wp_menu_object; |
| 114 | - $json_menu['ID'] = abs( $menu['term_id'] ); |
|
| 114 | + $json_menu['ID'] = abs($menu['term_id']); |
|
| 115 | 115 | $json_menu['name'] = $menu['name']; |
| 116 | 116 | $json_menu['slug'] = $menu['slug']; |
| 117 | 117 | $json_menu['description'] = $menu['description']; |
| 118 | - $json_menu['count'] = abs( $menu['count'] ); |
|
| 118 | + $json_menu['count'] = abs($menu['count']); |
|
| 119 | 119 | |
| 120 | 120 | $json_menu_items = array(); |
| 121 | - foreach ( $wp_menu_items as $item_object ) { |
|
| 122 | - $json_menu_items[] = $this->format_menu_item( $item_object ); |
|
| 121 | + foreach ($wp_menu_items as $item_object) { |
|
| 122 | + $json_menu_items[] = $this->format_menu_item($item_object); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | $json_menu['items'] = $json_menu_items; |
| 126 | 126 | $json_menu['meta']['links']['collection'] = $json_url; |
| 127 | - $json_menu['meta']['links']['self'] = $json_url . $id; |
|
| 127 | + $json_menu['meta']['links']['self'] = $json_url.$id; |
|
| 128 | 128 | |
| 129 | 129 | endif; |
| 130 | 130 | |
@@ -139,29 +139,29 @@ discard block |
||
| 139 | 139 | * @param int $id ID of the menu |
| 140 | 140 | * @return array Menu data |
| 141 | 141 | */ |
| 142 | - public function get_menu_html( $menu_id ) { |
|
| 142 | + public function get_menu_html($menu_id) { |
|
| 143 | 143 | |
| 144 | 144 | $json_url_base = get_json_url(); |
| 145 | - $wp_menu_object = $menu_id ? wp_get_nav_menu_object( $menu_id ) : array(); |
|
| 146 | - $wp_menu_items = $menu_id ? wp_get_nav_menu_items( $menu_id ) : array(); |
|
| 145 | + $wp_menu_object = $menu_id ? wp_get_nav_menu_object($menu_id) : array(); |
|
| 146 | + $wp_menu_items = $menu_id ? wp_get_nav_menu_items($menu_id) : array(); |
|
| 147 | 147 | |
| 148 | 148 | $json_menu = array(); |
| 149 | 149 | |
| 150 | - if ( $wp_menu_object ) : |
|
| 150 | + if ($wp_menu_object) : |
|
| 151 | 151 | |
| 152 | 152 | $menu = (array) $wp_menu_object; |
| 153 | - $json_menu['ID'] = abs( $menu['term_id'] ); |
|
| 153 | + $json_menu['ID'] = abs($menu['term_id']); |
|
| 154 | 154 | $json_menu['name'] = $menu['name']; |
| 155 | 155 | $json_menu['slug'] = $menu['slug']; |
| 156 | 156 | $json_menu['description'] = $menu['description']; |
| 157 | - $json_menu['count'] = abs( $menu['count'] ); |
|
| 157 | + $json_menu['count'] = abs($menu['count']); |
|
| 158 | 158 | |
| 159 | 159 | ob_start(); |
| 160 | - wp_nav_menu( array( 'menu' => $menu_id ) ); |
|
| 161 | - $json_menu['render_html']=ob_get_clean(); |
|
| 160 | + wp_nav_menu(array('menu' => $menu_id)); |
|
| 161 | + $json_menu['render_html'] = ob_get_clean(); |
|
| 162 | 162 | |
| 163 | - $json_menu['meta']['links']['collection'] = $json_url_base . '/menus/'; |
|
| 164 | - $json_menu['meta']['links']['self'] = $json_url_base . '/menu-html/' . $menu_id; |
|
| 163 | + $json_menu['meta']['links']['collection'] = $json_url_base.'/menus/'; |
|
| 164 | + $json_menu['meta']['links']['self'] = $json_url_base.'/menu-html/'.$menu_id; |
|
| 165 | 165 | |
| 166 | 166 | endif; |
| 167 | 167 | |
@@ -179,22 +179,22 @@ discard block |
||
| 179 | 179 | |
| 180 | 180 | $locations = get_nav_menu_locations(); |
| 181 | 181 | $registered_menus = get_registered_nav_menus(); |
| 182 | - $json_url = get_json_url() . '/menu-locations/'; |
|
| 182 | + $json_url = get_json_url().'/menu-locations/'; |
|
| 183 | 183 | $json_menus = array(); |
| 184 | 184 | |
| 185 | - if ( $locations && $registered_menus ) : |
|
| 185 | + if ($locations && $registered_menus) : |
|
| 186 | 186 | |
| 187 | - foreach ( $registered_menus as $slug => $label ) : |
|
| 187 | + foreach ($registered_menus as $slug => $label) : |
|
| 188 | 188 | |
| 189 | 189 | // Sanity check |
| 190 | - if ( ! isset( $locations[ $slug ] ) ) { |
|
| 190 | + if ( ! isset($locations[$slug])) { |
|
| 191 | 191 | continue; |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | - $json_menus[ $slug ]['ID'] = $locations[ $slug ]; |
|
| 195 | - $json_menus[ $slug ]['label'] = $label; |
|
| 196 | - $json_menus[ $slug ]['meta']['links']['collection'] = $json_url; |
|
| 197 | - $json_menus[ $slug ]['meta']['links']['self'] = $json_url . $slug; |
|
| 194 | + $json_menus[$slug]['ID'] = $locations[$slug]; |
|
| 195 | + $json_menus[$slug]['label'] = $label; |
|
| 196 | + $json_menus[$slug]['meta']['links']['collection'] = $json_url; |
|
| 197 | + $json_menus[$slug]['meta']['links']['self'] = $json_url.$slug; |
|
| 198 | 198 | |
| 199 | 199 | endforeach; |
| 200 | 200 | |
@@ -211,40 +211,40 @@ discard block |
||
| 211 | 211 | * @param string $location The theme location menu name |
| 212 | 212 | * @return array The menu for the corresponding location |
| 213 | 213 | */ |
| 214 | - public function get_menu_location( $location ) { |
|
| 214 | + public function get_menu_location($location) { |
|
| 215 | 215 | |
| 216 | 216 | $locations = get_nav_menu_locations(); |
| 217 | - if ( ! isset( $locations[ $location ] ) ) { |
|
| 217 | + if ( ! isset($locations[$location])) { |
|
| 218 | 218 | return array(); |
| 219 | 219 | } |
| 220 | 220 | |
| 221 | - $wp_menu = wp_get_nav_menu_object( $locations[ $location ] ); |
|
| 222 | - $menu_items = wp_get_nav_menu_items( $wp_menu->term_id ); |
|
| 221 | + $wp_menu = wp_get_nav_menu_object($locations[$location]); |
|
| 222 | + $menu_items = wp_get_nav_menu_items($wp_menu->term_id); |
|
| 223 | 223 | |
| 224 | 224 | $sorted_menu_items = $top_level_menu_items = $menu_items_with_children = array(); |
| 225 | 225 | |
| 226 | - foreach ( (array) $menu_items as $menu_item ) { |
|
| 227 | - $sorted_menu_items[ $menu_item->menu_order ] = $menu_item; |
|
| 226 | + foreach ((array) $menu_items as $menu_item) { |
|
| 227 | + $sorted_menu_items[$menu_item->menu_order] = $menu_item; |
|
| 228 | 228 | } |
| 229 | - foreach ( $sorted_menu_items as $menu_item ) { |
|
| 230 | - if ( (int) $menu_item->menu_item_parent !== 0 ) { |
|
| 231 | - $menu_items_with_children[ $menu_item->menu_item_parent ] = true; |
|
| 229 | + foreach ($sorted_menu_items as $menu_item) { |
|
| 230 | + if ((int) $menu_item->menu_item_parent !== 0) { |
|
| 231 | + $menu_items_with_children[$menu_item->menu_item_parent] = true; |
|
| 232 | 232 | } else { |
| 233 | 233 | $top_level_menu_items[] = $menu_item; |
| 234 | 234 | } |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | $menu = array(); |
| 238 | - while ( $sorted_menu_items ) : |
|
| 238 | + while ($sorted_menu_items) : |
|
| 239 | 239 | |
| 240 | 240 | $i = 0; |
| 241 | - foreach ( $top_level_menu_items as $top_item ) : |
|
| 241 | + foreach ($top_level_menu_items as $top_item) : |
|
| 242 | 242 | |
| 243 | - $menu[ $i ] = $this->format_menu_item( $top_item, false ); |
|
| 244 | - if ( isset( $menu_items_with_children[ $top_item->ID ] ) ) { |
|
| 245 | - $menu[ $i ]['children'] = $this->get_nav_menu_item_children( $top_item->ID, $menu_items, false ); |
|
| 243 | + $menu[$i] = $this->format_menu_item($top_item, false); |
|
| 244 | + if (isset($menu_items_with_children[$top_item->ID])) { |
|
| 245 | + $menu[$i]['children'] = $this->get_nav_menu_item_children($top_item->ID, $menu_items, false); |
|
| 246 | 246 | } else { |
| 247 | - $menu[ $i ]['children'] = array(); |
|
| 247 | + $menu[$i]['children'] = array(); |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | $i++; |
@@ -267,19 +267,19 @@ discard block |
||
| 267 | 267 | * @param bool $depth gives all children or direct children only |
| 268 | 268 | * @return array returns filtered array of nav_menu_items |
| 269 | 269 | */ |
| 270 | - public function get_nav_menu_item_children( $parent_id, $nav_menu_items, $depth = true ) { |
|
| 270 | + public function get_nav_menu_item_children($parent_id, $nav_menu_items, $depth = true) { |
|
| 271 | 271 | |
| 272 | 272 | $nav_menu_item_list = array(); |
| 273 | 273 | |
| 274 | - foreach ( (array) $nav_menu_items as $nav_menu_item ) : |
|
| 274 | + foreach ((array) $nav_menu_items as $nav_menu_item) : |
|
| 275 | 275 | |
| 276 | - if ( $nav_menu_item->menu_item_parent == $parent_id ) : |
|
| 276 | + if ($nav_menu_item->menu_item_parent == $parent_id) : |
|
| 277 | 277 | |
| 278 | - $nav_menu_item_list[] = $this->format_menu_item( $nav_menu_item, true, $nav_menu_items ); |
|
| 278 | + $nav_menu_item_list[] = $this->format_menu_item($nav_menu_item, true, $nav_menu_items); |
|
| 279 | 279 | |
| 280 | - if ( $depth ) { |
|
| 281 | - if ( $children = $this->get_nav_menu_item_children( $nav_menu_item->ID, $nav_menu_items ) ) { |
|
| 282 | - $nav_menu_item_list = array_merge( $nav_menu_item_list, $children ); |
|
| 280 | + if ($depth) { |
|
| 281 | + if ($children = $this->get_nav_menu_item_children($nav_menu_item->ID, $nav_menu_items)) { |
|
| 282 | + $nav_menu_item_list = array_merge($nav_menu_item_list, $children); |
|
| 283 | 283 | } |
| 284 | 284 | } |
| 285 | 285 | |
@@ -300,32 +300,32 @@ discard block |
||
| 300 | 300 | * @param array $menu the menu the item belongs to (used when $children is set to true) |
| 301 | 301 | * @return array a formatted menu item for JSON |
| 302 | 302 | */ |
| 303 | - public function format_menu_item( $menu_item, $children = false, $menu = array() ) { |
|
| 303 | + public function format_menu_item($menu_item, $children = false, $menu = array()) { |
|
| 304 | 304 | |
| 305 | 305 | $item = (array) $menu_item; |
| 306 | 306 | |
| 307 | 307 | $menu_item = array( |
| 308 | - 'ID' => abs( $item['ID'] ), |
|
| 308 | + 'ID' => abs($item['ID']), |
|
| 309 | 309 | 'order' => (int) $item['menu_order'], |
| 310 | - 'parent' => abs( $item['menu_item_parent'] ), |
|
| 310 | + 'parent' => abs($item['menu_item_parent']), |
|
| 311 | 311 | 'title' => $item['title'], |
| 312 | 312 | 'url' => $item['url'], |
| 313 | 313 | 'attr' => $item['attr_title'], |
| 314 | 314 | 'target' => $item['target'], |
| 315 | - 'classes' => implode( ' ', $item['classes'] ), |
|
| 315 | + 'classes' => implode(' ', $item['classes']), |
|
| 316 | 316 | 'xfn' => $item['xfn'], |
| 317 | 317 | 'description' => $item['description'], |
| 318 | - 'object_id' => abs( $item['object_id'] ), |
|
| 318 | + 'object_id' => abs($item['object_id']), |
|
| 319 | 319 | 'object' => $item['object'], |
| 320 | 320 | 'type' => $item['type'], |
| 321 | 321 | 'type_label' => $item['type_label'], |
| 322 | 322 | ); |
| 323 | 323 | |
| 324 | - if ( $children === true && ! empty( $menu ) ) { |
|
| 325 | - $menu_item['children'] = $this->get_nav_menu_item_children( $item['ID'], $menu ); |
|
| 324 | + if ($children === true && ! empty($menu)) { |
|
| 325 | + $menu_item['children'] = $this->get_nav_menu_item_children($item['ID'], $menu); |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | - return apply_filters( 'json_menus_format_menu_item', $menu_item ); |
|
| 328 | + return apply_filters('json_menus_format_menu_item', $menu_item); |
|
| 329 | 329 | } |
| 330 | 330 | |
| 331 | 331 | |
@@ -5,11 +5,11 @@ discard block |
||
| 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 | /** |
@@ -53,58 +53,58 @@ discard block |
||
| 53 | 53 | */ |
| 54 | 54 | public function register_routes() { |
| 55 | 55 | |
| 56 | - register_rest_route( self::get_plugin_namespace(), '/menus', array( |
|
| 56 | + register_rest_route(self::get_plugin_namespace(), '/menus', array( |
|
| 57 | 57 | array( |
| 58 | 58 | 'methods' => WP_REST_Server::READABLE, |
| 59 | - 'callback' => array( $this, 'get_menus' ), |
|
| 59 | + 'callback' => array($this, 'get_menus'), |
|
| 60 | 60 | ) |
| 61 | - ) ); |
|
| 61 | + )); |
|
| 62 | 62 | |
| 63 | - register_rest_route( self::get_plugin_namespace(), '/menus/(?P<id>\d+)', array( |
|
| 63 | + register_rest_route(self::get_plugin_namespace(), '/menus/(?P<id>\d+)', array( |
|
| 64 | 64 | array( |
| 65 | 65 | 'methods' => WP_REST_Server::READABLE, |
| 66 | - 'callback' => array( $this, 'get_menu' ), |
|
| 66 | + 'callback' => array($this, 'get_menu'), |
|
| 67 | 67 | 'args' => array( |
| 68 | 68 | 'context' => array( |
| 69 | 69 | 'default' => 'view', |
| 70 | 70 | ), |
| 71 | 71 | ), |
| 72 | 72 | ) |
| 73 | - ) ); |
|
| 73 | + )); |
|
| 74 | 74 | |
| 75 | 75 | |
| 76 | - register_rest_route( self::get_plugin_namespace(), '/menu-html/(?P<menu_id>[a-zA-Z0-9_-]+)', array( |
|
| 76 | + register_rest_route(self::get_plugin_namespace(), '/menu-html/(?P<menu_id>[a-zA-Z0-9_-]+)', array( |
|
| 77 | 77 | array( |
| 78 | 78 | 'methods' => WP_REST_Server::READABLE, |
| 79 | - 'callback' => array( $this, 'get_menu_html' ), |
|
| 79 | + 'callback' => array($this, 'get_menu_html'), |
|
| 80 | 80 | 'args' => array( |
| 81 | 81 | 'context' => array( |
| 82 | 82 | 'default' => 'view', |
| 83 | 83 | ), |
| 84 | 84 | ), |
| 85 | 85 | ) |
| 86 | - ) ); |
|
| 86 | + )); |
|
| 87 | 87 | |
| 88 | - register_rest_route( self::get_plugin_namespace(), '/menu-locations', array( |
|
| 88 | + register_rest_route(self::get_plugin_namespace(), '/menu-locations', array( |
|
| 89 | 89 | array( |
| 90 | 90 | 'methods' => WP_REST_Server::READABLE, |
| 91 | - 'callback' => array( $this, 'get_menu_locations' ), |
|
| 91 | + 'callback' => array($this, 'get_menu_locations'), |
|
| 92 | 92 | ) |
| 93 | - ) ); |
|
| 93 | + )); |
|
| 94 | 94 | |
| 95 | - register_rest_route( self::get_plugin_namespace(), '/menu-locations/(?P<location>[a-zA-Z0-9_-]+)', array( |
|
| 95 | + register_rest_route(self::get_plugin_namespace(), '/menu-locations/(?P<location>[a-zA-Z0-9_-]+)', array( |
|
| 96 | 96 | array( |
| 97 | 97 | 'methods' => WP_REST_Server::READABLE, |
| 98 | - 'callback' => array( $this, 'get_menu_location' ), |
|
| 98 | + 'callback' => array($this, 'get_menu_location'), |
|
| 99 | 99 | ) |
| 100 | - ) ); |
|
| 100 | + )); |
|
| 101 | 101 | |
| 102 | - register_rest_route( self::get_plugin_namespace(), '/menu-html-location/(?P<location>[a-zA-Z0-9_-]+)', array( |
|
| 102 | + register_rest_route(self::get_plugin_namespace(), '/menu-html-location/(?P<location>[a-zA-Z0-9_-]+)', array( |
|
| 103 | 103 | array( |
| 104 | 104 | 'methods' => WP_REST_Server::READABLE, |
| 105 | - 'callback' => array( $this, 'get_menu_html_location' ), |
|
| 105 | + 'callback' => array($this, 'get_menu_html_location'), |
|
| 106 | 106 | ) |
| 107 | - ) ); |
|
| 107 | + )); |
|
| 108 | 108 | |
| 109 | 109 | } |
| 110 | 110 | |
@@ -117,31 +117,31 @@ discard block |
||
| 117 | 117 | */ |
| 118 | 118 | public static function get_menus() { |
| 119 | 119 | |
| 120 | - $rest_url = trailingslashit( get_rest_url() . self::get_plugin_namespace() . '/menus/' ); |
|
| 121 | - $rest_url_base = get_rest_url() . self::get_plugin_namespace(); |
|
| 120 | + $rest_url = trailingslashit(get_rest_url().self::get_plugin_namespace().'/menus/'); |
|
| 121 | + $rest_url_base = get_rest_url().self::get_plugin_namespace(); |
|
| 122 | 122 | $wp_menus = wp_get_nav_menus(); |
| 123 | 123 | |
| 124 | 124 | $i = 0; |
| 125 | 125 | $rest_menus = array(); |
| 126 | - foreach ( $wp_menus as $wp_menu ) : |
|
| 126 | + foreach ($wp_menus as $wp_menu) : |
|
| 127 | 127 | |
| 128 | 128 | $menu = (array) $wp_menu; |
| 129 | 129 | |
| 130 | - $rest_menus[ $i ] = $menu; |
|
| 131 | - $rest_menus[ $i ]['ID'] = $menu['term_id']; |
|
| 132 | - $rest_menus[ $i ]['name'] = $menu['name']; |
|
| 133 | - $rest_menus[ $i ]['slug'] = $menu['slug']; |
|
| 134 | - $rest_menus[ $i ]['description'] = $menu['description']; |
|
| 135 | - $rest_menus[ $i ]['count'] = $menu['count']; |
|
| 130 | + $rest_menus[$i] = $menu; |
|
| 131 | + $rest_menus[$i]['ID'] = $menu['term_id']; |
|
| 132 | + $rest_menus[$i]['name'] = $menu['name']; |
|
| 133 | + $rest_menus[$i]['slug'] = $menu['slug']; |
|
| 134 | + $rest_menus[$i]['description'] = $menu['description']; |
|
| 135 | + $rest_menus[$i]['count'] = $menu['count']; |
|
| 136 | 136 | |
| 137 | - $rest_menus[ $i ]['meta']['links']['collection'] = $rest_url; |
|
| 138 | - $rest_menus[ $i ]['meta']['links']['self'] = $rest_url . $menu['term_id']; |
|
| 139 | - $rest_menus[ $i ]['meta']['links']['html'] = $rest_url_base . '/menu-html/' . $menu['term_id']; |
|
| 137 | + $rest_menus[$i]['meta']['links']['collection'] = $rest_url; |
|
| 138 | + $rest_menus[$i]['meta']['links']['self'] = $rest_url.$menu['term_id']; |
|
| 139 | + $rest_menus[$i]['meta']['links']['html'] = $rest_url_base.'/menu-html/'.$menu['term_id']; |
|
| 140 | 140 | |
| 141 | - $i ++; |
|
| 141 | + $i++; |
|
| 142 | 142 | endforeach; |
| 143 | 143 | |
| 144 | - return apply_filters( 'rest_menus_format_menus', $rest_menus ); |
|
| 144 | + return apply_filters('rest_menus_format_menus', $rest_menus); |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | |
@@ -152,38 +152,38 @@ discard block |
||
| 152 | 152 | * @param $request |
| 153 | 153 | * @return array Menu data |
| 154 | 154 | */ |
| 155 | - public function get_menu( $request ) { |
|
| 155 | + public function get_menu($request) { |
|
| 156 | 156 | |
| 157 | 157 | $id = (int) $request['id']; |
| 158 | - $rest_url = get_rest_url() . self::get_plugin_namespace() . '/menus/'; |
|
| 159 | - $wp_menu_object = $id ? wp_get_nav_menu_object( $id ) : array(); |
|
| 160 | - $wp_menu_items = $id ? wp_get_nav_menu_items( $id ) : array(); |
|
| 158 | + $rest_url = get_rest_url().self::get_plugin_namespace().'/menus/'; |
|
| 159 | + $wp_menu_object = $id ? wp_get_nav_menu_object($id) : array(); |
|
| 160 | + $wp_menu_items = $id ? wp_get_nav_menu_items($id) : array(); |
|
| 161 | 161 | |
| 162 | 162 | $rest_menu = array(); |
| 163 | 163 | |
| 164 | - if ( $wp_menu_object ) : |
|
| 164 | + if ($wp_menu_object) : |
|
| 165 | 165 | |
| 166 | 166 | $menu = (array) $wp_menu_object; |
| 167 | - $rest_menu['ID'] = abs( $menu['term_id'] ); |
|
| 167 | + $rest_menu['ID'] = abs($menu['term_id']); |
|
| 168 | 168 | $rest_menu['name'] = $menu['name']; |
| 169 | 169 | $rest_menu['slug'] = $menu['slug']; |
| 170 | 170 | $rest_menu['description'] = $menu['description']; |
| 171 | - $rest_menu['count'] = abs( $menu['count'] ); |
|
| 171 | + $rest_menu['count'] = abs($menu['count']); |
|
| 172 | 172 | |
| 173 | 173 | $rest_menu_items = array(); |
| 174 | - foreach ( $wp_menu_items as $item_object ) { |
|
| 175 | - $rest_menu_items[] = $this->format_menu_item( $item_object ); |
|
| 174 | + foreach ($wp_menu_items as $item_object) { |
|
| 175 | + $rest_menu_items[] = $this->format_menu_item($item_object); |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | $rest_menu_items = $this->nested_menu_items($rest_menu_items, 0); |
| 179 | 179 | |
| 180 | 180 | $rest_menu['items'] = $rest_menu_items; |
| 181 | 181 | $rest_menu['meta']['links']['collection'] = $rest_url; |
| 182 | - $rest_menu['meta']['links']['self'] = $rest_url . $id; |
|
| 182 | + $rest_menu['meta']['links']['self'] = $rest_url.$id; |
|
| 183 | 183 | |
| 184 | 184 | endif; |
| 185 | 185 | |
| 186 | - return apply_filters( 'rest_menus_format_menu', $rest_menu ); |
|
| 186 | + return apply_filters('rest_menus_format_menu', $rest_menu); |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | /** |
@@ -193,34 +193,34 @@ discard block |
||
| 193 | 193 | * @param $request |
| 194 | 194 | * @return array Menu data |
| 195 | 195 | */ |
| 196 | - public function get_menu_html( $request ) { |
|
| 196 | + public function get_menu_html($request) { |
|
| 197 | 197 | |
| 198 | 198 | $menu_id = $request['menu_id']; |
| 199 | - $rest_url_base = get_rest_url() . self::get_plugin_namespace(); |
|
| 200 | - $wp_menu_object = $menu_id ? wp_get_nav_menu_object( $menu_id) : array(); |
|
| 201 | - $wp_menu_items = $menu_id ? wp_get_nav_menu_items( $menu_id ) : array(); |
|
| 199 | + $rest_url_base = get_rest_url().self::get_plugin_namespace(); |
|
| 200 | + $wp_menu_object = $menu_id ? wp_get_nav_menu_object($menu_id) : array(); |
|
| 201 | + $wp_menu_items = $menu_id ? wp_get_nav_menu_items($menu_id) : array(); |
|
| 202 | 202 | |
| 203 | 203 | $rest_menu = array(); |
| 204 | 204 | |
| 205 | - if ( $wp_menu_object ) : |
|
| 205 | + if ($wp_menu_object) : |
|
| 206 | 206 | |
| 207 | 207 | $menu = (array) $wp_menu_object; |
| 208 | - $rest_menu['ID'] = abs( $menu['term_id'] ); |
|
| 208 | + $rest_menu['ID'] = abs($menu['term_id']); |
|
| 209 | 209 | $rest_menu['name'] = $menu['name']; |
| 210 | 210 | $rest_menu['slug'] = $menu['slug']; |
| 211 | 211 | $rest_menu['description'] = $menu['description']; |
| 212 | - $rest_menu['count'] = abs( $menu['count'] ); |
|
| 212 | + $rest_menu['count'] = abs($menu['count']); |
|
| 213 | 213 | |
| 214 | 214 | ob_start(); |
| 215 | - wp_nav_menu( array( 'menu' => $menu_id ) ); |
|
| 216 | - $rest_menu['html']=ob_get_clean(); |
|
| 215 | + wp_nav_menu(array('menu' => $menu_id)); |
|
| 216 | + $rest_menu['html'] = ob_get_clean(); |
|
| 217 | 217 | |
| 218 | - $rest_menu['meta']['links']['collection'] = $rest_url_base . '/menus/'; |
|
| 219 | - $rest_menu['meta']['links']['self'] = $rest_url_base . '/menu-html/' . $menu_id; |
|
| 218 | + $rest_menu['meta']['links']['collection'] = $rest_url_base.'/menus/'; |
|
| 219 | + $rest_menu['meta']['links']['self'] = $rest_url_base.'/menu-html/'.$menu_id; |
|
| 220 | 220 | |
| 221 | 221 | endif; |
| 222 | 222 | |
| 223 | - return apply_filters( 'rest_menus_format_menu', $rest_menu ); |
|
| 223 | + return apply_filters('rest_menus_format_menu', $rest_menu); |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | |
@@ -236,24 +236,24 @@ discard block |
||
| 236 | 236 | * @param $parent |
| 237 | 237 | * @return array |
| 238 | 238 | */ |
| 239 | - private function nested_menu_items( &$menu_items, $parent = null ) { |
|
| 239 | + private function nested_menu_items(&$menu_items, $parent = null) { |
|
| 240 | 240 | |
| 241 | 241 | $parents = array(); |
| 242 | 242 | $children = array(); |
| 243 | 243 | |
| 244 | 244 | // Separate menu_items into parents & children. |
| 245 | - array_map( function( $i ) use ( $parent, &$children, &$parents ){ |
|
| 246 | - if ( $i['id'] != $parent && $i['parent'] == $parent ) { |
|
| 245 | + array_map(function($i) use ($parent, &$children, &$parents){ |
|
| 246 | + if ($i['id'] != $parent && $i['parent'] == $parent) { |
|
| 247 | 247 | $parents[] = $i; |
| 248 | 248 | } else { |
| 249 | 249 | $children[] = $i; |
| 250 | 250 | } |
| 251 | - }, $menu_items ); |
|
| 251 | + }, $menu_items); |
|
| 252 | 252 | |
| 253 | - foreach ( $parents as &$parent ) { |
|
| 253 | + foreach ($parents as &$parent) { |
|
| 254 | 254 | |
| 255 | - if ( $this->has_children( $children, $parent['id'] ) ) { |
|
| 256 | - $parent['children'] = $this->nested_menu_items( $children, $parent['id'] ); |
|
| 255 | + if ($this->has_children($children, $parent['id'])) { |
|
| 256 | + $parent['children'] = $this->nested_menu_items($children, $parent['id']); |
|
| 257 | 257 | } |
| 258 | 258 | } |
| 259 | 259 | |
@@ -269,8 +269,8 @@ discard block |
||
| 269 | 269 | * @param int $id |
| 270 | 270 | * @return array |
| 271 | 271 | */ |
| 272 | - private function has_children( $items, $id ) { |
|
| 273 | - return array_filter( $items, function( $i ) use ( $id ) { |
|
| 272 | + private function has_children($items, $id) { |
|
| 273 | + return array_filter($items, function($i) use ($id) { |
|
| 274 | 274 | return $i['parent'] == $id; |
| 275 | 275 | } ); |
| 276 | 276 | } |
@@ -283,28 +283,28 @@ discard block |
||
| 283 | 283 | * @param $request |
| 284 | 284 | * @return array All registered menus locations |
| 285 | 285 | */ |
| 286 | - public static function get_menu_locations( $request ) { |
|
| 286 | + public static function get_menu_locations($request) { |
|
| 287 | 287 | |
| 288 | 288 | $locations = get_nav_menu_locations(); |
| 289 | 289 | $registered_menus = get_registered_nav_menus(); |
| 290 | - $rest_url = get_rest_url() . self::get_plugin_namespace() . '/menu-locations/'; |
|
| 291 | - $rest_url_base = get_rest_url() . self::get_plugin_namespace(); |
|
| 290 | + $rest_url = get_rest_url().self::get_plugin_namespace().'/menu-locations/'; |
|
| 291 | + $rest_url_base = get_rest_url().self::get_plugin_namespace(); |
|
| 292 | 292 | $rest_menus = array(); |
| 293 | 293 | |
| 294 | - if ( $locations && $registered_menus ) : |
|
| 294 | + if ($locations && $registered_menus) : |
|
| 295 | 295 | |
| 296 | - foreach ( $registered_menus as $slug => $label ) : |
|
| 296 | + foreach ($registered_menus as $slug => $label) : |
|
| 297 | 297 | |
| 298 | 298 | // Sanity check |
| 299 | - if ( ! isset( $locations[ $slug ] ) ) { |
|
| 299 | + if ( ! isset($locations[$slug])) { |
|
| 300 | 300 | continue; |
| 301 | 301 | } |
| 302 | 302 | |
| 303 | - $rest_menus[ $slug ]['ID'] = $locations[ $slug ]; |
|
| 304 | - $rest_menus[ $slug ]['label'] = $label; |
|
| 305 | - $rest_menus[ $slug ]['meta']['links']['collection'] = $rest_url; |
|
| 306 | - $rest_menus[ $slug ]['meta']['links']['self'] = $rest_url . $slug; |
|
| 307 | - $rest_menus[ $slug ]['meta']['links']['html'] = $rest_url_base . '/menu-html-location/' . $slug; |
|
| 303 | + $rest_menus[$slug]['ID'] = $locations[$slug]; |
|
| 304 | + $rest_menus[$slug]['label'] = $label; |
|
| 305 | + $rest_menus[$slug]['meta']['links']['collection'] = $rest_url; |
|
| 306 | + $rest_menus[$slug]['meta']['links']['self'] = $rest_url.$slug; |
|
| 307 | + $rest_menus[$slug]['meta']['links']['html'] = $rest_url_base.'/menu-html-location/'.$slug; |
|
| 308 | 308 | |
| 309 | 309 | endforeach; |
| 310 | 310 | |
@@ -321,64 +321,64 @@ discard block |
||
| 321 | 321 | * @param $request |
| 322 | 322 | * @return array The menu for the corresponding location |
| 323 | 323 | */ |
| 324 | - public function get_menu_location( $request ) { |
|
| 324 | + public function get_menu_location($request) { |
|
| 325 | 325 | |
| 326 | 326 | $params = $request->get_params(); |
| 327 | 327 | $location = $params['location']; |
| 328 | 328 | $locations = get_nav_menu_locations(); |
| 329 | 329 | |
| 330 | - if ( ! isset( $locations[ $location ] ) ) { |
|
| 330 | + if ( ! isset($locations[$location])) { |
|
| 331 | 331 | return array(); |
| 332 | 332 | } |
| 333 | 333 | |
| 334 | - $wp_menu = wp_get_nav_menu_object( $locations[ $location ] ); |
|
| 335 | - $menu_items = wp_get_nav_menu_items( $wp_menu->term_id ); |
|
| 334 | + $wp_menu = wp_get_nav_menu_object($locations[$location]); |
|
| 335 | + $menu_items = wp_get_nav_menu_items($wp_menu->term_id); |
|
| 336 | 336 | |
| 337 | 337 | /** |
| 338 | 338 | * wp_get_nav_menu_items() outputs a list that's already sequenced correctly. |
| 339 | 339 | * So the easiest thing to do is to reverse the list and then build our tree |
| 340 | 340 | * from the ground up |
| 341 | 341 | */ |
| 342 | - $rev_items = array_reverse ( $menu_items ); |
|
| 342 | + $rev_items = array_reverse($menu_items); |
|
| 343 | 343 | $rev_menu = array(); |
| 344 | 344 | $cache = array(); |
| 345 | - foreach ( $rev_items as $item ) : |
|
| 345 | + foreach ($rev_items as $item) : |
|
| 346 | 346 | $formatted = array( |
| 347 | - 'ID' => abs( $item->ID ), |
|
| 347 | + 'ID' => abs($item->ID), |
|
| 348 | 348 | 'order' => (int) $item->menu_order, |
| 349 | - 'parent' => abs( $item->menu_item_parent ), |
|
| 349 | + 'parent' => abs($item->menu_item_parent), |
|
| 350 | 350 | 'title' => $item->title, |
| 351 | 351 | 'url' => $item->url, |
| 352 | 352 | 'attr' => $item->attr_title, |
| 353 | 353 | 'target' => $item->target, |
| 354 | - 'classes' => implode( ' ', $item->classes ), |
|
| 354 | + 'classes' => implode(' ', $item->classes), |
|
| 355 | 355 | 'xfn' => $item->xfn, |
| 356 | 356 | 'description' => $item->description, |
| 357 | - 'object_id' => abs( $item->object_id ), |
|
| 357 | + 'object_id' => abs($item->object_id), |
|
| 358 | 358 | 'object' => $item->object, |
| 359 | 359 | 'type' => $item->type, |
| 360 | 360 | 'type_label' => $item->type_label, |
| 361 | 361 | 'children' => array(), |
| 362 | 362 | ); |
| 363 | 363 | // Pickup my children |
| 364 | - if ( array_key_exists ( $item->ID , $cache ) ) { |
|
| 365 | - $formatted['children'] = array_reverse ( $cache[ $item->ID ] ); |
|
| 364 | + if (array_key_exists($item->ID, $cache)) { |
|
| 365 | + $formatted['children'] = array_reverse($cache[$item->ID]); |
|
| 366 | 366 | } |
| 367 | 367 | |
| 368 | - $formatted = apply_filters( 'rest_menus_format_menu_item', $formatted ); |
|
| 368 | + $formatted = apply_filters('rest_menus_format_menu_item', $formatted); |
|
| 369 | 369 | |
| 370 | - if ( $item->menu_item_parent != 0 ) { |
|
| 370 | + if ($item->menu_item_parent != 0) { |
|
| 371 | 371 | // Wait for parent to pick me up |
| 372 | - if ( array_key_exists ( $item->menu_item_parent , $cache ) ) { |
|
| 373 | - array_push( $cache[ $item->menu_item_parent ], $formatted ); |
|
| 372 | + if (array_key_exists($item->menu_item_parent, $cache)) { |
|
| 373 | + array_push($cache[$item->menu_item_parent], $formatted); |
|
| 374 | 374 | } else { |
| 375 | - $cache[ $item->menu_item_parent ] = array( $formatted, ); |
|
| 375 | + $cache[$item->menu_item_parent] = array($formatted,); |
|
| 376 | 376 | } |
| 377 | 377 | } else { |
| 378 | - array_push( $rev_menu, $formatted ); |
|
| 378 | + array_push($rev_menu, $formatted); |
|
| 379 | 379 | } |
| 380 | 380 | endforeach; |
| 381 | - return array_reverse ( $rev_menu ); |
|
| 381 | + return array_reverse($rev_menu); |
|
| 382 | 382 | } |
| 383 | 383 | |
| 384 | 384 | |
@@ -389,37 +389,37 @@ discard block |
||
| 389 | 389 | * @param $request |
| 390 | 390 | * @return array The menu for the corresponding location |
| 391 | 391 | */ |
| 392 | - public function get_menu_html_location( $request ) { |
|
| 392 | + public function get_menu_html_location($request) { |
|
| 393 | 393 | |
| 394 | 394 | $params = $request->get_params(); |
| 395 | 395 | $location = $params['location']; |
| 396 | 396 | $locations = get_nav_menu_locations(); |
| 397 | 397 | |
| 398 | 398 | //Check if location exists and return empty array if it doesn't |
| 399 | - if ( ! isset( $locations[ $location ] ) ) { |
|
| 399 | + if ( ! isset($locations[$location])) { |
|
| 400 | 400 | return array(); |
| 401 | 401 | } |
| 402 | 402 | |
| 403 | - $rest_url_base = get_rest_url() . self::get_plugin_namespace(); |
|
| 404 | - $wp_menu_object = get_term( $locations[$location], 'nav_menu' ); |
|
| 403 | + $rest_url_base = get_rest_url().self::get_plugin_namespace(); |
|
| 404 | + $wp_menu_object = get_term($locations[$location], 'nav_menu'); |
|
| 405 | 405 | $rest_menu = array(); |
| 406 | 406 | |
| 407 | - if ( $wp_menu_object ) : |
|
| 407 | + if ($wp_menu_object) : |
|
| 408 | 408 | |
| 409 | 409 | $menu = (array) $wp_menu_object; |
| 410 | - $rest_menu['ID'] = abs( $menu['term_id'] ); |
|
| 410 | + $rest_menu['ID'] = abs($menu['term_id']); |
|
| 411 | 411 | $rest_menu['name'] = $menu['name']; |
| 412 | 412 | $rest_menu['slug'] = $menu['slug']; |
| 413 | 413 | $rest_menu['location_slug'] = $location; |
| 414 | 414 | $rest_menu['description'] = $menu['description']; |
| 415 | - $rest_menu['count'] = abs( $menu['count'] ); |
|
| 415 | + $rest_menu['count'] = abs($menu['count']); |
|
| 416 | 416 | |
| 417 | 417 | ob_start(); |
| 418 | - wp_nav_menu( array( 'theme_location' => $location ) ); |
|
| 419 | - $rest_menu['html']=ob_get_clean(); |
|
| 418 | + wp_nav_menu(array('theme_location' => $location)); |
|
| 419 | + $rest_menu['html'] = ob_get_clean(); |
|
| 420 | 420 | |
| 421 | - $rest_menu['meta']['links']['collection'] = $rest_url_base . '/menu-locations/'; |
|
| 422 | - $rest_menu['meta']['links']['self'] = $rest_url_base . '/menu-html-location/' . $location; |
|
| 421 | + $rest_menu['meta']['links']['collection'] = $rest_url_base.'/menu-locations/'; |
|
| 422 | + $rest_menu['meta']['links']['self'] = $rest_url_base.'/menu-html-location/'.$location; |
|
| 423 | 423 | |
| 424 | 424 | endif; |
| 425 | 425 | |
@@ -436,19 +436,19 @@ discard block |
||
| 436 | 436 | * @param bool $depth Gives all children or direct children only |
| 437 | 437 | * @return array returns filtered array of nav_menu_items |
| 438 | 438 | */ |
| 439 | - public function get_nav_menu_item_children( $parent_id, $nav_menu_items, $depth = true ) { |
|
| 439 | + public function get_nav_menu_item_children($parent_id, $nav_menu_items, $depth = true) { |
|
| 440 | 440 | |
| 441 | 441 | $nav_menu_item_list = array(); |
| 442 | 442 | |
| 443 | - foreach ( (array) $nav_menu_items as $nav_menu_item ) : |
|
| 443 | + foreach ((array) $nav_menu_items as $nav_menu_item) : |
|
| 444 | 444 | |
| 445 | - if ( $nav_menu_item->menu_item_parent == $parent_id ) : |
|
| 445 | + if ($nav_menu_item->menu_item_parent == $parent_id) : |
|
| 446 | 446 | |
| 447 | - $nav_menu_item_list[] = $this->format_menu_item( $nav_menu_item, true, $nav_menu_items ); |
|
| 447 | + $nav_menu_item_list[] = $this->format_menu_item($nav_menu_item, true, $nav_menu_items); |
|
| 448 | 448 | |
| 449 | - if ( $depth ) { |
|
| 450 | - if ( $children = $this->get_nav_menu_item_children( $nav_menu_item->ID, $nav_menu_items ) ) { |
|
| 451 | - $nav_menu_item_list = array_merge( $nav_menu_item_list, $children ); |
|
| 449 | + if ($depth) { |
|
| 450 | + if ($children = $this->get_nav_menu_item_children($nav_menu_item->ID, $nav_menu_items)) { |
|
| 451 | + $nav_menu_item_list = array_merge($nav_menu_item_list, $children); |
|
| 452 | 452 | } |
| 453 | 453 | } |
| 454 | 454 | |
@@ -469,32 +469,32 @@ discard block |
||
| 469 | 469 | * @param array $menu The menu the item belongs to (used when $children is set to true) |
| 470 | 470 | * @return array a formatted menu item for REST |
| 471 | 471 | */ |
| 472 | - public function format_menu_item( $menu_item, $children = false, $menu = array() ) { |
|
| 472 | + public function format_menu_item($menu_item, $children = false, $menu = array()) { |
|
| 473 | 473 | |
| 474 | 474 | $item = (array) $menu_item; |
| 475 | 475 | |
| 476 | 476 | $menu_item = array( |
| 477 | - 'id' => abs( $item['ID'] ), |
|
| 477 | + 'id' => abs($item['ID']), |
|
| 478 | 478 | 'order' => (int) $item['menu_order'], |
| 479 | - 'parent' => abs( $item['menu_item_parent'] ), |
|
| 479 | + 'parent' => abs($item['menu_item_parent']), |
|
| 480 | 480 | 'title' => $item['title'], |
| 481 | 481 | 'url' => $item['url'], |
| 482 | 482 | 'attr' => $item['attr_title'], |
| 483 | 483 | 'target' => $item['target'], |
| 484 | - 'classes' => implode( ' ', $item['classes'] ), |
|
| 484 | + 'classes' => implode(' ', $item['classes']), |
|
| 485 | 485 | 'xfn' => $item['xfn'], |
| 486 | 486 | 'description' => $item['description'], |
| 487 | - 'object_id' => abs( $item['object_id'] ), |
|
| 487 | + 'object_id' => abs($item['object_id']), |
|
| 488 | 488 | 'object' => $item['object'], |
| 489 | 489 | 'type' => $item['type'], |
| 490 | 490 | 'type_label' => $item['type_label'], |
| 491 | 491 | ); |
| 492 | 492 | |
| 493 | - if ( $children === true && ! empty( $menu ) ) { |
|
| 494 | - $menu_item['children'] = $this->get_nav_menu_item_children( $item['ID'], $menu ); |
|
| 493 | + if ($children === true && ! empty($menu)) { |
|
| 494 | + $menu_item['children'] = $this->get_nav_menu_item_children($item['ID'], $menu); |
|
| 495 | 495 | } |
| 496 | 496 | |
| 497 | - return apply_filters( 'rest_menus_format_menu_item', $menu_item ); |
|
| 497 | + return apply_filters('rest_menus_format_menu_item', $menu_item); |
|
| 498 | 498 | } |
| 499 | 499 | |
| 500 | 500 | |