|
2 | 2 | // bootstrap 5 wp_nav_menu walker
|
3 | 3 | class bootstrap_5_wp_nav_menu_walker extends Walker_Nav_menu
|
4 | 4 | {
|
| 5 | + private $current_item; |
| 6 | + private $dropdown_menu_alignment_values = [ |
| 7 | + 'dropdown-menu-start', |
| 8 | + 'dropdown-menu-end', |
| 9 | + 'dropdown-menu-sm-start', |
| 10 | + 'dropdown-menu-sm-end', |
| 11 | + 'dropdown-menu-md-start', |
| 12 | + 'dropdown-menu-md-end', |
| 13 | + 'dropdown-menu-lg-start', |
| 14 | + 'dropdown-menu-lg-end', |
| 15 | + 'dropdown-menu-xl-start', |
| 16 | + 'dropdown-menu-xl-end', |
| 17 | + 'dropdown-menu-xxl-start', |
| 18 | + 'dropdown-menu-xxl-end' |
| 19 | + ]; |
| 20 | + |
5 | 21 | function start_lvl(&$output, $depth = 0, $args = array())
|
6 | 22 | {
|
| 23 | + $dropdown_menu_class[] = ''; |
| 24 | + foreach($this->current_item->classes as $class) { |
| 25 | + if(in_array($class, $this->dropdown_menu_alignment_values)) { |
| 26 | + $dropdown_menu_class[] = $class; |
| 27 | + } |
| 28 | + } |
7 | 29 | $indent = str_repeat("\t", $depth);
|
8 | 30 | $submenu = ($depth > 0) ? ' sub-menu' : '';
|
9 |
| - $output .= "\n$indent<ul class=\"dropdown-menu$submenu depth_$depth\">\n"; |
| 31 | + $output .= "\n$indent<ul class=\"dropdown-menu$submenu " . esc_attr(implode(" ",$dropdown_menu_class)) . " depth_$depth\">\n"; |
10 | 32 | }
|
11 | 33 |
|
12 | 34 | function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0)
|
13 | 35 | {
|
| 36 | + $this->current_item = $item; |
14 | 37 |
|
15 | 38 | $indent = ($depth) ? str_repeat("\t", $depth) : '';
|
16 | 39 |
|
|
0 commit comments