mobile_menu_highlight = $mobile_menu_highlight;
}
public function start_lvl( &$output, $depth = 0, $args = array() ) {
if ( 'mega-content' === $this->get_menu_item_type() ) {
return;
}
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', 'wpr-mobile-sub-menu' );
$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}";
if ( defined('WPR_ADDONS_PRO_VERSION') && wpr_fs()->can_use_premium_code() && $depth === 0 ) {
$output .= '';
}
}
public function end_lvl( &$output, $depth = 0, $args = array() ) {
if ( 'mega-content' === $this->get_menu_item_type() ) {
return;
}
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 ) {
$this->set_menu_item_type( $item->ID, $depth );
if ( 'mega-content' === $this->get_menu_item_type() && 0 < $depth ) {
return;
}
// Get Settings
$settings = $this->get_mega_menu_settings($item->ID);
if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) {
$t = '';
$n = '';
} else {
$t = "\t";
$n = "\n";
}
$indent = ( $depth ) ? str_repeat( $t, $depth ) : '';
$id = apply_filters( 'nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args, $depth );
$id = $id ? ' id="' . esc_attr( $id ) . '"' : '';
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
$classes[] = 'menu-item-' . $item->ID;
if ( $this->has_mega_menu( $item->ID ) ) {
$classes[] = 'menu-item-has-children';
}
$id_attr = '';
if ( $settings ) {
if ( 'true' === $settings['wpr_mm_enable'] ) {
$classes[] = 'wpr-mega-menu-'. $settings['wpr_mm_enable'];
$id_attr = ' data-id="'. $item->ID .'"';
if ( defined('WPR_ADDONS_PRO_VERSION') && wpr_fs()->can_use_premium_code() && 'ajax' === $settings['wpr_mm_render'] && 'mega' === $settings['wpr_mm_mobile_content'] ) {
$classes[] = 'wpr-mega-menu-ajax';
}
}
}
$item_li_class = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args, $depth ) );
$item_li_class = $item_li_class ? ' class="' . esc_attr( $item_li_class ) . '"' : '';
$item_a_class = 'wpr-mobile-menu-item';
if ( in_array( 'current-menu-item', $item->classes ) && ('yes' === $this->mobile_menu_highlight) ) {
$item_a_class .= ' wpr-active-menu-item';
}
$output .= $indent .'';
$item_output = $args->before;
// Parent Item
if ( in_array( 'menu-item-has-children', $item->classes ) ) {
if ( ( in_array( 'current-menu-item', $item->classes ) || in_array( 'current-menu-ancestor', $item->classes ) ) && ('yes' === $this->mobile_menu_highlight) ) {
$item_a_class .= ' wpr-active-menu-item';
}
}
// Sub Menu Classes
if ( $depth > 0 ) {
$item_a_class = 'wpr-mobile-sub-menu-item';
if ( ( in_array( 'current-menu-item', $item->classes ) || in_array( 'current-menu-ancestor', $item->classes ) ) && ('yes' === $this->mobile_menu_highlight) ) {
$item_a_class .= ' wpr-active-menu-item';
}
}
$item_icon_html = '';
$item_badge_html = '';
// If has Settings
if ( $settings ) {
// Icon
if ( defined('WPR_ADDONS_PRO_VERSION') && wpr_fs()->can_use_premium_code() && '' !== $settings['wpr_mm_icon_picker'] ) {
$font_size = '' !== $settings['wpr_mm_icon_size'] ? $settings['wpr_mm_icon_size'] .'px' : 'inherit';
$color = '' !== $settings['wpr_mm_icon_color'] ? $settings['wpr_mm_icon_color'] : 'inherit';
$item_icon_style = 'style="font-size: '. $font_size .'; color: '. $color .'"';
$item_icon_html = '';
}
// Badge
if ( defined('WPR_ADDONS_PRO_VERSION') && wpr_fs()->can_use_premium_code() && '' !== $settings['wpr_mm_badge_text'] ) {
$item_badge_style = 'color: '. $settings['wpr_mm_badge_color'] .';';
$item_badge_style .= 'background-color: '. $settings['wpr_mm_badge_bg_color'] .';';
$item_badge_html = '';
}
}
// Link Attributes
$atts = [];
$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 : '#';
$atts['class'] = $item_a_class;
$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 . '"';
}
}
// Link Output
$item_output .= '';
$item_output .= $item_icon_html;
$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
$item_output .= $item_badge_html;
$item_output .= in_array( 'menu-item-has-children', $item->classes ) || $this->has_mega_menu($item->ID) ? '' : '';
$item_output .= '';
$item_output .= $args->after;
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
}
public function end_el( &$output, $item, $depth = 0, $args = array() ) {
if ( 'mega-content' === $this->get_menu_item_type() && 0 < $depth ) {
return;
}
if ( $depth === 0 ) {
if ( $this->has_mega_menu($item->ID) ) {
// Get Settings
$settings = $this->get_mega_menu_settings($item->ID);
if ( 'ajax' === $settings['wpr_mm_render'] ) {
$output .= '';
} else {
$elementor = \Elementor\Plugin::instance();
$mega_id = get_post_meta( $item->ID, 'wpr-mega-menu-item', true);
$content = $elementor->frontend->get_builder_content_for_display($mega_id);
$output .= '';
}
}
$output .= "\n";
}
}
public function set_menu_item_type( $item_id = 0, $depth = 0 ) {
if ( 0 < $depth ) {
return;
}
$item_type = 'default-content';
if ( $this->has_mega_menu( $item_id ) ) {
$item_type = 'mega-content';
}
wp_cache_set( 'menu-item-type', $item_type, 'wpr-mega-menu' );
}
public function get_menu_item_type() {
return wp_cache_get( 'menu-item-type', 'wpr-mega-menu' );
}
public function has_mega_menu( $item_id ) {
$settings = get_post_meta( $item_id, 'wpr-mega-menu-settings', true);
$mega_content = defined('WPR_ADDONS_PRO_VERSION') && wpr_fs()->can_use_premium_code() && isset($settings['wpr_mm_mobile_content']) ? $settings['wpr_mm_mobile_content'] : 'mega';
return isset($settings['wpr_mm_enable']) && 'true' === $settings['wpr_mm_enable'] && 'mega' === $mega_content ? true : false;
}
public function get_mega_menu_settings( $item_id ) {
$settings = get_post_meta( $item_id, 'wpr-mega-menu-settings', true);
return ! empty($settings) ? $settings : false;
}
}