Guest User

class.wp-megamenu

a guest
Nov 10th, 2020
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 34.32 KB | None | 0 0
  1. <?php
  2. /**
  3. * Class wp_megamenu
  4. */
  5.  
  6. if ( ! class_exists('wp_megamenu')) {
  7.  
  8.  
  9.     class wp_megamenu extends Walker_Nav_Menu {
  10.  
  11.         private $container_type = null;
  12.         private $wpmm_item_id = null;
  13.  
  14.         function start_lvl(&$output, $depth = 0, $args = array()) {
  15.             //In a child UL, add the 'wp-megamenu-submenu' class
  16.             $indent = str_repeat("\t", $depth);
  17.  
  18.             $is_row_content_strees_extra_div = '';
  19.             if ($this->container_type === 'wpmm-strees-row-and-content'){
  20.                 $is_row_content_strees_extra_div = "<div class='wpmm-row-content-strees-extra'></div> ";
  21.             }
  22.  
  23.             if ($this->container_type === 'wpmm-strees-row' || $this->container_type === 'wpmm-strees-row-and-content' ){
  24.                 $output .= "\n{$indent}<div id='{$this->wpmm_item_id}' class='{$this->container_type}-container'> {$is_row_content_strees_extra_div} <ul class=\"wp-megamenu-sub-menu\">\n";
  25.             }else{
  26.                 $output .= "\n{$indent}<ul class=\"wp-megamenu-sub-menu\" >\n";
  27.             }
  28.         }
  29.  
  30.         function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0) {
  31.  
  32.             global $wp_query;
  33.  
  34.             $nav_term_id            = $args->menu->term_id;
  35.             $theme_id               = wpmm_theme_by_selected_nav_id($nav_term_id);
  36.             $theme_options_array    = get_wpmm_theme_full_options_as_array($theme_id);
  37.             $display_mode           = get_wpmm_theme_option_from_array('display_mode', $theme_options_array);
  38.             $wpmm_item_settings     = maybe_unserialize(get_post_meta($item->ID, 'wpmm_layout', true));
  39.  
  40.             if(! empty($wpmm_item_settings['options']['logged_in_only']) && !is_user_logged_in()){
  41.                 return;
  42.             }
  43.  
  44.             $item_center_logo_url = false;
  45.             $item_center_logo_type = false;
  46.             if ( ! empty($wpmm_item_settings['options']['mark_as_logo'])){
  47.                 if ($wpmm_item_settings['options']['mark_as_logo'] === 'enable'){
  48.                     $item_center_logo_type = $wpmm_item_settings['options']['item_logo_type'];
  49.  
  50.                     if ($item_center_logo_type === 'image'){
  51.                         $item_center_logo_url = $wpmm_item_settings['options']['item_logo_url'];
  52.                     }
  53.  
  54.                     if ($item_center_logo_type === 'text'){
  55.                         $item_center_logo_text = $wpmm_item_settings['options']['item_logo_text'];
  56.                     }
  57.  
  58.                 }
  59.             }
  60.  
  61.             $indent = ($depth) ? str_repeat("\t", $depth) : '';
  62.  
  63.             $li_attributes = '';
  64.             $class_names = $value = '';
  65.  
  66.             $classes = empty($item->classes) ? array() : (array)$item->classes;
  67.             $classes[] = 'wp-megamenu-item-' . $item->ID;
  68.  
  69.             if ($item_center_logo_url){
  70.                 $classes[] = 'wpmm-logo-item wp-megamenu-item-logo-' . $item->ID;;
  71.             }
  72.  
  73.             $item_a_class = array();
  74.             if ($depth ==0){
  75.                 $wpmm_menu_type = empty($wpmm_item_settings['menu_type']) ? ' wpmm_dropdown_menu ': " {$wpmm_item_settings['menu_type']} ";
  76.                 $classes[] = $wpmm_menu_type;
  77.  
  78.                 if ( ! empty($theme_options_array['animation_type']) ){
  79.                     $classes[] = 'wpmm-'.$theme_options_array['animation_type'];
  80.                 }
  81.  
  82.                 $wpmm_ite_fixed_width = '';
  83.                 if (is_array($wpmm_item_settings) &&  ! empty($wpmm_item_settings['options']['strees_row_width']) ){
  84.                     $wpmm_ite_fixed_width = 'wpmm-item-fixed-width';
  85.                 }
  86.                 if (! empty($wpmm_item_settings['menu_strees_row']) ){
  87.                     if ($wpmm_item_settings['menu_strees_row'] == 'wpmm-strees-default'){
  88.                         $classes[] = $wpmm_ite_fixed_width;
  89.                     }
  90.                 }else{
  91.                     $classes[] = $wpmm_ite_fixed_width;
  92.                 }
  93.  
  94.             }
  95.             if ($depth ==0 && ! empty($wpmm_item_settings['menu_strees_row'])){
  96.                 $this->container_type = $wpmm_item_settings['menu_strees_row'];
  97.                 $this->wpmm_item_id = 'wpmm-strees-row-'.$item->ID;
  98.                 $classes[] = $wpmm_item_settings['menu_strees_row'];
  99.             }else{
  100.                 $this->container_type = null;
  101.             }
  102.             if( $depth == 1 ) {
  103.                 if ( ! empty($item->wpmm_column_class)){
  104.                     $classes[] = " {$item->wpmm_column_class} " ;
  105.                 }
  106.             }
  107.  
  108.             if (is_array($wpmm_item_settings) &&  ! empty($wpmm_item_settings['options']['hide_item_on_mobile']) && $wpmm_item_settings['options']['hide_item_on_mobile'] === 'true' ){
  109.                 $classes[] = 'wpmm-hide-mobile';
  110.             }
  111.             if (is_array($wpmm_item_settings) &&  ! empty($wpmm_item_settings['options']['hide_item_on_desktop']) && $wpmm_item_settings['options']['hide_item_on_desktop'] === 'true' ){
  112.                 $classes[] = 'wpmm-hide-desktop';
  113.             }
  114.  
  115.             $item_id = 'wp-megamenu-item-' . $item->ID;
  116.  
  117.             if (is_array($wpmm_item_settings) &&  ! empty($wpmm_item_settings['options']['dropdown_alignment']) && $wpmm_item_settings['options']['dropdown_alignment'] === 'left' ){
  118.                 $classes[] = 'wpmm-submenu-left';
  119.             }else{
  120.                 $classes[] = 'wpmm-submenu-right';
  121.             }
  122.  
  123.             // Make sure you still add all of the WordPress classes.
  124.             $class_names = join(' ', apply_filters('nav_menu_css_class', array_filter($classes), $item, $args));
  125.             $class_names = ' class="' . esc_attr($class_names) . '"';
  126.  
  127.             $id = apply_filters('nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args);
  128.             $id = strlen($id) ? ' id="' . esc_attr($item_id) . '"' : '';
  129.  
  130.             $output .= $indent . '<li' . $id . $value . $class_names . $li_attributes . '>';
  131.  
  132.             $attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : '';
  133.             $attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : '';
  134.             $attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) .'"' : '';
  135.             $attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';
  136.  
  137.             /**
  138.              * Anchor class
  139.              */
  140.             $item_a_class = apply_filters('wpmm_item_anchor_classes', $item_a_class );
  141.             $menu_item_a_attributes = '';
  142.             if (count($item_a_class)) {
  143.                 $menu_item_a_attributes .= ' class="'.join(' ',$item_a_class).'" ';
  144.             }
  145.  
  146.             // Social Link Target
  147.             if ( ! empty($item->type) && $item->type === 'wpmm_social'){
  148.                 if ( empty($theme_options_array['social_links_target']) ||
  149.                      $theme_options_array['social_links_target'] !== '_self'){
  150.                     $attributes .= ' target="_blank" ';
  151.                 }else {
  152.                     $attributes .= ' target="_self" ';
  153.                 }
  154.             }else{
  155.                 $attributes .= !empty($item->target) ? ' target="' . esc_attr($item->target) . '"' : '';
  156.             }
  157.  
  158.             # Menu Items.
  159.             $item_output = '';
  160.  
  161.             if ($item->type === 'wpmm_row' || $item->type === 'wpmm_col'){
  162.                 $item_output = '';
  163.             } elseif ( $item->type === 'widget'){
  164.                 $item_output = $item->output;
  165.             }else {
  166.  
  167.                 $wpmm_icon = $icon_position = '';
  168.  
  169.                 if ( !empty( $wpmm_item_settings['options']['menu_icon_image'] ) ) {
  170.                     $wpmm_icon .= "<span class='wpmm-image-icon wpmm-selected-icon {$icon_position}'>";
  171.                         $wpmm_icon .= "<img class='custom-menu-image' src='{$wpmm_item_settings['options']['menu_icon_image']}'>";
  172.                     $wpmm_icon .= "</span>";
  173.                 } else {
  174.                     if (is_array($wpmm_item_settings) &&  ! empty($wpmm_item_settings['options']['icon'])){
  175.                        
  176.                         if ( ! empty($wpmm_item_settings['options']['icon_position'])){
  177.                             $icon_position = 'wpmm-selected-icon-'.$wpmm_item_settings['options']['icon_position'];
  178.                         }
  179.                         $wpmm_icon .= "<span class='wpmm-selected-icon {$icon_position}'><i class='{$wpmm_item_settings['options']['icon']}'></i></span>";
  180.                     }
  181.                 }
  182.  
  183.                 # Title.
  184.                $item_title = $args->link_before . apply_filters('the_title', $item->title, $item->ID) . $args->link_after;
  185.                 if ( is_array($wpmm_item_settings) && ! empty($wpmm_item_settings['options']['hide_text'])){
  186.                     if ($wpmm_item_settings['options']['hide_text'] == 'true'){
  187.                         $item_title = '';
  188.                     }
  189.                 }
  190.  
  191.                 $menu_href = !empty($item->url) ? ' href="' . esc_attr($item->url) . '"' : '';
  192.                 if (is_array($wpmm_item_settings) &&  ! empty($wpmm_item_settings['options']['disable_link'])){
  193.                     if ($wpmm_item_settings['options']['disable_link'] == 'true'){
  194.                         $menu_href = ' href="javascript:;" ';
  195.                     }
  196.                 }
  197.  
  198.                 $item_output .= '<a' . $attributes . '>';
  199.  
  200.                     if ($depth == 0 && $item_center_logo_type){
  201.                         if ($item_center_logo_type === 'image'){
  202.                             $item_output .= "<img src='{$item_center_logo_url}' />";
  203.                         }elseif($item_center_logo_type === 'text'){
  204.                             $item_output .= $item_center_logo_text;
  205.                         }
  206.                     }
  207.  
  208.                     if ( is_array($wpmm_item_settings) && ! empty($wpmm_item_settings['options']['icon_position'])){
  209.                         if ($wpmm_item_settings['options']['icon_position'] == 'left'){
  210.                             $item_output .= $wpmm_icon;
  211.                         }elseif ($wpmm_item_settings['options']['icon_position'] == 'top'){
  212.                             $item_output .= $wpmm_icon;
  213.                         }
  214.                     }else{
  215.                         $item_output .= $wpmm_icon;
  216.                     }
  217.  
  218.                     $item_output .= $item_title;
  219.  
  220.                     if ( is_array($wpmm_item_settings) &&  !empty($wpmm_item_settings['options']['icon_position']) ) {
  221.                         if ($wpmm_item_settings['options']['icon_position'] == 'right'){
  222.                             $item_output .= ' '.$wpmm_icon;
  223.                         }
  224.                     }
  225.  
  226.                     //Show dropdown menu indicator
  227.                     if (is_array($wpmm_item_settings)) {
  228.  
  229.                         if ( ! empty( $wpmm_item_settings['options']['hide_arrow'] ) && $wpmm_item_settings['options']['hide_arrow'] != 'true' ) {
  230.  
  231.                             if ( $depth == 0 && $args->has_children && ! empty( $theme_options_array['dropdown_arrow_down'] ) ) {
  232.                                 $item_output .= ' <b class="fa ' . $theme_options_array['dropdown_arrow_down'] . '"></b> ';
  233.                             } elseif ( $depth > 0 && $args->has_children && ! empty( $theme_options_array['dropdown_arrow_right'] ) ) {
  234.  
  235.                                 $right_arrow_caret = '<b class="fa fa-angle-right"></b>';
  236.                                 if ( ! empty( $theme_options_array['dropdown_arrow_right'] ) ) {
  237.                                     $right_arrow_caret = '<b class="fa ' . $theme_options_array['dropdown_arrow_right'] . '"></b>';
  238.                                 }
  239.                                 $left_arrow_caret = '<b class="fa fa-angle-left"></b>';
  240.                                 if ( ! empty( $theme_options_array['dropdown_arrow_left'] ) ) {
  241.                                     $left_arrow_caret = '<b class="fa ' . $theme_options_array['dropdown_arrow_left'] . '"></b>';
  242.                                 }
  243.  
  244.                                 //dropdown_alignment
  245.                                 if ( ! empty( $wpmm_item_settings['options']['dropdown_alignment'] ) ) {
  246.                                     $dropdown_alignment = $wpmm_item_settings['options']['dropdown_alignment'];
  247.  
  248.                                     if ( $dropdown_alignment === 'left' ) {
  249.                                         $item_output .= $left_arrow_caret;
  250.                                     } else {
  251.                                         $item_output .= $right_arrow_caret;
  252.                                     }
  253.                                 } else {
  254.                                     $item_output .= $right_arrow_caret;
  255.                                 }
  256.                                 //$item_output .= ' <b class="fa '.$theme_options_array['dropdown_arrow_right'].'"></b> ';
  257.                             }
  258.                         }
  259.  
  260.  
  261.                         if ( $args->has_children && empty( $wpmm_item_settings['options']['hide_arrow'] ) && ! empty( $theme_options_array['dropdown_arrow_down']
  262.                             ) ) {
  263.                             $item_output .= ' <b class="fa ' . $theme_options_array['dropdown_arrow_down'] . '"></b> ';
  264.                         }
  265.                     }else{ //Sett a
  266.                         if ( $args->has_children && empty( $wpmm_item_settings['options']['hide_arrow'] ) && ! empty( $theme_options_array['dropdown_arrow_down']) ) {
  267.                             $item_output .= ' <b class="fa ' . $theme_options_array['dropdown_arrow_down'] . '"></b> ';
  268.                         }
  269.                     }
  270.  
  271.                     # Print badge.
  272.                    if ( is_array($wpmm_item_settings) && ! empty($wpmm_item_settings['options']['badge_text']) ) {
  273.                         $item_output .= "<span class='wpmm-badge wpmm-badge-{$wpmm_item_settings['options']['badge_style']}'>{$wpmm_item_settings['options']['badge_text']}</span>";
  274.                     }
  275.  
  276.                     # Append Description.
  277.                    if ( isset( $item->description ) && ! empty( $item->description ) ) {
  278.                         if ( strlen($item->description) > 0 ) {
  279.                             $item_output .= sprintf('<span class="wpmm_item_description">%s</span>', esc_html($item->description));
  280.                         }
  281.                     }
  282.                    
  283.                 $item_output .= '</a>';
  284.  
  285.  
  286.                 $item_output .= $args->after;
  287.             }
  288.  
  289.             # Search item
  290.             $home_url                   = esc_url(home_url('/'));
  291.             $search_query               = get_search_query();
  292.             $enable_search_bar          = get_wpmm_theme_option('enable_search_bar', $theme_id);
  293.             $search_field_placeholder   = get_wpmm_theme_option('search_field_placeholder', $theme_id);
  294.             $search_placholder          = $search_field_placeholder ? $search_field_placeholder : __( "Search", "wp-megamenu" );
  295.  
  296.             $search_form = "
  297.                <form action='$home_url' method='get' role='search'>
  298.                     <div class='search-wrap'>
  299.                         <div class='search pull-right wpmm-top-search'>
  300.                             <input type='text' value='$search_query' name='s' id='s' class='form-control' placeholder='$search_placholder' autocomplete='off' />   
  301.                         </div>
  302.                     </div>
  303.                </form>  
  304.            ";
  305.  
  306.             if ($enable_search_bar == 'true' && $depth == 0 && $item->type === 'wpmm_search_form') {
  307.                 $item_output = "
  308.                     <div class='wpmm-search-wrap'>
  309.                         <a href='#' class='wpmm-search search-open-icon'><i class='fa fa-search'></i></a>
  310.                         <a href='#' class='wpmm-search search-close-icon'><i class='fa fa-times'></i></a>
  311.                         <div class='wpmm-search-input-wrap'>
  312.                             <div class='top-search-overlay'></div>
  313.                             $search_form
  314.                         </div>
  315.                     </div>
  316.                ";
  317.             }
  318.  
  319.  
  320.             # Login form
  321.            if (function_exists('wpmm_pro_init')){
  322.                 $enable_login_form  = get_wpmm_theme_option('enable_login_form', $theme_id);
  323.                 $login_signup       = get_wpmm_theme_option('login_signup', $theme_id);
  324.                 $login_text         = ( !empty( $login_signup ) ) ? $login_signup : 'Login/Signup';
  325.  
  326.                 // print_r($login_background_logo);
  327.                 $login_background_logo = get_wpmm_theme_option('login_background_logo', $theme_id);
  328.                 if (isset($login_background_logo)) {
  329.                     $theme_bg = $login_background_logo;
  330.                 }else {
  331.                     $theme_bg = '';
  332.                 }
  333.  
  334.                 if ($enable_login_form == 'true' && $depth == 0 && $item->type === 'wpmm_login_form') {
  335.                     if ( !empty($login_text) ) {
  336.                         if(is_user_logged_in()) {
  337.                             $item_output = "<a href='".wp_logout_url(home_url())."''>
  338.                                 <i class='fa fa-sign-out'></i>
  339.                                 ".esc_html__('Log out', 'wp-megamenu')."
  340.                             </a>";
  341.                         } else{
  342.                             $item_output = "<a class='show' aria-haspopup='true' href='#modal-login'><i class='fa fa-user-o'></i>$login_text</a>
  343.  
  344.                             <div class='wpmm-mask' role='dialog'></div>
  345.                                 <div class='cont'>
  346.                                     <button class='close' role='button'>&times;</button>
  347.                                     <div class='form sign-in'>
  348.                                         <h2>". __('Hey, Welcome Back!', 'wp-megamenu') ."</br>
  349.                                         <span>". __('Use your credentials to login to the website.', 'wp-megamenu') ."</span></h2>
  350.                                         <form id='login' action='login' method='post'>
  351.                                             <div class='login-error alert alert-danger' role='alert'></div>
  352.                                             <label>
  353.                                                 <input type='text'  id='usernamelogin' name='username' class='form-control' placeholder='Username'>
  354.                                             </label>
  355.  
  356.                                             <label>
  357.                                                 <input type='password' id='passwordlogin' name='password' class='form-control' placeholder='Password'>
  358.                                             </label>
  359.  
  360.                                             <label>
  361.                                                 <p class='forgot-pass'><input type='checkbox' id='rememberlogin' name='remember' >Remember me</p>
  362.                                             </label>
  363.  
  364.                                             <input type='submit' class='btn btn-primary submit_button submit'  value='Sign In' name='submit'>
  365.                                             ".wp_nonce_field( 'ajax-login-nonce', 'securitylogin' )."
  366.                                         </form>
  367.  
  368.                                         <span class='lost_password'>
  369.                                             <a href=".esc_url( wp_lostpassword_url() ).">".__( 'Lost your password?', 'wp-megamenu' )."</a>
  370.                                         </span>
  371.                                     </div>
  372.  
  373.                                     <div class='sub-cont'>
  374.                                         <div class='form sign-up'>
  375.                                             <h2>". __('Let’s start a journey!', 'wp-megamenu') ."
  376.                                             </br><span>". __('You’ll become a new member of our family by signing up.', 'wp-megamenu') ."</span></h2>
  377.                                             <form id='register' action='login' method='post'>
  378.                                                 <div class='login-error alert alert-danger' role='alert'></div>
  379.  
  380.                                                 <label>
  381.                                                     <input type='text' id='username' name='username' class='form-control' placeholder='Username'>
  382.                                                 </label>
  383.  
  384.                                                 <label>
  385.                                                     <input type='text' id='email' name='email' class='form-control' placeholder='Email'>
  386.                                                 </label>
  387.  
  388.                                                 <label>
  389.                                                     <input type='password' id='password' name='password' class='form-control' placeholder='Password'>
  390.                                                 </label>
  391.  
  392.                                                 <input type='submit' class='btn btn-primary submit_button submit'  value='Register' name='submit'>
  393.                                                 ".wp_nonce_field( 'ajax-register-nonce', 'security' )."
  394.                                             </form>
  395.                                         </div>
  396.  
  397.                                          
  398.                                         <div class='img' style='background-image: url(". $theme_bg ."); background-size: cover;background-position: 50% 50%;'>
  399.                                             <div class='img__text m--up'>
  400.                                                 <h2>Wanna Join?</h2>
  401.                                                 <p>Sign up to be a part of our family. Spoiler: we don’t spam.</p>
  402.                                             </div>
  403.                                             <div class='img__text m--in'>
  404.                                                 <h2>Log in!</h2>
  405.                                                 <p>Are you already a part of our family? Well, don’t wait up!</p>
  406.                                             </div>
  407.                                             <div class='img__btn'>
  408.                                                 <span class='m--up'>Sign Up</span>
  409.                                                 <span class='m--in'>Sign In</span>
  410.                                             </div>
  411.                                         </div>
  412.                                     </div>
  413.                                 </div>
  414.                             ";
  415.  
  416.                         }
  417.                     }
  418.                 }
  419.  
  420.                 # Woocart.
  421.                 $enable_woocart     = get_wpmm_theme_option('enable_woocart', $theme_id);
  422.                 if ($enable_woocart == 'true' && $depth == 0 && $item->type === 'wpmm_woo_cart') {     
  423.                     if ( class_exists( 'WooCommerce' ) ) {
  424.                         if( !is_cart() && !is_checkout()){
  425.                             $item_output = "<div class='wpmm-menu-cart'>
  426.                                     ".wpmm_header_cart()."
  427.                                     <div class='wpmm-widget-cart'>
  428.                                         ".wpmm_header_cart_widgets()."
  429.                                     </div>
  430.                                 </div> 
  431.                             ";
  432.                         }
  433.                     }
  434.                 }
  435.             }
  436.  
  437.  
  438.             // # Old Code.
  439.             // $search_form = "
  440.             //  <form class='wpmm-search-form' action='$home_url'>
  441.             //      <input type='text' placeholder='$search_placholder' name='s' />
  442.             //  </form>
  443.             // ";
  444.  
  445.             // #Menu Search bar enable from here
  446.             // if ($enable_search_bar == 'true' && $depth == 0 && $item->type === 'wpmm_search_form'){
  447.             //  $item_output = "<a href='#'> <i class='fa fa-search wpmm_search_icon'></i></a>";
  448.             //  $item_output .= $search_form;
  449.             // }
  450.  
  451.             $output .= apply_filters('walker_nav_menu_start_el', $item_output, $item, $depth, $args);
  452.            
  453.         }
  454.  
  455.         //Overwrite display_element function to add has_children attribute. Not needed in >= Wordpress 3.4
  456.         function display_element($element, &$children_elements, $max_depth, $depth = 0, $args, &$output){
  457.             if (!$element)
  458.                 return;
  459.  
  460.             //Add Twenty Fifteen Themes Support
  461.             if (!isset($element->description)){
  462.                 $element->description = '';
  463.             }
  464.             //End Twenty Fifteen Support
  465.  
  466.             $id_field = $this->db_fields['id'];
  467.  
  468.             //display this element
  469.             if (is_array($args[0]))
  470.                 $args[0]['has_children'] = !empty($children_elements[$element->$id_field]);
  471.             else if (is_object($args[0]))
  472.                 $args[0]->has_children = !empty($children_elements[$element->$id_field]);
  473.             $cb_args = array_merge(array(&$output, $element, $depth), $args);
  474.             call_user_func_array(array(&$this, 'start_el'), $cb_args);
  475.  
  476.             $id = $element->$id_field;
  477.  
  478.             // descend only when the depth is right and there are childrens for this element
  479.             if (($max_depth == 0 || $max_depth > $depth + 1) && isset($children_elements[$id])) {
  480.                 foreach ($children_elements[$id] as $child) {
  481.                     if (!isset($newlevel)) {
  482.                         $newlevel = true;
  483.                         //start the child delimiter
  484.                         $cb_args = array_merge(array(&$output, $depth), $args);
  485.                         call_user_func_array(array(&$this, 'start_lvl'), $cb_args);
  486.                     }
  487.                     $this->display_element($child, $children_elements, $max_depth, $depth + 1, $args, $output);
  488.                 }
  489.                 unset($children_elements[$id]);
  490.             }
  491.  
  492.             if (isset($newlevel) && $newlevel) {
  493.                 //end the child delimiter
  494.                 $cb_args = array_merge(array(&$output, $depth), $args);
  495.                 call_user_func_array(array(&$this, 'end_lvl'), $cb_args);
  496.  
  497.                 //$wpmm_item_settings = get_post_meta($element->ID, 'wpmm_layout', true);
  498.                 if ($depth ==0 && ($this->container_type === 'wpmm-strees-row' || $this->container_type === 'wpmm-strees-row-and-content' )  ) {
  499.                     $output .= '</div>';
  500.                 }
  501.             }
  502.             //end this element
  503.             $cb_args = array_merge(array(&$output, $element, $depth), $args);
  504.             $cb_args =
  505.  
  506.             call_user_func_array(array(&$this, 'end_el'), $cb_args);
  507.         }
  508.     }
  509. }
  510.  
  511.  
  512. add_filter('wp_nav_menu_args', 'overrite_functions_wp_megamenu', 9999);
  513. function overrite_functions_wp_megamenu($args){
  514.     if (empty($args['theme_location'])) {
  515.         return $args;
  516.     }
  517.  
  518.     $wpmm_db_version = get_option('WPMM_VER');
  519.     if (version_compare($wpmm_db_version, '1.1.1', '>')) {
  520.         $wpmm_options = get_option( 'wpmm_options' );
  521.         if ( empty( $wpmm_options[ $args['theme_location'] ]['is_enabled'] ) || $wpmm_options[ $args['theme_location'] ]['is_enabled'] != '1' ) {
  522.             return $args;
  523.         }
  524.     }
  525.     //Get Nav term id || Nav theme id by Location
  526.     $locations = get_nav_menu_locations();
  527.     $theme_id = null;
  528.     if ( ! empty($locations[ $args['theme_location'] ])){
  529.         $menu_id = $locations[ $args['theme_location'] ] ;
  530.         $wp_nav_menu_object = wp_get_nav_menu_object($menu_id);
  531.         $theme_id = wpmm_theme_by_selected_nav_id($wp_nav_menu_object->term_id);
  532.     }
  533.  
  534.     $sticky_class = '';
  535.     $menu_layout_class = '';
  536.     $menu_custom_class = '';
  537.     $brand_logo = '';
  538.     $logo_width = '';
  539.     $logo_height = '';
  540.     $toggle_btn_open_text = __('MENU', 'wp-megamenu');
  541.     $toggle_bar_close_icon = 'true';
  542.  
  543.  
  544.     if ($theme_id){
  545.  
  546.         $wpmm_orientation = get_wpmm_theme_option('wpmm_orientation', $theme_id);
  547.         $enable_sticky_menu = get_wpmm_theme_option('enable_sticky_menu', $theme_id);
  548.  
  549.         if($enable_sticky_menu == 'true'){ #OR $wpmm_orientation !== 'wpmm_vertical'
  550.            if( $wpmm_orientation != null ){
  551.                 $sticky_class = 'wpmm-sticky';
  552.             }
  553.         }
  554.  
  555.         $menu_layout = get_wpmm_theme_option('menu_layout', $theme_id);
  556.         if ($menu_layout){
  557.             $menu_layout_class = " wpmm-{$menu_layout} ";
  558.         }
  559.  
  560.         $menu_custom_class = get_wpmm_theme_option('wpmm_class', $theme_id);
  561.  
  562.         $brand_logo = get_wpmm_theme_option('brand_logo', $theme_id);
  563.         $brand_logo_width = get_wpmm_theme_option('brand_logo_width', $theme_id);
  564.         $brand_logo_height = get_wpmm_theme_option('brand_logo_height', $theme_id);
  565.         if ( ! empty($brand_logo_width)){
  566.             $logo_width = wpmm_unit_to_int($brand_logo_width);
  567.             $logo_width = " width='{$logo_width}px' ";
  568.         }
  569.         if ( ! empty($brand_logo_height)){
  570.             $logo_height = wpmm_unit_to_int($brand_logo_height);
  571.             $logo_height = " height='{$logo_height}px' ";
  572.         }
  573.  
  574.         $toggle_btn_open_text = get_wpmm_theme_option('toggle_btn_open_text', $theme_id);
  575.         $toggle_bar_close_icon = get_wpmm_theme_option('toggle_bar_close_icon', $theme_id);
  576.         do_action('wpmm_before_nav_theme_activate', $theme_id);
  577.     }
  578.  
  579.    
  580.  
  581.     /**
  582.      * Backword Compatibility
  583.      *
  584.      * is this newer version
  585.      */
  586.     if (version_compare($wpmm_db_version, '1.1.1', '>')) {
  587.         $container = 'nav';
  588.         $config_container = get_wpmm_option('container_tag');
  589.         if ($config_container == 'div'){
  590.             $container = $config_container;
  591.         }
  592.  
  593.         $wp_title = get_bloginfo( 'name' );
  594.  
  595.         $home_url = '';
  596.         $brand_logo_wrap = '';
  597.         if (! empty($brand_logo)){
  598.             $home_url = esc_url( home_url( '/' ) );
  599.             $brand_logo_wrap = "<div class='wpmm_brand_logo_wrap'><a href='{$home_url}'> <img src='{$brand_logo}' {$logo_width} {$logo_height} alt='{$wp_title}'/> </a> </div>";
  600.         }
  601.  
  602.         $wpmm_on_mobile = '';
  603.         $disable_wpmm_on_mobile = get_wpmm_option('disable_wpmm_on_mobile');
  604.  
  605.         if ($disable_wpmm_on_mobile != true) {
  606.             $close_icon_class = $toggle_bar_close_icon == 'false' ? '' : 'show-close-icon';
  607.             $wpmm_on_mobile = '<a href="javascript:;" class="wpmm_mobile_menu_btn '. $close_icon_class .'"><i class="fa fa-bars"></i> '.$toggle_btn_open_text.'</a>';
  608.         }
  609.  
  610.  
  611.  
  612.         $item_wrap = '
  613.             <div class="wpmm-fullwidth-wrap"></div>
  614.             <div class="wpmm-nav-wrap wpmm-main-wrap-'.$args['theme_location'].'">
  615.                 ' .$wpmm_on_mobile.' '.$brand_logo_wrap.'
  616.                     <ul id="%1$s" class="%2$s" >%3$s</ul>
  617.             </div>
  618.         ';
  619.  
  620.  
  621.         $wpmm_wrap_class = '';
  622.         if ($theme_id){
  623.             $wpmm_wrap_class = "wp-megamenu-wrap {$sticky_class} {$menu_layout_class} {$menu_custom_class}";
  624.         }
  625.    
  626.  
  627.         $argunets = array(
  628.             'menu'              => $args['menu'],
  629.             'theme_location'    => $args['theme_location'],
  630.             'container'         => $container,
  631.             'container_aria_label' => '',
  632.             'container_id'      => 'wp-megamenu-' . $args['theme_location'],
  633.             'container_class'   => $wpmm_wrap_class,
  634.             'menu_class'        => 'wp-megamenu',
  635.             'echo'              => true,
  636.             'fallback_cb'       => 'wp_page_menu',
  637.             'before'            => '',
  638.             'after'             => '',
  639.             'link_before'       => '',
  640.             'link_after'        => '',
  641.             'items_wrap'        => $item_wrap,
  642.             'depth'             => 0,
  643.             'walker'            => new wp_megamenu()
  644.         );
  645.  
  646.         return $argunets;
  647.     }else{
  648.  
  649.         $auto_intergration_menu = (array) get_wpmm_option('auto_intergration_menu');
  650.         if (count($auto_intergration_menu)){
  651.             if ( ! in_array($args['theme_location'], $auto_intergration_menu )) {
  652.                 return $args;
  653.             }
  654.  
  655.             $container = 'nav';
  656.             $config_container = get_wpmm_option('container_tag');
  657.             if ($config_container == 'div'){
  658.                 $container = $config_container;
  659.             }
  660.  
  661.             $home_url = '';
  662.             $brand_logo_wrap = '';
  663.             if (! empty($brand_logo)){
  664.                 $home_url = esc_url( home_url( '/' ) );
  665.                 $brand_logo_wrap = "<div class='wpmm_brand_logo_wrap'><a href='{$home_url}'> <img src='{$brand_logo}' {$logo_width} {$logo_height}/> </a> </div>";
  666.             }
  667.  
  668.             $wpmm_on_mobile = '';
  669.             $disable_wpmm_on_mobile = get_wpmm_option('disable_wpmm_on_mobile');
  670.             if ($disable_wpmm_on_mobile != 'true') {
  671.                 $close_icon_class = $toggle_bar_close_icon == 'false' ? '' : 'show-close-icon';
  672.                 $wpmm_on_mobile = '<a href="javascript:;" class="wpmm_mobile_menu_btn '.$close_icon_class.'"><i class="fa fa-bars"></i> '.$toggle_btn_open_text.'</a>';
  673.             }
  674.  
  675.             $item_wrap = '<div class="wpmm-fullwidth-wrap"></div><div class="wpmm-nav-wrap wpmm-main-wrap-'
  676.                          .$args['theme_location'].'">' .$wpmm_on_mobile.' '.$brand_logo_wrap. '<ul id="%1$s" '.apply_filters('wpmm_custom_attributes', '', $theme_id).' class="%2$s">%3$s</ul></div>';
  677.  
  678.  
  679.             $wpmm_wrap_class = '';
  680.  
  681.             if ($theme_id){
  682.                 $wpmm_wrap_class = "wp-megamenu-wrap {$sticky_class} {$menu_layout_class} {$menu_custom_class} ";
  683.             }
  684.  
  685.             return $argunets = array(
  686.                 //'menu'              => wp_get_nav_menu_object( $args['menu_id'] ),
  687.                 'menu'              => $args['menu'],
  688.                 'theme_location'    => $args['theme_location'],
  689.                 'container'         => $container,
  690.                 'container_id'      => 'wp-megamenu-' . $args['theme_location'],
  691.                 'container_class'   => apply_filters('wpmm_wraper_class', $wpmm_wrap_class, $theme_id),
  692.                 'menu_class'        => 'wp-megamenu',
  693.                 'echo'              => true,
  694.                 'fallback_cb'       => 'wp_page_menu',
  695.                 'before'            => '',
  696.                 'after'             => '',
  697.                 'link_before'       => '',
  698.                 'link_after'        => '',
  699.                 'items_wrap'        => $item_wrap,
  700.                 'depth'             => 0,
  701.                 'walker'            => new wp_megamenu()
  702.             );
  703.  
  704.             // echo '<pre>';
  705.             // print_r($argunets);
  706.             // echo '</pre>';
  707.  
  708.         }
  709.  
  710.  
  711.     }
  712.     return $args;
  713. }
  714.  
  715. add_action('admin_footer', 'wp_megamenu_add_menu_settings_wrap_admin_footer');
  716. function wp_megamenu_add_menu_settings_wrap_admin_footer() {
  717.     $current_screen = get_current_screen();
  718.     if (property_exists($current_screen,'base')){
  719.         if ($current_screen->base === 'nav-menus'){
  720.             $html = '<div id="wpmmSettingOverlay" style="display: none;"></div><div class="wp-megamenu-item-settins-wrap" style="display: none;">';
  721.             $html .= '<div class="wpmm-item-settings-content">';
  722.             $html .= '</div>';
  723.             $html .= '</div>';
  724.             echo $html;
  725.         }
  726.     }
  727. }
  728.  
  729.  
  730. /**
  731.  * @param array $args
  732.  *
  733.  * @return array
  734.  *
  735.  * @since 1.1.9
  736.  */
  737. function wp_megamenu_nav_args($args = array()){
  738.     if ( ! function_exists('wpmm_theme_by_selected_nav_id')){
  739.         include WPMM_DIR.'classes/wp_megamenu_functions.php';
  740.     }
  741.  
  742.     //Get Nav term id || Nav theme id by Location
  743.     $locations = get_nav_menu_locations();
  744.     $theme_id = null;
  745.     $menu_object = false;
  746.     $theme_location = false;
  747.     $menu_id = '';
  748.     if ( isset($args['theme_location'] ) && ! empty($locations[ $args['theme_location'] ])){
  749.         $menu_id = $locations[ $args['theme_location'] ] ;
  750.         $menu_object = wp_get_nav_menu_object($menu_id);
  751.         $theme_id = wpmm_theme_by_selected_nav_id($menu_object->term_id);
  752.  
  753.         $theme_location = $args['theme_location'];
  754.     }else if ( isset($args['menu'])){
  755.         $menu_id =  $args['menu'];
  756.         $menu_object = wp_get_nav_menu_object($args['menu']);
  757.         if ($menu_object){
  758.             $theme_id = wpmm_theme_by_selected_nav_id($menu_object->term_id);
  759.         }
  760.     }
  761.  
  762.     if ( ! $menu_object){
  763.         return array();
  764.     }
  765.  
  766.     $sticky_class = '';
  767.     $menu_layout_class = '';
  768.     $menu_custom_class = '';
  769.     $brand_logo = '';
  770.     $logo_width = '';
  771.     $logo_height = '';
  772.     $toggle_btn_open_text = __('MENU', 'wp-megamenu');
  773.     $toggle_bar_close_icon = 'true';
  774.  
  775.     if ($theme_id){
  776.         //sticky menu class
  777.         $wpmm_orientation = get_wpmm_theme_option('wpmm_orientation', $theme_id);
  778.         $enable_sticky_menu = get_wpmm_theme_option('enable_sticky_menu', $theme_id);
  779.         if($enable_sticky_menu == 'true'){
  780.             if($wpmm_orientation == null OR $wpmm_orientation !== 'wpmm_vertical'){
  781.                 $sticky_class = 'wpmm-sticky';
  782.             }
  783.         }
  784.  
  785.  
  786.         $menu_layout = get_wpmm_theme_option('menu_layout', $theme_id);
  787.         if ($menu_layout){
  788.             $menu_layout_class = " wpmm-{$menu_layout} ";
  789.         }
  790.  
  791.         $menu_custom_class = get_wpmm_theme_option('wpmm_class', $theme_id);
  792.  
  793.         $brand_logo = get_wpmm_theme_option('brand_logo', $theme_id);
  794.  
  795.         $brand_logo_width = get_wpmm_theme_option('brand_logo_width', $theme_id);
  796.         $brand_logo_height = get_wpmm_theme_option('brand_logo_height', $theme_id);
  797.         if ( ! empty($brand_logo_width)){
  798.             $logo_width = wpmm_unit_to_int($brand_logo_width);
  799.             $logo_width = " width='{$logo_width}px' ";
  800.         }
  801.         if ( ! empty($brand_logo_height)){
  802.             $logo_height = wpmm_unit_to_int($brand_logo_height);
  803.             $logo_height = " height='{$logo_height}px' ";
  804.         }
  805.  
  806.         $toggle_btn_open_text = get_wpmm_theme_option('toggle_btn_open_text', $theme_id);
  807.         $toggle_bar_close_icon = get_wpmm_theme_option('toggle_bar_close_icon', $theme_id);
  808.  
  809.         do_action('wpmm_before_nav_theme_activate', $theme_id);
  810.     }
  811.  
  812.  
  813.     $container = 'nav';
  814.     $config_container = get_wpmm_option('container_tag');
  815.     if ($config_container == 'div'){
  816.         $container = $config_container;
  817.     }
  818.  
  819.     $home_url = '';
  820.     $brand_logo_wrap = '';
  821.     if (! empty($brand_logo)){
  822.         $home_url = esc_url( home_url( '/' ) );
  823.         $brand_logo_wrap = "<div class='wpmm_brand_logo_wrap'><a href='{$home_url}'> <img src='{$brand_logo}' {$logo_width} {$logo_height}/> </a> </div>";
  824.     }
  825.  
  826.     $wpmm_on_mobile = '';
  827.     $disable_wpmm_on_mobile = get_wpmm_option('disable_wpmm_on_mobile');
  828.  
  829.     if ($disable_wpmm_on_mobile != true) {
  830.         $close_icon_class = $toggle_bar_close_icon == 'false' ? '' : 'show-close-icon';
  831.         $wpmm_on_mobile = '<a href="javascript:;" class="wpmm_mobile_menu_btn '.$close_icon_class.'"><i class="fa fa-bars"></i> '.$toggle_btn_open_text.'</a>';
  832.     }
  833.  
  834.  
  835.     $wpmm_menu_attributes = '';
  836.     $item_wrap = '
  837.         <div class="wpmm-fullwidth-wrap"></div>
  838.         <div class="wpmm-nav-wrap wpmm-main-wrap-' .'">
  839.             ' .$wpmm_on_mobile.' '.$brand_logo_wrap.' <ul id="%1$s" '. apply_filters('wpmm_custom_attributes', $wpmm_menu_attributes, $theme_id) .' class="%2$s">%3$s</ul>
  840.         </div>
  841.     ';
  842.  
  843.     $wpmm_wrap_class = '';
  844.     if ($theme_id){
  845.         $wpmm_wrap_class = "wp-megamenu-wrap {$sticky_class} {$menu_layout_class} {$menu_custom_class} ";
  846.     }
  847.     $menu_object = wp_get_nav_menu_object($menu_id);
  848.     $container_class = $theme_location ? $theme_location : $menu_object->slug;
  849.  
  850.     $args['menu'] = $menu_object;
  851.  
  852.     if ($theme_location){
  853.         $args['theme_location'] = $theme_location;
  854.     }
  855.  
  856.     $args['container'] = $container;
  857.     $args['container_id'] = 'wp-megamenu-'.$menu_object->slug;
  858.     $args['container_class'] = apply_filters('wpmm_wraper_class', $wpmm_wrap_class, $theme_id);
  859.     $args['menu_class'] = 'wp-megamenu';
  860.     $args['echo'] = true;
  861.     $args['fallback_cb'] = 'wp_page_menu';
  862.     $args['items_wrap'] = $item_wrap;
  863.     $args['depth'] = 0;
  864.     $args['walker'] = new wp_megamenu();
  865.  
  866.     return $args;
  867. }
  868.  
  869.  
Add Comment
Please, Sign In to add comment