ID;
$template_id = get_post_meta($id, '_menu_item_nexus_mega_menu_template_id', true);
$is_mega = get_post_meta($id, '_menu_item_nexus_is_mega_menu', true);
if ($is_mega && $template_id) {
// Force has-children class
if (!in_array('menu-item-has-children', $element->classes)) {
$element->classes[] = 'menu-item-has-children';
}
$element->classes[] = 'nexus-mega-menu-item';
// Suppress native children because we are replacing them with a template
// We save them nicely just in case, but usually we just want to nuke them.
$children_elements[$id] = array();
}
return parent::display_element($element, $children_elements, $max_depth, $depth, $args, $output);
}
public function start_el(&$output, $item, $depth = 0, $args = null, $id = 0)
{
// We'll hook into 'nav_menu_item_title' or similar to inject the Icon?
// Or we can just modify $item->title before calling parent.
$icon_type = get_post_meta($item->ID, '_menu_item_nexus_icon_type', true); // Default is icon_class if empty
$icon_html = '';
if ($icon_type === 'image') {
$icon_id = get_post_meta($item->ID, '_menu_item_nexus_icon_image_id', true);
if ($icon_id) {
$img = wp_get_attachment_image_src($icon_id, 'thumbnail'); // Or full? Thumbnail usually fine for icons.
// If SVG, WP treats it as image but sometimes standard sizes might not work perfectly without SVG support plugin.
// We will fallback to full URL if thumbnail missing.
$url = $img ? $img[0] : wp_get_attachment_url($icon_id);
if ($url) {
// SVG/Image
$icon_html = '';
}
}
} else {
// Standard Class
$icon_class = get_post_meta($item->ID, '_menu_item_nexus_icon_class', true);
if (!empty($icon_class)) {
$icon_html = ' ';
}
}
if (!empty($icon_html)) {
$item->title = $icon_html . $item->title;
}
parent::start_el($output, $item, $depth, $args, $id);
// Now inject Mega Menu Content if needed
$template_id = get_post_meta($item->ID, '_menu_item_nexus_mega_menu_template_id', true);
$is_mega = get_post_meta($item->ID, '_menu_item_nexus_is_mega_menu', true);
$width_type = get_post_meta($item->ID, '_menu_item_nexus_mega_menu_width_type', true);
$custom_width = get_post_meta($item->ID, '_menu_item_nexus_mega_menu_custom_width', true); // For 'custom'
$container_width = get_post_meta($item->ID, '_menu_item_nexus_mega_menu_container_width', true); // For 'container' type if implies a specific value, or just use variable.
// User request: "container option will make the mega menu take the container size mentioned in the container width"
// This implies the USER inputs the width in a field called "Container Width" or matches the section.
// Let's assume user wants to input it or it uses a standard.
// "mentioned in the container width" -> Probably an input field added for this option.
if (empty($width_type))
$width_type = 'full';
if ($is_mega && $template_id && class_exists('\Elementor\Plugin')) {
$content = \Elementor\Plugin::instance()->frontend->get_builder_content_for_display($template_id);
$classes = array('nexus-mega-menu-container', 'sub-menu');
$styles = array();
if ($width_type === 'full') {
$classes[] = 'nexus-mega-menu-full-width';
// CSS will handle left:0, width:100% relative to wrapper or viewport depending on design
// CSS will handle left:0, width:100% relative to wrapper or viewport depending on design
} else if ($width_type === 'custom' && !empty($custom_width)) {
$classes[] = 'nexus-mega-menu-custom-width';
$styles[] = 'width: ' . esc_attr($custom_width);
} else if ($width_type === 'container') {
$classes[] = 'nexus-mega-menu-container-width';
// If there's a specific width user entered:
if (!empty($container_width)) {
$styles[] = '--nexus-mega-menu-max-width: ' . esc_attr($container_width);
}
}
$style_str = !empty($styles) ? ' style="' . implode(';', $styles) . '"' : '';
// Wrapper for the mega menu
$output .= '