2010-02-24 03:06:36 -05:00
|
|
|
<?php
|
2010-03-31 03:54:09 -04:00
|
|
|
/**
|
2016-06-06 11:18:31 -04:00
|
|
|
* Nav Menu API: Template functions
|
2010-03-31 03:54:09 -04:00
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Nav_Menus
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
|
|
|
|
2016-08-31 12:31:29 -04:00
|
|
|
/** Walker_Nav_Menu class */
|
|
|
|
require_once ABSPATH . WPINC . '/class-walker-nav-menu.php';
|
|
|
|
|
2010-02-24 03:06:36 -05:00
|
|
|
/**
|
2010-02-28 15:00:49 -05:00
|
|
|
* Displays a navigation menu.
|
2010-02-24 03:06:36 -05:00
|
|
|
*
|
|
|
|
* @since 3.0.0
|
2016-09-08 01:32:03 -04:00
|
|
|
* @since 4.7.0 Added the `item_spacing` argument.
|
2020-07-06 16:44:02 -04:00
|
|
|
* @since 5.5.0 Added the `container_aria_label` argument.
|
2010-02-24 03:06:36 -05:00
|
|
|
*
|
2014-02-21 13:32:15 -05:00
|
|
|
* @param array $args {
|
|
|
|
* Optional. Array of nav menu arguments.
|
|
|
|
*
|
2020-07-07 05:28:01 -04:00
|
|
|
* @type int|string|WP_Term $menu Desired menu. Accepts a menu ID, slug, name, or object.
|
|
|
|
* Default empty.
|
|
|
|
* @type string $menu_class CSS class to use for the ul element which forms the menu.
|
|
|
|
* Default 'menu'.
|
2020-07-06 16:44:02 -04:00
|
|
|
* @type string $menu_id The ID that is applied to the ul element which forms the menu.
|
|
|
|
* Default is the menu slug, incremented.
|
2020-07-07 05:28:01 -04:00
|
|
|
* @type string $container Whether to wrap the ul, and what to wrap it with.
|
|
|
|
* Default 'div'.
|
|
|
|
* @type string $container_class Class that is applied to the container.
|
|
|
|
* Default 'menu-{menu slug}-container'.
|
2020-07-06 16:44:02 -04:00
|
|
|
* @type string $container_id The ID that is applied to the container. Default empty.
|
2020-07-07 05:28:01 -04:00
|
|
|
* @type string $container_aria_label The aria-label attribute that is applied to the container
|
|
|
|
* when it's a nav element. Default empty.
|
2021-01-03 17:04:04 -05:00
|
|
|
* @type callable|false $fallback_cb If the menu doesn't exist, a callback function will fire.
|
2020-07-06 16:44:02 -04:00
|
|
|
* Default is 'wp_page_menu'. Set to false for no fallback.
|
|
|
|
* @type string $before Text before the link markup. Default empty.
|
|
|
|
* @type string $after Text after the link markup. Default empty.
|
|
|
|
* @type string $link_before Text before the link text. Default empty.
|
|
|
|
* @type string $link_after Text after the link text. Default empty.
|
|
|
|
* @type bool $echo Whether to echo the menu or return it. Default true.
|
2020-07-07 05:28:01 -04:00
|
|
|
* @type int $depth How many levels of the hierarchy are to be included.
|
|
|
|
* 0 means all. Default 0.
|
|
|
|
* Default 0.
|
2020-07-06 16:44:02 -04:00
|
|
|
* @type object $walker Instance of a custom walker class. Default empty.
|
2020-07-07 05:28:01 -04:00
|
|
|
* @type string $theme_location Theme location to be used. Must be registered with
|
|
|
|
* register_nav_menu() in order to be selectable by the user.
|
|
|
|
* @type string $items_wrap How the list items should be wrapped. Uses printf() format with
|
|
|
|
* numbered placeholders. Default is a ul with an id and class.
|
|
|
|
* @type string $item_spacing Whether to preserve whitespace within the menu's HTML.
|
|
|
|
* Accepts 'preserve' or 'discard'. Default 'preserve'.
|
2014-02-21 13:32:15 -05:00
|
|
|
* }
|
2020-01-21 15:13:05 -05:00
|
|
|
* @return void|string|false Void if 'echo' argument is true, menu output if 'echo' is false.
|
|
|
|
* False if there are no items or no menu was found.
|
2010-02-24 03:06:36 -05:00
|
|
|
*/
|
|
|
|
function wp_nav_menu( $args = array() ) {
|
2010-06-02 13:04:07 -04:00
|
|
|
static $menu_id_slugs = array();
|
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
$defaults = array(
|
2020-07-06 16:44:02 -04:00
|
|
|
'menu' => '',
|
|
|
|
'container' => 'div',
|
|
|
|
'container_class' => '',
|
|
|
|
'container_id' => '',
|
|
|
|
'container_aria_label' => '',
|
|
|
|
'menu_class' => 'menu',
|
|
|
|
'menu_id' => '',
|
|
|
|
'echo' => true,
|
|
|
|
'fallback_cb' => 'wp_page_menu',
|
|
|
|
'before' => '',
|
|
|
|
'after' => '',
|
|
|
|
'link_before' => '',
|
|
|
|
'link_after' => '',
|
|
|
|
'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',
|
|
|
|
'item_spacing' => 'preserve',
|
|
|
|
'depth' => 0,
|
|
|
|
'walker' => '',
|
|
|
|
'theme_location' => '',
|
2017-11-30 18:11:00 -05:00
|
|
|
);
|
2010-03-17 12:27:25 -04:00
|
|
|
|
2010-02-27 18:06:56 -05:00
|
|
|
$args = wp_parse_args( $args, $defaults );
|
2016-09-06 05:06:31 -04:00
|
|
|
|
|
|
|
if ( ! in_array( $args['item_spacing'], array( 'preserve', 'discard' ), true ) ) {
|
2020-01-28 19:45:18 -05:00
|
|
|
// Invalid value, fall back to default.
|
2016-09-06 05:06:31 -04:00
|
|
|
$args['item_spacing'] = $defaults['item_spacing'];
|
|
|
|
}
|
|
|
|
|
2013-09-12 14:48:09 -04:00
|
|
|
/**
|
2016-05-22 14:28:27 -04:00
|
|
|
* Filters the arguments used to display a navigation menu.
|
2013-09-12 14:48:09 -04:00
|
|
|
*
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2014-02-20 00:08:13 -05:00
|
|
|
* @see wp_nav_menu()
|
|
|
|
*
|
|
|
|
* @param array $args Array of wp_nav_menu() arguments.
|
2013-09-12 14:48:09 -04:00
|
|
|
*/
|
2010-02-28 15:00:49 -05:00
|
|
|
$args = apply_filters( 'wp_nav_menu_args', $args );
|
2010-02-24 03:45:26 -05:00
|
|
|
$args = (object) $args;
|
2010-03-01 07:53:51 -05:00
|
|
|
|
2014-03-03 15:43:15 -05:00
|
|
|
/**
|
2016-05-22 14:28:27 -04:00
|
|
|
* Filters whether to short-circuit the wp_nav_menu() output.
|
2014-03-03 15:43:15 -05:00
|
|
|
*
|
2020-06-26 14:49:09 -04:00
|
|
|
* Returning a non-null value from the filter will short-circuit wp_nav_menu(),
|
|
|
|
* echoing that value if $args->echo is true, returning that value otherwise.
|
2014-03-03 15:43:15 -05:00
|
|
|
*
|
|
|
|
* @since 3.9.0
|
|
|
|
*
|
|
|
|
* @see wp_nav_menu()
|
|
|
|
*
|
|
|
|
* @param string|null $output Nav menu output to short-circuit with. Default null.
|
2016-09-07 12:15:30 -04:00
|
|
|
* @param stdClass $args An object containing wp_nav_menu() arguments.
|
2014-03-03 15:43:15 -05:00
|
|
|
*/
|
|
|
|
$nav_menu = apply_filters( 'pre_wp_nav_menu', null, $args );
|
|
|
|
|
|
|
|
if ( null !== $nav_menu ) {
|
|
|
|
if ( $args->echo ) {
|
|
|
|
echo $nav_menu;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $nav_menu;
|
|
|
|
}
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Get the nav menu based on the requested menu.
|
2010-02-28 15:00:49 -05:00
|
|
|
$menu = wp_get_nav_menu_object( $args->menu );
|
2010-03-17 12:27:25 -04:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Get the nav menu based on the theme_location.
|
2019-07-02 19:42:58 -04:00
|
|
|
$locations = get_nav_menu_locations();
|
|
|
|
if ( ! $menu && $args->theme_location && $locations && isset( $locations[ $args->theme_location ] ) ) {
|
2010-05-14 02:20:30 -04:00
|
|
|
$menu = wp_get_nav_menu_object( $locations[ $args->theme_location ] );
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2010-05-13 18:14:54 -04:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Get the first menu that has items if we still can't find a menu.
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( ! $menu && ! $args->theme_location ) {
|
2014-09-29 11:45:16 -04:00
|
|
|
$menus = wp_get_nav_menus();
|
2010-02-24 03:45:26 -05:00
|
|
|
foreach ( $menus as $menu_maybe ) {
|
2019-07-02 19:42:58 -04:00
|
|
|
$menu_items = wp_get_nav_menu_items( $menu_maybe->term_id, array( 'update_post_term_cache' => false ) );
|
|
|
|
if ( $menu_items ) {
|
2010-02-24 03:45:26 -05:00
|
|
|
$menu = $menu_maybe;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-05-03 16:26:11 -04:00
|
|
|
|
2015-06-16 16:33:25 -04:00
|
|
|
if ( empty( $args->menu ) ) {
|
|
|
|
$args->menu = $menu;
|
|
|
|
}
|
|
|
|
|
2010-04-26 21:05:58 -04:00
|
|
|
// If the menu exists, get its items.
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( $menu && ! is_wp_error( $menu ) && ! isset( $menu_items ) ) {
|
2012-10-15 10:17:50 -04:00
|
|
|
$menu_items = wp_get_nav_menu_items( $menu->term_id, array( 'update_post_term_cache' => false ) );
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2010-03-26 15:36:49 -04:00
|
|
|
|
2012-09-16 13:07:56 -04:00
|
|
|
/*
|
|
|
|
* If no menu was found:
|
2013-07-10 01:14:43 -04:00
|
|
|
* - Fall back (if one was specified), or bail.
|
2012-09-16 13:07:56 -04:00
|
|
|
*
|
|
|
|
* If no menu items were found:
|
2013-07-10 01:14:43 -04:00
|
|
|
* - Fall back, but only if no theme location was specified.
|
2012-09-16 13:07:56 -04:00
|
|
|
* - Otherwise, bail.
|
|
|
|
*/
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( ( ! $menu || is_wp_error( $menu ) || ( isset( $menu_items ) && empty( $menu_items ) && ! $args->theme_location ) )
|
|
|
|
&& isset( $args->fallback_cb ) && $args->fallback_cb && is_callable( $args->fallback_cb ) ) {
|
2010-04-07 11:25:48 -04:00
|
|
|
return call_user_func( $args->fallback_cb, (array) $args );
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2010-05-03 16:26:11 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( ! $menu || is_wp_error( $menu ) ) {
|
2010-05-03 18:03:52 -04:00
|
|
|
return false;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2010-05-03 18:03:52 -04:00
|
|
|
|
2019-07-02 19:42:58 -04:00
|
|
|
$nav_menu = '';
|
|
|
|
$items = '';
|
2010-04-07 11:25:48 -04:00
|
|
|
|
2010-06-02 13:04:07 -04:00
|
|
|
$show_container = false;
|
|
|
|
if ( $args->container ) {
|
2013-09-12 14:48:09 -04:00
|
|
|
/**
|
2016-05-22 14:28:27 -04:00
|
|
|
* Filters the list of HTML tags that are valid for use as menu containers.
|
2013-09-12 14:48:09 -04:00
|
|
|
*
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2019-10-26 17:09:04 -04:00
|
|
|
* @param string[] $tags The acceptable HTML tags for use as menu containers.
|
|
|
|
* Default is array containing 'div' and 'nav'.
|
2013-09-12 14:48:09 -04:00
|
|
|
*/
|
2010-06-02 13:04:07 -04:00
|
|
|
$allowed_tags = apply_filters( 'wp_nav_menu_container_allowedtags', array( 'div', 'nav' ) );
|
2020-04-04 23:02:11 -04:00
|
|
|
|
|
|
|
if ( is_string( $args->container ) && in_array( $args->container, $allowed_tags, true ) ) {
|
2010-06-02 13:04:07 -04:00
|
|
|
$show_container = true;
|
2017-11-30 18:11:00 -05:00
|
|
|
$class = $args->container_class ? ' class="' . esc_attr( $args->container_class ) . '"' : ' class="menu-' . $menu->slug . '-container"';
|
|
|
|
$id = $args->container_id ? ' id="' . esc_attr( $args->container_id ) . '"' : '';
|
2020-07-06 16:44:02 -04:00
|
|
|
$aria_label = ( 'nav' === $args->container && $args->container_aria_label ) ? ' aria-label="' . esc_attr( $args->container_aria_label ) . '"' : '';
|
|
|
|
$nav_menu .= '<' . $args->container . $id . $class . $aria_label . '>';
|
2010-06-02 13:04:07 -04:00
|
|
|
}
|
2010-04-07 11:25:48 -04:00
|
|
|
}
|
2010-03-26 15:36:49 -04:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Set up the $menu_item variables.
|
2010-05-31 10:54:50 -04:00
|
|
|
_wp_menu_item_classes_by_context( $menu_items );
|
2010-05-25 09:30:10 -04:00
|
|
|
|
2019-07-02 19:42:58 -04:00
|
|
|
$sorted_menu_items = array();
|
|
|
|
$menu_items_with_children = array();
|
2013-09-24 12:01:09 -04:00
|
|
|
foreach ( (array) $menu_items as $menu_item ) {
|
|
|
|
$sorted_menu_items[ $menu_item->menu_order ] = $menu_item;
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( $menu_item->menu_item_parent ) {
|
2013-09-24 12:01:09 -04:00
|
|
|
$menu_items_with_children[ $menu_item->menu_item_parent ] = true;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2013-09-24 12:01:09 -04:00
|
|
|
}
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Add the menu-item-has-children class where applicable.
|
2013-09-24 12:01:09 -04:00
|
|
|
if ( $menu_items_with_children ) {
|
|
|
|
foreach ( $sorted_menu_items as &$menu_item ) {
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( isset( $menu_items_with_children[ $menu_item->ID ] ) ) {
|
2013-09-24 12:01:09 -04:00
|
|
|
$menu_item->classes[] = 'menu-item-has-children';
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2013-09-24 12:01:09 -04:00
|
|
|
}
|
|
|
|
}
|
2010-05-25 22:42:15 -04:00
|
|
|
|
2013-09-24 12:01:09 -04:00
|
|
|
unset( $menu_items, $menu_item );
|
2010-10-19 03:48:22 -04:00
|
|
|
|
2013-09-12 14:48:09 -04:00
|
|
|
/**
|
2016-05-22 14:28:27 -04:00
|
|
|
* Filters the sorted list of menu item objects before generating the menu's HTML.
|
2013-09-12 14:48:09 -04:00
|
|
|
*
|
|
|
|
* @since 3.1.0
|
|
|
|
*
|
2016-09-07 12:15:30 -04:00
|
|
|
* @param array $sorted_menu_items The menu items, sorted by each menu item's menu order.
|
|
|
|
* @param stdClass $args An object containing wp_nav_menu() arguments.
|
2013-09-12 14:48:09 -04:00
|
|
|
*/
|
2010-08-27 12:13:39 -04:00
|
|
|
$sorted_menu_items = apply_filters( 'wp_nav_menu_objects', $sorted_menu_items, $args );
|
2010-03-26 15:36:49 -04:00
|
|
|
|
2010-04-26 21:05:58 -04:00
|
|
|
$items .= walk_nav_menu_tree( $sorted_menu_items, $args->depth, $args );
|
2017-11-30 18:11:00 -05:00
|
|
|
unset( $sorted_menu_items );
|
2010-03-26 15:36:49 -04:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Attributes.
|
2010-06-02 13:04:07 -04:00
|
|
|
if ( ! empty( $args->menu_id ) ) {
|
2010-11-21 08:37:09 -05:00
|
|
|
$wrap_id = $args->menu_id;
|
2010-06-02 13:04:07 -04:00
|
|
|
} else {
|
2010-11-21 08:37:09 -05:00
|
|
|
$wrap_id = 'menu-' . $menu->slug;
|
2020-04-04 23:02:11 -04:00
|
|
|
|
|
|
|
while ( in_array( $wrap_id, $menu_id_slugs, true ) ) {
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( preg_match( '#-(\d+)$#', $wrap_id, $matches ) ) {
|
|
|
|
$wrap_id = preg_replace( '#-(\d+)$#', '-' . ++$matches[1], $wrap_id );
|
|
|
|
} else {
|
2010-11-21 08:37:09 -05:00
|
|
|
$wrap_id = $wrap_id . '-1';
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2010-06-02 13:04:07 -04:00
|
|
|
}
|
2010-05-28 12:32:57 -04:00
|
|
|
}
|
2010-11-21 08:37:09 -05:00
|
|
|
$menu_id_slugs[] = $wrap_id;
|
|
|
|
|
2010-11-21 08:32:02 -05:00
|
|
|
$wrap_class = $args->menu_class ? $args->menu_class : '';
|
2010-03-26 15:36:49 -04:00
|
|
|
|
2013-09-12 14:48:09 -04:00
|
|
|
/**
|
2016-05-22 14:28:27 -04:00
|
|
|
* Filters the HTML list content for navigation menus.
|
2013-09-12 14:48:09 -04:00
|
|
|
*
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2014-02-20 00:08:13 -05:00
|
|
|
* @see wp_nav_menu()
|
|
|
|
*
|
2016-09-07 12:15:30 -04:00
|
|
|
* @param string $items The HTML list content for the menu items.
|
|
|
|
* @param stdClass $args An object containing wp_nav_menu() arguments.
|
2013-09-12 14:48:09 -04:00
|
|
|
*/
|
2010-05-12 23:50:26 -04:00
|
|
|
$items = apply_filters( 'wp_nav_menu_items', $items, $args );
|
2013-09-12 14:48:09 -04:00
|
|
|
/**
|
2016-05-22 14:28:27 -04:00
|
|
|
* Filters the HTML list content for a specific navigation menu.
|
2013-09-12 14:48:09 -04:00
|
|
|
*
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2014-02-20 00:08:13 -05:00
|
|
|
* @see wp_nav_menu()
|
|
|
|
*
|
2016-09-07 12:15:30 -04:00
|
|
|
* @param string $items The HTML list content for the menu items.
|
|
|
|
* @param stdClass $args An object containing wp_nav_menu() arguments.
|
2013-09-12 14:48:09 -04:00
|
|
|
*/
|
2010-05-12 23:50:26 -04:00
|
|
|
$items = apply_filters( "wp_nav_menu_{$menu->slug}_items", $items, $args );
|
2010-11-21 08:37:09 -05:00
|
|
|
|
2013-07-10 01:14:43 -04:00
|
|
|
// Don't print any markup if there are no items at this point.
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( empty( $items ) ) {
|
2013-07-10 01:14:43 -04:00
|
|
|
return false;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2013-07-10 01:14:43 -04:00
|
|
|
|
2010-11-21 08:37:09 -05:00
|
|
|
$nav_menu .= sprintf( $args->items_wrap, esc_attr( $wrap_id ), esc_attr( $wrap_class ), $items );
|
|
|
|
unset( $items );
|
2010-03-26 15:36:49 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( $show_container ) {
|
2010-06-02 13:04:07 -04:00
|
|
|
$nav_menu .= '</' . $args->container . '>';
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2010-04-07 11:25:48 -04:00
|
|
|
|
2013-09-12 14:48:09 -04:00
|
|
|
/**
|
2016-05-22 14:28:27 -04:00
|
|
|
* Filters the HTML content for navigation menus.
|
2013-09-12 14:48:09 -04:00
|
|
|
*
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2014-02-20 00:08:13 -05:00
|
|
|
* @see wp_nav_menu()
|
|
|
|
*
|
2016-09-07 12:15:30 -04:00
|
|
|
* @param string $nav_menu The HTML content for the navigation menu.
|
|
|
|
* @param stdClass $args An object containing wp_nav_menu() arguments.
|
2013-09-12 14:48:09 -04:00
|
|
|
*/
|
2010-04-07 11:25:48 -04:00
|
|
|
$nav_menu = apply_filters( 'wp_nav_menu', $nav_menu, $args );
|
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( $args->echo ) {
|
2010-04-07 11:25:48 -04:00
|
|
|
echo $nav_menu;
|
2017-11-30 18:11:00 -05:00
|
|
|
} else {
|
2010-04-07 11:25:48 -04:00
|
|
|
return $nav_menu;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2010-02-24 03:06:36 -05:00
|
|
|
}
|
|
|
|
|
2010-05-25 09:30:10 -04:00
|
|
|
/**
|
2020-07-08 09:15:03 -04:00
|
|
|
* Adds the class property classes for the current context, if applicable.
|
2010-05-25 09:30:10 -04:00
|
|
|
*
|
|
|
|
* @access private
|
2013-12-24 13:57:12 -05:00
|
|
|
* @since 3.0.0
|
2010-05-25 09:30:10 -04:00
|
|
|
*
|
2019-08-03 21:59:56 -04:00
|
|
|
* @global WP_Query $wp_query WordPress Query object.
|
2019-08-03 21:19:56 -04:00
|
|
|
* @global WP_Rewrite $wp_rewrite WordPress rewrite component.
|
2015-05-26 18:10:25 -04:00
|
|
|
*
|
2010-05-25 09:30:10 -04:00
|
|
|
* @param array $menu_items The current menu item objects to which to add the class property information.
|
|
|
|
*/
|
2010-05-26 12:25:29 -04:00
|
|
|
function _wp_menu_item_classes_by_context( &$menu_items ) {
|
2013-01-21 09:44:30 -05:00
|
|
|
global $wp_query, $wp_rewrite;
|
2010-05-25 09:30:10 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
$queried_object = $wp_query->get_queried_object();
|
2010-05-25 09:30:10 -04:00
|
|
|
$queried_object_id = (int) $wp_query->queried_object_id;
|
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
$active_object = '';
|
|
|
|
$active_ancestor_item_ids = array();
|
|
|
|
$active_parent_item_ids = array();
|
|
|
|
$active_parent_object_ids = array();
|
2010-06-11 12:00:29 -04:00
|
|
|
$possible_taxonomy_ancestors = array();
|
2017-11-30 18:11:00 -05:00
|
|
|
$possible_object_parents = array();
|
|
|
|
$home_page_id = (int) get_option( 'page_for_posts' );
|
2010-05-25 22:42:15 -04:00
|
|
|
|
2010-05-25 09:30:10 -04:00
|
|
|
if ( $wp_query->is_singular && ! empty( $queried_object->post_type ) && ! is_post_type_hierarchical( $queried_object->post_type ) ) {
|
|
|
|
foreach ( (array) get_object_taxonomies( $queried_object->post_type ) as $taxonomy ) {
|
|
|
|
if ( is_taxonomy_hierarchical( $taxonomy ) ) {
|
2010-06-11 12:00:29 -04:00
|
|
|
$term_hierarchy = _get_term_hierarchy( $taxonomy );
|
2017-11-30 18:11:00 -05:00
|
|
|
$terms = wp_get_object_terms( $queried_object_id, $taxonomy, array( 'fields' => 'ids' ) );
|
2010-06-11 12:00:29 -04:00
|
|
|
if ( is_array( $terms ) ) {
|
2010-05-25 09:30:10 -04:00
|
|
|
$possible_object_parents = array_merge( $possible_object_parents, $terms );
|
2017-11-30 18:11:00 -05:00
|
|
|
$term_to_ancestor = array();
|
2010-06-11 12:00:29 -04:00
|
|
|
foreach ( (array) $term_hierarchy as $anc => $descs ) {
|
2017-11-30 18:11:00 -05:00
|
|
|
foreach ( (array) $descs as $desc ) {
|
2010-06-11 12:00:29 -04:00
|
|
|
$term_to_ancestor[ $desc ] = $anc;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2010-06-11 12:00:29 -04:00
|
|
|
}
|
2010-06-11 16:19:35 -04:00
|
|
|
|
2010-06-11 12:00:29 -04:00
|
|
|
foreach ( $terms as $desc ) {
|
|
|
|
do {
|
|
|
|
$possible_taxonomy_ancestors[ $taxonomy ][] = $desc;
|
|
|
|
if ( isset( $term_to_ancestor[ $desc ] ) ) {
|
|
|
|
$_desc = $term_to_ancestor[ $desc ];
|
|
|
|
unset( $term_to_ancestor[ $desc ] );
|
|
|
|
$desc = $_desc;
|
|
|
|
} else {
|
|
|
|
$desc = 0;
|
|
|
|
}
|
|
|
|
} while ( ! empty( $desc ) );
|
|
|
|
}
|
|
|
|
}
|
2010-05-25 09:30:10 -04:00
|
|
|
}
|
|
|
|
}
|
2010-06-11 12:00:29 -04:00
|
|
|
} elseif ( ! empty( $queried_object->taxonomy ) && is_taxonomy_hierarchical( $queried_object->taxonomy ) ) {
|
2017-11-30 18:11:00 -05:00
|
|
|
$term_hierarchy = _get_term_hierarchy( $queried_object->taxonomy );
|
2010-06-11 12:00:29 -04:00
|
|
|
$term_to_ancestor = array();
|
|
|
|
foreach ( (array) $term_hierarchy as $anc => $descs ) {
|
2017-11-30 18:11:00 -05:00
|
|
|
foreach ( (array) $descs as $desc ) {
|
2010-06-11 12:00:29 -04:00
|
|
|
$term_to_ancestor[ $desc ] = $anc;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2010-06-11 12:00:29 -04:00
|
|
|
}
|
|
|
|
$desc = $queried_object->term_id;
|
|
|
|
do {
|
|
|
|
$possible_taxonomy_ancestors[ $queried_object->taxonomy ][] = $desc;
|
|
|
|
if ( isset( $term_to_ancestor[ $desc ] ) ) {
|
|
|
|
$_desc = $term_to_ancestor[ $desc ];
|
|
|
|
unset( $term_to_ancestor[ $desc ] );
|
|
|
|
$desc = $_desc;
|
|
|
|
} else {
|
|
|
|
$desc = 0;
|
|
|
|
}
|
|
|
|
} while ( ! empty( $desc ) );
|
2010-05-25 09:30:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
$possible_object_parents = array_filter( $possible_object_parents );
|
|
|
|
|
2019-03-21 15:48:50 -04:00
|
|
|
$front_page_url = home_url();
|
|
|
|
$front_page_id = (int) get_option( 'page_on_front' );
|
|
|
|
$privacy_policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' );
|
2010-12-05 22:54:57 -05:00
|
|
|
|
2010-05-25 14:54:42 -04:00
|
|
|
foreach ( (array) $menu_items as $key => $menu_item ) {
|
2010-10-21 15:55:28 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
$menu_items[ $key ]->current = false;
|
2010-10-21 15:55:28 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
$classes = (array) $menu_item->classes;
|
2010-06-02 09:48:26 -04:00
|
|
|
$classes[] = 'menu-item';
|
|
|
|
$classes[] = 'menu-item-type-' . $menu_item->type;
|
2010-10-29 18:49:42 -04:00
|
|
|
$classes[] = 'menu-item-object-' . $menu_item->object;
|
2010-06-02 09:48:26 -04:00
|
|
|
|
2016-10-25 21:58:30 -04:00
|
|
|
// This menu item is set as the 'Front Page'.
|
|
|
|
if ( 'post_type' === $menu_item->type && $front_page_id === (int) $menu_item->object_id ) {
|
|
|
|
$classes[] = 'menu-item-home';
|
|
|
|
}
|
|
|
|
|
2019-03-21 15:48:50 -04:00
|
|
|
// This menu item is set as the 'Privacy Policy Page'.
|
|
|
|
if ( 'post_type' === $menu_item->type && $privacy_policy_page_id === (int) $menu_item->object_id ) {
|
|
|
|
$classes[] = 'menu-item-privacy-policy';
|
|
|
|
}
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// If the menu item corresponds to a taxonomy term for the currently queried non-hierarchical post object.
|
2020-05-16 14:42:12 -04:00
|
|
|
if ( $wp_query->is_singular && 'taxonomy' === $menu_item->type
|
2020-04-09 11:43:10 -04:00
|
|
|
&& in_array( (int) $menu_item->object_id, $possible_object_parents, true )
|
|
|
|
) {
|
2010-05-25 09:30:10 -04:00
|
|
|
$active_parent_object_ids[] = (int) $menu_item->object_id;
|
2017-11-30 18:11:00 -05:00
|
|
|
$active_parent_item_ids[] = (int) $menu_item->db_id;
|
|
|
|
$active_object = $queried_object->post_type;
|
2010-05-25 22:42:15 -04:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// If the menu item corresponds to the currently queried post or taxonomy object.
|
2010-05-25 09:30:10 -04:00
|
|
|
} elseif (
|
2020-04-04 23:02:11 -04:00
|
|
|
$menu_item->object_id == $queried_object_id
|
|
|
|
&& (
|
2020-05-16 14:42:12 -04:00
|
|
|
( ! empty( $home_page_id ) && 'post_type' === $menu_item->type
|
|
|
|
&& $wp_query->is_home && $home_page_id == $menu_item->object_id )
|
|
|
|
|| ( 'post_type' === $menu_item->type && $wp_query->is_singular )
|
|
|
|
|| ( 'taxonomy' === $menu_item->type
|
2020-04-09 11:43:10 -04:00
|
|
|
&& ( $wp_query->is_category || $wp_query->is_tag || $wp_query->is_tax )
|
|
|
|
&& $queried_object->taxonomy == $menu_item->object )
|
2010-05-25 22:42:15 -04:00
|
|
|
)
|
2010-05-25 09:30:10 -04:00
|
|
|
) {
|
2017-11-30 18:11:00 -05:00
|
|
|
$classes[] = 'current-menu-item';
|
|
|
|
$menu_items[ $key ]->current = true;
|
|
|
|
$_anc_id = (int) $menu_item->db_id;
|
2010-06-14 17:19:55 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
while (
|
2020-04-04 23:02:11 -04:00
|
|
|
( $_anc_id = (int) get_post_meta( $_anc_id, '_menu_item_menu_item_parent', true ) )
|
|
|
|
&& ! in_array( $_anc_id, $active_ancestor_item_ids, true )
|
2010-06-14 17:19:55 -04:00
|
|
|
) {
|
|
|
|
$active_ancestor_item_ids[] = $_anc_id;
|
|
|
|
}
|
|
|
|
|
2020-05-16 14:42:12 -04:00
|
|
|
if ( 'post_type' === $menu_item->type && 'page' === $menu_item->object ) {
|
2020-01-28 19:45:18 -05:00
|
|
|
// Back compat classes for pages to match wp_page_menu().
|
2010-06-02 09:48:26 -04:00
|
|
|
$classes[] = 'page_item';
|
|
|
|
$classes[] = 'page-item-' . $menu_item->object_id;
|
|
|
|
$classes[] = 'current_page_item';
|
|
|
|
}
|
2016-10-23 20:32:32 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
$active_parent_item_ids[] = (int) $menu_item->menu_item_parent;
|
2010-05-25 09:30:10 -04:00
|
|
|
$active_parent_object_ids[] = (int) $menu_item->post_parent;
|
2017-11-30 18:11:00 -05:00
|
|
|
$active_object = $menu_item->object;
|
2010-05-25 09:30:10 -04:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// If the menu item corresponds to the currently queried post type archive.
|
2015-10-24 13:46:25 -04:00
|
|
|
} elseif (
|
2020-05-16 14:42:12 -04:00
|
|
|
'post_type_archive' === $menu_item->type
|
2020-04-04 23:02:11 -04:00
|
|
|
&& is_post_type_archive( array( $menu_item->object ) )
|
2015-10-24 13:46:25 -04:00
|
|
|
) {
|
2017-11-30 18:11:00 -05:00
|
|
|
$classes[] = 'current-menu-item';
|
|
|
|
$menu_items[ $key ]->current = true;
|
|
|
|
$_anc_id = (int) $menu_item->db_id;
|
2017-07-05 17:31:44 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
while (
|
2020-04-04 23:02:11 -04:00
|
|
|
( $_anc_id = (int) get_post_meta( $_anc_id, '_menu_item_menu_item_parent', true ) )
|
|
|
|
&& ! in_array( $_anc_id, $active_ancestor_item_ids, true )
|
2017-07-05 17:31:44 -04:00
|
|
|
) {
|
|
|
|
$active_ancestor_item_ids[] = $_anc_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
$active_parent_item_ids[] = (int) $menu_item->menu_item_parent;
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// If the menu item corresponds to the currently requested URL.
|
2020-05-16 14:42:12 -04:00
|
|
|
} elseif ( 'custom' === $menu_item->object && isset( $_SERVER['HTTP_HOST'] ) ) {
|
2011-09-21 22:25:57 -04:00
|
|
|
$_root_relative_current = untrailingslashit( $_SERVER['REQUEST_URI'] );
|
2017-05-12 16:35:43 -04:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// If it's the customize page then it will strip the query var off the URL before entering the comparison block.
|
2017-05-12 16:35:43 -04:00
|
|
|
if ( is_customize_preview() ) {
|
|
|
|
$_root_relative_current = strtok( untrailingslashit( $_SERVER['REQUEST_URI'] ), '?' );
|
|
|
|
}
|
2018-02-24 08:44:31 -05:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
$current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_root_relative_current );
|
|
|
|
$raw_item_url = strpos( $menu_item->url, '#' ) ? substr( $menu_item->url, 0, strpos( $menu_item->url, '#' ) ) : $menu_item->url;
|
|
|
|
$item_url = set_url_scheme( untrailingslashit( $raw_item_url ) );
|
2013-01-18 08:44:22 -05:00
|
|
|
$_indexless_current = untrailingslashit( preg_replace( '/' . preg_quote( $wp_rewrite->index, '/' ) . '$/', '', $current_url ) );
|
2010-10-21 15:55:28 -04:00
|
|
|
|
2018-02-24 08:44:31 -05:00
|
|
|
$matches = array(
|
2018-08-16 21:51:36 -04:00
|
|
|
$current_url,
|
|
|
|
urldecode( $current_url ),
|
|
|
|
$_indexless_current,
|
|
|
|
urldecode( $_indexless_current ),
|
|
|
|
$_root_relative_current,
|
|
|
|
urldecode( $_root_relative_current ),
|
2018-02-24 08:44:31 -05:00
|
|
|
);
|
|
|
|
|
2020-04-04 23:02:11 -04:00
|
|
|
if ( $raw_item_url && in_array( $item_url, $matches, true ) ) {
|
2017-11-30 18:11:00 -05:00
|
|
|
$classes[] = 'current-menu-item';
|
|
|
|
$menu_items[ $key ]->current = true;
|
|
|
|
$_anc_id = (int) $menu_item->db_id;
|
2010-06-14 17:19:55 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
while (
|
2020-04-04 23:02:11 -04:00
|
|
|
( $_anc_id = (int) get_post_meta( $_anc_id, '_menu_item_menu_item_parent', true ) )
|
|
|
|
&& ! in_array( $_anc_id, $active_ancestor_item_ids, true )
|
2010-06-14 17:19:55 -04:00
|
|
|
) {
|
|
|
|
$active_ancestor_item_ids[] = $_anc_id;
|
|
|
|
}
|
|
|
|
|
2020-04-04 23:02:11 -04:00
|
|
|
if ( in_array( home_url(), array( untrailingslashit( $current_url ), untrailingslashit( $_indexless_current ) ), true ) ) {
|
2020-01-28 19:45:18 -05:00
|
|
|
// Back compat for home link to match wp_page_menu().
|
2010-06-02 09:48:26 -04:00
|
|
|
$classes[] = 'current_page_item';
|
|
|
|
}
|
2017-11-30 18:11:00 -05:00
|
|
|
$active_parent_item_ids[] = (int) $menu_item->menu_item_parent;
|
2010-05-25 09:30:10 -04:00
|
|
|
$active_parent_object_ids[] = (int) $menu_item->post_parent;
|
2017-11-30 18:11:00 -05:00
|
|
|
$active_object = $menu_item->object;
|
2010-12-05 22:54:57 -05:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Give front page item the 'current-menu-item' class when extra query arguments are involved.
|
2010-12-05 22:54:57 -05:00
|
|
|
} elseif ( $item_url == $front_page_url && is_front_page() ) {
|
|
|
|
$classes[] = 'current-menu-item';
|
2010-05-25 09:30:10 -04:00
|
|
|
}
|
2010-10-21 15:55:28 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( untrailingslashit( $item_url ) == home_url() ) {
|
2010-06-22 18:05:43 -04:00
|
|
|
$classes[] = 'menu-item-home';
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2010-05-25 09:30:10 -04:00
|
|
|
}
|
2010-06-02 16:04:07 -04:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Back-compat with wp_page_menu(): add "current_page_parent" to static home page link for any non-page query.
|
2020-05-16 14:42:12 -04:00
|
|
|
if ( ! empty( $home_page_id ) && 'post_type' === $menu_item->type
|
|
|
|
&& empty( $wp_query->is_page ) && $home_page_id == $menu_item->object_id
|
|
|
|
) {
|
2010-06-02 09:48:26 -04:00
|
|
|
$classes[] = 'current_page_parent';
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2010-06-02 09:48:26 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
$menu_items[ $key ]->classes = array_unique( $classes );
|
2010-05-25 09:30:10 -04:00
|
|
|
}
|
2010-06-14 17:19:55 -04:00
|
|
|
$active_ancestor_item_ids = array_filter( array_unique( $active_ancestor_item_ids ) );
|
2017-11-30 18:11:00 -05:00
|
|
|
$active_parent_item_ids = array_filter( array_unique( $active_parent_item_ids ) );
|
2010-05-25 09:30:10 -04:00
|
|
|
$active_parent_object_ids = array_filter( array_unique( $active_parent_object_ids ) );
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Set parent's class.
|
2010-05-25 14:54:42 -04:00
|
|
|
foreach ( (array) $menu_items as $key => $parent_item ) {
|
2017-11-30 18:11:00 -05:00
|
|
|
$classes = (array) $parent_item->classes;
|
|
|
|
$menu_items[ $key ]->current_item_ancestor = false;
|
|
|
|
$menu_items[ $key ]->current_item_parent = false;
|
2010-10-21 15:55:28 -04:00
|
|
|
|
2010-05-25 22:42:15 -04:00
|
|
|
if (
|
2020-04-04 23:02:11 -04:00
|
|
|
isset( $parent_item->type )
|
|
|
|
&& (
|
2020-01-28 19:45:18 -05:00
|
|
|
// Ancestral post object.
|
2010-06-11 12:00:29 -04:00
|
|
|
(
|
2020-05-16 14:42:12 -04:00
|
|
|
'post_type' === $parent_item->type
|
2020-04-04 23:02:11 -04:00
|
|
|
&& ! empty( $queried_object->post_type )
|
|
|
|
&& is_post_type_hierarchical( $queried_object->post_type )
|
2020-04-09 11:43:10 -04:00
|
|
|
&& in_array( (int) $parent_item->object_id, $queried_object->ancestors, true )
|
2020-04-04 23:02:11 -04:00
|
|
|
&& $parent_item->object != $queried_object->ID
|
2010-06-11 12:00:29 -04:00
|
|
|
) ||
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Ancestral term.
|
2010-06-11 12:00:29 -04:00
|
|
|
(
|
2020-05-16 14:42:12 -04:00
|
|
|
'taxonomy' === $parent_item->type
|
2020-04-04 23:02:11 -04:00
|
|
|
&& isset( $possible_taxonomy_ancestors[ $parent_item->object ] )
|
2020-04-09 11:43:10 -04:00
|
|
|
&& in_array( (int) $parent_item->object_id, $possible_taxonomy_ancestors[ $parent_item->object ], true )
|
2020-04-04 23:02:11 -04:00
|
|
|
&& (
|
2010-12-22 12:40:51 -05:00
|
|
|
! isset( $queried_object->term_id ) ||
|
|
|
|
$parent_item->object_id != $queried_object->term_id
|
|
|
|
)
|
2010-06-11 12:00:29 -04:00
|
|
|
)
|
|
|
|
)
|
2010-06-02 09:48:26 -04:00
|
|
|
) {
|
2020-04-04 23:02:11 -04:00
|
|
|
if ( ! empty( $queried_object->taxonomy ) ) {
|
|
|
|
$classes[] = 'current-' . $queried_object->taxonomy . '-ancestor';
|
|
|
|
} else {
|
|
|
|
$classes[] = 'current-' . $queried_object->post_type . '-ancestor';
|
|
|
|
}
|
2010-06-02 09:48:26 -04:00
|
|
|
}
|
2010-06-11 12:00:29 -04:00
|
|
|
|
2020-04-04 23:02:11 -04:00
|
|
|
if ( in_array( (int) $parent_item->db_id, $active_ancestor_item_ids, true ) ) {
|
|
|
|
$classes[] = 'current-menu-ancestor';
|
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
$menu_items[ $key ]->current_item_ancestor = true;
|
2010-06-14 17:19:55 -04:00
|
|
|
}
|
2020-04-04 23:02:11 -04:00
|
|
|
if ( in_array( (int) $parent_item->db_id, $active_parent_item_ids, true ) ) {
|
|
|
|
$classes[] = 'current-menu-parent';
|
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
$menu_items[ $key ]->current_item_parent = true;
|
2010-08-27 12:13:39 -04:00
|
|
|
}
|
2020-04-04 23:02:11 -04:00
|
|
|
if ( in_array( (int) $parent_item->object_id, $active_parent_object_ids, true ) ) {
|
2010-06-02 09:48:26 -04:00
|
|
|
$classes[] = 'current-' . $active_object . '-parent';
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2010-06-02 16:04:07 -04:00
|
|
|
|
2020-05-16 14:42:12 -04:00
|
|
|
if ( 'post_type' === $parent_item->type && 'page' === $parent_item->object ) {
|
2020-01-28 19:45:18 -05:00
|
|
|
// Back compat classes for pages to match wp_page_menu().
|
2020-04-04 23:02:11 -04:00
|
|
|
if ( in_array( 'current-menu-parent', $classes, true ) ) {
|
2010-06-02 09:48:26 -04:00
|
|
|
$classes[] = 'current_page_parent';
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2020-04-04 23:02:11 -04:00
|
|
|
if ( in_array( 'current-menu-ancestor', $classes, true ) ) {
|
2010-06-02 09:48:26 -04:00
|
|
|
$classes[] = 'current_page_ancestor';
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2010-06-02 09:48:26 -04:00
|
|
|
}
|
2010-06-02 16:04:07 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
$menu_items[ $key ]->classes = array_unique( $classes );
|
2010-05-25 09:30:10 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-28 15:00:49 -05:00
|
|
|
/**
|
2020-07-08 09:15:03 -04:00
|
|
|
* Retrieves the HTML list content for nav menu items.
|
2010-02-28 15:00:49 -05:00
|
|
|
*
|
2010-04-26 21:05:58 -04:00
|
|
|
* @uses Walker_Nav_Menu to create HTML list content.
|
2010-07-13 17:30:59 -04:00
|
|
|
* @since 3.0.0
|
2015-05-26 18:10:25 -04:00
|
|
|
*
|
2016-09-07 12:15:30 -04:00
|
|
|
* @param array $items The menu items, sorted by each menu item's menu order.
|
|
|
|
* @param int $depth Depth of the item in reference to parents.
|
|
|
|
* @param stdClass $r An object containing wp_nav_menu() arguments.
|
|
|
|
* @return string The HTML list content for the menu items.
|
2010-03-15 12:26:46 -04:00
|
|
|
*/
|
2010-04-26 21:05:58 -04:00
|
|
|
function walk_nav_menu_tree( $items, $depth, $r ) {
|
2017-11-30 18:11:00 -05:00
|
|
|
$walker = ( empty( $r->walker ) ) ? new Walker_Nav_Menu : $r->walker;
|
2010-03-26 15:36:49 -04:00
|
|
|
|
2019-09-15 07:31:57 -04:00
|
|
|
return $walker->walk( $items, $depth, $r );
|
2010-02-24 03:06:36 -05:00
|
|
|
}
|
2010-04-26 21:05:58 -04:00
|
|
|
|
2010-07-13 17:30:59 -04:00
|
|
|
/**
|
|
|
|
* Prevents a menu item ID from being used more than once.
|
|
|
|
*
|
|
|
|
* @since 3.0.1
|
|
|
|
* @access private
|
2015-05-26 18:10:25 -04:00
|
|
|
*
|
|
|
|
* @param string $id
|
|
|
|
* @param object $item
|
|
|
|
* @return string
|
2010-07-13 17:30:59 -04:00
|
|
|
*/
|
|
|
|
function _nav_menu_item_id_use_once( $id, $item ) {
|
|
|
|
static $_used_ids = array();
|
2020-04-04 23:02:11 -04:00
|
|
|
|
|
|
|
if ( in_array( $item->ID, $_used_ids, true ) ) {
|
2010-07-13 17:30:59 -04:00
|
|
|
return '';
|
2015-05-26 18:10:25 -04:00
|
|
|
}
|
2020-04-04 23:02:11 -04:00
|
|
|
|
2010-07-13 17:30:59 -04:00
|
|
|
$_used_ids[] = $item->ID;
|
2020-04-04 23:02:11 -04:00
|
|
|
|
2010-07-13 17:30:59 -04:00
|
|
|
return $id;
|
|
|
|
}
|