settings->get( 'disable_megamenu' ) ) { add_filter( 'avada_menu_options', [ $this, 'add_megamenu_fields' ], 20, 4 ); } // Add the menu arrow highlights. add_filter( 'avada_menu_arrow_hightlight', [ $this, 'add_menu_arrow_highlight' ], 10, 2 ); // Add special menu items meta box. add_action( 'admin_head-nav-menus.php', [ $this, 'add_special_links_meta_box' ] ); } /** * Register megamenu javascript assets. * * @since 3.4 * @access public * @param string $hook The hook we're currently on. * @return void */ public function register_scripts( $hook ) { if ( 'nav-menus.php' === $hook ) { // Scripts. wp_enqueue_media(); wp_register_script( 'avada-megamenu', Avada::$template_dir_url . '/assets/admin/js/mega-menu.js', [], self::$theme_info->get( 'Version' ), false ); wp_enqueue_script( 'avada-megamenu' ); } } /** * Enqueue megamenu stylesheets * * @since 3.4 * @access public * @param string $hook The hook we're currently on. * @return void */ public function register_stylesheets( $hook ) { if ( 'nav-menus.php' === $hook ) { wp_enqueue_style( 'avada-megamenu', Avada::$template_dir_url . '/assets/css/mega-menu.css', false, self::$theme_info->get( 'Version' ) ); } } /** * Adds the menu button fields. * * @static * @access public * @since 6.0.0 * @return array. */ public static function menu_options_map() { return [ 'megamenu-style' => [ 'id' => 'megamenu-style', 'label' => esc_attr__( 'Menu First Level Style', 'Avada' ), 'choices' => [ '' => esc_attr__( 'Default Style', 'Avada' ), 'fusion-button-small' => esc_attr__( 'Button Small', 'Avada' ), 'fusion-button-medium' => esc_attr__( 'Button Medium', 'Avada' ), 'fusion-button-large' => esc_attr__( 'Button Large', 'Avada' ), 'fusion-button-xlarge' => esc_attr__( 'Button xLarge', 'Avada' ), ], 'description' => esc_attr__( 'Select to use normal text (default) for the parent level menu item, or a button. Button styles are controlled in Global Options > Avada Builder Elements.', 'Avada' ), 'type' => 'select', 'default' => '', 'save_id' => 'fusion_menu_style', ], 'megamenu-icon' => [ 'id' => 'megamenu-icon', 'label' => esc_attr__( 'Icon Select', 'Avada' ), 'description' => esc_attr__( 'Select an icon for your menu item. For top-level menu items, icon styles can be controlled in Global Options > Menu > Main Menu Icons.', 'Avada' ), 'type' => 'iconpicker', 'default' => '', ], 'megamenu-icononly' => [ 'id' => 'megamenu-icononly', 'label' => esc_attr__( 'Icon/Thumbnail Only', 'Avada' ), 'description' => esc_attr__( 'Turn on to only show the icon/image thumbnail while hiding the menu text. Important: this does not apply to the mobile menu.', 'Avada' ), 'type' => 'radio-buttonset', 'default' => 'off', 'choices' => [ 'icononly' => esc_attr__( 'On', 'Avada' ), 'off' => esc_attr__( 'Off', 'Avada' ), ], 'save_id' => 'fusion_menu_icononly', ], 'megamenu-highlight-label' => [ 'id' => 'megamenu-highlight-label', 'label' => esc_attr__( 'Menu Highlight Label', 'Avada' ), 'description' => esc_attr__( 'Set the highlight label for menu item.', 'Avada' ), 'type' => 'text', 'save_id' => 'fusion_highlight_label', ], 'megamenu-highlight-label-background' => [ 'id' => 'megamenu-highlight-label-background', /* translators: "" tags. */ 'label' => sprintf( esc_html__( '%1$sMenu Highlight Label Background Color%2$s%3$sCart Counter Background Color%4$s', 'Avada' ), '', '', '', '' ), /* translators: %1$s: tag. %2$s: "TGlobal Options" link. %3$s: tag. %4$s: tag. %5$s: tag. */ 'description' => sprintf( esc_html__( '%1$sSet the highlight label background color. To set a border radius, visit %2$s and modify the Menu Highlight Label Radius option.%3$s%4$s Set cart counter background color.%5$s', 'Avada' ), '', '' . esc_html__( 'Global Options', 'Avada' ) . '', '', '', '' ), 'type' => 'color-alpha', 'save_id' => 'fusion_highlight_label_background', 'dependency' => [ [ 'field' => 'megamenu-highlight-label', 'value' => '', 'comparison' => '!=', ], ], ], 'megamenu-highlight-label-color' => [ 'id' => 'megamenu-highlight-label-color', /* translators: "" tags. */ 'label' => sprintf( esc_html__( '%1$sMenu Highlight Label Text Color%2$s%3$sCart Counter Text Color%4$s', 'Avada' ), '', '', '', '' ), /* translators: "" tags. */ 'description' => sprintf( esc_html__( '%1$sSet the highlight label text color.%2$s%3$sSet the cart counter text color.%4$s', 'Avada' ), '', '', '', '' ), 'type' => 'color', 'save_id' => 'fusion_highlight_label_color', 'dependency' => [ [ 'field' => 'megamenu-highlight-label', 'value' => '', 'comparison' => '!=', ], ], ], 'megamenu-highlight-label-border-color' => [ 'id' => 'megamenu-highlight-label-border-color', /* translators: "" tags. */ 'label' => sprintf( esc_html__( '%1$sMenu Highlight Label Border Color%2$s%3$sCart Counter Border Color %4$s', 'Avada' ), '', '', '', '' ), /* translators: "" tags. */ 'description' => sprintf( esc_html__( '%1$sSet the highlight label border color.%2$s%3$Sset the cart counter border color.%4$s', 'Avada' ), '', '', '', '' ), 'type' => 'color', 'save_id' => 'fusion_highlight_label_border_color', 'dependency' => [ [ 'field' => 'megamenu-highlight-label', 'value' => '', 'comparison' => '!=', ], ], ], 'megamenu-modal' => [ 'id' => 'megamenu-modal', 'label' => esc_attr__( 'Modal Window Anchor', 'Avada' ), 'description' => esc_attr__( 'Add the class name of the modal window you want to open on menu item click.', 'Avada' ), 'type' => 'text', ], ]; } /** * Adds Avada special menu items meta box. * * @since 7.0 * @access public * @return void */ public function add_special_links_meta_box() { add_meta_box( 'avada_special_items_nav_link', __( 'Avada Special Menu Items', 'Avada' ), [ $this, 'special_menut_items' ], 'nav-menus', 'side', 'low' ); } /** * Outputs contents of Avada special menu items meta box. * * @since 7.0 * @access public * @return void */ public function special_menut_items() { ?>
IMPORTANT NOTE: These items only work in Avada Builder Menu element.', 'Avada' ); // phpcs:ignore WordPress.Security.EscapeOutput ?>
    esc_html__( 'Search', 'Avada' ), '#fusion-sliding-bar-toggle' => esc_html__( 'Sliding Bar Toggle', 'Avada' ), ]; if ( class_exists( 'WooCommerce' ) ) { $endpoints['#fusion-woo-cart'] = esc_html__( 'WooCommerce Cart', 'Avada' ); $endpoints['#fusion-woo-my-account'] = esc_html__( 'WooCommerce My Account', 'Avada' ); } $i = -1; foreach ( $endpoints as $key => $value ) : ?>

