Advertisement
Guest User

Untitled

a guest
Jul 30th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 32.90 KB | None | 0 0
  1. <?php
  2.  
  3. class tie_mega_menu_walker extends Walker_Nav_Menu {
  4.  
  5. private $tie_megamenu_type = '';
  6. private $tie_megamenu_icon = '';
  7. private $tie_megamenu_image = '';
  8. private $tie_megamenu_position = '';
  9. private $tie_megamenu_position_y = '';
  10. private $tie_megamenu_repeat = '';
  11. private $tie_megamenu_min_height = '';
  12. private $tie_megamenu_padding_left = '';
  13. private $tie_megamenu_padding_right = '';
  14. private $tie_has_children = '';
  15.  
  16. /**
  17. * Starts the list before the elements are added.
  18. */
  19. public function start_lvl( &$output, $depth = 0, $args = array() ) {
  20. $indent = str_repeat("\t", $depth);
  21.  
  22. if( $depth === 0 && $this->tie_megamenu_type == 'links' ){
  23. $output .= "\n$indent<ul class=\"sub-menu-columns\">\n";
  24. }
  25. elseif( $depth === 1 && $this->tie_megamenu_type == 'links' ){
  26. $output .= "\n$indent<ul class=\"sub-menu-columns-item\">\n";
  27. }
  28. elseif( $depth === 0 && $this->tie_megamenu_type == 'sub-posts' ){
  29. $output .= "\n$indent<ul class=\"sub-menu mega-cat-more-links\">\n";
  30. }
  31. elseif( $depth === 0 && $this->tie_megamenu_type == 'recent' ){
  32. $output .= "\n$indent<ul class=\"mega-recent-featured-list sub-list\">\n";
  33. }
  34. else{
  35. $output .= "\n$indent<ul class=\"sub-menu menu-sub-content\">\n";
  36. }
  37. }
  38.  
  39.  
  40. /**
  41. * Ends the list of after the elements are added.
  42. */
  43. public function end_lvl( &$output, $depth = 0, $args = array() ) {
  44. $indent = str_repeat("\t", $depth);
  45. $output .= "$indent</ul>\n";
  46.  
  47. }
  48.  
  49.  
  50. /**
  51. * Start the element output.
  52. */
  53. public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
  54. $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
  55.  
  56. $classes = empty( $item->classes ) ? array() : (array) $item->classes;
  57. $classes[] = 'menu-item-' . $item->ID;
  58.  
  59. /**
  60. * Filter the CSS class(es) applied to a menu item's <li>.
  61. */
  62. $class_names = join( " " , apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) );
  63.  
  64.  
  65. //By TieLabs ===========
  66. $a_class = $item_output = '';
  67.  
  68. // Define the mega vars
  69. if( $depth === 0 ){
  70.  
  71. $this->tie_has_children = 0;
  72. if( !empty( $args->has_children ) )
  73. $this->tie_has_children = $args->has_children;
  74.  
  75. $this->tie_megamenu_type = get_post_meta( $item->ID, 'tie_megamenu_type', true );
  76. $this->tie_megamenu_columns = get_post_meta( $item->ID, 'tie_megamenu_columns', true );
  77. $this->tie_megamenu_image = get_post_meta( $item->ID, 'tie_megamenu_image', true );
  78. $this->tie_megamenu_position = get_post_meta( $item->ID, 'tie_megamenu_position', true );
  79. $this->tie_megamenu_position_y = get_post_meta( $item->ID, 'tie_megamenu_position_y', true );
  80. $this->tie_megamenu_repeat = get_post_meta( $item->ID, 'tie_megamenu_repeat', true );
  81. $this->tie_megamenu_min_height = get_post_meta( $item->ID, 'tie_megamenu_min_height', true );
  82. $this->tie_megamenu_padding_left = get_post_meta( $item->ID, 'tie_megamenu_padding_left', true );
  83. $this->tie_megamenu_padding_right = get_post_meta( $item->ID, 'tie_megamenu_padding_right', true );
  84. }
  85. $this->tie_megamenu_icon = get_post_meta( $item->ID, 'tie_megamenu_icon', true);
  86.  
  87. //Menu Classes
  88. if( $depth === 0 && !empty( $this->tie_megamenu_type ) && $this->tie_megamenu_type != 'disable' ){
  89. $class_names .= ' mega-menu';
  90.  
  91. if( $this->tie_megamenu_type == 'sub-posts' && $item->object == 'category' ){
  92. $class_names .= ' mega-cat ';
  93. }
  94. elseif( $this->tie_megamenu_type == 'links' ){
  95. $columns = ( !empty( $this->tie_megamenu_columns ) ? $this->tie_megamenu_columns : 2 );
  96. $class_names .= ' mega-links mega-links-'.$columns.'col ';
  97. }
  98. elseif( $this->tie_megamenu_type == 'recent' ){
  99. $class_names .= ' mega-recent-featured ';
  100. }
  101. }
  102.  
  103. if( $depth === 1 && $this->tie_megamenu_type == 'links' ){
  104. $class_names .=' mega-link-column ';
  105. $a_class = ' class="mega-links-head" ';
  106. }
  107. // =====================
  108.  
  109. $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';
  110.  
  111. /**
  112. * Filter the ID applied to a menu item's <li>.
  113. */
  114. $id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args );
  115. $id = $id ? ' id="' . esc_attr( $id ) . '"' : '';
  116.  
  117. $output .= $indent . '<li' . $id . $class_names .'>';
  118.  
  119. $atts = array();
  120. $atts['title'] = ! empty( $item->attr_title ) ? $item->attr_title : '';
  121. $atts['target'] = ! empty( $item->target ) ? $item->target : '';
  122. $atts['rel'] = ! empty( $item->xfn ) ? $item->xfn : '';
  123. $atts['href'] = ! empty( $item->url ) ? $item->url : '';
  124.  
  125. /**
  126. * Filter the HTML attributes applied to a menu item's <a>.
  127. *
  128. */
  129. $atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args );
  130.  
  131. $attributes = '';
  132. foreach ( $atts as $attr => $value ) {
  133. if ( ! empty( $value ) ) {
  134. $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value );
  135. $attributes .= ' ' . $attr . '="' . $value . '"';
  136. }
  137. }
  138.  
  139. if( !empty( $args->before ) ) $item_output = $args->before;
  140. $item_output .= '<a'.$a_class . $attributes .'>';
  141.  
  142. if( !empty( $this->tie_megamenu_icon ) )
  143. $item_output .= '<i class="fa '.$this->tie_megamenu_icon.'"></i>';
  144.  
  145. /** This filter is documented in wp-includes/post-template.php */
  146. $item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
  147. $item_output .= '</a>';
  148. $item_output .= $args->after;
  149.  
  150.  
  151. //By TieLabs ===========
  152. if( $depth === 0 && !empty( $this->tie_megamenu_type ) && $this->tie_megamenu_type != 'disable' ){
  153.  
  154. $img = $padding_left = $padding_right = $style = $min_height ='';
  155. if ( !empty( $this->tie_megamenu_image )) {
  156. $img = " background-image: url($this->tie_megamenu_image) ; background-position: $this->tie_megamenu_position_y $this->tie_megamenu_position ; background-repeat: $this->tie_megamenu_repeat ; ";
  157. }
  158. if ( !empty( $this->tie_megamenu_padding_left ) ) {
  159. $padding_left = $this->tie_megamenu_padding_left;
  160. if ( strpos( $padding_left , 'px' ) === false && strpos( $padding_left , '%' ) === false ) $padding_left .= 'px';
  161. $padding_left = " padding-left : $padding_left; ";
  162. }
  163. if ( !empty( $this->tie_megamenu_padding_right ) ) {
  164. $padding_right = $this->tie_megamenu_padding_right;
  165. if ( strpos( $padding_right , 'px' ) === false && strpos( $padding_right , '%' ) === false ) $padding_right .= 'px';
  166. $padding_right = " padding-right : $padding_right; ";
  167. }
  168. if ( !empty( $this->tie_megamenu_min_height ) ) {
  169. $min_height = $this->tie_megamenu_min_height;
  170. if ( strpos( $min_height , 'px' ) === false ) $min_height .= 'px';
  171. $min_height = " min-height : $min_height; ";
  172. }
  173.  
  174. if ( !empty( $img ) || !empty( $padding_left ) || !empty( $padding_right ) ) $style=' style="'.$img.$padding_left.$padding_right.$min_height.'"';
  175.  
  176. $item_output .="\n<div class=\"mega-menu-block menu-sub-content\"$style>\n";
  177. }
  178. // =====================
  179.  
  180. /**
  181. * Filter a menu item's starting output.
  182. */
  183. $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
  184. }
  185.  
  186.  
  187. /**
  188. * Ends the element output, if needed.
  189. */
  190. public function end_el( &$output, $item, $depth = 0, $args = array() ) {
  191.  
  192. //By TieLabs ===========
  193. if( $depth === 0 && !empty( $this->tie_megamenu_type ) && $this->tie_megamenu_type != 'disable' ){
  194. global $post;
  195.  
  196. $output .="\n<div class=\"mega-menu-content\">\n";
  197.  
  198. //Sub Categories ===============================================================
  199. if( $this->tie_megamenu_type == 'sub-posts' && $item->object == 'category' ){
  200. $no_sub_categories = $sub_categories_exists = $sub_categories = '';
  201.  
  202. $query_args = array(
  203. 'child_of' => $item->object_id,
  204. );
  205. $sub_categories = get_categories($query_args);
  206.  
  207. //Check if the Category doesn't contain any sub categories.
  208. if( count($sub_categories) == 0) {
  209. $sub_categories = array( $item->object_id ) ;
  210. $no_sub_categories = true ;
  211. }else{
  212. $sub_categories_exists = ' mega-cat-sub-exists';
  213. }
  214.  
  215. $output .= '<div class="mega-cat-wrapper"> ';
  216.  
  217. if( !$no_sub_categories ){
  218. $output .= '<ul class="mega-cat-sub-categories"> ';
  219. foreach( $sub_categories as $category ) {
  220. $output .= '<li><a href="#mega-cat-'.$item->ID.'-'.$category->term_id.'">'.$category->name.'</a></li>';
  221. }
  222. $output .= '</ul> ';
  223. }
  224.  
  225. $output .= ' <div class="mega-cat-content'. $sub_categories_exists.'">';
  226.  
  227. foreach( $sub_categories as $category ) {
  228.  
  229. if( !$no_sub_categories )
  230. $cat_id = $category->term_id;
  231. else
  232. $cat_id = $category;
  233.  
  234. $output .= '<div id="mega-cat-'.$item->ID.'-'.$cat_id.'" class="mega-cat-content-tab">';
  235.  
  236. $original_post = $post;
  237.  
  238. $args = array(
  239. 'posts_per_page' => 4,
  240. 'cat' => $cat_id,
  241. 'no_found_rows' => true,
  242. 'ignore_sticky_posts' => true
  243. );
  244. $cat_query = new WP_Query( $args );
  245. while ( $cat_query->have_posts() ) {
  246. $cat_query->the_post();
  247. $img_classes = tie_get_post_class( 'post-thumbnail' );
  248. $post_time = tie_get_time( true );
  249. $img_title = esc_attr( get_the_title() );
  250. $output .= '<div class="mega-menu-post">';
  251. if ( function_exists("has_post_thumbnail") && has_post_thumbnail() )
  252. $output .= '<div '.$img_classes.'><a class="mega-menu-link" href="'. get_permalink().'" title="'.get_the_title().'"><img src="'.tie_thumb_src( 'tie-medium' ).'" width="310" height="165" alt="'.$img_title.'" /><span class="fa overlay-icon"></span></a></div>';
  253. $output .= '<h3 class="post-box-title"><a class="mega-menu-link" href="'. get_permalink().'" title="'.get_the_title().'">'.get_the_title().'</a></h3>
  254. '.$post_time.'
  255. </div> <!-- mega-menu-post -->';
  256. }
  257.  
  258. $post = $original_post;
  259. wp_reset_query();
  260.  
  261. $output .= '</div><!-- .mega-cat-content-tab --> ';
  262. }
  263.  
  264. $output .= '</div> <!-- .mega-cat-content -->
  265. <div class="clear"></div>
  266. </div> <!-- .mega-cat-Wrapper --> ';
  267. }
  268.  
  269. // End of Sub Categories =====================================================
  270.  
  271. //Recent + Check also ========================================================
  272. if( $this->tie_megamenu_type == 'recent' && $item->object == 'category' ){
  273. $count = 0;
  274. $output_more_posts = '';
  275. $posts_number = ( empty( $this->tie_has_children ) ? 7 : 4 );
  276.  
  277. $original_post = $post;
  278.  
  279. $args = array(
  280. 'posts_per_page' => $posts_number,
  281. 'cat' => $item->object_id,
  282. 'no_found_rows' => true,
  283. 'ignore_sticky_posts' => true
  284. );
  285.  
  286. $cat_query = new WP_Query( $args );
  287. while ( $cat_query->have_posts() ) { $count ++ ;
  288. $cat_query->the_post();
  289. $img_classes = tie_get_post_class( 'post-thumbnail' );
  290. $post_time = tie_get_time( true );
  291. $img_title = esc_attr( get_the_title() );
  292.  
  293. if( $count == 1){
  294. $output .= '<div class="mega-recent-post">';
  295. if ( function_exists("has_post_thumbnail") && has_post_thumbnail() )
  296. $output .= '<div '.$img_classes.'><a class="mega-menu-link" href="'. get_permalink().'" title="'.get_the_title().'"><img src="'.tie_thumb_src( 'slider' ).'" width="660" height="330" alt="'.$img_title.'" /><span class="fa overlay-icon"></span></a></div>';
  297. $output .= '<h3 class="post-box-title"><a class="mega-menu-link" href="'. get_permalink().'" title="'.get_the_title().'">'.get_the_title().'</a></h3>
  298. '.$post_time.'
  299. </div> <!-- mega-recent-post -->';
  300. }else{
  301. $output_more_posts .= '<li>';
  302. if ( function_exists("has_post_thumbnail") && has_post_thumbnail() )
  303. $output_more_posts .= '<div '.$img_classes.'><a class="mega-menu-link" href="'. get_permalink().'" title="'.get_the_title().'"><img src="'.tie_thumb_src( ).'" width="110" height="75" alt="'.$img_title.'" /><span class="fa overlay-icon"></span></a></div>';
  304. $output_more_posts .= '<h3 class="post-box-title"><a class="mega-menu-link" href="'. get_permalink().'" title="'.get_the_title().'">'.get_the_title().'</a></h3>'.$post_time;
  305. $output_more_posts .= '</li>';
  306. }
  307. }
  308.  
  309. $post = $original_post;
  310. wp_reset_query();
  311.  
  312. $output .= '<div class="mega-check-also"><ul>'.$output_more_posts.'</ul></div> <!-- mega-check-also -->';
  313.  
  314. }
  315.  
  316. // End of Sub Categories =====================================================
  317.  
  318. $output .= "\n</div><!-- .mega-menu-content --> \n</div><!-- .mega-menu-block --> \n";
  319. }
  320. // =====================
  321.  
  322. $output .= "</li>\n";
  323. }
  324.  
  325.  
  326. function display_element( $element, &$children_elements, $max_depth, $depth=0, $args = array() , &$output ) {
  327. $id_field = $this->db_fields['id'];
  328. if ( is_object( $args[0] ) ) {
  329. $args[0]->has_children = ! empty( $children_elements[$element->$id_field] );
  330. }
  331. return parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
  332. }
  333. } // Walker_Nav_Menu
  334.  
  335.  
  336.  
  337. // Back end modification on Menus page ===============================================
  338. add_filter( 'wp_edit_nav_menu_walker', 'tie_custom_nav_edit_walker',10,2 );
  339. function tie_custom_nav_edit_walker($walker,$menu_id) {
  340. return 'tie_mega_menu_edit_walker';
  341. }
  342.  
  343.  
  344. // The Custom Tielabs menu fields
  345. add_action( 'wp_nav_menu_item_custom_fields', 'tie_add_megamenu_fields', 10, 4 );
  346. function tie_add_megamenu_fields( $item_id, $item, $depth, $args ) { ?>
  347.  
  348. <div class="clear"></div>
  349. <div class="tie-mega-menu-type">
  350. <p class="field-megamenu-icon description description-wide">
  351. <label for="edit-menu-item-megamenu-icon-<?php echo $item_id; ?>">
  352. <?php _e( 'Menu Icon', 'tie' ); ?>
  353. <input type="hidden" id="edit-menu-item-megamenu-icon-<?php echo $item_id; ?>" class="widefat code edit-menu-item-megamenu-icon" name="menu-item-tie-megamenu-icon[<?php echo $item_id; ?>]" value="<?php echo $item->tie_megamenu_icon; ?>" />
  354. <div id="preview_edit-menu-item-megamenu-icon-<?php echo $item_id; ?>" data-target="#edit-menu-item-megamenu-icon-<?php echo $item_id; ?>" class="button icon-picker fa <?php echo $item->tie_megamenu_icon; ?>"></div>
  355. </label>
  356. </p>
  357.  
  358.  
  359. <p class="field-megamenu-type description description-wide">
  360. <label for="edit-menu-item-megamenu-type-<?php echo $item_id; ?>">
  361. <?php _e( 'Enable Mega Menu ?', 'tie' ); ?>
  362. <select id="edit-menu-item-megamenu-type-<?php echo $item_id; ?>" class="widefat code edit-menu-item-megamenu-type" name="menu-item-tie-megamenu-type[<?php echo $item_id; ?>]">
  363. <option value=""><?php _e( 'Disable', 'tie' ); ?></option>
  364. <?php if( $item->object == 'category' ){ ?>
  365. <option value="sub-posts" <?php selected( $item->tie_megamenu_type, 'sub-posts' ); ?>><?php _e( 'Sub Categories + Posts', 'tie' ); ?></option>
  366. <option value="recent" <?php selected( $item->tie_megamenu_type, 'recent' ); ?>><?php _e( 'Recent post + Check also', 'tie' ); ?></option>
  367. <?php } ?>
  368. <option value="links" <?php selected( $item->tie_megamenu_type, 'links' ); ?>><?php _e( 'Mega Links', 'tie' ); ?></option>
  369. </select>
  370. </label>
  371. </p>
  372. <p class="field-megamenu-columns description description-wide">
  373. <label for="edit-menu-item-megamenu-columns-<?php echo $item_id; ?>">
  374. <?php _e( 'Mega Links - Columns', 'tie' ); ?>
  375. <select id="edit-menu-item-megamenu-columns-<?php echo $item_id; ?>" class="widefat code edit-menu-item-megamenu-columns" name="menu-item-tie-megamenu-columns[<?php echo $item_id; ?>]">
  376. <option value=""></option>
  377. <option value="2" <?php selected( $item->tie_megamenu_columns, '2' ); ?>>2</option>
  378. <option value="3" <?php selected( $item->tie_megamenu_columns, '3' ); ?>>3</option>
  379. <option value="4" <?php selected( $item->tie_megamenu_columns, '4' ); ?>>4</option>
  380. <option value="5" <?php selected( $item->tie_megamenu_columns, '5' ); ?>>5</option>
  381. </select>
  382. </label>
  383. </p>
  384.  
  385. <p class="field-megamenu-image description description-wide">
  386. <label for="edit-menu-item-megamenu-image-<?php echo $item_id; ?>">
  387. <?php _e( 'Mega Menu Background Image', 'tie' ); ?>
  388. </label>
  389. <input type="text" id="edit-menu-item-megamenu-image-<?php echo $item_id; ?>" class="widefat code edit-menu-item-megamenu-image" name="menu-item-tie-megamenu-image[<?php echo $item_id; ?>]" value="<?php echo $item->tie_megamenu_image; ?>" />
  390. <select id="edit-menu-item-megamenu-position-<?php echo $item_id; ?>" class="widefat code edit-menu-item-megamenu-position" name="menu-item-tie-megamenu-position[<?php echo $item_id; ?>]">
  391. <option value=""></option>
  392. <option value="center" <?php selected( $item->tie_megamenu_position, 'center' ); ?>><?php _e( 'Center', 'tie' ); ?></option>
  393. <option value="right" <?php selected( $item->tie_megamenu_position, 'right' ); ?>><?php _e( 'Right', 'tie' ); ?></option>
  394. <option value="left" <?php selected( $item->tie_megamenu_position, 'left' ); ?>><?php _e( 'Left', 'tie' ); ?></option>
  395. </select>
  396. <select id="edit-menu-item-megamenu-position-y-<?php echo $item_id; ?>" class="widefat code edit-menu-item-megamenu-position-y" name="menu-item-tie-megamenu-position-y[<?php echo $item_id; ?>]">
  397. <option value=""></option>
  398. <option value="center" <?php selected( $item->tie_megamenu_position_y, 'center' ); ?>><?php _e( 'Center', 'tie' ); ?></option>
  399. <option value="top" <?php selected( $item->tie_megamenu_position_y, 'top' ); ?>><?php _e( 'Top', 'tie' ); ?></option>
  400. <option value="bottom" <?php selected( $item->tie_megamenu_position_y, 'bottom' ); ?>><?php _e( 'Bottom', 'tie' ); ?></option>
  401. </select>
  402. <select id="edit-menu-item-megamenu-repeat-<?php echo $item_id; ?>" class="widefat code edit-menu-item-megamenu-repeat" name="menu-item-tie-megamenu-repeat[<?php echo $item_id; ?>]">
  403. <option value=""></option>
  404. <option value="no-repeat" <?php selected( $item->tie_megamenu_repeat, 'no-repeat' ); ?>><?php _e( 'no-repeat', 'tie' ); ?></option>
  405. <option value="repeat" <?php selected( $item->tie_megamenu_repeat, 'repeat' ); ?>><?php _e( 'repeat', 'tie' ); ?></option>
  406. <option value="repeat-x" <?php selected( $item->tie_megamenu_repeat, 'repeat-x' ); ?>><?php _e( 'repeat-x', 'tie' ); ?></option>
  407. <option value="repeat-y" <?php selected( $item->tie_megamenu_repeat, 'repeat-y' ); ?>><?php _e( 'repeat-y', 'tie' ); ?></option>
  408. </select>
  409. </p>
  410.  
  411. <p class="field-megamenu-styling description description-thin">
  412. <label for="edit-menu-item-megamenu-padding-right-<?php echo $item_id; ?>">
  413. <?php _e( 'Padding Right', 'tie' ); ?>
  414. <input type="text" id="edit-menu-item-megamenu-padding-right-<?php echo $item_id; ?>" class="widefat code edit-menu-item-megamenu-padding-right" name="menu-item-tie-megamenu-padding-right[<?php echo $item_id; ?>]" value="<?php echo $item->tie_megamenu_padding_right; ?>" />
  415. </label>
  416. </p>
  417.  
  418. <p class="field-megamenu-styling description description-thin">
  419. <label for="edit-menu-item-megamenu-padding-left-<?php echo $item_id; ?>">
  420. <?php _e( 'Padding left', 'tie' ); ?>
  421. <input type="text" id="edit-menu-item-megamenu-padding-left-<?php echo $item_id; ?>" class="widefat code edit-menu-item-megamenu-padding-left" name="menu-item-tie-megamenu-padding-left[<?php echo $item_id; ?>]" value="<?php echo $item->tie_megamenu_padding_left; ?>" />
  422. </label>
  423. </p>
  424.  
  425. <p class="field-megamenu-styling description description-thin">
  426. <label for="edit-menu-item-megamenu-min-height-<?php echo $item_id; ?>">
  427. <?php _e( 'Min Height', 'tie' ); ?>
  428. <input type="text" id="edit-menu-item-megamenu-min-height-<?php echo $item_id; ?>" class="widefat code edit-menu-item-megamenu-min-height" name="menu-item-tie-megamenu-min-height[<?php echo $item_id; ?>]" value="<?php echo $item->tie_megamenu_min_height; ?>" />
  429. </label>
  430. </p>
  431.  
  432.  
  433. </div><!-- .tie-mega-menu-type-->
  434. <?php }
  435.  
  436.  
  437. // Save The custom Fields
  438. add_action('wp_update_nav_menu_item', 'tie_custom_nav_update', 10, 3);
  439. function tie_custom_nav_update($menu_id, $menu_item_db_id, $args ) {
  440.  
  441. $custom_meta_fields = array(
  442. 'menu-item-tie-megamenu-type',
  443. 'menu-item-tie-megamenu-columns',
  444. 'menu-item-tie-megamenu-icon',
  445. 'menu-item-tie-megamenu-image',
  446. 'menu-item-tie-megamenu-position',
  447. 'menu-item-tie-megamenu-position-y',
  448. 'menu-item-tie-megamenu-min-height',
  449. 'menu-item-tie-megamenu-repeat',
  450. 'menu-item-tie-megamenu-padding-left',
  451. 'menu-item-tie-megamenu-padding-right'
  452. );
  453.  
  454. foreach( $custom_meta_fields as $custom_meta_field ){
  455. $save_option_name = str_replace( 'menu-item-', '', $custom_meta_field);
  456. $save_option_name = str_replace( '-', '_', $save_option_name);
  457.  
  458. if ( !empty($_REQUEST[ $custom_meta_field ][ $menu_item_db_id ] ) ) {
  459. $custom_value = $_REQUEST[ $custom_meta_field ][ $menu_item_db_id ];
  460. update_post_meta( $menu_item_db_id, $save_option_name, $custom_value );
  461. }else{
  462. delete_post_meta( $menu_item_db_id, $save_option_name );
  463. }
  464. }
  465. }
  466.  
  467. /*
  468. * Adds value of new field to $item object that will be passed to Walker_Nav_Menu_Edit_Custom
  469. */
  470. add_filter( 'wp_setup_nav_menu_item','tie_custom_nav_item' );
  471. function tie_custom_nav_item($menu_item) {
  472. $menu_item->tie_megamenu_type = get_post_meta( $menu_item->ID, 'tie_megamenu_type', true );
  473. $menu_item->tie_megamenu_icon = get_post_meta( $menu_item->ID, 'tie_megamenu_icon', true );
  474. $menu_item->tie_megamenu_image = get_post_meta( $menu_item->ID, 'tie_megamenu_image', true );
  475. $menu_item->tie_megamenu_position = get_post_meta( $menu_item->ID, 'tie_megamenu_position', true );
  476. $menu_item->tie_megamenu_position_y = get_post_meta( $menu_item->ID, 'tie_megamenu_position_y', true );
  477. $menu_item->tie_megamenu_repeat = get_post_meta( $menu_item->ID, 'tie_megamenu_repeat', true );
  478. $menu_item->tie_megamenu_min_height = get_post_meta( $menu_item->ID, 'tie_megamenu_min_height', true );
  479. $menu_item->tie_megamenu_padding_left = get_post_meta( $menu_item->ID, 'tie_megamenu_padding_left', true );
  480. $menu_item->tie_megamenu_padding_right = get_post_meta( $menu_item->ID, 'tie_megamenu_padding_right', true );
  481. return $menu_item;
  482. }
  483.  
  484.  
  485. /**
  486. * Navigation Menu template functions
  487. */
  488. class tie_mega_menu_edit_walker extends Walker_Nav_Menu {
  489. /**
  490. * Starts the list before the elements are added.
  491. *
  492. * @see Walker_Nav_Menu::start_lvl()
  493. *
  494. * @since 3.0.0
  495. *
  496. * @param string $output Passed by reference.
  497. * @param int $depth Depth of menu item. Used for padding.
  498. * @param array $args Not used.
  499. */
  500. public function start_lvl( &$output, $depth = 0, $args = array() ) {}
  501.  
  502. /**
  503. * Ends the list of after the elements are added.
  504. *
  505. * @see Walker_Nav_Menu::end_lvl()
  506. *
  507. * @since 3.0.0
  508. *
  509. * @param string $output Passed by reference.
  510. * @param int $depth Depth of menu item. Used for padding.
  511. * @param array $args Not used.
  512. */
  513. public function end_lvl( &$output, $depth = 0, $args = array() ) {}
  514.  
  515. /**
  516. * Start the element output.
  517. *
  518. * @see Walker_Nav_Menu::start_el()
  519. * @since 3.0.0
  520. *
  521. * @param string $output Passed by reference. Used to append additional content.
  522. * @param object $item Menu item data object.
  523. * @param int $depth Depth of menu item. Used for padding.
  524. * @param array $args Not used.
  525. * @param int $id Not used.
  526. */
  527. public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
  528. global $_wp_nav_menu_max_depth;
  529. $_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth;
  530.  
  531. ob_start();
  532. $item_id = esc_attr( $item->ID );
  533. $removed_args = array(
  534. 'action',
  535. 'customlink-tab',
  536. 'edit-menu-item',
  537. 'menu-item',
  538. 'page-tab',
  539. '_wpnonce',
  540. );
  541.  
  542. $original_title = '';
  543. if ( 'taxonomy' == $item->type ) {
  544. $original_title = get_term_field( 'name', $item->object_id, $item->object, 'raw' );
  545. if ( is_wp_error( $original_title ) )
  546. $original_title = false;
  547. } elseif ( 'post_type' == $item->type ) {
  548. $original_object = get_post( $item->object_id );
  549. $original_title = get_the_title( $original_object->ID );
  550. }
  551.  
  552. $classes = array(
  553. 'menu-item menu-item-depth-' . $depth,
  554. 'menu-item-' . esc_attr( $item->object ),
  555. 'menu-item-edit-' . ( ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? 'active' : 'inactive'),
  556. );
  557.  
  558. $title = $item->title;
  559.  
  560. if ( ! empty( $item->_invalid ) ) {
  561. $classes[] = 'menu-item-invalid';
  562. /* translators: %s: title of menu item which is invalid */
  563. $title = sprintf( __( '%s (Invalid)' ), $item->title );
  564. } elseif ( isset( $item->post_status ) && 'draft' == $item->post_status ) {
  565. $classes[] = 'pending';
  566. /* translators: %s: title of menu item in draft status */
  567. $title = sprintf( __('%s (Pending)'), $item->title );
  568. }
  569.  
  570. $title = ( ! isset( $item->label ) || '' == $item->label ) ? $title : $item->label;
  571.  
  572. $submenu_text = '';
  573. if ( 0 == $depth )
  574. $submenu_text = 'style="display: none;"';
  575.  
  576. ?>
  577. <li id="menu-item-<?php echo $item_id; ?>" class="<?php echo implode(' ', $classes ); ?>">
  578. <dl class="menu-item-bar">
  579. <dt class="menu-item-handle">
  580. <span class="item-title"><span class="menu-item-title"><?php echo esc_html( $title ); ?></span> <span class="is-submenu" <?php echo $submenu_text; ?>><?php _e( 'sub item' ); ?></span></span>
  581. <span class="item-controls">
  582. <span class="item-type"><?php echo esc_html( $item->type_label ); ?></span>
  583. <span class="item-order hide-if-js">
  584. <a href="<?php
  585. echo wp_nonce_url(
  586. add_query_arg(
  587. array(
  588. 'action' => 'move-up-menu-item',
  589. 'menu-item' => $item_id,
  590. ),
  591. remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
  592. ),
  593. 'move-menu_item'
  594. );
  595. ?>" class="item-move-up"><abbr title="<?php esc_attr_e('Move up'); ?>">&#8593;</abbr></a>
  596. |
  597. <a href="<?php
  598. echo wp_nonce_url(
  599. add_query_arg(
  600. array(
  601. 'action' => 'move-down-menu-item',
  602. 'menu-item' => $item_id,
  603. ),
  604. remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
  605. ),
  606. 'move-menu_item'
  607. );
  608. ?>" class="item-move-down"><abbr title="<?php esc_attr_e('Move down'); ?>">&#8595;</abbr></a>
  609. </span>
  610. <a class="item-edit" id="edit-<?php echo $item_id; ?>" title="<?php esc_attr_e('Edit Menu Item'); ?>" href="<?php
  611. echo ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? admin_url( 'nav-menus.php' ) : add_query_arg( 'edit-menu-item', $item_id, remove_query_arg( $removed_args, admin_url( 'nav-menus.php#menu-item-settings-' . $item_id ) ) );
  612. ?>"><?php _e( 'Edit Menu Item' ); ?></a>
  613. </span>
  614. </dt>
  615. </dl>
  616.  
  617. <div class="menu-item-settings" id="menu-item-settings-<?php echo $item_id; ?>">
  618. <?php if( 'custom' == $item->type ) : ?>
  619. <p class="field-url description description-wide">
  620. <label for="edit-menu-item-url-<?php echo $item_id; ?>">
  621. <?php _e( 'URL' ); ?><br />
  622. <input type="text" id="edit-menu-item-url-<?php echo $item_id; ?>" class="widefat code edit-menu-item-url" name="menu-item-url[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->url ); ?>" />
  623. </label>
  624. </p>
  625. <?php endif; ?>
  626. <p class="description description-thin">
  627. <label for="edit-menu-item-title-<?php echo $item_id; ?>">
  628. <?php _e( 'Navigation Label' ); ?><br />
  629. <input type="text" id="edit-menu-item-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-title" name="menu-item-title[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->title ); ?>" />
  630. </label>
  631. </p>
  632. <p class="description description-thin">
  633. <label for="edit-menu-item-attr-title-<?php echo $item_id; ?>">
  634. <?php _e( 'Title Attribute' ); ?><br />
  635. <input type="text" id="edit-menu-item-attr-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-attr-title" name="menu-item-attr-title[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->post_excerpt ); ?>" />
  636. </label>
  637. </p>
  638. <p class="field-link-target description">
  639. <label for="edit-menu-item-target-<?php echo $item_id; ?>">
  640. <input type="checkbox" id="edit-menu-item-target-<?php echo $item_id; ?>" value="_blank" name="menu-item-target[<?php echo $item_id; ?>]"<?php checked( $item->target, '_blank' ); ?> />
  641. <?php _e( 'Open link in a new window/tab' ); ?>
  642. </label>
  643. </p>
  644. <p class="field-css-classes description description-thin">
  645. <label for="edit-menu-item-classes-<?php echo $item_id; ?>">
  646. <?php _e( 'CSS Classes (optional)' ); ?><br />
  647. <input type="text" id="edit-menu-item-classes-<?php echo $item_id; ?>" class="widefat code edit-menu-item-classes" name="menu-item-classes[<?php echo $item_id; ?>]" value="<?php echo esc_attr( implode(' ', $item->classes ) ); ?>" />
  648. </label>
  649. </p>
  650. <p class="field-xfn description description-thin">
  651. <label for="edit-menu-item-xfn-<?php echo $item_id; ?>">
  652. <?php _e( 'Link Relationship (XFN)' ); ?><br />
  653. <input type="text" id="edit-menu-item-xfn-<?php echo $item_id; ?>" class="widefat code edit-menu-item-xfn" name="menu-item-xfn[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->xfn ); ?>" />
  654. </label>
  655. </p>
  656. <p class="field-description description description-wide">
  657. <label for="edit-menu-item-description-<?php echo $item_id; ?>">
  658. <?php _e( 'Description' ); ?><br />
  659. <textarea id="edit-menu-item-description-<?php echo $item_id; ?>" class="widefat edit-menu-item-description" rows="3" cols="20" name="menu-item-description[<?php echo $item_id; ?>]"><?php echo esc_html( $item->description ); // textarea_escaped ?></textarea>
  660. <span class="description"><?php _e('The description will be displayed in the menu if the current theme supports it.'); ?></span>
  661. </label>
  662. </p>
  663.  
  664.  
  665. <?php
  666. //By Tielabs **************************************************
  667.  
  668. do_action( 'wp_nav_menu_item_custom_fields', $item_id, $item, $depth, $args );
  669.  
  670. // END ********************************************************
  671. ?>
  672.  
  673. <p class="field-move hide-if-no-js description description-wide">
  674. <label>
  675. <span><?php _e( 'Move' ); ?></span>
  676. <a href="#" class="menus-move-up"><?php _e( 'Up one' ); ?></a>
  677. <a href="#" class="menus-move-down"><?php _e( 'Down one' ); ?></a>
  678. <a href="#" class="menus-move-left"></a>
  679. <a href="#" class="menus-move-right"></a>
  680. <a href="#" class="menus-move-top"><?php _e( 'To the top' ); ?></a>
  681. </label>
  682. </p>
  683.  
  684. <div class="menu-item-actions description-wide submitbox">
  685. <?php if( 'custom' != $item->type && $original_title !== false ) : ?>
  686. <p class="link-to-original">
  687. <?php printf( __('Original: %s'), '<a href="' . esc_attr( $item->url ) . '">' . esc_html( $original_title ) . '</a>' ); ?>
  688. </p>
  689. <?php endif; ?>
  690. <a class="item-delete submitdelete deletion" id="delete-<?php echo $item_id; ?>" href="<?php
  691. echo wp_nonce_url(
  692. add_query_arg(
  693. array(
  694. 'action' => 'delete-menu-item',
  695. 'menu-item' => $item_id,
  696. ),
  697. admin_url( 'nav-menus.php' )
  698. ),
  699. 'delete-menu_item_' . $item_id
  700. ); ?>"><?php _e( 'Remove' ); ?></a> <span class="meta-sep hide-if-no-js"> | </span> <a class="item-cancel submitcancel hide-if-no-js" id="cancel-<?php echo $item_id; ?>" href="<?php echo esc_url( add_query_arg( array( 'edit-menu-item' => $item_id, 'cancel' => time() ), admin_url( 'nav-menus.php' ) ) );
  701. ?>#menu-item-settings-<?php echo $item_id; ?>"><?php _e('Cancel'); ?></a>
  702. </div>
  703.  
  704. <input class="menu-item-data-db-id" type="hidden" name="menu-item-db-id[<?php echo $item_id; ?>]" value="<?php echo $item_id; ?>" />
  705. <input class="menu-item-data-object-id" type="hidden" name="menu-item-object-id[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object_id ); ?>" />
  706. <input class="menu-item-data-object" type="hidden" name="menu-item-object[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object ); ?>" />
  707. <input class="menu-item-data-parent-id" type="hidden" name="menu-item-parent-id[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_item_parent ); ?>" />
  708. <input class="menu-item-data-position" type="hidden" name="menu-item-position[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_order ); ?>" />
  709. <input class="menu-item-data-type" type="hidden" name="menu-item-type[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->type ); ?>" />
  710. </div><!-- .menu-item-settings-->
  711. <ul class="menu-item-transport"></ul>
  712. <?php
  713. $output .= ob_get_clean();
  714. }
  715.  
  716.  
  717. } // Walker_Nav_Menu
  718. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement