@@ -2,5 +2,5 @@ |
||
2 | 2 | /** |
3 | 3 | * Init our WordPress Theme. |
4 | 4 | */ |
5 | -require_once( __DIR__ . '/vendor/autoload.php' ); |
|
5 | +require_once(__DIR__.'/vendor/autoload.php'); |
|
6 | 6 | \Classy\Classy::get_instance(); |
@@ -2,6 +2,6 @@ |
||
2 | 2 | |
3 | 3 | global $post; |
4 | 4 | |
5 | -$classypost = new \Classy\Models\Post( $post ); |
|
5 | +$classypost = new \Classy\Models\Post($post); |
|
6 | 6 | |
7 | -Classy\Classy::render( 'layout.comments', array( 'post' => $classypost ) ); |
|
7 | +Classy\Classy::render('layout.comments', array('post' => $classypost)); |
@@ -3,4 +3,4 @@ |
||
3 | 3 | * Theme header. |
4 | 4 | */ |
5 | 5 | $framework = get_theme_framework(); |
6 | -$framework::render( 'layout.header' ); |
|
6 | +$framework::render('layout.header'); |
@@ -3,4 +3,4 @@ |
||
3 | 3 | * Theme footer. |
4 | 4 | */ |
5 | 5 | $framework = get_theme_framework(); |
6 | -$framework::render( 'layout.footer' ); |
|
6 | +$framework::render('layout.footer'); |
@@ -26,11 +26,11 @@ discard block |
||
26 | 26 | * |
27 | 27 | * @param int $pid Image attachment ID. |
28 | 28 | */ |
29 | - public function __construct( $pid = null ) { |
|
29 | + public function __construct($pid = null) { |
|
30 | 30 | $this->ID = 0; |
31 | 31 | |
32 | 32 | // Checks if image with this id exists. |
33 | - if ( null !== $pid && wp_get_attachment_image_src( $pid ) ) { |
|
33 | + if (null !== $pid && wp_get_attachment_image_src($pid)) { |
|
34 | 34 | $this->ID = $pid; |
35 | 35 | } |
36 | 36 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public static function get_default_image() { |
44 | 44 | // You can put here any url. |
45 | - return CLASSY_THEME_DIR . '/assets/noimage.png'; |
|
45 | + return CLASSY_THEME_DIR.'/assets/noimage.png'; |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
@@ -52,9 +52,9 @@ discard block |
||
52 | 52 | * |
53 | 53 | * @return string |
54 | 54 | */ |
55 | - public function src( $size = 'medium' ) { |
|
56 | - if ( $this->ID ) { |
|
57 | - $thumb = wp_get_attachment_image_src( $this->ID, $size ); |
|
55 | + public function src($size = 'medium') { |
|
56 | + if ($this->ID) { |
|
57 | + $thumb = wp_get_attachment_image_src($this->ID, $size); |
|
58 | 58 | |
59 | 59 | return $thumb[0]; |
60 | 60 | } |
@@ -66,8 +66,8 @@ discard block |
||
66 | 66 | * |
67 | 67 | * @param int $uid User id. |
68 | 68 | */ |
69 | - public function __construct( $uid = null ) { |
|
70 | - $this->ID = $this->verify_id( $uid ); |
|
69 | + public function __construct($uid = null) { |
|
70 | + $this->ID = $this->verify_id($uid); |
|
71 | 71 | |
72 | 72 | $this->init(); |
73 | 73 | } |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | * |
80 | 80 | * @return int |
81 | 81 | */ |
82 | - private function verify_id( $uid ) { |
|
82 | + private function verify_id($uid) { |
|
83 | 83 | // @todo: Realize this method. |
84 | 84 | return $uid; |
85 | 85 | } |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | private function init() { |
91 | 91 | $this->object = $this->get_object(); |
92 | 92 | |
93 | - $this->import( $this->object ); |
|
93 | + $this->import($this->object); |
|
94 | 94 | |
95 | 95 | $this->setup_user_name(); |
96 | 96 | } |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | * @return object |
102 | 102 | */ |
103 | 103 | private function get_object() { |
104 | - return get_user_by( 'id', $this->ID ); |
|
104 | + return get_user_by('id', $this->ID); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
@@ -155,8 +155,8 @@ discard block |
||
155 | 155 | * @return string |
156 | 156 | */ |
157 | 157 | public function link() { |
158 | - if ( ! $this->link ) { |
|
159 | - $this->link = get_author_posts_url( $this->ID ); |
|
158 | + if (!$this->link) { |
|
159 | + $this->link = get_author_posts_url($this->ID); |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | return $this->link; |
@@ -167,8 +167,8 @@ discard block |
||
167 | 167 | */ |
168 | 168 | private function setup_user_name() { |
169 | 169 | $this->name = 'Anonymous'; |
170 | - if ( isset( $this->object->first_name ) && isset( $this->object->last_name ) ) { |
|
171 | - $this->name = $this->object->first_name . ' ' . $this->object->last_name; |
|
170 | + if (isset($this->object->first_name) && isset($this->object->last_name)) { |
|
171 | + $this->name = $this->object->first_name.' '.$this->object->last_name; |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | $this->display_name = $this->object->display_name; |
@@ -98,12 +98,12 @@ discard block |
||
98 | 98 | * |
99 | 99 | * @param object|int $post WP_Post or WP_Post.ID. |
100 | 100 | */ |
101 | - public function __construct( $post = null ) { |
|
102 | - if ( is_integer( $post ) ) { |
|
101 | + public function __construct($post = null) { |
|
102 | + if (is_integer($post)) { |
|
103 | 103 | $this->ID = $post; |
104 | 104 | $this->init(); |
105 | - } elseif ( is_a( $post, '\WP_Post' ) ) { |
|
106 | - $this->import( $post ); |
|
105 | + } elseif (is_a($post, '\WP_Post')) { |
|
106 | + $this->import($post); |
|
107 | 107 | } |
108 | 108 | } |
109 | 109 | |
@@ -113,8 +113,8 @@ discard block |
||
113 | 113 | protected function init() { |
114 | 114 | $post = $this->get_object(); |
115 | 115 | |
116 | - if ( is_a( $post, '\WP_Post' ) ) { |
|
117 | - $this->import( $post ); |
|
116 | + if (is_a($post, '\WP_Post')) { |
|
117 | + $this->import($post); |
|
118 | 118 | } |
119 | 119 | } |
120 | 120 | |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | * @return \WP_Post |
125 | 125 | */ |
126 | 126 | public function get_object() { |
127 | - return get_post( $this->ID ); |
|
127 | + return get_post($this->ID); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | /** |
@@ -133,10 +133,10 @@ discard block |
||
133 | 133 | * @return boolean |
134 | 134 | */ |
135 | 135 | public function can_edit() { |
136 | - if ( ! function_exists( 'current_user_can' ) ) { |
|
136 | + if (!function_exists('current_user_can')) { |
|
137 | 137 | return false; |
138 | 138 | } |
139 | - if ( current_user_can( 'edit_post', $this->ID ) ) { |
|
139 | + if (current_user_can('edit_post', $this->ID)) { |
|
140 | 140 | return true; |
141 | 141 | } |
142 | 142 | |
@@ -149,8 +149,8 @@ discard block |
||
149 | 149 | * @return string |
150 | 150 | */ |
151 | 151 | public function get_edit_url() { |
152 | - if ( $this->can_edit() ) { |
|
153 | - return get_edit_post_link( $this->ID ); |
|
152 | + if ($this->can_edit()) { |
|
153 | + return get_edit_post_link($this->ID); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | return ''; |
@@ -173,9 +173,9 @@ discard block |
||
173 | 173 | 'fields' => 'ids', |
174 | 174 | ); |
175 | 175 | |
176 | - $images = get_children( $attrs ); |
|
176 | + $images = get_children($attrs); |
|
177 | 177 | |
178 | - if ( ! count( $images ) ) { |
|
178 | + if (!count($images)) { |
|
179 | 179 | return false; |
180 | 180 | } |
181 | 181 | |
@@ -192,11 +192,11 @@ discard block |
||
192 | 192 | |
193 | 193 | $images = $this->get_attached_images(); |
194 | 194 | |
195 | - if ( $images ) { |
|
195 | + if ($images) { |
|
196 | 196 | |
197 | - foreach ( $images as $image_id ) { |
|
197 | + foreach ($images as $image_id) { |
|
198 | 198 | |
199 | - $_return[] = new Image( $image_id ); |
|
199 | + $_return[] = new Image($image_id); |
|
200 | 200 | |
201 | 201 | } |
202 | 202 | } |
@@ -222,13 +222,13 @@ discard block |
||
222 | 222 | 'fields' => 'ids', |
223 | 223 | ); |
224 | 224 | |
225 | - $images = get_children( $attrs ); |
|
225 | + $images = get_children($attrs); |
|
226 | 226 | |
227 | - if ( ! count( $images ) ) { |
|
227 | + if (!count($images)) { |
|
228 | 228 | return false; |
229 | 229 | } |
230 | 230 | |
231 | - $images = array_values( $images ); |
|
231 | + $images = array_values($images); |
|
232 | 232 | |
233 | 233 | return $images[0]; |
234 | 234 | } |
@@ -242,8 +242,8 @@ discard block |
||
242 | 242 | |
243 | 243 | $image_id = $this->get_first_attached_image_id(); |
244 | 244 | |
245 | - if ( $image_id ) { |
|
246 | - return new Image( $image_id ); |
|
245 | + if ($image_id) { |
|
246 | + return new Image($image_id); |
|
247 | 247 | } |
248 | 248 | |
249 | 249 | return new Image(); |
@@ -255,12 +255,12 @@ discard block |
||
255 | 255 | * @return Image |
256 | 256 | */ |
257 | 257 | public function thumbnail() { |
258 | - if ( function_exists( 'get_post_thumbnail_id' ) ) { |
|
259 | - $image_id = get_post_thumbnail_id( $this->ID ); |
|
258 | + if (function_exists('get_post_thumbnail_id')) { |
|
259 | + $image_id = get_post_thumbnail_id($this->ID); |
|
260 | 260 | |
261 | - if ( $image_id ) { |
|
261 | + if ($image_id) { |
|
262 | 262 | |
263 | - return new Image( $image_id ); |
|
263 | + return new Image($image_id); |
|
264 | 264 | |
265 | 265 | } |
266 | 266 | } |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | * @return string |
275 | 275 | */ |
276 | 276 | public function get_title() { |
277 | - return apply_filters( 'the_title', $this->post_title, $this->ID ); |
|
277 | + return apply_filters('the_title', $this->post_title, $this->ID); |
|
278 | 278 | } |
279 | 279 | |
280 | 280 | /** |
@@ -293,24 +293,24 @@ discard block |
||
293 | 293 | * |
294 | 294 | * @return string Post content |
295 | 295 | */ |
296 | - public function get_content( $page = 0 ) { |
|
297 | - if ( 0 === absint( $page ) && $this->post_content ) { |
|
298 | - return apply_filters( 'the_content', $this->post_content ); |
|
296 | + public function get_content($page = 0) { |
|
297 | + if (0 === absint($page) && $this->post_content) { |
|
298 | + return apply_filters('the_content', $this->post_content); |
|
299 | 299 | } |
300 | 300 | |
301 | 301 | $content = $this->post_content; |
302 | 302 | |
303 | - if ( $page ) { |
|
304 | - $contents = explode( '<!--nextpage-->', $content ); |
|
303 | + if ($page) { |
|
304 | + $contents = explode('<!--nextpage-->', $content); |
|
305 | 305 | |
306 | 306 | $page--; |
307 | 307 | |
308 | - if ( count( $contents ) > $page ) { |
|
309 | - $content = $contents[ $page ]; |
|
308 | + if (count($contents) > $page) { |
|
309 | + $content = $contents[$page]; |
|
310 | 310 | } |
311 | 311 | } |
312 | 312 | |
313 | - $content = apply_filters( 'the_content', ($content) ); |
|
313 | + $content = apply_filters('the_content', ($content)); |
|
314 | 314 | |
315 | 315 | return $content; |
316 | 316 | } |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | * @return object |
331 | 331 | */ |
332 | 332 | public function get_post_type() { |
333 | - return get_post_type_object( $this->post_type ); |
|
333 | + return get_post_type_object($this->post_type); |
|
334 | 334 | } |
335 | 335 | |
336 | 336 | /** |
@@ -339,11 +339,11 @@ discard block |
||
339 | 339 | * @return string |
340 | 340 | */ |
341 | 341 | public function get_permalink() { |
342 | - if ( isset( $this->permalink ) ) { |
|
342 | + if (isset($this->permalink)) { |
|
343 | 343 | return $this->permalink; |
344 | 344 | } |
345 | 345 | |
346 | - $this->permalink = get_permalink( $this->ID ); |
|
346 | + $this->permalink = get_permalink($this->ID); |
|
347 | 347 | |
348 | 348 | return $this->permalink; |
349 | 349 | } |
@@ -369,84 +369,84 @@ discard block |
||
369 | 369 | * |
370 | 370 | * @return string Post preview. |
371 | 371 | */ |
372 | - public function get_preview( $len = 50, $force = false, $readmore = 'Read More', $strip = true ) { |
|
372 | + public function get_preview($len = 50, $force = false, $readmore = 'Read More', $strip = true) { |
|
373 | 373 | $text = ''; |
374 | 374 | $trimmed = false; |
375 | 375 | |
376 | - if ( isset( $this->post_excerpt ) && strlen( $this->post_excerpt ) ) { |
|
376 | + if (isset($this->post_excerpt) && strlen($this->post_excerpt)) { |
|
377 | 377 | |
378 | - if ( $force ) { |
|
379 | - $text = Helper::trim_words( $this->post_excerpt, $len, false ); |
|
378 | + if ($force) { |
|
379 | + $text = Helper::trim_words($this->post_excerpt, $len, false); |
|
380 | 380 | $trimmed = true; |
381 | 381 | } else { |
382 | 382 | $text = $this->post_excerpt; |
383 | 383 | } |
384 | 384 | } |
385 | 385 | |
386 | - if ( ! strlen( $text ) && preg_match( '/<!--\s?more(.*?)?-->/', $this->post_content, $readmore_matches ) ) { |
|
386 | + if (!strlen($text) && preg_match('/<!--\s?more(.*?)?-->/', $this->post_content, $readmore_matches)) { |
|
387 | 387 | |
388 | - $pieces = explode( $readmore_matches[0], $this->post_content ); |
|
388 | + $pieces = explode($readmore_matches[0], $this->post_content); |
|
389 | 389 | $text = $pieces[0]; |
390 | 390 | |
391 | - if ( $force ) { |
|
392 | - $text = Helper::trim_words( $text, $len, false ); |
|
391 | + if ($force) { |
|
392 | + $text = Helper::trim_words($text, $len, false); |
|
393 | 393 | $trimmed = true; |
394 | 394 | } |
395 | 395 | |
396 | - $text = do_shortcode( $text ); |
|
396 | + $text = do_shortcode($text); |
|
397 | 397 | |
398 | 398 | } |
399 | 399 | |
400 | - if ( ! strlen( $text ) ) { |
|
400 | + if (!strlen($text)) { |
|
401 | 401 | |
402 | - $text = Helper::trim_words( $this->get_content(), $len, false ); |
|
402 | + $text = Helper::trim_words($this->get_content(), $len, false); |
|
403 | 403 | $trimmed = true; |
404 | 404 | |
405 | 405 | } |
406 | 406 | |
407 | - if ( ! strlen( trim( $text ) ) ) { |
|
407 | + if (!strlen(trim($text))) { |
|
408 | 408 | |
409 | - return trim( $text ); |
|
409 | + return trim($text); |
|
410 | 410 | |
411 | 411 | } |
412 | 412 | |
413 | - if ( $strip ) { |
|
413 | + if ($strip) { |
|
414 | 414 | |
415 | - $text = trim( strip_tags( $text ) ); |
|
415 | + $text = trim(strip_tags($text)); |
|
416 | 416 | |
417 | 417 | } |
418 | 418 | |
419 | - if ( strlen( $text ) ) { |
|
419 | + if (strlen($text)) { |
|
420 | 420 | |
421 | - $text = trim( $text ); |
|
422 | - $last = $text[ strlen( $text ) - 1 ]; |
|
421 | + $text = trim($text); |
|
422 | + $last = $text[strlen($text) - 1]; |
|
423 | 423 | |
424 | - if ( '.' !== $last && $trimmed ) { |
|
424 | + if ('.' !== $last && $trimmed) { |
|
425 | 425 | $text .= ' … '; |
426 | 426 | } |
427 | 427 | |
428 | - if ( ! $strip ) { |
|
429 | - $last_p_tag = strrpos( $text, '</p>' ); |
|
430 | - if ( false !== $last_p_tag ) { |
|
431 | - $text = substr( $text, 0, $last_p_tag ); |
|
428 | + if (!$strip) { |
|
429 | + $last_p_tag = strrpos($text, '</p>'); |
|
430 | + if (false !== $last_p_tag) { |
|
431 | + $text = substr($text, 0, $last_p_tag); |
|
432 | 432 | } |
433 | - if ( '.' !== $last && $trimmed ) { |
|
433 | + if ('.' !== $last && $trimmed) { |
|
434 | 434 | $text .= ' … '; |
435 | 435 | } |
436 | 436 | } |
437 | 437 | |
438 | - if ( $readmore && isset( $readmore_matches ) && ! empty( $readmore_matches[1] ) ) { |
|
439 | - $text .= ' <a href="' . $this->get_permalink() . '" class="read-more">' . trim( $readmore_matches[1] ) . '</a>'; |
|
440 | - } elseif ( $readmore ) { |
|
441 | - $text .= ' <a href="' . $this->get_permalink() . '" class="read-more">' . trim( $readmore ) . '</a>'; |
|
438 | + if ($readmore && isset($readmore_matches) && !empty($readmore_matches[1])) { |
|
439 | + $text .= ' <a href="'.$this->get_permalink().'" class="read-more">'.trim($readmore_matches[1]).'</a>'; |
|
440 | + } elseif ($readmore) { |
|
441 | + $text .= ' <a href="'.$this->get_permalink().'" class="read-more">'.trim($readmore).'</a>'; |
|
442 | 442 | } |
443 | 443 | |
444 | - if ( ! $strip ) { |
|
444 | + if (!$strip) { |
|
445 | 445 | $text .= '</p>'; |
446 | 446 | } |
447 | 447 | } |
448 | 448 | |
449 | - return trim( $text ); |
|
449 | + return trim($text); |
|
450 | 450 | } |
451 | 451 | |
452 | 452 | /** |
@@ -457,7 +457,7 @@ discard block |
||
457 | 457 | * |
458 | 458 | * @return array |
459 | 459 | */ |
460 | - public function get_comments( $status = 'approve', $order = 'DESC' ) { |
|
460 | + public function get_comments($status = 'approve', $order = 'DESC') { |
|
461 | 461 | |
462 | 462 | $_return = array(); |
463 | 463 | |
@@ -467,25 +467,25 @@ discard block |
||
467 | 467 | 'order' => $order, |
468 | 468 | ); |
469 | 469 | |
470 | - $comments = get_comments( $args ); |
|
470 | + $comments = get_comments($args); |
|
471 | 471 | |
472 | - foreach ( $comments as $comment ) { |
|
472 | + foreach ($comments as $comment) { |
|
473 | 473 | |
474 | - $_return[ $comment->comment_ID ] = new Comment( $comment ); |
|
474 | + $_return[$comment->comment_ID] = new Comment($comment); |
|
475 | 475 | |
476 | 476 | } |
477 | 477 | |
478 | - foreach ( $_return as $key => $comment ) { |
|
478 | + foreach ($_return as $key => $comment) { |
|
479 | 479 | |
480 | - if ( $comment->has_parent() ) { |
|
480 | + if ($comment->has_parent()) { |
|
481 | 481 | |
482 | - $_return[ $comment->comment_parent ]->add_child( $comment ); |
|
482 | + $_return[$comment->comment_parent]->add_child($comment); |
|
483 | 483 | |
484 | - unset( $_return[ $key ] ); |
|
484 | + unset($_return[$key]); |
|
485 | 485 | |
486 | 486 | } |
487 | 487 | } |
488 | 488 | |
489 | - return array_values( $_return ); |
|
489 | + return array_values($_return); |
|
490 | 490 | } |
491 | 491 | } |
@@ -29,9 +29,9 @@ discard block |
||
29 | 29 | |
30 | 30 | $request = Hierarchy::get_current_request(); |
31 | 31 | |
32 | - $file = Hierarchy::get_available_file( 'view', $request ); |
|
32 | + $file = Hierarchy::get_available_file('view', $request); |
|
33 | 33 | |
34 | - $view = self::get_blade_view( $file ); |
|
34 | + $view = self::get_blade_view($file); |
|
35 | 35 | |
36 | 36 | return $view; |
37 | 37 | |
@@ -44,9 +44,9 @@ discard block |
||
44 | 44 | * |
45 | 45 | * @return string |
46 | 46 | */ |
47 | - public static function get_blade_view( $view ) { |
|
47 | + public static function get_blade_view($view) { |
|
48 | 48 | |
49 | - return str_replace( '/', '.', $view ); |
|
49 | + return str_replace('/', '.', $view); |
|
50 | 50 | |
51 | 51 | } |
52 | 52 | |
@@ -59,21 +59,21 @@ discard block |
||
59 | 59 | |
60 | 60 | $templates = array(); |
61 | 61 | |
62 | - $files = (array) glob( CLASSY_THEME_PATH . '/' . self::$folder . '/*/*.blade.php' ); |
|
62 | + $files = (array) glob(CLASSY_THEME_PATH.'/'.self::$folder.'/*/*.blade.php'); |
|
63 | 63 | |
64 | - foreach ( $files as $filename ) { |
|
64 | + foreach ($files as $filename) { |
|
65 | 65 | |
66 | - if ( ! empty( $filename ) ) { |
|
66 | + if (!empty($filename)) { |
|
67 | 67 | |
68 | - if ( ! preg_match( '/\{\{\-\-\s*Template Name:(.*)\s*\-\-\}\}/mi', file_get_contents( $filename ), $header ) ) { continue; } |
|
68 | + if (!preg_match('/\{\{\-\-\s*Template Name:(.*)\s*\-\-\}\}/mi', file_get_contents($filename), $header)) { continue; } |
|
69 | 69 | |
70 | - $template_name = trim( $header[1] ); |
|
70 | + $template_name = trim($header[1]); |
|
71 | 71 | |
72 | - preg_match( '/\/([^\/]*)\.blade.php$/is', $filename, $filename_match ); |
|
72 | + preg_match('/\/([^\/]*)\.blade.php$/is', $filename, $filename_match); |
|
73 | 73 | |
74 | - $template_file = 'classy-' . $filename_match[1]; |
|
74 | + $template_file = 'classy-'.$filename_match[1]; |
|
75 | 75 | |
76 | - $templates[ $template_file ] = $template_name; |
|
76 | + $templates[$template_file] = $template_name; |
|
77 | 77 | |
78 | 78 | } |
79 | 79 | } |
@@ -38,22 +38,22 @@ discard block |
||
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_array( $locations ) && count( $locations ) ) { |
|
47 | - $menu_id = $this->get_locations_menu_id( $locations, $arg ); |
|
48 | - } elseif ( is_string( $arg ) ) { |
|
49 | - $menu_id = $this->get_menu_id_by_name( $arg ); |
|
44 | + if (is_numeric($arg) && 0 !== absint($arg)) { |
|
45 | + $menu_id = $this->check_menu_id($arg); |
|
46 | + } elseif (is_array($locations) && count($locations)) { |
|
47 | + $menu_id = $this->get_locations_menu_id($locations, $arg); |
|
48 | + } elseif (is_string($arg)) { |
|
49 | + $menu_id = $this->get_menu_id_by_name($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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |