megamenu_id = 0; $this->count = 0; } public function start_lvl(&$output, $depth = 0, $args = array()){ if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) { $t = ''; $n = ''; } else { $t = "\t"; $n = "\n"; } $indent = str_repeat( $t, $depth ); // Default class. $classes = array( 'sub-menu', 'dglib-submenu-depth'.$depth ); $class_names = join( ' ', apply_filters( 'nav_menu_submenu_css_class', $classes, $args, $depth ) ); $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : ''; $output .= "{$n}{$indent}{$n}"; } public function end_lvl(&$output, $depth = 0, $args = array()){ if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) { $t = ''; $n = ''; } else { $t = "\t"; $n = "\n"; } $indent = str_repeat( $t, $depth ); $output .= "$indent{$n}"; } public function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0){ $megamenu_options = 'menu-item-dglib-megamenu'; $megamenu_values = get_post_meta( $item->ID, $megamenu_options, true ); $enable_megamenu = (isset($megamenu_values['enable_megamenu'])) ? absint($megamenu_values['enable_megamenu']) : 0; $description_tips = (isset($megamenu_values['description_tips'])) ? esc_html($megamenu_values['description_tips']) : ''; $menu_icon = (isset($megamenu_values['menu_icon'])) ? esc_attr($megamenu_values['menu_icon']) : ''; $megamenu_categories = (isset($megamenu_values['megamenu_categories'])) ? $megamenu_values['megamenu_categories'] : array(); if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) { $t = ''; $n = ''; } else { $t = "\t"; $n = "\n"; } $indent = ( $depth ) ? str_repeat( $t, $depth ) : ''; $classes = empty( $item->classes ) ? array() : (array) $item->classes; $classes[] = 'menu-item-' . $item->ID; if($enable_megamenu){ $classes[] = 'dglib-has-megamenu'; $classes[] = 'menu-item-has-children'; }else{ $classes[] = 'dglib-no-megamenu'; } $args = apply_filters( 'nav_menu_item_args', $args, $item, $depth ); $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args, $depth ) ); $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : ''; $id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args, $depth ); $id = $id ? ' id="' . esc_attr( $id ) . '"' : ''; $output .= $indent . ''; $megamenu_ajax_data = array( 'type' => 'POST', 'dataType' => 'json', 'url' => admin_url( 'admin-ajax.php' ), 'data' => array( 'action' => 'dglib_megamenu_posts', 'term_ids' => '', 'posts_per_page' => 4, 'megamenu_nonce_value' => wp_create_nonce( 'dglib_megamenu_posts_nonce' ) ), ); $megamenu_html = ''; if($enable_megamenu && $megamenu_categories && $depth<1){ $megamenu_html .= ''; // .dglib-megamenu-wrapper } $atts = array(); $atts['title'] = ! empty( $item->attr_title ) ? $item->attr_title : ''; $atts['target'] = ! empty( $item->target ) ? $item->target : ''; $atts['rel'] = ! empty( $item->xfn ) ? $item->xfn : ''; $atts['href'] = ! empty( $item->url ) ? $item->url : ''; if ($description_tips) { $atts['class'] = 'dglib-has-menu-tips'; } $atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args, $depth ); $attributes = ''; foreach ( $atts as $attr => $value ) { if ( ! empty( $value ) ) { $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value ); $attributes .= ' ' . $attr . '="' . $value . '"'; } } $fa_icon_html = ($menu_icon) ? '' : ''; $description_html = ($description_tips && $item->description) ? ''.$item->description.'' : ''; /** This filter is documented in wp-includes/post-template.php */ $title = apply_filters( 'the_title', $item->title, $item->ID ); $args_arr = (array)$args; $title = apply_filters( 'nav_menu_item_title', $title, $item, $args, $depth ); $item_output = $args_arr['before']; $item_output .= ''; $item_output .= $fa_icon_html; $item_output .= $args_arr['link_before'] . $title . $args_arr['link_after']; $item_output .= ''; $item_output .= $description_html; $item_output .= $args_arr['after']; $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ); $output .= $megamenu_html; } public function display_element($element, &$children_elements, $max_depth, $depth, $args, &$output){ if (!$element) { return; } $id_field = $this->db_fields['id']; //display this element if (is_array($args[0])) { $args[0]['has_children'] = !empty($children_elements[$element->$id_field]); } elseif (is_object($args[0])) { $args[0]->has_children = !empty($children_elements[$element->$id_field]); } $cb_args = array_merge(array(&$output, $element, $depth), $args); call_user_func_array(array(&$this, 'start_el'), $cb_args); $id = $element->$id_field; // descend only when the depth is right and there are childrens for this element if (($max_depth == 0 || $max_depth > $depth + 1) && isset($children_elements[$id])) { foreach ($children_elements[ $id ] as $child) { if (!isset($newlevel)) { $newlevel = true; //start the child delimiter $cb_args = array_merge(array(&$output, $depth), $args); call_user_func_array(array(&$this, 'start_lvl'), $cb_args); } $this->display_element($child, $children_elements, $max_depth, $depth + 1, $args, $output); } unset($children_elements[ $id ]); } if (isset($newlevel) && $newlevel) { //end the child delimiter $cb_args = array_merge(array(&$output, $depth), $args); call_user_func_array(array(&$this, 'end_lvl'), $cb_args); } //end this element $cb_args = array_merge(array(&$output, $element, $depth), $args); call_user_func_array(array(&$this, 'end_el'), $cb_args); } }