wp/wp-includes/nav-menu-template.php
author ymh <ymh.work@gmail.com>
Mon, 14 Oct 2019 17:39:30 +0200
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
child 9 177826044cd9
permissions -rw-r--r--
resynchronize code repo with production
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
     3
 * Nav Menu API: Template functions
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 * @package WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 * @subpackage Nav_Menus
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    10
/** Walker_Nav_Menu class */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    11
require_once ABSPATH . WPINC . '/class-walker-nav-menu.php';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
 * Displays a navigation menu.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
 * @since 3.0.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    17
 * @since 4.7.0 Added the `item_spacing` argument.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    18
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    19
 * @staticvar array $menu_id_slugs
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    21
 * @param array $args {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    22
 *     Optional. Array of nav menu arguments.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    23
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    24
 *     @type int|string|WP_Term $menu            Desired menu. Accepts a menu ID, slug, name, or object. Default empty.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    25
 *     @type string             $menu_class      CSS class to use for the ul element which forms the menu. Default 'menu'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    26
 *     @type string             $menu_id         The ID that is applied to the ul element which forms the menu.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    27
 *                                               Default is the menu slug, incremented.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    28
 *     @type string             $container       Whether to wrap the ul, and what to wrap it with. Default 'div'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    29
 *     @type string             $container_class Class that is applied to the container. Default 'menu-{menu slug}-container'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    30
 *     @type string             $container_id    The ID that is applied to the container. Default empty.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    31
 *     @type callable|bool      $fallback_cb     If the menu doesn't exists, a callback function will fire.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    32
 *                                               Default is 'wp_page_menu'. Set to false for no fallback.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    33
 *     @type string             $before          Text before the link markup. Default empty.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    34
 *     @type string             $after           Text after the link markup. Default empty.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    35
 *     @type string             $link_before     Text before the link text. Default empty.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    36
 *     @type string             $link_after      Text after the link text. Default empty.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    37
 *     @type bool               $echo            Whether to echo the menu or return it. Default true.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    38
 *     @type int                $depth           How many levels of the hierarchy are to be included. 0 means all. Default 0.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    39
 *     @type object             $walker          Instance of a custom walker class. Default empty.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    40
 *     @type string             $theme_location  Theme location to be used. Must be registered with register_nav_menu()
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    41
 *                                               in order to be selectable by the user.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    42
 *     @type string             $items_wrap      How the list items should be wrapped. Default is a ul with an id and class.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    43
 *                                               Uses printf() format with numbered placeholders.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    44
 *     @type string             $item_spacing    Whether to preserve whitespace within the menu's HTML. Accepts 'preserve' or 'discard'. Default 'preserve'.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    45
 * }
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    46
 * @return string|false|void Menu output if $echo is false, false if there are no items or no menu was found.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
