63 * @param int $depth Depth of menu item. Used for padding. |
63 * @param int $depth Depth of menu item. Used for padding. |
64 * @param int $current_page Menu item ID. |
64 * @param int $current_page Menu item ID. |
65 * @param object $args |
65 * @param object $args |
66 */ |
66 */ |
67 function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { |
67 function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { |
68 global $wp_query; |
|
69 $indent = ( $depth ) ? str_repeat( "\t", $depth ) : ''; |
68 $indent = ( $depth ) ? str_repeat( "\t", $depth ) : ''; |
70 |
69 |
71 $class_names = $value = ''; |
70 $class_names = $value = ''; |
72 |
71 |
73 $classes = empty( $item->classes ) ? array() : (array) $item->classes; |
72 $classes = empty( $item->classes ) ? array() : (array) $item->classes; |
154 |
153 |
155 // get the first menu that has items if we still can't find a menu |
154 // get the first menu that has items if we still can't find a menu |
156 if ( ! $menu && !$args->theme_location ) { |
155 if ( ! $menu && !$args->theme_location ) { |
157 $menus = wp_get_nav_menus(); |
156 $menus = wp_get_nav_menus(); |
158 foreach ( $menus as $menu_maybe ) { |
157 foreach ( $menus as $menu_maybe ) { |
159 if ( $menu_items = wp_get_nav_menu_items($menu_maybe->term_id) ) { |
158 if ( $menu_items = wp_get_nav_menu_items( $menu_maybe->term_id, array( 'update_post_term_cache' => false ) ) ) { |
160 $menu = $menu_maybe; |
159 $menu = $menu_maybe; |
161 break; |
160 break; |
162 } |
161 } |
163 } |
162 } |
164 } |
163 } |
165 |
164 |
166 // If the menu exists, get its items. |
165 // If the menu exists, get its items. |
167 if ( $menu && ! is_wp_error($menu) && !isset($menu_items) ) |
166 if ( $menu && ! is_wp_error($menu) && !isset($menu_items) ) |
168 $menu_items = wp_get_nav_menu_items( $menu->term_id ); |
167 $menu_items = wp_get_nav_menu_items( $menu->term_id, array( 'update_post_term_cache' => false ) ); |
169 |
168 |
170 // If no menu was found or if the menu has no items and no location was requested, call the fallback_cb if it exists |
169 /* |
|
170 * If no menu was found: |
|
171 * - Fallback (if one was specified), or bail. |
|
172 * |
|
173 * If no menu items were found: |
|
174 * - Fallback, but only if no theme location was specified. |
|
175 * - Otherwise, bail. |
|
176 */ |
171 if ( ( !$menu || is_wp_error($menu) || ( isset($menu_items) && empty($menu_items) && !$args->theme_location ) ) |
177 if ( ( !$menu || is_wp_error($menu) || ( isset($menu_items) && empty($menu_items) && !$args->theme_location ) ) |
172 && $args->fallback_cb && is_callable( $args->fallback_cb ) ) |
178 && $args->fallback_cb && is_callable( $args->fallback_cb ) ) |
173 return call_user_func( $args->fallback_cb, (array) $args ); |
179 return call_user_func( $args->fallback_cb, (array) $args ); |
174 |
180 |
175 // If no fallback function was specified and the menu doesn't exists, bail. |
181 if ( !$menu || is_wp_error( $menu ) || empty( $menu_items ) ) |
176 if ( !$menu || is_wp_error($menu) ) |
|
177 return false; |
182 return false; |
178 |
183 |
179 $nav_menu = $items = ''; |
184 $nav_menu = $items = ''; |
180 |
185 |
181 $show_container = false; |
186 $show_container = false; |
285 } while ( ! empty( $desc ) ); |
290 } while ( ! empty( $desc ) ); |
286 } |
291 } |
287 } |
292 } |
288 } |
293 } |
289 } |
294 } |
290 } elseif ( ! empty( $queried_object->post_type ) && is_post_type_hierarchical( $queried_object->post_type ) ) { |
|
291 _get_post_ancestors( $queried_object ); |
|
292 } elseif ( ! empty( $queried_object->taxonomy ) && is_taxonomy_hierarchical( $queried_object->taxonomy ) ) { |
295 } elseif ( ! empty( $queried_object->taxonomy ) && is_taxonomy_hierarchical( $queried_object->taxonomy ) ) { |
293 $term_hierarchy = _get_term_hierarchy( $queried_object->taxonomy ); |
296 $term_hierarchy = _get_term_hierarchy( $queried_object->taxonomy ); |
294 $term_to_ancestor = array(); |
297 $term_to_ancestor = array(); |
295 foreach ( (array) $term_hierarchy as $anc => $descs ) { |
298 foreach ( (array) $term_hierarchy as $anc => $descs ) { |
296 foreach ( (array) $descs as $desc ) |
299 foreach ( (array) $descs as $desc ) |
332 } elseif ( |
335 } elseif ( |
333 $menu_item->object_id == $queried_object_id && |
336 $menu_item->object_id == $queried_object_id && |
334 ( |
337 ( |
335 ( ! empty( $home_page_id ) && 'post_type' == $menu_item->type && $wp_query->is_home && $home_page_id == $menu_item->object_id ) || |
338 ( ! empty( $home_page_id ) && 'post_type' == $menu_item->type && $wp_query->is_home && $home_page_id == $menu_item->object_id ) || |
336 ( 'post_type' == $menu_item->type && $wp_query->is_singular ) || |
339 ( 'post_type' == $menu_item->type && $wp_query->is_singular ) || |
337 ( 'taxonomy' == $menu_item->type && ( $wp_query->is_category || $wp_query->is_tag || $wp_query->is_tax ) ) |
340 ( 'taxonomy' == $menu_item->type && ( $wp_query->is_category || $wp_query->is_tag || $wp_query->is_tax ) && $queried_object->taxonomy == $menu_item->object ) |
338 ) |
341 ) |
339 ) { |
342 ) { |
340 $classes[] = 'current-menu-item'; |
343 $classes[] = 'current-menu-item'; |
341 $menu_items[$key]->current = true; |
344 $menu_items[$key]->current = true; |
342 $_anc_id = (int) $menu_item->db_id; |
345 $_anc_id = (int) $menu_item->db_id; |
359 $active_object = $menu_item->object; |
362 $active_object = $menu_item->object; |
360 |
363 |
361 // if the menu item corresponds to the currently-requested URL |
364 // if the menu item corresponds to the currently-requested URL |
362 } elseif ( 'custom' == $menu_item->object ) { |
365 } elseif ( 'custom' == $menu_item->object ) { |
363 $_root_relative_current = untrailingslashit( $_SERVER['REQUEST_URI'] ); |
366 $_root_relative_current = untrailingslashit( $_SERVER['REQUEST_URI'] ); |
364 $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_root_relative_current; |
367 $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_root_relative_current ); |
365 $raw_item_url = strpos( $menu_item->url, '#' ) ? substr( $menu_item->url, 0, strpos( $menu_item->url, '#' ) ) : $menu_item->url; |
368 $raw_item_url = strpos( $menu_item->url, '#' ) ? substr( $menu_item->url, 0, strpos( $menu_item->url, '#' ) ) : $menu_item->url; |
366 $item_url = untrailingslashit( $raw_item_url ); |
369 $item_url = untrailingslashit( $raw_item_url ); |
367 $_indexless_current = untrailingslashit( preg_replace( '/index.php$/', '', $current_url ) ); |
370 $_indexless_current = untrailingslashit( preg_replace( '/index.php$/', '', $current_url ) ); |
368 |
371 |
369 if ( $raw_item_url && in_array( $item_url, array( $current_url, $_indexless_current, $_root_relative_current ) ) ) { |
372 if ( $raw_item_url && in_array( $item_url, array( $current_url, $_indexless_current, $_root_relative_current ) ) ) { |
470 */ |
473 */ |
471 function walk_nav_menu_tree( $items, $depth, $r ) { |
474 function walk_nav_menu_tree( $items, $depth, $r ) { |
472 $walker = ( empty($r->walker) ) ? new Walker_Nav_Menu : $r->walker; |
475 $walker = ( empty($r->walker) ) ? new Walker_Nav_Menu : $r->walker; |
473 $args = array( $items, $depth, $r ); |
476 $args = array( $items, $depth, $r ); |
474 |
477 |
475 return call_user_func_array( array(&$walker, 'walk'), $args ); |
478 return call_user_func_array( array($walker, 'walk'), $args ); |
476 } |
479 } |
477 |
480 |
478 /** |
481 /** |
479 * Prevents a menu item ID from being used more than once. |
482 * Prevents a menu item ID from being used more than once. |
480 * |
483 * |