<?php
/**
 * Customise navigation menu codes
 */
class FJ_Walker_Nav_Menu extends Walker_Nav_Menu {
	
	public function start_lvl( &$output, $depth = 0, $args = array() ) {
		$indent = str_repeat("\t", $depth);
		$output .= "\n$indent<ul class=\"sub-menu dropdown-menu\">\n";
	}
	
}


/**
 * Modify menu item classes
 */
function franz_nav_menu_css_class( $classes, $item, $args ){
	if ( in_array( 'current-menu-item', $classes ) ) $classes[] = 'active';
	if ( ( $item->menu_item_parent ) && in_array( 'menu-item-has-children', $classes ) ) $classes[] = 'dropdown-submenu';
	return $classes;
}
add_filter( 'nav_menu_css_class', 'franz_nav_menu_css_class', 10, 3 );


/**
 * Modify menu item attributes
 */
function franz_nav_menu_link_attributes( $atts, $item, $args ){
	if ( in_array( 'menu-item-has-children', $item->classes ) && $args->depth != 1 ) {
		$atts['class'] = 'dropdown-toggle';
		$atts['data-toggle'] = 'dropdown';
	}
	return $atts;
}
add_filter( 'nav_menu_link_attributes', 'franz_nav_menu_link_attributes', 10, 3 );


/**
 * Modify final menu item output
 */
function franz_walker_nav_menu_start_el( $item_output, $item, $depth, $args ){
	if ( in_array( 'menu-item-has-children', $item->classes ) && ( ( $depth + 1 ) < $args->depth || $args->depth == 0 ) ) {
		$item_output = str_replace( '</a>', ' <i class="fa fa-chevron-down"></i></a>', $item_output );
	}
	return $item_output;
}
add_filter( 'walker_nav_menu_start_el', 'franz_walker_nav_menu_start_el', 10, 4 );


function test_menu( $args ){
	disect_it( $args );
}
//add_filter( 'wp_page_menu_args', 'test_menu' );