Completed
Push — master ( e50f0d...82e66b )
by Andrew
36s
created
app/core/classes/Menu.php 2 patches
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -38,22 +38,22 @@  discard block
 block discarded – undo
38 38
 	 *
39 39
 	 * @param string $arg It can be menu id, slug or full name.
40 40
 	 */
41
-	public function __construct( $arg = null ) {
41
+	public function __construct($arg = null) {
42 42
 		$locations = get_nav_menu_locations();
43 43
 
44
-		if ( is_numeric( $arg ) && 0 !== absint( $arg ) ) {
45
-			$menu_id = $this->check_menu_id( $arg );
46
-		} elseif ( is_string( $arg ) ) {
47
-			$menu_id = $this->get_menu_id_by_name( $arg );
48
-		} elseif ( is_array( $locations ) && count( $locations ) ) {
49
-			$menu_id = $this->get_locations_menu_id( $locations, $arg );
44
+		if (is_numeric($arg) && 0 !== absint($arg)) {
45
+			$menu_id = $this->check_menu_id($arg);
46
+		} elseif (is_string($arg)) {
47
+			$menu_id = $this->get_menu_id_by_name($arg);
48
+		} elseif (is_array($locations) && count($locations)) {
49
+			$menu_id = $this->get_locations_menu_id($locations, $arg);
50 50
 		}
51 51
 
52
-		if ( ! isset( $menu_id ) ) {
52
+		if (!isset($menu_id)) {
53 53
 			$menu_id = $this->get_first_menu_id();
54 54
 		}
55 55
 
56
-		if ( $menu_id ) {
56
+		if ($menu_id) {
57 57
 			$this->ID = $menu_id;
58 58
 			$this->title = $this->get_menu_name_by_id();
59 59
 			$this->init();
@@ -65,21 +65,21 @@  discard block
 block discarded – undo
65 65
 	 */
66 66
 	protected function init() {
67 67
 		$_return = array();
68
-		$items = wp_get_nav_menu_items( $this->ID );
68
+		$items = wp_get_nav_menu_items($this->ID);
69 69
 
70
-		foreach ( $items as $item ) {
71
-			$_return[ $item->ID ] = new Menu_Item( $item );
70
+		foreach ($items as $item) {
71
+			$_return[$item->ID] = new Menu_Item($item);
72 72
 		}
73 73
 
74 74
 		// Apply nesting.
75
-		foreach ( $_return as $item_id => $item ) {
75
+		foreach ($_return as $item_id => $item) {
76 76
 			if (
77
-				isset( $item->menu_item_parent ) &&
77
+				isset($item->menu_item_parent) &&
78 78
 				$item->menu_item_parent &&
79
-				isset( $_return[ $item->menu_item_parent ] )
79
+				isset($_return[$item->menu_item_parent])
80 80
 			) {
81
-				$_return[ $item->menu_item_parent ]->add_child( $item );
82
-				unset( $_return[ $item_id ] );
81
+				$_return[$item->menu_item_parent]->add_child($item);
82
+				unset($_return[$item_id]);
83 83
 			}
84 84
 		}
85 85
 
@@ -92,10 +92,10 @@  discard block
 block discarded – undo
92 92
 	 * @return int|bool
93 93
 	 */
94 94
 	protected function get_first_menu_id() {
95
-		$menus = get_terms( 'nav_menu', array( 'hide_empty' => true ) );
95
+		$menus = get_terms('nav_menu', array('hide_empty' => true));
96 96
 
97
-		if ( is_array( $menus ) && count( $menus ) ) {
98
-			if ( isset( $menus[0]->term_id ) ) {
97
+		if (is_array($menus) && count($menus)) {
98
+			if (isset($menus[0]->term_id)) {
99 99
 				return $menus[0]->term_id;
100 100
 			}
101 101
 		}
@@ -110,13 +110,13 @@  discard block
 block discarded – undo
110 110
 	 * @param  int|string $arg navigation id.
111 111
 	 * @return int
112 112
 	 */
113
-	protected function get_locations_menu_id( $locations, $arg ) {
114
-		if ( is_numeric( $arg ) ) {
115
-			$arg = array_search( $arg, $locations );
113
+	protected function get_locations_menu_id($locations, $arg) {
114
+		if (is_numeric($arg)) {
115
+			$arg = array_search($arg, $locations);
116 116
 		}
117 117
 
118
-		if ( isset( $locations[ $arg ] ) ) {
119
-			$menu_id = $locations[ $arg ];
118
+		if (isset($locations[$arg])) {
119
+			$menu_id = $locations[$arg];
120 120
 
121 121
 			return $menu_id;
122 122
 		}
@@ -129,12 +129,12 @@  discard block
 block discarded – undo
129 129
 	 *
130 130
 	 * @return int|boolean
131 131
 	 */
132
-	protected function check_menu_id( $menu_id ) {
133
-		$menus = get_terms( 'nav_menu', array( 'hide_empty' => true ) );
132
+	protected function check_menu_id($menu_id) {
133
+		$menus = get_terms('nav_menu', array('hide_empty' => true));
134 134
 
135
-		if ( is_array( $menus ) && count( $menus ) ) {
136
-			foreach ( $menus as $menu ) {
137
-				if ( absint( $menu->term_id ) === absint( $menu_id ) ) {
135
+		if (is_array($menus) && count($menus)) {
136
+			foreach ($menus as $menu) {
137
+				if (absint($menu->term_id) === absint($menu_id)) {
138 138
 					return $menu_id;
139 139
 				}
140 140
 			}
@@ -150,13 +150,13 @@  discard block
 block discarded – undo
150 150
 	 *
151 151
 	 * @return int|bool
152 152
 	 */
153
-	protected function get_menu_id_by_name( $slug = null ) {
154
-		if ( $slug && is_string( $slug ) ) {
155
-			if ( $menu_id = get_term_by( 'slug', $slug, 'nav_menu' ) ) {
153
+	protected function get_menu_id_by_name($slug = null) {
154
+		if ($slug && is_string($slug)) {
155
+			if ($menu_id = get_term_by('slug', $slug, 'nav_menu')) {
156 156
 				return $menu_id;
157 157
 			}
158 158
 
159
-			if ( $menu_id = get_term_by( 'name', $slug, 'nav_menu' ) ) {
159
+			if ($menu_id = get_term_by('name', $slug, 'nav_menu')) {
160 160
 				return $menu_id;
161 161
 			}
162 162
 		}
@@ -170,9 +170,9 @@  discard block
 block discarded – undo
170 170
 	 * @return int|bool
171 171
 	 */
172 172
 	protected function get_menu_name_by_id() {
173
-		$menu_obj = wp_get_nav_menu_object( $this->ID );
173
+		$menu_obj = wp_get_nav_menu_object($this->ID);
174 174
 
175
-		if ( $menu_obj ) {
175
+		if ($menu_obj) {
176 176
 			return $menu_obj->name;
177 177
 		}
178 178
 
Please login to merge, or discard this patch.
Braces   +4 added lines, -2 removed lines patch added patch discarded remove patch
@@ -43,9 +43,11 @@
 block discarded – undo
43 43
 
44 44
 		if ( is_numeric( $arg ) && 0 !== absint( $arg ) ) {
45 45
 			$menu_id = $this->check_menu_id( $arg );
46
-		} elseif ( is_string( $arg ) ) {
46
+		}
47
+		elseif ( is_string( $arg ) ) {
47 48
 			$menu_id = $this->get_menu_id_by_name( $arg );
48
-		} elseif ( is_array( $locations ) && count( $locations ) ) {
49
+		}
50
+		elseif ( is_array( $locations ) && count( $locations ) ) {
49 51
 			$menu_id = $this->get_locations_menu_id( $locations, $arg );
50 52
 		}
51 53
 
Please login to merge, or discard this patch.