args = array_merge( [ 'megamenu_width' => fusion_get_option( 'megamenu_width' ), 'megamenu_interior_content_width' => fusion_get_option( 'megamenu_interior_content_width' ), 'site_width' => fusion_get_option( 'site_width' ), 'megamenu_max_width' => fusion_get_option( 'megamenu_max_width' ), 'menu_icon_position' => fusion_get_option( 'menu_icon_position' ), 'disable_megamenu' => fusion_get_option( 'disable_megamenu' ), 'button_type' => fusion_get_option( 'button_type' ), 'submenu_mode' => 'dropdown', 'transition_type' => '', 'direction' => 'row', 'expand_method' => 'hover', 'accordion_expand_method' => 'click', 'lazy_load' => 'avada' === fusion_get_option( 'lazy_load' ), 'arrows' => '', 'arrow_border' => false, 'click_spacing' => false, 'submenu' => false, ], $args ); if ( $this->args['submenu'] ) { $this->class_base = 'awb-submenu'; } } /** * Start level. * * @see Walker::start_lvl() * @since 3.0.0 * * @param string $output Passed by reference. Used to append additional content. * @param int $depth Depth of page. Used for padding. * @param array $args Not used. */ public function start_lvl( &$output, $depth = 0, $args = [] ) { if ( 0 === $depth && 'enabled' === $this->menu_megamenu_status ) { $output .= '{first_level}'; $output .= '
'; $col_span = ' col-span-' . $this->max_num_of_columns * 2; if ( $this->total_num_of_columns < $this->max_num_of_columns ) { $col_span = ' col-span-' . $this->total_num_of_columns * 2; } $total_column_width_per_row = []; foreach ( $this->menu_megamenu_rowwidth_matrix as $row => $columns ) { $total_column_width_per_row[ $row ] = array_sum( $columns ); } $max_row_width = max( $total_column_width_per_row ); $megamenu_interior_width = '"'; // Set overall width of megamenu. $megamenu_width = $this->args['megamenu_width']; if ( 'viewport_width' === $megamenu_width ) { $this->menu_megamenu_maxwidth = '100vw'; $wrapper_width = ( $max_row_width * 100 ) . 'vw'; if ( 'site_width' === $this->args['megamenu_interior_content_width'] && 'fullwidth' === $this->menu_megamenu_width ) { $megamenu_interior_width = ' fusion-megamenu-sitewidth" style="margin: 0 auto;width: 100%;max-width: ' . str_replace( '%', 'vw', $this->args['site_width'] ) . ';"'; } } elseif ( 'site_width' === $megamenu_width ) { $this->menu_megamenu_maxwidth = str_replace( '%', 'vw', $this->args['site_width'] ); if ( false === strpos( $this->menu_megamenu_maxwidth, 'calc' ) ) { $wrapper_width = ( $max_row_width * Fusion_Sanitize::number( $this->menu_megamenu_maxwidth ) ) . Fusion_Sanitize::get_unit( $this->menu_megamenu_maxwidth ); } else { $wrapper_width = 'calc(' . $max_row_width . ' * (' . str_replace( [ 'calc(', ')' ], [ '', '' ], $this->menu_megamenu_maxwidth ) . '))'; } } else { $this->menu_megamenu_maxwidth = (int) $this->args['megamenu_max_width'] . 'px'; $wrapper_width = ( $max_row_width * (int) $this->menu_megamenu_maxwidth ) . 'px'; } if ( 'fullwidth' === $this->menu_megamenu_width ) { $col_span = ' col-span-12 fusion-megamenu-fullwidth'; if ( 'site_width' === $megamenu_width ) { $col_span .= ' fusion-megamenu-width-site-width'; } // Overall megamenu wrapper width in px is max width for fullwidth megamenu. $wrapper_width = $this->menu_megamenu_maxwidth; } $background_image = ''; $data_bg = ''; if ( ! empty( $this->menu_megamenu_background_image ) ) { if ( $this->args['lazy_load'] ) { $data_bg = ' data-bg="' . $this->menu_megamenu_background_image . '"'; } else { $background_image .= ';background-image: url(' . $this->menu_megamenu_background_image . ');'; } } $output = str_replace( '{first_level}', '
', $output ); $output = str_replace( '{megamenu_final_width}', 'style="width:' . $wrapper_width . $background_image . ';"' . $data_bg . ' data-width="' . $wrapper_width . '"', $output ); $output = str_replace( '{megamenu_interior_width}', $megamenu_interior_width, $output ); $output = str_replace( '{fusion_all_widgets}', $this->total_num_of_widgets === $this->total_num_of_columns ? 'fusion-has-all-widgets' : '', $output ); $replacement = ( $this->total_num_of_columns > $this->max_num_of_columns ) ? ' fusion-megamenu-border' : ''; $output = str_replace( '{megamenu_border}', $replacement, $output ); foreach ( $this->submenu_matrix as $row => $columns ) { $layout_columns = 12 / $columns; $layout_columns = ( 5 === $columns ) ? 2 : $layout_columns; $replacement = 'fusion-megamenu-row-columns-' . $columns; $replacement .= ( ( $row - 1 ) * $this->max_num_of_columns + $columns < $this->total_num_of_columns ) ? ' fusion-megamenu-border' : ''; $output = str_replace( '{row_number_' . $row . '}', $replacement, $output ); $replacement = ( count( $this->submenu_matrix ) === $row ) ? '' : 'fusion-megamenu-border'; $output = str_replace( '{force_row_border_' . $row . '}', $replacement, $output ); $output = str_replace( '{current_row_' . $row . '}', 'fusion-megamenu-columns-' . $columns . ' col-lg-' . $layout_columns . ' col-md-' . $layout_columns . ' col-sm-' . $layout_columns, $output ); $output = str_replace( '{fusion_columns}', 'fusion-columns-' . $columns . ' columns-per-row-' . $columns, $output ); } foreach ( $this->menu_megamenu_rowwidth_matrix as $row => $columns ) { foreach ( $columns as $column => $column_width ) { $weighted_width = ( 100 / $max_row_width * $column_width ) . '%'; $output = str_replace( '{column_width_' . $row . '_' . $column . '}', $weighted_width, $output ); } } // Regular ul close. } else { $output .= ''; } } /** * Start element. * * @see Walker::start_el() * @since 3.0.0 * * @param string $output Passed by reference. Used to append additional content. * @param object $item Menu item data object. * @param int $depth Depth of menu item. Used for padding. * @param stdClass $args The arguments. * @param int $id Menu item ID. */ public function start_el( &$output, $item, $depth = 0, $args = [], $id = 0 ) { $item_output = ''; $class_columns = ''; $menu_highlight_label = ''; $is_rtl = is_rtl(); $menu_icon_position = $this->args['menu_icon_position']; $submenu_mode = $this->args['submenu_mode']; $expand_method = $this->args['expand_method']; $accordion_expand_method = $this->args['accordion_expand_method']; $transition_type = $this->args['transition_type']; $this->add_mega_menu_to_end = false; $submenu_disallowed_special_items = [ 'fusion-search', 'fusion-woo-my-account', 'fusion-woo-cart' ]; /** * Filters the arguments for a single nav menu item. * * @since 4.4.0 * * @param stdClass $args An object of wp_nav_menu() arguments. * @param WP_Post $item Menu item data object. * @param int $depth Depth of menu item. Used for padding. */ $args = apply_filters( 'nav_menu_item_args', $args, $item, $depth ); if ( null === $item->menu_item_parent ) { $item->menu_item_parent = '0'; } if ( ! $this->top_level_menu_items_count && 'flyout' === $this->args['submenu_mode'] ) { $menu_elements = wp_get_nav_menu_items( $args->menu, [ 'meta_key' => '_menu_item_menu_item_parent', // phpcs:ignore WordPress.DB.SlowDBQuery 'meta_value' => '0', // phpcs:ignore WordPress.DB.SlowDBQuery ] ); // Array of menu item types we don't consider as 'top level' menu items. $exclude_menu_items = apply_filters( 'fusion_exclude_top_menu_items', [ 'wpml_ls_menu_item' ] ); if ( is_array( $menu_elements ) ) { foreach ( $menu_elements as $key => $menu_element ) { if ( isset( $menu_element->type ) && in_array( $menu_element->type, $exclude_menu_items, true ) ) { unset( $menu_elements[ $key ] ); } } $this->top_level_menu_items_count = count( $menu_elements ); foreach ( $menu_elements as $menu_element ) { if ( null === $menu_element->menu_item_parent ) { $menu_element->menu_item_parent = '0'; } } } } // Set some vars. $meta_data = get_post_meta( $item->ID ); $fusion_meta = ! empty( $meta_data['_menu_item_fusion_megamenu'][0] ) ? maybe_unserialize( $meta_data['_menu_item_fusion_megamenu'][0] ) : []; $fusion_meta = apply_filters( 'avada_menu_meta', $fusion_meta, $item->ID ); $show_cart_contents = false; $inline_search = false; $search_dropdown = false; $this->menu_style = isset( $fusion_meta['style'] ) && 0 === $depth ? $fusion_meta['style'] : ''; $this->menu_megamenu_icon = isset( $fusion_meta['icon'] ) ? $fusion_meta['icon'] : ''; $this->menu_megamenu_modal = isset( $fusion_meta['modal'] ) ? $fusion_meta['modal'] : ''; $this->menu_title_only = isset( $fusion_meta['icononly'] ) ? $fusion_meta['icononly'] : ''; $this->fusion_highlight_label = isset( $fusion_meta['highlight_label'] ) ? $fusion_meta['highlight_label'] : ''; $this->fusion_highlight_label_background = isset( $fusion_meta['highlight_label_background'] ) ? $fusion_meta['highlight_label_background'] : ''; $this->fusion_highlight_label_color = isset( $fusion_meta['highlight_label_color'] ) ? $fusion_meta['highlight_label_color'] : ''; $this->fusion_highlight_label_border_color = isset( $fusion_meta['highlight_label_border_color'] ) ? $fusion_meta['highlight_label_border_color'] : ''; // Non legacy mega menu selection. $this->megamenu_select = isset( $fusion_meta['select'] ) && ! empty( $fusion_meta['select'] ) ? $fusion_meta['select'] : false; $megamenu_no_children = false; // Special case, mega menu with no children. if ( $this->megamenu_select && ! $args->has_children ) { // If mega menu and no children, hide caret. $megamenu_no_children = true; $args->has_children = true; $this->add_mega_menu_to_end = true; $item->classes[] = 'menu-item-has-children'; } // Skip disallowed special items in submenu element. if ( isset( $fusion_meta['special_link'] ) && in_array( $fusion_meta['special_link'], $submenu_disallowed_special_items, true ) && false !== strpos( $this->class_base, 'awb-submenu' ) ) { return; } // Thumbnail is not outside of mega menu scope. if ( ! empty( $fusion_meta['thumbnail'] ) ) { $thumbnail_id = isset( $fusion_meta['thumbnail_id'] ) ? $fusion_meta['thumbnail_id'] : 0; $thumbnail_data = fusion_library()->images->get_attachment_data_by_helper( $thumbnail_id, $fusion_meta['thumbnail'] ); if ( $thumbnail_data ) { $this->menu_megamenu_thumbnail = '' . $thumbnail_data['alt'] . ''; } else { $this->menu_megamenu_thumbnail = ''; } } else { $this->menu_megamenu_thumbnail = ''; } // Add the bg image markup for flyout menu items. if ( 1 === $depth && 'flyout' === $this->args['submenu_mode'] && isset( $fusion_meta['background_image'] ) && '' !== $fusion_meta['background_image'] ) { if ( $this->args['lazy_load'] ) { $this->flyout_menu_bg_markup .= '
'; } else { $this->flyout_menu_bg_markup .= '
'; } } if ( ! empty( $item->fusion_highlight_label ) ) { $highlight_style = ''; if ( ! empty( $item->fusion_highlight_label_background ) ) { $highlight_style .= 'background-color:' . $item->fusion_highlight_label_background . ';'; } if ( ! empty( $item->fusion_highlight_label_border_color ) ) { $highlight_style .= 'border-color:' . $item->fusion_highlight_label_border_color . ';'; } if ( ! empty( $item->fusion_highlight_label_color ) ) { $highlight_style .= 'color:' . $item->fusion_highlight_label_color . ';'; } $menu_highlight_label = '' . esc_html( $item->fusion_highlight_label ) . ''; } // Megamenu is enabled. if ( $this->args['disable_megamenu'] && ! $this->megamenu_select ) { if ( 0 === $depth ) { $this->menu_megamenu_status = isset( $fusion_meta['status'] ) ? $fusion_meta['status'] : 'disabled'; $this->menu_megamenu_width = isset( $fusion_meta['width'] ) ? $fusion_meta['width'] : ''; $allowed_columns = isset( $fusion_meta['columns'] ) ? $fusion_meta['columns'] : ''; if ( 'auto' !== $allowed_columns ) { $this->max_num_of_columns = (int) $allowed_columns; } $this->num_of_columns = 0; $this->total_num_of_columns = 0; $this->total_num_of_widgets = 0; $this->num_of_rows = 1; $this->menu_megamenu_rowwidth_matrix = []; $this->menu_megamenu_rowwidth_matrix[ $this->num_of_rows ] = []; $this->menu_megamenu_background_image = isset( $fusion_meta['background_image'] ) ? $fusion_meta['background_image'] : ''; } elseif ( 1 === $depth ) { $megamenu_column_background_image = isset( $fusion_meta['background_image'] ) ? $fusion_meta['background_image'] : ''; } $this->menu_megamenu_title = isset( $fusion_meta['title'] ) ? $fusion_meta['title'] : ''; $this->menu_megamenu_widgetarea = isset( $fusion_meta['widgetarea'] ) ? $fusion_meta['widgetarea'] : ''; // Megamenu is disabled. } else { $this->menu_megamenu_status = 'disabled'; } // We are inside a megamenu. if ( 1 === $depth && 'enabled' === $this->menu_megamenu_status ) { if ( isset( $fusion_meta['columnwidth'] ) && $fusion_meta['columnwidth'] ) { $this->menu_megamenu_columnwidth = floatval( $fusion_meta['columnwidth'] ) . '%'; } else { $this->menu_megamenu_columnwidth = '16.6666%'; if ( 'fullwidth' === $this->menu_megamenu_width && $this->max_num_of_columns ) { $this->menu_megamenu_columnwidth = 100 / $this->max_num_of_columns . '%'; } elseif ( 1 === $this->max_num_of_columns ) { $this->menu_megamenu_columnwidth = '100%'; } } $this->num_of_columns++; $this->total_num_of_columns++; // Check if we need to start a new row. if ( $this->num_of_columns > $this->max_num_of_columns || $this->previous_column_was_100_percent ) { $this->num_of_columns = 1; $this->num_of_rows++; $force_row_border = ''; if ( $this->previous_column_was_100_percent ) { $this->previous_column_was_100_percent = false; $force_row_border = ' {force_row_border_' . $this->num_of_rows . '}'; } $output .= '