function wp_nav_menu( $args = array() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
	static $menu_id_slugs = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
	$defaults = array( 'menu' => '', 'container' => 'div', 'container_class' => '', 'container_id' => '', 'menu_class' => 'menu', 'menu_id' => '',
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    52
	'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',
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
	'depth' => 0, 'walker' => '', 'theme_location' => '' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
	$args = wp_parse_args( $args, $defaults );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    56
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    57
	if ( ! in_array( $args['item_spacing'], array( 'preserve', 'discard' ), true ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    58
		// invalid value, fall back to default.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    59
		$args['item_spacing'] = $defaults['item_spacing'];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    60
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    61
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    63
	 * Filters the arguments used to display a navigation menu.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    67
	 * @see wp_nav_menu()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    68
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    69
	 * @param array $args Array of wp_nav_menu() arguments.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
	$args = apply_filters( 'wp_nav_menu_args', $args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
	$args = (object) $args;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    74
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    75
	 * Filters whether to short-circuit the wp_nav_menu() output.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    76
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    77
	 * Returning a non-null value to the filter will short-circuit
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    78
	 * wp_nav_menu(), echoing that value if $args->echo is true,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    79
	 * returning that value otherwise.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    80
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    81
	 * @since 3.9.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    82
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    83
	 * @see wp_nav_menu()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    84
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    85
	 * @param string|null $output Nav menu output to short-circuit with. Default null.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    86
	 * @param stdClass    $args   An object containing wp_nav_menu() arguments.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    87
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    88
	$nav_menu = apply_filters( 'pre_wp_nav_menu', null, $args );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    89
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    90
	if ( null !== $nav_menu ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    91
		if ( $args->echo ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    92
			echo $nav_menu;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    93
			return;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    94
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    95
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    96
		return $nav_menu;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    97
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    98
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
	// Get the nav menu based on the requested menu
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
	$menu = wp_get_nav_menu_object( $args->menu );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
	// Get the nav menu based on the theme_location
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
	if ( ! $menu && $args->theme_location && ( $locations = get_nav_menu_locations() ) && isset( $locations[ $args->theme_location ] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
		$menu = wp_get_nav_menu_object( $locations[ $args->theme_location ] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
	// get the first menu that has items if we still can't find a menu
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
	if ( ! $menu && !$args->theme_location ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
		$menus = wp_get_nav_menus();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
		foreach ( $menus as $menu_maybe ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
			if ( $menu_items = wp_get_nav_menu_items( $menu_maybe->term_id, array( 'update_post_term_cache' => false ) ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
				$menu = $menu_maybe;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   117
	if ( empty( $args->menu ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   118
		$args->menu = $menu;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   119
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   120
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
	// If the menu exists, get its items.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
	if ( $menu && ! is_wp_error($menu) && !isset($menu_items) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
		$menu_items = wp_get_nav_menu_items( $menu->term_id, array( 'update_post_term_cache' => false ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
	/*
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
	 * If no menu was found:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
	 *  - Fall back (if one was specified), or bail.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
	 * If no menu items were found:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
	 *  - Fall back, but only if no theme location was specified.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
	 *  - Otherwise, bail.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
	if ( ( !$menu || is_wp_error($menu) || ( isset($menu_items) && empty($menu_items) && !$args->theme_location ) )
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   134
		&& isset( $args->fallback_cb ) && $args->fallback_cb && is_callable( $args->fallback_cb ) )
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
			return call_user_func( $args->fallback_cb, (array) $args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
	if ( ! $menu || is_wp_error( $menu ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
	$nav_menu = $items = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
	$show_container = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
	if ( $args->container ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
		/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   145
		 * Filters the list of HTML tags that are valid for use as menu containers.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
		 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
		 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   149
		 * @param array $tags The acceptable HTML tags for use as menu containers.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   150
		 *                    Default is array containing 'div' and 'nav'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
		 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
		$allowed_tags = apply_filters( 'wp_nav_menu_container_allowedtags', array( 'div', 'nav' ) );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   153
		if ( is_string( $args->container ) && in_array( $args->container, $allowed_tags ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
			$show_container = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
			$class = $args->container_class ? ' class="' . esc_attr( $args->container_class ) . '"' : ' class="menu-'. $menu->slug .'-container"';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
			$id = $args->container_id ? ' id="' . esc_attr( $args->container_id ) . '"' : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
			$nav_menu .= '<'. $args->container . $id . $class . '>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
	// Set up the $menu_item variables
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
	_wp_menu_item_classes_by_context( $menu_items );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
	$sorted_menu_items = $menu_items_with_children = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
	foreach ( (array) $menu_items as $menu_item ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
		$sorted_menu_items[ $menu_item->menu_order ] = $menu_item;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
		if ( $menu_item->menu_item_parent )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
			$menu_items_with_children[ $menu_item->menu_item_parent ] = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
	// Add the menu-item-has-children class where applicable
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
	if ( $menu_items_with_children ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
		foreach ( $sorted_menu_items as &$menu_item ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
			if ( isset( $menu_items_with_children[ $menu_item->ID ] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
				$menu_item->classes[] = 'menu-item-has-children';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
	unset( $menu_items, $menu_item );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   182
	 * Filters the sorted list of menu item objects before generating the menu's HTML.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
	 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   186
	 * @param array    $sorted_menu_items The menu items, sorted by each menu item's menu order.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   187
	 * @param stdClass $args              An object containing wp_nav_menu() arguments.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
	$sorted_menu_items = apply_filters( 'wp_nav_menu_objects', $sorted_menu_items, $args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
	$items .= walk_nav_menu_tree( $sorted_menu_items, $args->depth, $args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
	unset($sorted_menu_items);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
	// Attributes
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
	if ( ! empty( $args->menu_id ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
		$wrap_id = $args->menu_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
		$wrap_id = 'menu-' . $menu->slug;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
		while ( in_array( $wrap_id, $menu_id_slugs ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   200
			if ( preg_match( '#-(\d+)$#', $wrap_id, $matches ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
				$wrap_id = preg_replace('#-(\d+)$#', '-' . ++$matches[1], $wrap_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
			else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
				$wrap_id = $wrap_id . '-1';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
	$menu_id_slugs[] = $wrap_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   207
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   208
	$wrap_class = $args->menu_class ? $args->menu_class : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   211
	 * Filters the HTML list content for navigation menus.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   215
	 * @see wp_nav_menu()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   216
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   217
	 * @param string   $items The HTML list content for the menu items.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   218
	 * @param stdClass $args  An object containing wp_nav_menu() arguments.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
	$items = apply_filters( 'wp_nav_menu_items', $items, $args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   222
	 * Filters the HTML list content for a specific navigation menu.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   223
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   226
	 * @see wp_nav_menu()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   227
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   228
	 * @param string   $items The HTML list content for the menu items.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   229
	 * @param stdClass $args  An object containing wp_nav_menu() arguments.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
	$items = apply_filters( "wp_nav_menu_{$menu->slug}_items", $items, $args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
	// Don't print any markup if there are no items at this point.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
	if ( empty( $items ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   237
	$nav_menu .= sprintf( $args->items_wrap, esc_attr( $wrap_id ), esc_attr( $wrap_class ), $items );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   238
	unset( $items );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
	if ( $show_container )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
		$nav_menu .= '</' . $args->container . '>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   244
	 * Filters the HTML content for navigation menus.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   248
	 * @see wp_nav_menu()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   249
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   250
	 * @param string   $nav_menu The HTML content for the navigation menu.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   251
	 * @param stdClass $args     An object containing wp_nav_menu() arguments.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
	$nav_menu = apply_filters( 'wp_nav_menu', $nav_menu, $args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
	if ( $args->echo )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
		echo $nav_menu;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
		return $nav_menu;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   261
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
 * Add the class property classes for the current context, if applicable.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   263
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
 * @access private
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   265
 * @since 3.0.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   267
 * @global WP_Query   $wp_query
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   268
 * @global WP_Rewrite $wp_rewrite
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   269
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   270
 * @param array $menu_items The current menu item objects to which to add the class property information.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
function _wp_menu_item_classes_by_context( &$menu_items ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   273
	global $wp_query, $wp_rewrite;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
	$queried_object = $wp_query->get_queried_object();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
	$queried_object_id = (int) $wp_query->queried_object_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
	$active_object = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
	$active_ancestor_item_ids = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
	$active_parent_item_ids = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   281
	$active_parent_object_ids = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   282
	$possible_taxonomy_ancestors = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
	$possible_object_parents = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
	$home_page_id = (int) get_option( 'page_for_posts' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   286
	if ( $wp_query->is_singular && ! empty( $queried_object->post_type ) && ! is_post_type_hierarchical( $queried_object->post_type ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   287
		foreach ( (array) get_object_taxonomies( $queried_object->post_type ) as $taxonomy ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   288
			if ( is_taxonomy_hierarchical( $taxonomy ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   289
				$term_hierarchy = _get_term_hierarchy( $taxonomy );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   290
				$terms = wp_get_object_terms( $queried_object_id, $taxonomy, array( 'fields' => 'ids' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   291
				if ( is_array( $terms ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   292
					$possible_object_parents = array_merge( $possible_object_parents, $terms );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   293
					$term_to_ancestor = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   294
					foreach ( (array) $term_hierarchy as $anc => $descs ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   295
						foreach ( (array) $descs as $desc )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   296
							$term_to_ancestor[ $desc ] = $anc;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   297
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   298
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   299
					foreach ( $terms as $desc ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   300
						do {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   301
							$possible_taxonomy_ancestors[ $taxonomy ][] = $desc;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   302
							if ( isset( $term_to_ancestor[ $desc ] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
								$_desc = $term_to_ancestor[ $desc ];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
								unset( $term_to_ancestor[ $desc ] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   305
								$desc = $_desc;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   306
							} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   307
								$desc = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
							}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   309
						} while ( ! empty( $desc ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   311
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   313
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   314
	} elseif ( ! empty( $queried_object->taxonomy ) && is_taxonomy_hierarchical( $queried_object->taxonomy ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   315
		$term_hierarchy = _get_term_hierarchy( $queried_object->taxonomy );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   316
		$term_to_ancestor = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   317
		foreach ( (array) $term_hierarchy as $anc => $descs ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   318
			foreach ( (array) $descs as $desc )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   319
				$term_to_ancestor[ $desc ] = $anc;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   320
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   321
		$desc = $queried_object->term_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   322
		do {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   323
			$possible_taxonomy_ancestors[ $queried_object->taxonomy ][] = $desc;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   324
			if ( isset( $term_to_ancestor[ $desc ] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   325
				$_desc = $term_to_ancestor[ $desc ];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   326
				unset( $term_to_ancestor[ $desc ] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   327
				$desc = $_desc;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   328
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   329
				$desc = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   330
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   331
		} while ( ! empty( $desc ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   332
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   333
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   334
	$possible_object_parents = array_filter( $possible_object_parents );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   335
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   336
	$front_page_url = home_url();
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   337
	$front_page_id  = (int) get_option( 'page_on_front' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   339
	foreach ( (array) $menu_items as $key => $menu_item ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   340
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   341
		$menu_items[$key]->current = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   342
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   343
		$classes = (array) $menu_item->classes;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   344
		$classes[] = 'menu-item';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   345
		$classes[] = 'menu-item-type-' . $menu_item->type;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
		$classes[] = 'menu-item-object-' . $menu_item->object;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   348
		// This menu item is set as the 'Front Page'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   349
		if ( 'post_type' === $menu_item->type && $front_page_id === (int) $menu_item->object_id ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   350
			$classes[] = 'menu-item-home';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   351
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   352
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   353
		// if the menu item corresponds to a taxonomy term for the currently-queried non-hierarchical post object
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   354
		if ( $wp_query->is_singular && 'taxonomy' == $menu_item->type && in_array( $menu_item->object_id, $possible_object_parents ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   355
			$active_parent_object_ids[] = (int) $menu_item->object_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
			$active_parent_item_ids[] = (int) $menu_item->db_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   357
			$active_object = $queried_object->post_type;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   358
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   359
		// if the menu item corresponds to the currently-queried post or taxonomy object
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   360
		} elseif (
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   361
			$menu_item->object_id == $queried_object_id &&
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   362
			(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   363
				( ! empty( $home_page_id ) && 'post_type' == $menu_item->type && $wp_query->is_home && $home_page_id == $menu_item->object_id ) ||
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   364
				( 'post_type' == $menu_item->type && $wp_query->is_singular ) ||
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   365
				( 'taxonomy' == $menu_item->type && ( $wp_query->is_category || $wp_query->is_tag || $wp_query->is_tax ) && $queried_object->taxonomy == $menu_item->object )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   366
			)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   367
		) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   368
			$classes[] = 'current-menu-item';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   369
			$menu_items[$key]->current = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   370
			$_anc_id = (int) $menu_item->db_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   371
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   372
			while(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   373
				( $_anc_id = get_post_meta( $_anc_id, '_menu_item_menu_item_parent', true ) ) &&
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   374
				! in_array( $_anc_id, $active_ancestor_item_ids )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   375
			) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   376
				$active_ancestor_item_ids[] = $_anc_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   377
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   378
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   379
			if ( 'post_type' == $menu_item->type && 'page' == $menu_item->object ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   380
				// Back compat classes for pages to match wp_page_menu()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   381
				$classes[] = 'page_item';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   382
				$classes[] = 'page-item-' . $menu_item->object_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   383
				$classes[] = 'current_page_item';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   384
			}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   385
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
			$active_parent_item_ids[] = (int) $menu_item->menu_item_parent;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   387
			$active_parent_object_ids[] = (int) $menu_item->post_parent;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   388
			$active_object = $menu_item->object;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   389
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   390
		// if the menu item corresponds to the currently-queried post type archive
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   391
		} elseif (
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   392
			'post_type_archive' == $menu_item->type &&
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   393
			is_post_type_archive( array( $menu_item->object ) )
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   394
		) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   395
			$classes[] = 'current-menu-item';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   396
			$menu_items[$key]->current = true;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   397
			$_anc_id = (int) $menu_item->db_id;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   398
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   399
			while(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   400
				( $_anc_id = get_post_meta( $_anc_id, '_menu_item_menu_item_parent', true ) ) &&
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   401
				! in_array( $_anc_id, $active_ancestor_item_ids )
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   402
			) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   403
				$active_ancestor_item_ids[] = $_anc_id;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   404
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   405
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   406
			$active_parent_item_ids[] = (int) $menu_item->menu_item_parent;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   407
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   408
		// if the menu item corresponds to the currently-requested URL
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   409
		} elseif ( 'custom' == $menu_item->object && isset( $_SERVER['HTTP_HOST'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   410
			$_root_relative_current = untrailingslashit( $_SERVER['REQUEST_URI'] );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   411
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   412
			//if it is the customize page then it will strips the query var off the url before entering the comparison block.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   413
			if ( is_customize_preview() ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   414
				$_root_relative_current = strtok( untrailingslashit( $_SERVER['REQUEST_URI'] ), '?' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   415
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   416
			$current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_root_relative_current );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   417
			$raw_item_url = strpos( $menu_item->url, '#' ) ? substr( $menu_item->url, 0, strpos( $menu_item->url, '#' ) ) : $menu_item->url;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   418
			$item_url = set_url_scheme( untrailingslashit( $raw_item_url ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   419
			$_indexless_current = untrailingslashit( preg_replace( '/' . preg_quote( $wp_rewrite->index, '/' ) . '$/', '', $current_url ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   420
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   421
			if ( $raw_item_url && in_array( $item_url, array( $current_url, $_indexless_current, $_root_relative_current ) ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   422
				$classes[] = 'current-menu-item';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   423
				$menu_items[$key]->current = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   424
				$_anc_id = (int) $menu_item->db_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   425
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   426
				while(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   427
					( $_anc_id = get_post_meta( $_anc_id, '_menu_item_menu_item_parent', true ) ) &&
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   428
					! in_array( $_anc_id, $active_ancestor_item_ids )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   429
				) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   430
					$active_ancestor_item_ids[] = $_anc_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   431
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   432
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   433
				if ( in_array( home_url(), array( untrailingslashit( $current_url ), untrailingslashit( $_indexless_current ) ) ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   434
					// Back compat for home link to match wp_page_menu()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   435
					$classes[] = 'current_page_item';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   436
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   437
				$active_parent_item_ids[] = (int) $menu_item->menu_item_parent;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   438
				$active_parent_object_ids[] = (int) $menu_item->post_parent;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   439
				$active_object = $menu_item->object;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   440
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   441
			// give front page item current-menu-item class when extra query arguments involved
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   442
			} elseif ( $item_url == $front_page_url && is_front_page() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   443
				$classes[] = 'current-menu-item';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   444
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   445
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   446
			if ( untrailingslashit($item_url) == home_url() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   447
				$classes[] = 'menu-item-home';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   448
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   449
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   450
		// back-compat with wp_page_menu: add "current_page_parent" to static home page link for any non-page query
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   451
		if ( ! empty( $home_page_id ) && 'post_type' == $menu_item->type && empty( $wp_query->is_page ) && $home_page_id == $menu_item->object_id )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   452
			$classes[] = 'current_page_parent';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   453
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   454
		$menu_items[$key]->classes = array_unique( $classes );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   455
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   456
	$active_ancestor_item_ids = array_filter( array_unique( $active_ancestor_item_ids ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   457
	$active_parent_item_ids = array_filter( array_unique( $active_parent_item_ids ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   458
	$active_parent_object_ids = array_filter( array_unique( $active_parent_object_ids ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   459
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   460
	// set parent's class
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   461
	foreach ( (array) $menu_items as $key => $parent_item ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   462
		$classes = (array) $parent_item->classes;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   463
		$menu_items[$key]->current_item_ancestor = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   464
		$menu_items[$key]->current_item_parent = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   465
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   466
		if (
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   467
			isset( $parent_item->type ) &&
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   468
			(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   469
				// ancestral post object
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   470
				(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   471
					'post_type' == $parent_item->type &&
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   472
					! empty( $queried_object->post_type ) &&
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   473
					is_post_type_hierarchical( $queried_object->post_type ) &&
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   474
					in_array( $parent_item->object_id, $queried_object->ancestors ) &&
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   475
					$parent_item->object != $queried_object->ID
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   476
				) ||
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   477
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   478
				// ancestral term
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   479
				(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   480
					'taxonomy' == $parent_item->type &&
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   481
					isset( $possible_taxonomy_ancestors[ $parent_item->object ] ) &&
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   482
					in_array( $parent_item->object_id, $possible_taxonomy_ancestors[ $parent_item->object ] ) &&
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   483
					(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   484
						! isset( $queried_object->term_id ) ||
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   485
						$parent_item->object_id != $queried_object->term_id
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   486
					)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   487
				)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   488
			)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   489
		) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   490
			$classes[] = empty( $queried_object->taxonomy ) ? 'current-' . $queried_object->post_type . '-ancestor' : 'current-' . $queried_object->taxonomy . '-ancestor';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   491
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   492
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   493
		if ( in_array(  intval( $parent_item->db_id ), $active_ancestor_item_ids ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   494
			$classes[] = 'current-menu-ancestor';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   495
			$menu_items[$key]->current_item_ancestor = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   496
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   497
		if ( in_array( $parent_item->db_id, $active_parent_item_ids ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   498
			$classes[] = 'current-menu-parent';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   499
			$menu_items[$key]->current_item_parent = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   500
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   501
		if ( in_array( $parent_item->object_id, $active_parent_object_ids ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   502
			$classes[] = 'current-' . $active_object . '-parent';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   503
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   504
		if ( 'post_type' == $parent_item->type && 'page' == $parent_item->object ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   505
			// Back compat classes for pages to match wp_page_menu()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   506
			if ( in_array('current-menu-parent', $classes) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   507
				$classes[] = 'current_page_parent';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   508
			if ( in_array('current-menu-ancestor', $classes) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   509
				$classes[] = 'current_page_ancestor';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   510
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   511
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   512
		$menu_items[$key]->classes = array_unique( $classes );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   513
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   514
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   515
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   516
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   517
 * Retrieve the HTML list content for nav menu items.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   518
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   519
 * @uses Walker_Nav_Menu to create HTML list content.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   520
 * @since 3.0.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   521
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   522
 * @param array    $items The menu items, sorted by each menu item's menu order.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   523
 * @param int      $depth Depth of the item in reference to parents.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   524
 * @param stdClass $r     An object containing wp_nav_menu() arguments.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   525
 * @return string The HTML list content for the menu items.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   526
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   527
function walk_nav_menu_tree( $items, $depth, $r ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   528
	$walker = ( empty($r->walker) ) ? new Walker_Nav_Menu : $r->walker;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   529
	$args = array( $items, $depth, $r );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   530
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   531
	return call_user_func_array( array( $walker, 'walk' ), $args );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   532
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   533
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   534
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   535
 * Prevents a menu item ID from being used more than once.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   536
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   537
 * @since 3.0.1
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   538
 * @access private
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   539
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   540
 * @staticvar array $used_ids
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   541
 * @param string $id
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   542
 * @param object $item
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   543
 * @return string
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   544
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   545
function _nav_menu_item_id_use_once( $id, $item ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   546
	static $_used_ids = array();
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   547
	if ( in_array( $item->ID, $_used_ids ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   548
		return '';
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   549
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   550
	$_used_ids[] = $item->ID;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   551
	return $id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   552
}