[ 'id' => 'fusion-megamenu-special-link', 'label' => esc_attr__( 'Special Link Type', 'Avada' ), 'description' => esc_attr__( 'Select to add a special link type.', 'Avada' ), 'type' => 'hidden', 'value' => 0 === $depth ? ltrim( $item_url, '#' ) : '', 'save_id' => 'fusion_special_link', ], 'megamenu-show-woo-cart-counter' => [ 'id' => 'megamenu-show-woo-cart-counter', 'label' => esc_attr__( 'Show WooCommerce Cart Counter', 'Avada' ), 'description' => esc_attr__( 'Turn on to only show the cart products counter.', 'Avada' ), 'type' => 'radio-buttonset', 'default' => 'no', 'choices' => [ 'yes' => esc_attr__( 'On', 'Avada' ), 'no' => esc_attr__( 'Off', 'Avada' ), ], 'save_id' => 'fusion_show_woo_cart_counter', 'dependency' => [ [ 'field' => 'fusion-megamenu-special-link', 'value' => 'fusion-woo-cart', 'comparison' => '==', ], ], ], 'megamenu-show-woo-cart-contents' => [ 'id' => 'megamenu-show-woo-cart-contents', 'label' => esc_attr__( 'Show WooCommerce Cart Contents Dropdown', 'Avada' ), 'description' => esc_attr__( 'Turn on to show the cart contents dropdown.', 'Avada' ), 'type' => 'radio-buttonset', 'default' => 'no', 'choices' => [ 'yes' => esc_attr__( 'On', 'Avada' ), 'no' => esc_attr__( 'Off', 'Avada' ), ], 'save_id' => 'fusion_show_woo_cart_contents', 'dependency' => [ [ 'field' => 'fusion-megamenu-special-link', 'value' => 'fusion-woo-cart', 'comparison' => '==', ], ], ], 'megamenu-searchform-mode' => [ 'id' => 'megamenu-searchform-mode', 'label' => esc_html__( 'Search-Form Mode', 'Avada' ), 'description' => esc_html__( 'Select how your search-form will be displayed.', 'Avada' ), 'type' => 'radio-buttonset', 'default' => 'inline', 'choices' => [ 'inline' => esc_html__( 'Inline', 'Avada' ), 'dropdown' => esc_html__( 'Dropdown', 'Avada' ), 'overlay' => esc_html__( 'Overlay', 'Avada' ), ], 'save_id' => 'fusion_searchform_mode', 'dependency' => [ [ 'field' => 'fusion-megamenu-special-link', 'value' => 'fusion-search', 'comparison' => '==', ], ], ], ]; return array_merge( $custom_fields, $fields ); } /** * Adds the megamenu fields. * * @access public * @since 6.0.0 * @param array $fields Current fields map. * @return array. */ public function add_megamenu_fields( $fields ) { global $wp_registered_sidebars; $sidebars = [ '0' => esc_attr__( 'Select Widget Area', 'Avada' ), ]; if ( ! empty( $wp_registered_sidebars ) && is_array( $wp_registered_sidebars ) ) { foreach ( $wp_registered_sidebars as $sidebar ) { $sidebars[ esc_attr( $sidebar['id'] ) ] = esc_attr( $sidebar['name'] ); } } $mega_fields = [ 'megamenu-status' => [ 'id' => 'megamenu-status', 'label' => esc_html__( 'Fusion Mega Menu', 'Avada' ), 'choices' => [ 'enabled' => esc_attr__( 'On', 'Avada' ), 'off' => esc_attr__( 'Off', 'Avada' ), ], 'description' => esc_html__( 'Turn on to enable the mega menu. Note this will only work for the main menu.', 'Avada' ), 'type' => 'radio-buttonset', 'default' => 'off', 'dependency' => [ [ 'field' => 'depth', 'value' => '1', 'comparison' => '==', ], ], ], 'megamenu-background-image' => [ 'id' => 'megamenu-background-image', 'label' => esc_html__( 'Mega Menu / Flyout Menu Background Image', 'Avada' ), 'description' => __( 'Select an image for the mega menu or flyout menu background.
Mega Menu: In case of mega menu, if left empty, the Main Menu Dropdown Background Color will be used. Each mega menu column can have its own background image, or you can have one image that spreads across the entire mega menu width.
Flyout Menu: When used in the flyout menu, the image will be shown full screen when hovering the corresponding menu item.', 'Avada' ), 'type' => 'media', 'dependency' => [ [ 'field' => 'depth', 'value' => '3', 'comparison' => '<', ], [ 'field' => 'parent_megamenu-status', 'value' => 'enabled', 'comparison' => '==', ], ], ], 'megamenu-thumbnail' => [ 'id' => 'megamenu-thumbnail', 'label' => esc_html__( 'Mega Menu Thumbnail', 'Avada' ), 'description' => esc_html__( 'Select an image to use as a thumbnail for the menu item. For top-level items, the size of the thumbnail can be controlled in Global Options > Menu > Main Menu Icons.', 'Avada' ), 'type' => 'media', 'dependency' => [ [ 'field' => 'parent_megamenu-status', 'value' => 'enabled', 'comparison' => '==', ], ], ], 'megamenu-width' => [ 'id' => 'megamenu-width', 'label' => esc_attr__( 'Mega Menu Wrapper Width', 'Avada' ), 'choices' => [ 'fullwidth' => esc_attr__( 'Max Width', 'Avada' ), 'off' => esc_attr__( 'Fit Content', 'Avada' ), ], /* translators: %s: "Global Options" link. */ 'description' => sprintf( esc_attr__( 'Controls the width of mega menu. In case of max width, it is taken from the site width option in %s. Note this overrides the column width option.', 'Avada' ), '' . esc_html__( 'Global Options', 'Avada' ) . '' ), 'type' => 'radio-buttonset', 'default' => 'off', 'dependency' => [ [ 'field' => 'depth', 'value' => '1', 'comparison' => '==', ], [ 'field' => 'megamenu-status', 'value' => 'enabled', 'comparison' => '==', ], ], ], 'megamenu-columns' => [ 'id' => 'megamenu-columns', 'label' => esc_attr__( 'Mega Menu Number of Columns', 'Avada' ), 'choices' => [ 'auto' => esc_attr__( 'Auto', 'Avada' ), '1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5', '6' => '6', ], 'description' => esc_attr__( 'Select the number of columns you want to use.', 'Avada' ), 'type' => 'select', 'default' => 'auto', 'dependency' => [ [ 'field' => 'depth', 'value' => '1', 'comparison' => '==', ], [ 'field' => 'megamenu-status', 'value' => 'enabled', 'comparison' => '==', ], ], ], 'megamenu-columnwidth' => [ 'id' => 'megamenu-columnwidth', 'label' => esc_attr__( 'Mega Menu Column Width', 'Avada' ), 'description' => esc_attr__( 'Set the width of the column. In percentage, ex 60%.', 'Avada' ), 'type' => 'text', 'dependency' => [ [ 'field' => 'depth', 'value' => '2', 'comparison' => '==', ], [ 'field' => 'parent_megamenu-status', 'value' => 'enabled', 'comparison' => '==', ], [ 'field' => 'parent_megamenu-width', 'value' => 'fullwidth', 'comparison' => '!=', ], ], ], 'megamenu-title' => [ 'id' => 'megamenu-title', 'label' => esc_attr__( 'Mega Menu Column Title', 'Avada' ), 'choices' => [ 'enabled' => esc_attr__( 'On', 'Avada' ), 'disabled' => esc_attr__( 'Off', 'Avada' ), ], 'description' => esc_attr__( 'Turn on to display item as linked column title. Turn off to display item as normal mega menu entry.', 'Avada' ), 'type' => 'radio-buttonset', 'default' => 'enabled', 'dependency' => [ [ 'field' => 'depth', 'value' => '2', 'comparison' => '==', ], [ 'field' => 'parent_megamenu-status', 'value' => 'enabled', 'comparison' => '==', ], ], ], 'megamenu-widgetarea' => [ 'id' => 'megamenu-widgetarea', 'label' => esc_attr__( 'Mega Menu Widget Area', 'Avada' ), 'choices' => $sidebars, 'description' => esc_attr__( 'Select a widget area to be used as the content for the column.', 'Avada' ), 'type' => 'select', 'default' => '0', 'dependency' => [ [ 'field' => 'depth', 'value' => '1', 'comparison' => '>', ], [ 'field' => 'depth', 'value' => '4', 'comparison' => '<', ], [ 'field' => 'parent_megamenu-status', 'value' => 'enabled', 'comparison' => '==', ], ], ], ]; return array_merge( $fields, $mega_fields ); } /** * Adds the markup for the options. * * @access public * @since 6.0.0 * @param string $item_id The ID of the menu item. * @param object $item The menu item object. * @param int $depth The menu item depth (starts at 0). * @return void. */ public function parse_options( $item_id, $item, $depth ) { $fields = self::menu_options_map(); $specials = [ '#fusion-woo-cart', '#fusion-woo-my-account', '#fusion-search', '#fusion-sliding-bar-toggle' ]; // Add special-links options. if ( isset( $item->object ) && 'custom' === $item->object && in_array( $item->url, $specials, true ) ) { $fields = self::special_link_options_map( $fields, $item->url, $depth ); // Do not show URL field for special links options. $this->hide_url_field( $item->ID ); } $fields = apply_filters( 'avada_menu_options', $fields ); if ( is_array( $fields ) ) { foreach ( $fields as $field ) { // Defaults. $field['id'] = isset( $field['id'] ) ? $field['id'] : ''; $field['label'] = isset( $field['label'] ) ? $field['label'] : ''; $field['choices'] = isset( $field['choices'] ) ? $field['choices'] : []; $field['description'] = isset( $field['description'] ) ? $field['description'] : ''; $field['default'] = isset( $field['default'] ) ? $field['default'] : ''; $field['dependency'] = isset( $field['dependency'] ) ? $field['dependency'] : []; $field['save_id'] = isset( $field['save_id'] ) ? $field['save_id'] : 'fusion_' . str_replace( '-', '_', $field['id'] ); if ( isset( $field['type'] ) ) { switch ( $field['type'] ) { case 'text': $this->text( $field['id'], $field['label'], $field['description'], $field['dependency'], $item_id, $item, $field['save_id'] ); break; case 'hidden': $this->hidden( $field['id'], $item_id, $item, $field['value'] ); break; case 'radio-buttonset': $this->radio_buttonset( $field['id'], $field['label'], $field['choices'], $field['description'], $field['default'], $field['dependency'], $item_id, $item, $field['save_id'] ); break; case 'select': $this->select( $field['id'], $field['label'], $field['choices'], $field['description'], $field['default'], $field['dependency'], $item_id, $item, $field['save_id'] ); break; case 'color-alpha': $this->color_alpha( $field['id'], $field['label'], $field['description'], $field['default'], $field['dependency'], $item_id, $item, $field['save_id'] ); break; case 'color': $this->color( $field['id'], $field['label'], $field['description'], $field['default'], $field['dependency'], $item_id, $item, $field['save_id'] ); break; case 'media': $this->media( $field['id'], $field['label'], $field['description'], $field['dependency'], $item_id, $item, $field['save_id'] ); break; case 'iconpicker': $this->iconpicker( $field['id'], $field['label'], $field['description'], $field['dependency'], $item_id, $item, $field['save_id'] ); break; } } } } } /** * Text controls. * * @access public * @since 6.0.0 * @param string $id The ID. * @param string $label The label. * @param string $desc The description. * @param array $dependency The dependencies array. * @param string $item_id The ID of the menu item. * @param object $item The menu item object. * @param string $save_id The save ID if it is different from ID. */ public function text( $id, $label, $desc = '', $dependency = [], $item_id, $item, $save_id ) { ?>

$label ) : ?> { $save_id } ) ? $item->{ $save_id } : $default; ?>

color_alpha( $id, $label, $desc, $default, $dependency, $item_id, $item, $save_id ); } /** * Media field. * * @access public * @since 6.0.0 * @param string $id ID of input field. * @param string $label Label of field. * @param string $desc Description of field. * @param array $dependency The dependencies array. * @param string $item_id The ID of the menu item. * @param object $item The menu item object. * @param string $save_id The save ID if it is different from ID. */ public function media( $id, $label, $desc = '', $dependency = [], $item_id, $item, $save_id ) { $media_id = str_replace( 'megamenu-', '', $id ); ?>

fusion_megamenu_thumbnail ) ? $item->fusion_megamenu_thumbnail_id : 0; if ( ! $thumbnail_id && isset( $item->fusion_megamenu_thumbnail ) && '' !== $item->fusion_megamenu_thumbnail ) { $thumbnail_id = Fusion_Images::get_attachment_id_from_url( $item->fusion_megamenu_thumbnail ); } ?>
fusion_megamenu_thumbnail ) ) ? 'style="display:inline;"' : ''; ?>" />
settings->get( 'menu_highlight_style' ); $header_layout = Avada()->settings->get( 'header_layout' ); $svg = ''; if ( 'arrow' === $menu_highlight_style && 'v6' !== $header_layout ) { $header_position = fusion_get_option( 'header_position' ); $svg_height = Fusion_Sanitize::size( Avada()->settings->get( 'menu_arrow_size', 'height' ) ); $svg_height_int = intval( $svg_height ); $svg_width = Fusion_Sanitize::size( Avada()->settings->get( 'menu_arrow_size', 'width' ) ); $svg_width_int = intval( $svg_width ); $svg_bg = 'fill="' . Fusion_Sanitize::color( fusion_get_option( 'header_bg_color' ) ) . '"'; $svg_border = ''; $header_2_3_border = ( 'v2' === $header_layout || 'v3' === $header_layout ); $header_4_5_border = ( ( 'v4' === $header_layout || 'v5' === $header_layout ) && 1 === Fusion_Color::new_color( Fusion_Sanitize::color( fusion_get_option( 'header_bg_color' ) ) )->alpha ); if ( 'top' !== $header_position || $header_2_3_border || $header_4_5_border ) { $svg_border = 'class="header_border_color_stroke" stroke-width="1"'; } if ( 'left' === $header_position ) { $svg = ' '; } elseif ( 'right' === $header_position ) { $svg = ' '; } elseif ( 'top' === $header_position ) { $svg = ' '; } // Add svg markup for dropdown. if ( $has_children ) { $svg_bg = 'fill="' . Fusion_Sanitize::color( Avada()->settings->get( 'menu_sub_bg_color' ) ) . '"'; if ( 'top' === $header_position ) { $dropdownsvg = ' '; } elseif ( 'left' === $header_position ) { $dropdownsvg = ' '; } elseif ( 'right' === $header_position ) { $dropdownsvg = ' '; } $svg = $svg . $dropdownsvg; } } return $title . $svg; } } } /* Omit closing PHP tag to avoid "Headers already sent" issues. */