Advertisement
Guest User

Untitled

a guest
Apr 7th, 2019
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 34.04 KB | None | 0 0
  1. <?php
  2.  
  3. add_action( 'wp_update_nav_menu_item', 'update_menu', 100, 3);
  4. add_filter( 'wp_edit_nav_menu_walker', 'modify_backend_walker' , 100);
  5.  
  6. # Custom walker class for the wp_nav_menu
  7. class my_theme_megamenu_walker extends Walker_Nav_Menu
  8. {
  9. /**
  10. * What the class handles.
  11. *
  12. * @see Walker::$tree_type
  13. * @since 3.0.0
  14. * @var string
  15. */
  16. var $tree_type = array( 'post_type', 'taxonomy', 'custom' );
  17.  
  18. /**
  19. * Database fields to use.
  20. *
  21. * @see Walker::$db_fields
  22. * @since 3.0.0
  23. * @todo Decouple this.
  24. * @var array
  25. */
  26. var $db_fields = array( 'parent' => 'menu_item_parent', 'id' => 'db_id' );
  27.  
  28. //save current item so it can be used in start level
  29. private $curItem;
  30. private $megamenu;
  31. /**
  32. * Starts the list before the elements are added.
  33. *
  34. * @see Walker::start_lvl()
  35. *
  36. * @since 3.0.0
  37. *
  38. * @param string $output Passed by reference. Used to append additional content.
  39. * @param int $depth Depth of menu item. Used for padding.
  40. * @param array $args An array of arguments. @see wp_nav_menu()
  41. */
  42. function start_lvl( &$output, $depth = 0, $args = array() ) {
  43. $indent = str_repeat("\t", $depth);
  44.  
  45. $megamenu = get_post_meta( $this->curItem->ID, '_menu-item-megamenu', true);
  46. $megamenu_width = get_post_meta( $this->curItem->ID, '_menu-item-columns', true);
  47.  
  48. if($depth === 1) {
  49.  
  50. $tag = "ul";
  51. } else {
  52. $tag = "ul";
  53. }
  54.  
  55. if($megamenu) {
  56.  
  57. $output .= "\n$indent<div class=\"mega-menu mobile-styles ".$megamenu_width." \"><ul>\n";
  58. } else {
  59. $output .= "\n$indent<".$tag." class=\"sub-menu \">\n";
  60. }
  61.  
  62. }
  63.  
  64. /**
  65. * Ends the list of after the elements are added.
  66. *
  67. * @see Walker::end_lvl()
  68. *
  69. * @since 3.0.0
  70. *
  71. * @param string $output Passed by reference. Used to append additional content.
  72. * @param int $depth Depth of menu item. Used for padding.
  73. * @param array $args An array of arguments. @see wp_nav_menu()
  74. */
  75. function end_lvl( &$output, $depth = 0, $args = array() ) {
  76. $indent = str_repeat("\t", $depth);
  77.  
  78. $megamenu = get_post_meta( $this->curItem->ID, '_menu-item-megamenu', true);
  79.  
  80. if($depth === 1) {
  81.  
  82. if($megamenu) {
  83.  
  84. $output .= "\n$indent</ul>\n";
  85. } else {
  86. $output .= "\n$indent</ul>\n";
  87. }
  88. } else {
  89. if($megamenu) {
  90. $output .= "\n$indent</ul>\n";
  91. } else {
  92. $output .= "\n$indent</ul>\n";
  93. }
  94. }
  95.  
  96. }
  97.  
  98. /**
  99. * Start the element output.
  100. *
  101. * @see Walker::start_el()
  102. *
  103. * @since 3.0.0
  104. *
  105. * @param string $output Passed by reference. Used to append additional content.
  106. * @param object $item Menu item data object.
  107. * @param int $depth Depth of menu item. Used for padding.
  108. * @param array $args An array of arguments. @see wp_nav_menu()
  109. * @param int $id Current item ID.
  110. */
  111. function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
  112. $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
  113.  
  114. //save current item to private curItem to use it in start_lvl
  115. $this->curItem = $item;
  116.  
  117. $class_names = '';
  118. $this->megamenu = get_post_meta( $item->ID, '_menu-item-megamenu', true);
  119. $classes = empty( $item->classes ) ? array() : (array) $item->classes;
  120. $classes[] = 'menu-item-' . $item->ID;
  121. $classes[] = 'parentid'.get_post_meta( $item->ID, '_menu_item_menu_item_parent', true);
  122. /**
  123. * Filter the CSS class(es) applied to a menu item's <li>.
  124. *
  125. * @since 3.0.0
  126. *
  127. * @see wp_nav_menu()
  128. *
  129. * @param array $classes The CSS classes that are applied to the menu item's <li>.
  130. * @param object $item The current menu item.
  131. * @param array $args An array of wp_nav_menu() arguments.
  132. */
  133. $hiddenstatus = get_post_meta( $item->ID, '_menu-item-hiddenonmobile', true);
  134. if($hiddenstatus == 'hide') {
  135. $classes[] = 'hidden-on-mobile';
  136. }
  137. $classes[] = 'depth'.$depth;
  138. if($depth === 0 && $this->megamenu != '') {
  139. $classes[] = 'has-megamenu';
  140. } else {
  141. $classes[] = 'dropdown';
  142. }
  143.  
  144. if($depth === 1) {
  145. $parent = get_post_meta( $item->ID, '_menu_item_menu_item_parent', true);
  146. $parent_has_megamenu = get_post_meta( $parent, '_menu-item-megamenu', true);
  147.  
  148. if ($parent_has_megamenu == '_blank') {
  149.  
  150. $widthclass = get_post_meta( $item->ID, '_menu-item-columns', true);
  151. $classes[] = $widthclass;
  152. }
  153.  
  154. }
  155. $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) );
  156. $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';
  157.  
  158. /**
  159. * Filter the ID applied to a menu item's <li>.
  160. *
  161. * @since 3.0.1
  162. *
  163. * @see wp_nav_menu()
  164. *
  165. * @param string $menu_id The ID that is applied to the menu item's <li>.
  166. * @param object $item The current menu item.
  167. * @param array $args An array of wp_nav_menu() arguments.
  168. */
  169. $id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args );
  170. $id = $id ? ' id="' . esc_attr( $id ) . '"' : '';
  171.  
  172.  
  173. $output .= $indent . '<li' . $id . $class_names .'>';
  174.  
  175. $atts = array();
  176. $atts['title'] = ! empty( $item->attr_title ) ? $item->attr_title : '';
  177. $atts['target'] = ! empty( $item->target ) ? $item->target : '';
  178. $atts['rel'] = ! empty( $item->xfn ) ? $item->xfn : '';
  179. $atts['href'] = ! empty( $item->url ) ? $item->url : '';
  180.  
  181. /**
  182. * Filter the HTML attributes applied to a menu item's <a>.
  183. *
  184. * @since 3.6.0
  185. *
  186. * @see wp_nav_menu()
  187. *
  188. * @param array $atts {
  189. * The HTML attributes applied to the menu item's <a>, empty strings are ignored.
  190. *
  191. * @type string $title Title attribute.
  192. * @type string $target Target attribute.
  193. * @type string $rel The rel attribute.
  194. * @type string $href The href attribute.
  195. * }
  196. * @param object $item The current menu item.
  197. * @param array $args An array of wp_nav_menu() arguments.
  198. */
  199. $atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args );
  200. $is_clickable = get_post_meta($item->object_id, 'link_disabled', true);
  201. $jsarg = ($is_clickable == '1') ? 'onclick="return false;"' : '';
  202. $attributes = '';
  203. foreach ( $atts as $attr => $value ) {
  204. if ( ! empty( $value ) ) {
  205. $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value );
  206. $attributes .= ' ' . $attr . '="' . $value . '"';
  207. }
  208. }
  209. $linkrole = get_post_meta( $item->ID, '_menu-item-linkrole', true);
  210.  
  211. $item_output = $args->before;
  212. $icon = get_post_meta( $item->ID, '_menu-item-icon', true);
  213. if(!empty($icon)){
  214. if(substr($icon,0, 2) == 'ln'){
  215. $icon = '<i class="'.esc_attr($icon).'"></i> ';
  216. } else {
  217. $icon = '<i class=" sl sl-icon-'.esc_attr($icon).'"></i> ';
  218. }
  219.  
  220. }
  221. if($depth === 1 ) {
  222. if($linkrole == 'title' ) {
  223. $item_output .= $args->link_before .'<span class="mega-menu-headline">'.$icon. apply_filters( 'the_title', $item->title, $item->ID ) .'</span>'. $args->link_after;
  224. } elseif($linkrole == 'paragraph') {
  225. $content = get_post_meta( $item->ID, '_menu-item-html', true);
  226. $item_output .= '<p>';
  227. $item_output .= $args->link_before;
  228. $item_output .= do_shortcode($content);
  229. $item_output .= $args->link_after;
  230. $item_output .= '</p>';
  231. } elseif($linkrole == 'paragraphtitle') {
  232. $content = get_post_meta( $item->ID, '_menu-item-html', true);
  233. $item_output .= '<p>';
  234. $item_output .= $args->link_before .'<span class="mega-menu-headline"">'.$icon. apply_filters( 'the_title', $item->title, $item->ID ) .'</span>';
  235. $item_output .= do_shortcode($content);
  236. $item_output .= $args->link_after;
  237. $item_output .= '</p>';
  238. } else if($linkrole == 'hidden') {
  239.  
  240. } else {
  241. $item_output .= '<a'. $attributes .' '.$jsarg.'>';
  242. $item_output .= $args->link_before .$icon. apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
  243. $item_output .= '</a>';
  244. }
  245. } elseif( $depth === 0 ) {
  246. $item_output .= '<a'. $attributes .' '.$jsarg.'>';
  247. $item_output .= $args->link_before .$icon. apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
  248. $item_output .= '</a>';
  249. } else {
  250. $item_output .= '<a'. $attributes .' '.$jsarg.'>';
  251. $item_output .= $args->link_before .$icon. apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
  252. $item_output .= '</a>';
  253. }
  254.  
  255.  
  256. /* if($depth === 0 && $this->megamenu != '') {
  257. $item_output .= '<div class="mega two-cols">
  258. <div class="mega-section">';
  259. }*/
  260.  
  261. $item_output .= $args->after;
  262.  
  263. /**
  264. * Filter a menu item's starting output.
  265. *
  266. * The menu item's starting output only includes $args->before, the opening <a>,
  267. * the menu item's title, the closing </a>, and $args->after. Currently, there is
  268. * no filter for modifying the opening and closing <li> for a menu item.
  269. *
  270. * @since 3.0.0
  271. *
  272. * @see wp_nav_menu()
  273. *
  274. * @param string $item_output The menu item's starting HTML output.
  275. * @param object $item Menu item data object.
  276. * @param int $depth Depth of menu item. Used for padding.
  277. * @param array $args An array of wp_nav_menu() arguments.
  278. */
  279. $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
  280. }
  281.  
  282. /**
  283. * Ends the element output, if needed.
  284. *
  285. * @see Walker::end_el()
  286. *
  287. * @since 3.0.0
  288. *
  289. * @param string $output Passed by reference. Used to append additional content.
  290. * @param object $item Page data object. Not used.
  291. * @param int $depth Depth of page. Not Used.
  292. * @param array $args An array of arguments. @see wp_nav_menu()
  293. */
  294. function end_el( &$output, $item, $depth = 0, $args = array() ) {
  295.  
  296. $this->megamenu = get_post_meta( $item->ID, '_menu-item-megamenu', true);
  297. if($depth === 0 && $this->megamenu != '') {
  298. $output .= "</div>\n";
  299. } else {
  300. $output .= "</li>\n";
  301. }
  302. }
  303.  
  304. }
  305.  
  306.  
  307.  
  308. /**
  309. * Walker_Nav_Menu class copied from
  310. */
  311.  
  312. class my_theme_walker_nav_edit extends Walker_Nav_Menu {
  313. /**
  314. * @see Walker_Nav_Menu::start_lvl()
  315. * @since 3.0.0
  316. *
  317. * @param string $output Passed by reference.
  318. */
  319. function start_lvl(&$output, $depth = 0, $args = array()) {}
  320.  
  321. /**
  322. * @see Walker_Nav_Menu::end_lvl()
  323. * @since 3.0.0
  324. *
  325. * @param string $output Passed by reference.
  326. */
  327. function end_lvl(&$output, $depth = 0, $args = array()) {
  328. }
  329.  
  330. /**
  331. * @see Walker::start_el()
  332. * @since 3.0.0
  333. *
  334. * @param string $output Passed by reference. Used to append additional content.
  335. * @param object $item Menu item data object.
  336. * @param int $depth Depth of menu item. Used for padding.
  337. * @param object $args
  338. */
  339. public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
  340. global $_wp_nav_menu_max_depth;
  341. $_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth;
  342.  
  343. ob_start();
  344. $item_id = esc_attr( $item->ID );
  345. $removed_args = array(
  346. 'action',
  347. 'customlink-tab',
  348. 'edit-menu-item',
  349. 'menu-item',
  350. 'page-tab',
  351. '_wpnonce',
  352. );
  353.  
  354.  
  355. $original_title = false;
  356. if ( 'taxonomy' == $item->type ) {
  357. $original_title = get_term_field( 'name', $item->object_id, $item->object, 'raw' );
  358. if ( is_wp_error( $original_title ) )
  359. $original_title = false;
  360. } elseif ( 'post_type' == $item->type ) {
  361. $original_object = get_post( $item->object_id );
  362. $original_title = get_the_title( $original_object->ID );
  363. } elseif ( 'post_type_archive' == $item->type ) {
  364. $original_object = get_post_type_object( $item->object );
  365. if ( $original_object ) {
  366. $original_title = $original_object->labels->archives;
  367. }
  368. }
  369.  
  370. $classes = array(
  371. 'menu-item menu-item-depth-' . $depth,
  372. 'menu-item-' . esc_attr( $item->object ),
  373. 'menu-item-edit-' . ( ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? 'active' : 'inactive'),
  374. );
  375.  
  376. $title = $item->title;
  377.  
  378. if ( ! empty( $item->_invalid ) ) {
  379. $classes[] = 'menu-item-invalid';
  380. /* translators: %s: title of menu item which is invalid */
  381. $title = sprintf( esc_html__( '%s (Invalid)','my_theme' ), $item->title );
  382. } elseif ( isset( $item->post_status ) && 'draft' == $item->post_status ) {
  383. $classes[] = 'pending';
  384. /* translators: %s: title of menu item in draft status */
  385. $title = sprintf( esc_html__('%s (Pending)','my_theme'), $item->title );
  386. }
  387.  
  388. $title = ( ! isset( $item->label ) || '' == $item->label ) ? $title : $item->label;
  389.  
  390. $submenu_text = '';
  391. if ( 0 == $depth )
  392. $submenu_text = 'style="display: none;"';
  393.  
  394. ?>
  395. <li id="menu-item-<?php echo esc_attr($item_id); ?>" class="<?php echo implode(' ', $classes ); ?>">
  396. <div class="menu-item-bar">
  397. <div class="menu-item-handle">
  398. <span class="item-title"><span class="menu-item-title"><?php echo esc_html( $title ); ?></span> <span class="is-submenu" <?php echo esc_attr($submenu_text); ?>><?php esc_html_e( 'sub item','my_theme' ); ?></span></span>
  399. <span class="item-controls">
  400. <span class="item-type"><?php echo esc_html( $item->type_label ); ?></span>
  401. <span class="item-order hide-if-js">
  402. <a href="<?php
  403. echo wp_nonce_url(
  404. add_query_arg(
  405. array(
  406. 'action' => 'move-up-menu-item',
  407. 'menu-item' => $item_id,
  408. ),
  409. remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
  410. ),
  411. 'move-menu_item'
  412. );
  413. ?>" class="item-move-up" aria-label="<?php esc_attr_e( 'Move up','my_theme' ) ?>">&#8593;</a>
  414. |
  415. <a href="<?php
  416. echo wp_nonce_url(
  417. add_query_arg(
  418. array(
  419. 'action' => 'move-down-menu-item',
  420. 'menu-item' => $item_id,
  421. ),
  422. remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
  423. ),
  424. 'move-menu_item'
  425. );
  426. ?>" class="item-move-down" aria-label="<?php esc_attr_e( 'Move down','my_theme' ) ?>">&#8595;</a>
  427. </span>
  428. <a class="item-edit" id="edit-<?php echo esc_attr($item_id); ?>" href="<?php
  429. 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 ) ) );
  430. ?>" aria-label="<?php esc_attr_e( 'Edit menu item','my_theme' ); ?>"><?php esc_html_e( 'Edit','my_theme' ); ?></a>
  431. </span>
  432. </div>
  433. </div>
  434.  
  435.  
  436. <div class="menu-item-settings wp-clearfix" id="menu-item-settings-<?php echo esc_attr($item_id); ?>">
  437. <?php if ( 'custom' == $item->type ) : ?>
  438. <p class="field-url description description-wide">
  439. <label for="edit-menu-item-url-<?php echo esc_attr($item_id); ?>">
  440. <?php esc_html_e( 'URL','my_theme' ); ?><br />
  441. <input type="text" id="edit-menu-item-url-<?php echo esc_attr($item_id); ?>" class="widefat code edit-menu-item-url" name="menu-item-url[<?php echo esc_attr($item_id); ?>]" value="<?php echo esc_attr( $item->url ); ?>" />
  442. </label>
  443. </p>
  444. <?php endif; ?>
  445. <p class="description description-wide">
  446. <label for="edit-menu-item-title-<?php echo esc_attr($item_id); ?>">
  447. <?php esc_html_e( 'Navigation Label','my_theme' ); ?><br />
  448. <input type="text" id="edit-menu-item-title-<?php echo esc_attr($item_id); ?>" class="widefat edit-menu-item-title" name="menu-item-title[<?php echo esc_attr($item_id); ?>]" value="<?php echo esc_attr( $item->title ); ?>" />
  449. </label>
  450. </p>
  451. <p class="field-title-attribute field-attr-title description description-wide">
  452. <label for="edit-menu-item-attr-title-<?php echo esc_attr($item_id); ?>">
  453. <?php esc_html_e( 'Title Attribute','my_theme' ); ?><br />
  454. <input type="text" id="edit-menu-item-attr-title-<?php echo esc_attr($item_id); ?>" class="widefat edit-menu-item-attr-title" name="menu-item-attr-title[<?php echo esc_attr($item_id); ?>]" value="<?php echo esc_attr( $item->post_excerpt ); ?>" />
  455. </label>
  456. </p>
  457. <p class="field-link-target description">
  458. <label for="edit-menu-item-target-<?php echo esc_attr($item_id); ?>">
  459. <input type="checkbox" id="edit-menu-item-target-<?php echo esc_attr($item_id); ?>" value="_blank" name="menu-item-target[<?php echo esc_attr($item_id); ?>]"<?php checked( $item->target, '_blank' ); ?> />
  460. <?php esc_html_e( 'Open link in a new tab','my_theme' ); ?>
  461. </label>
  462. </p>
  463. <p class="field-css-classes description description-thin">
  464. <label for="edit-menu-item-classes-<?php echo esc_attr($item_id); ?>">
  465. <?php esc_html_e( 'CSS Classes (optional)','my_theme' ); ?><br />
  466. <input type="text" id="edit-menu-item-classes-<?php echo esc_attr($item_id); ?>" class="widefat code edit-menu-item-classes" name="menu-item-classes[<?php echo esc_attr($item_id); ?>]" value="<?php echo esc_attr( implode(' ', $item->classes ) ); ?>" />
  467. </label>
  468. </p>
  469. <p class="field-xfn description description-thin">
  470. <label for="edit-menu-item-xfn-<?php echo esc_attr($item_id); ?>">
  471. <?php esc_html_e( 'Link Relationship (XFN)' ,'my_theme'); ?><br />
  472. <input type="text" id="edit-menu-item-xfn-<?php echo esc_attr($item_id); ?>" class="widefat code edit-menu-item-xfn" name="menu-item-xfn[<?php echo esc_attr($item_id); ?>]" value="<?php echo esc_attr( $item->xfn ); ?>" />
  473. </label>
  474. </p>
  475. <p class="field-description description description-wide">
  476. <label for="edit-menu-item-description-<?php echo esc_attr($item_id); ?>">
  477. <?php esc_html_e( 'Description','my_theme' ); ?><br />
  478. <textarea id="edit-menu-item-description-<?php echo esc_attr($item_id); ?>" class="widefat edit-menu-item-description" rows="3" cols="20" name="menu-item-description[<?php echo esc_attr($item_id); ?>]"><?php echo esc_html( $item->description ); // textarea_escaped ?></textarea>
  479. <span class="description"><?php esc_html_e('The description will be displayed in the menu if the current theme supports it.','my_theme'); ?></span>
  480. </label>
  481. </p>
  482. <p class="field-menu-columns description description-thin">
  483. <?php $icon = get_post_meta( $item->ID, '_menu-item-icon', true); ?>
  484. <label for="edit-menu-item-icon-<?php echo esc_attr($item_id); ?>"><?php esc_html_e( 'Icon','my_theme' ); ?>
  485. <select id="edit-menu-item-icon-<?php echo esc_attr($item_id); ?>" class="widefat edit-menu-item-icon" name="menu-item-icon[<?php echo esc_attr($item_id); ?>]">
  486. <?php
  487.  
  488. echo get_my_theme_icons_dropdown($icon);
  489. ?>
  490. </select>
  491. </label>
  492. </p>
  493.  
  494. <!-- custom element for columns number -->
  495.  
  496. <?php if($depth === 0) { ?>
  497.  
  498. <p class="field-megamenu description">
  499. <label for="edit-menu-item-megamenu-<?php echo esc_attr($item_id); ?>">
  500. <?php $statuscheckbox=''; $megamenu = get_post_meta( $item->ID, '_menu-item-megamenu', true); if($megamenu != "") $statuscheckbox = "checked='checked'";?>
  501. <input type="checkbox" id="edit-menu-item-megamenu-<?php echo esc_attr($item_id); ?>" value="_blank" name="menu-item-megamenu[<?php echo esc_attr($item_id); ?>]"<?php echo esc_attr($statuscheckbox); ?> />
  502. <?php esc_html_e( 'Enable megamenu','my_theme' ); ?>
  503. </label>
  504. </p>
  505. <p class="field-menu-columns description description-thin">
  506. <label for="edit-menu-item-colwidth-<?php echo esc_attr($item_id); ?>"><?php esc_html_e( 'Number of columns','my_theme' ); ?>
  507. <select id="edit-menu-item-colwidth-<?php echo esc_attr($item_id); ?>" class="widefat edit-menu-item-columns" name="menu-item-columns[<?php echo esc_attr($item_id); ?>]">
  508. <?php $col = get_post_meta( $item->ID, '_menu-item-columns', true); ?>
  509.  
  510. <option value="two-columns" <?php if($col == 'two-columns') { echo 'selected'; } ?>><?php esc_html_e('2 columns','my_theme'); ?></option>
  511. <option value="three-columns" <?php if($col == 'three-columns') { echo 'selected'; } ?>><?php esc_html_e('3 columns','my_theme'); ?></option>
  512. <option value="four-columns" <?php if($col == 'four-columns') { echo 'selected'; } ?>><?php esc_html_e('4 columns','my_theme'); ?></option>
  513. </select>
  514. </label>
  515. </p>
  516.  
  517. <?php } ?>
  518. <?php if($depth === 1) { ?>
  519.  
  520. <p class="field-menu-linkrole description description-thin">
  521. <label for="edit-menu-item-linkrole-<?php echo esc_attr($item_id); ?>"><?php esc_html_e( 'Act as link or title','my_theme' ); ?>
  522. <select id="edit-menu-item-linkrole-<?php echo esc_attr($item_id); ?>" class="widefat edit-menu-item-linkrole" name="menu-item-linkrole[<?php echo esc_attr($item_id); ?>]">
  523. <?php $val = get_post_meta( $item->ID, '_menu-item-linkrole', true); ?>
  524. <option value="link" <?php if($val == 'link') { echo 'selected'; } ?>><?php esc_html_e('Link', "my_theme"); ?></option>
  525. <option value="hidden" <?php if($val == 'hidden') { echo 'selected'; } ?>><?php esc_html_e('Hidden element', "my_theme"); ?></option>
  526. <option value="title" <?php if($val == 'title') { echo 'selected'; } ?>><?php esc_html_e('Title','my_theme'); ?></option>
  527. <option value="paragraph" <?php if($val == 'paragraph') { echo 'selected'; } ?>><?php esc_html_e('Text','my_theme'); ?></option>
  528. <option value="paragraphtitle" <?php if($val == 'paragraphtitle') { echo 'selected'; } ?>><?php esc_html_e('Text with title','my_theme'); ?></option>
  529. </select>
  530. </label>
  531. </p>
  532. <p class="field-menu-linkrole description description-wide">
  533. <label for="edit-menu-item-html-<?php echo esc_attr($item_id); ?>"><?php esc_html_e( 'Custom html text','my_theme' ); ?>
  534. <?php $content = get_post_meta( $item->ID, '_menu-item-html', true); ?>
  535. <textarea id="edit-menu-item-html-<?php echo esc_attr($item_id); ?>" class="widefat edit-menu-item-html" rows="3" cols="20" name="menu-item-html[<?php echo esc_attr($item_id); ?>]"><?php
  536. $allowed_tags = wp_kses_allowed_html( 'post' );
  537. echo wp_kses( $content, $allowed_html_array );
  538.  
  539. ?></textarea>
  540. </label>
  541. </p>
  542. <?php } ?>
  543. <p class="field-hiddenonmobile description description-wide">
  544. <label for="edit-menu-item-hiddenonmobile-<?php echo esc_attr($item_id); ?>">
  545. <?php $statuscheckbox=''; $mobilestatus = get_post_meta( $item->ID, '_menu-item-hiddenonmobile', true); if($mobilestatus == "hide") $statuscheckbox = "checked='checked'";?>
  546. <input type="checkbox" id="edit-menu-item-hiddenonmobile-<?php echo esc_attr($item_id); ?>" value="hide" name="menu-item-hiddenonmobile[<?php echo esc_attr($item_id); ?>]" <?php echo esc_attr($statuscheckbox); ?> />
  547. <?php esc_html_e( 'Hide on mobile navigation','my_theme' ); ?>
  548. </label>
  549. </p>
  550.  
  551.  
  552.  
  553. <!-- eof custom element for columns number -->
  554. <p class="field-move hide-if-no-js description description-wide">
  555. <label>
  556. <span><?php esc_html_e( 'Move','my_theme' ); ?></span>
  557. <a href="#" class="menus-move menus-move-up" data-dir="up"><?php esc_html_e( 'Up one','my_theme' ); ?></a>
  558. <a href="#" class="menus-move menus-move-down" data-dir="down"><?php esc_html_e( 'Down one','my_theme' ); ?></a>
  559. <a href="#" class="menus-move menus-move-left" data-dir="left"></a>
  560. <a href="#" class="menus-move menus-move-right" data-dir="right"></a>
  561. <a href="#" class="menus-move menus-move-top" data-dir="top"><?php esc_html_e( 'To the top','my_theme' ); ?></a>
  562. </label>
  563. </p>
  564.  
  565. <div class="menu-item-actions description-wide submitbox">
  566. <?php if ( 'custom' != $item->type && $original_title !== false ) : ?>
  567. <p class="link-to-original">
  568. <?php printf( esc_html__('Original: %s','my_theme'), '<a href="' . esc_attr( $item->url ) . '">' . esc_html( $original_title ) . '</a>' ); ?>
  569. </p>
  570. <?php endif; ?>
  571. <a class="item-delete submitdelete deletion" id="delete-<?php echo esc_attr($item_id); ?>" href="<?php
  572. echo wp_nonce_url(
  573. add_query_arg(
  574. array(
  575. 'action' => 'delete-menu-item',
  576. 'menu-item' => $item_id,
  577. ),
  578. admin_url( 'nav-menus.php' )
  579. ),
  580. 'delete-menu_item_' . $item_id
  581. ); ?>"><?php esc_html_e( 'Remove' ,'my_theme'); ?></a> <span class="meta-sep hide-if-no-js"> | </span> <a class="item-cancel submitcancel hide-if-no-js" id="cancel-<?php echo esc_attr($item_id); ?>" href="<?php echo esc_url( add_query_arg( array( 'edit-menu-item' => $item_id, 'cancel' => time() ), admin_url( 'nav-menus.php' ) ) );
  582. ?>#menu-item-settings-<?php echo esc_attr($item_id); ?>"><?php esc_html_e('Cancel','my_theme'); ?></a>
  583. </div>
  584.  
  585. <input class="menu-item-data-db-id" type="hidden" name="menu-item-db-id[<?php echo esc_attr($item_id); ?>]" value="<?php echo esc_attr($item_id); ?>" />
  586. <input class="menu-item-data-object-id" type="hidden" name="menu-item-object-id[<?php echo esc_attr($item_id); ?>]" value="<?php echo esc_attr( $item->object_id ); ?>" />
  587. <input class="menu-item-data-object" type="hidden" name="menu-item-object[<?php echo esc_attr($item_id); ?>]" value="<?php echo esc_attr( $item->object ); ?>" />
  588. <input class="menu-item-data-parent-id" type="hidden" name="menu-item-parent-id[<?php echo esc_attr($item_id); ?>]" value="<?php echo esc_attr( $item->menu_item_parent ); ?>" />
  589. <input class="menu-item-data-position" type="hidden" name="menu-item-position[<?php echo esc_attr($item_id); ?>]" value="<?php echo esc_attr( $item->menu_order ); ?>" />
  590. <input class="menu-item-data-type" type="hidden" name="menu-item-type[<?php echo esc_attr($item_id); ?>]" value="<?php echo esc_attr( $item->type ); ?>" />
  591. </div><!-- .menu-item-settings-->
  592. <ul class="menu-item-transport"></ul>
  593. <?php
  594. $output .= ob_get_clean();
  595. }
  596. }
  597.  
  598. function modify_backend_walker($name)
  599. {
  600. return 'my_theme_walker_nav_edit';
  601. }
  602.  
  603. /*
  604. * Save and Update the Custom Navigation Menu Item Properties by checking all $_POST vars with the name of $check
  605. * @param int $menu_id
  606. * @param int $menu_item_db
  607. */
  608. function update_menu($menu_id, $menu_item_db)
  609. {
  610. $check = array('columns','linkrole','megamenu', 'icon','columnscont','pureicon','html','hiddenonmobile','colwidth' );
  611.  
  612. foreach ( $check as $key )
  613. {
  614. if(!isset($_POST['menu-item-'.$key][$menu_item_db]))
  615. {
  616. $_POST['menu-item-'.$key][$menu_item_db] = "";
  617. }
  618.  
  619. $value = $_POST['menu-item-'.$key][$menu_item_db];
  620. update_post_meta( $menu_item_db, '_menu-item-'.$key, $value );
  621. }
  622. }
  623.  
  624.  
  625.  
  626. //responsive walker
  627.  
  628. class Walker_Nav_Menu_Dropdown extends Walker_Nav_Menu{
  629. var $to_depth = -1;
  630. private $curItem;
  631. function start_lvl(&$output, $depth = 0, $args = array()){
  632. $id = $this->curItem->ID;
  633. $linkrole = get_post_meta( $id, '_menu-item-linkrole', true);
  634. $types = array( 'paragraph', 'title' );
  635. if(!in_array( $linkrole, $types )) {
  636.  
  637. $output .= '</option>';
  638. }
  639. }
  640.  
  641. function end_lvl(&$output, $depth = 0, $args = array()){
  642. $indent = str_repeat("\t", $depth); // don't output children closing tag
  643. }
  644.  
  645. function start_el(&$output, $item, $depth = 0, $args = array(), $current_object_id = 0){
  646. $this->curItem = $item;
  647. $indent = ( $depth ) ? str_repeat( "&nbsp;", $depth * 4 ) : '';
  648. $class_names = $value = '';
  649. $classes = empty( $item->classes ) ? array() : (array) $item->classes;
  650. $classes[] = 'menu-item-' . $item->ID;
  651. $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) );
  652. $class_names = ' class="' . esc_attr( $class_names ) . '"';
  653. $id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args );
  654. $id = strlen( $id ) ? ' id="' . esc_attr( $id ) . '"' : '';
  655. $value = ' value="'. $item->url .'"';
  656. $linkrole = get_post_meta( $item->ID, '_menu-item-linkrole', true);
  657. $types = array( 'paragraph', 'titleh4', 'titleh5' );
  658. $args = (object) $args;
  659. if(!in_array( $linkrole, $types )) {
  660. $output .= '<option'.$id.$value.$class_names.'>';
  661. $item_output = $args->before;
  662.  
  663. $item_output .= $args->link_before. apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
  664. $output .= $indent.$item_output;
  665. }
  666. }
  667.  
  668. function end_el(&$output, $item, $depth = 0, $args = array()){
  669. $linkrole = get_post_meta( $item->ID, '_menu-item-linkrole', true);
  670. if($linkrole != 'paragraph' || $linkrole != 'titleh4' || $linkrole != 'titleh5') {
  671. if(substr($output, -9) != '</option>') {
  672. $output .= "</option>"; // replace closing </li> with the option tag
  673.  
  674. }
  675. }
  676. }
  677. }
  678.  
  679. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement