| 1 |
<?php |
| 2 |
namespace QuadLayers\QuadMenu\Frontend\Walker; |
| 3 |
|
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
die( '-1' ); |
| 6 |
} |
| 7 |
|
| 8 |
/** |
| 9 |
* QuadMenuWalker Class |
| 10 |
*/ |
| 11 |
class QuadMenu_Walker extends \Walker_Nav_Menu { |
| 12 |
|
| 13 |
public $item_stack = array(); |
| 14 |
public $current_umitem; |
| 15 |
public $auto_child = ''; |
| 16 |
|
| 17 |
function __construct() { |
| 18 |
} |
| 19 |
|
| 20 |
function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) { |
| 21 |
|
| 22 |
if ( ! $element ) { |
| 23 |
return; |
| 24 |
} |
| 25 |
|
| 26 |
$id_field = $this->db_fields['id']; |
| 27 |
|
| 28 |
$has_children = ! empty( $children_elements[ $element->{$id_field} ] ); |
| 29 |
|
| 30 |
if ( isset( $args[0] ) && is_array( $args[0] ) ) { |
| 31 |
$args[0]['has_children'] = $has_children; |
| 32 |
} |
| 33 |
|
| 34 |
$cb_args = array_merge( array( &$output, $element, $depth ), $args ); |
| 35 |
|
| 36 |
$id = $element->{$id_field}; // Moved up |
| 37 |
|
| 38 |
$umitem_obect_class = apply_filters( 'quadmenu_item_object_class', '\\QuadLayers\\QuadMenu\\Frontend\\Walker\\QuadMenu_Item_Default', $element, $id, $this->auto_child ); |
| 39 |
|
| 40 |
if ( ! class_exists( $umitem_obect_class ) ) { |
| 41 |
$umitem_obect_class = '\\QuadLayers\\QuadMenu\\Frontend\\Walker\\QuadMenu_Item_Default'; |
| 42 |
} |
| 43 |
|
| 44 |
$umitem = new $umitem_obect_class( $output, $element, $depth, $cb_args[3], $id, $this, $has_children, $children_elements ); // The $args that get passed to start_el are $cb[3] -- i.e. the 4the element in the array merged above |
| 45 |
|
| 46 |
$this->push_item( $umitem ); |
| 47 |
|
| 48 |
call_user_func_array( array( $this, 'start_el' ), $cb_args ); |
| 49 |
|
| 50 |
// descend only when the depth is right and there are childrens for this element |
| 51 |
if ( ( $max_depth == 0 || $max_depth > $depth + 1 ) && isset( $children_elements[ $id ] ) ) { |
| 52 |
|
| 53 |
foreach ( $children_elements[ $id ] as $child ) { |
| 54 |
|
| 55 |
if ( ! isset( $newlevel ) ) { |
| 56 |
$newlevel = true; |
| 57 |
// start the child delimiter |
| 58 |
$cb_args = array_merge( array( &$output, $depth ), $args ); |
| 59 |
call_user_func_array( array( $this, 'start_lvl' ), $cb_args ); |
| 60 |
} |
| 61 |
$this->display_element( $child, $children_elements, $max_depth, $depth + 1, $args, $output ); |
| 62 |
} |
| 63 |
|
| 64 |
// Unset this item's children elements |
| 65 |
unset( $children_elements[ $id ] ); // TODO!!! |
| 66 |
} |
| 67 |
|
| 68 |
if ( isset( $newlevel ) && $newlevel ) { |
| 69 |
// end the child delimiter |
| 70 |
$cb_args = array_merge( array( &$output, $depth ), $args ); |
| 71 |
call_user_func_array( array( $this, 'end_lvl' ), $cb_args ); |
| 72 |
} |
| 73 |
|
| 74 |
$cb_args = array_merge( array( &$output, $element, $depth ), $args ); |
| 75 |
|
| 76 |
call_user_func_array( array( $this, 'end_el' ), $cb_args ); |
| 77 |
} |
| 78 |
|
| 79 |
function start_lvl( &$output, $depth = 0, $args = array() ) { |
| 80 |
// $indent = str_repeat("\t", $depth); |
| 81 |
$this->current_umitem->start_lvl(); |
| 82 |
} |
| 83 |
|
| 84 |
function end_lvl( &$output, $depth = 0, $args = array() ) { |
| 85 |
// $indent = str_repeat("\t", $depth); |
| 86 |
$this->current_umitem->end_lvl(); |
| 87 |
} |
| 88 |
|
| 89 |
function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { |
| 90 |
|
| 91 |
$this->current_umitem->start_el(); |
| 92 |
} |
| 93 |
|
| 94 |
function end_el( &$output, $item, $depth = 0, $args = array() ) { |
| 95 |
$this->current_umitem->end_el(); |
| 96 |
$this->pop_item(); |
| 97 |
} |
| 98 |
|
| 99 |
function push_item( $umitem ) { |
| 100 |
$this->item_stack[] = $umitem; |
| 101 |
$this->current_umitem = $umitem; |
| 102 |
} |
| 103 |
|
| 104 |
function pop_item() { |
| 105 |
$umitem = array_pop( $this->item_stack ); |
| 106 |
$this->current_umitem = $this->current_item(); |
| 107 |
} |
| 108 |
|
| 109 |
function current_item() { |
| 110 |
return end( $this->item_stack ); |
| 111 |
} |
| 112 |
|
| 113 |
public static function fallback( $args ) { |
| 114 |
|
| 115 |
global $_wp_registered_nav_menus; |
| 116 |
|
| 117 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 118 |
return; |
| 119 |
} |
| 120 |
|
| 121 |
extract( $args ); |
| 122 |
|
| 123 |
ob_start(); |
| 124 |
?> |
| 125 |
<li class="quadmenu-item quadmenu-item-object-custom quadmenu-item-level-0 quadmenu-item-type-default quadmenu-has-title quadmenu-has-icon quadmenu-has-link"> |
| 126 |
<a title="<?php printf( esc_html__( 'Add a menu to %1$s', 'quadmenu' ), $_wp_registered_nav_menus[ $theme_location ] ); ?>" href="<?php echo admin_url( 'nav-menus.php' ); ?>"> |
| 127 |
<span class="quadmenu-item-content"> |
| 128 |
<span class="quadmenu-text"><?php printf( esc_html__( 'Add a menu to %1$s', 'quadmenu' ), $_wp_registered_nav_menus[ $theme_location ] ); ?></span> |
| 129 |
</span> |
| 130 |
</a> |
| 131 |
</li> |
| 132 |
<li class="quadmenu-item quadmenu-item-object-custom quadmenu-item-level-0 quadmenu-item-type-default quadmenu-has-title quadmenu-has-icon quadmenu-has-link"> |
| 133 |
<a title="<?php esc_html_e( 'Documentation', 'quadmenu' ); ?>" href="<?php echo esc_url( 'https://quadmenu.com/documentation/?utm_source=quadmenu_plugin&utm_medium=admin_frontend&utm_campaign=documentation&utm_content=documentation_link' ); ?>"> |
| 134 |
<span class="quadmenu-item-content"> |
| 135 |
<span class="quadmenu-text"><?php esc_html_e( 'Documentation', 'quadmenu' ); ?></span> |
| 136 |
</span> |
| 137 |
</a> |
| 138 |
</li> |
| 139 |
<li class="quadmenu-item quadmenu-item-object-custom quadmenu-item-level-0 quadmenu-item-type-default quadmenu-has-title quadmenu-has-icon quadmenu-has-link"> |
| 140 |
<a title="<?php esc_html_e( 'Demo', 'quadmenu' ); ?>" href="<?php echo esc_url( 'https://quadmenu.com/?utm_source=quadmenu_plugin&utm_medium=admin_frontend&utm_campaign=demo&utm_content=demo_link' ); ?>"> |
| 141 |
<span class="quadmenu-item-content"> |
| 142 |
<span class="quadmenu-text"><?php esc_html_e( 'Demo', 'quadmenu' ); ?></span> |
| 143 |
</span> |
| 144 |
</a> |
| 145 |
</li> |
| 146 |
<?php |
| 147 |
$menu = ob_get_clean(); |
| 148 |
|
| 149 |
$nav_menu = sprintf( $items_wrap, esc_attr( $menu_id ), esc_attr( $menu_class ), $menu ); |
| 150 |
|
| 151 |
return quadmenu_layout( $nav_menu, (object) $args ); |
| 152 |
} |
| 153 |
} |
| 154 |
|