Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.03 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * Menu Walker
  5. *
  6. * @see Walker::start_lvl()
  7. * @since 3.0.0
  8. *
  9. * @param string $output Passed by reference. Used to append additional content.
  10. * @param int $depth Depth of page. Used for padding.
  11. * @param object $args Arguments.
  12. */
  13. public function start_lvl(&$output, $depth = 0, $args = array())
  14. {
  15. $indent = str_repeat("t", $depth);
  16. $output .= "n$indent<ul role="menu" class=" dvt-nav-dropdown closed">n";
  17. }
  18.  
  19. /**
  20. * Bootstrap Menu Walker start
  21. *
  22. * @see Walker::start_el()
  23. * @since 3.0.0
  24. *
  25. * @param string $output Passed by reference. Used to append additional content.
  26. * @param object $item Menu item data object.
  27. * @param int $depth Depth of menu item. Used for padding.
  28. * @param object $args Arguments.
  29. * @param int $id Menu item ID.
  30. */
  31. public function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0)
  32. {
  33. // Set level of indent.
  34. $indent = ($depth) ? str_repeat("t", $depth) : '';
  35.  
  36. // Create nav menu item.
  37. $nav_menu_atts = array();
  38. $nav_menu_atts['id'] = apply_filters('nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args);
  39. $nav_menu_atts['class'] = empty($item->classes) ? array() : (array) $item->classes;
  40. $nav_menu_atts['class'] = apply_filters('nav_menu_css_class', $nav_menu_atts['class'], $item, $args);
  41.  
  42. // Create link attributes.
  43. $nav_menu_link_atts = array();
  44. $nav_menu_link_atts['title'] = ! empty($item->title) ? $item->title : '';
  45. $nav_menu_link_atts['target'] = ! empty($item->target) ? $item->target : '';
  46. $nav_menu_link_atts['rel'] = ! empty($item->xfn) ? $item->xfn : '';
  47.  
  48. // If item has_children add atts to a.
  49. $nav_menu_link_atts['href'] = $args->has_children && 0 === $depth ? '#' : (!empty($item->url) ? $item->url : '');
  50.  
  51. $nav_menu_link_atts = apply_filters('nav_menu_link_attributes', $nav_menu_link_atts, $item, $args);
  52.  
  53. // Output LI menu item.
  54. $output .= $indent;
  55. $output .= '<li';
  56. // Output menu attributes.
  57. foreach ($nav_menu_atts as $attr => $value) {
  58. // Output attribute name.
  59. $output .= ' ' . esc_attr($attr);
  60. if (!empty($value)) {
  61. $output .= '="';
  62. // Add switch to handle escaping.
  63. switch ($attr) {
  64. case 'class':
  65. $output .= esc_attr(join(' ', array_filter($value)));
  66. break;
  67. default:
  68. $output .= esc_attr($value);
  69. break;
  70. }
  71. $output .= '"';
  72. }
  73. }
  74. $output .= '>';
  75.  
  76. // Output A link.
  77. $item_output = $args->before;
  78. $item_output .= '<a';
  79. // Output link attributes.
  80. foreach ($nav_menu_link_atts as $attr => $value) {
  81. if (!empty($value)) {
  82. // Output attribute name.
  83. $item_output .= ' ' . esc_attr($attr) . '="';
  84. // Add switch to handle escaping.
  85. switch ($attr) {
  86. case 'href':
  87. $item_output .= esc_url($value);
  88. break;
  89.  
  90. case 'class':
  91. $item_output .= esc_attr(join(' ', array_filter($value)));
  92. break;
  93.  
  94. default:
  95. $item_output .= esc_attr($value);
  96. break;
  97. }
  98. $item_output .= '"';
  99. }
  100. }
  101. $item_output .= '>';
  102. $item_output .= $args->link_before . apply_filters('the_title', $item->title, $item->ID) . $args->link_after;
  103. $item_output .= '</a>';
  104. $item_output .= $args->after;
  105.  
  106. $output .= apply_filters('walker_nav_menu_start_el', $item_output, $item, $depth, $args);
  107. }
  108.  
  109. /**
  110. * Traverse elements to create list from elements.
  111. *
  112. * Display one element if the element doesn't have any children otherwise,
  113. * display the element and its children. Will only traverse up to the max
  114. * depth and no ignore elements under that depth.
  115. *
  116. * This method shouldn't be called directly, use the walk() method instead.
  117. *
  118. * @see Walker::start_el()
  119. * @since 2.5.0
  120. *
  121. * @param object $element Data object.
  122. * @param array $children_elements List of elements to continue traversing.
  123. * @param int $max_depth Max depth to traverse.
  124. * @param int $depth Depth of current element.
  125. * @param array $args Arguments.
  126. * @param string $output Passed by reference. Used to append additional content.
  127. * @return null Null on failure with no changes to parameters.
  128. */
  129. public function display_element($element, &$children_elements, $max_depth, $depth, $args, &$output)
  130. {
  131. if (! $element) {
  132. return;
  133. }
  134.  
  135. $id_field = $this->db_fields['id'];
  136.  
  137. // Display this element.
  138. if (is_object($args[0])) {
  139. $args[0]->has_children = ! empty($children_elements[ $element->$id_field ]);
  140. }
  141.  
  142. parent::display_element($element, $children_elements, $max_depth, $depth, $args, $output);
  143. }
  144.  
  145. /**
  146. * Menu Fallback
  147. * =============
  148. * If this function is assigned to the wp_nav_menu's fallback_cb variable
  149. * and a manu has not been assigned to the theme location in the WordPress
  150. * menu manager the function with display nothing to a non-logged in user,
  151. * and will add a link to the WordPress menu manager if logged in as an admin.
  152. *
  153. * @param array $args passed from the wp_nav_menu function.
  154. */
  155. public static function fallback($args)
  156. {
  157. if (current_user_can('manage_options')) {
  158. $fb_output = null;
  159.  
  160. if ($args['container']) {
  161. echo '<' . esc_html($args['container']);
  162.  
  163. if ($args['container_id']) {
  164. echo ' id="' . esc_attr($args['container_id']) . '"';
  165. }
  166.  
  167. if ($args['container_class']) {
  168. echo ' class="' . esc_attr($args['container_class']) . '"';
  169. }
  170.  
  171. echo '>';
  172. }
  173.  
  174. echo '<ul';
  175.  
  176. if ($args['menu_id']) {
  177. echo ' id="' . esc_attr($args['menu_id']) . '"';
  178. }
  179.  
  180. if ($args['menu_class']) {
  181. echo ' class="' . esc_attr($args['menu_class']) . '"';
  182. }
  183.  
  184. echo '>';
  185. echo '</ul>';
  186.  
  187. if ($args['container']) {
  188. echo '</' . esc_html($args['container']) . '>';
  189. }
  190. }
  191. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement