lsx_nav_menu_args()   A
last analyzed

Complexity

Conditions 5
Paths 8

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 8
nc 8
nop 1
dl 0
loc 16
rs 9.6111
c 0
b 0
f 0
1
<?php
2
/**
3
 * LSX functions and definitions - Navigation Walker.
4
 *
5
 * @package    lsx
6
 * @subpackage navigation
7
 * @category   bootstrap-walker
8
 */
9
10
if ( ! defined( 'ABSPATH' ) ) {
11
	exit;
12
}
13
14
add_filter( 'nav_menu_item_id', '__return_null' );
15
16
if ( ! function_exists( 'lsx_nav_menu_css_class' ) ) :
17
18
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$classes" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$item" missing
Loading history...
19
	 * Remove the id="" on nav menu items.
20
	 * Return 'menu-slug' for nav menu classes.
21
	 *
22
	 * @package    lsx
23
	 * @subpackage navigation
24
	 * @category   bootstrap-walker
25
	 */
26
	function lsx_nav_menu_css_class( $classes, $item ) {
27
		$slug    = sanitize_title( $item->title );
28
		$classes = preg_replace( '/(current(-menu-|[-_]page[-_])(item|parent|ancestor))/', 'active', $classes );
29
		$classes = preg_replace( '/^((menu|page)[-_\w+]+)+/', '', $classes );
30
31
		$classes[] = 'menu-' . $slug;
32
		$classes   = array_unique( $classes );
33
34
		return array_filter( $classes, 'lsx_is_element_empty' );
35
	}
36
37
endif;
38
39
add_filter( 'nav_menu_css_class', 'lsx_nav_menu_css_class', 10, 2 );
40
41
if ( ! function_exists( 'lsx_nav_menu_args' ) ) :
42
43
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$args" missing
Loading history...
44
	 * Clean up wp_nav_menu_args.
45
	 *
46
	 * Remove the container.
47
	 * Use LSX_Nav_Walker() by default.
48
	 *
49
	 * @package    lsx
50
	 * @subpackage navigation
51
	 * @category   bootstrap-walker
52
	 */
53
	function lsx_nav_menu_args( $args = '' ) {
54
		$roots_nav_menu_args['container'] = false;
0 ignored issues
show
Comprehensibility Best Practice introduced by
$roots_nav_menu_args was never initialized. Although not strictly required by PHP, it is generally a good practice to add $roots_nav_menu_args = array(); before regardless.
Loading history...
55
56
		if ( ! $args['items_wrap'] ) {
57
			$roots_nav_menu_args['items_wrap'] = '<ul class="%2$s">%3$s</ul>';
58
		}
59
60
		if ( current_theme_supports( 'bootstrap-top-navbar' ) && ! $args['depth'] ) {
61
			$roots_nav_menu_args['depth'] = 2;
62
		}
63
64
		if ( ! $args['walker'] ) {
65
			$roots_nav_menu_args['walker'] = new LSX_Nav_Walker();
66
		}
67
68
		return array_merge( $args, $roots_nav_menu_args );
69
	}
70
71
endif;
72
73
add_filter( 'wp_nav_menu_args', 'lsx_nav_menu_args' );
74