wp/wp-includes/nav-menu-template.php
author ymh <ymh.work@gmail.com>
Tue, 09 Jun 2015 03:35:32 +0200
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
permissions -rw-r--r--
upgrade wordpress + plugins
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
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 * Navigation Menu template functions
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
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
 * Create HTML list of nav menu items.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
 * @uses Walker
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
class Walker_Nav_Menu extends Walker {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
	 * What the class handles.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
	 * @see Walker::$tree_type
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
	 * @var string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    24
	public $tree_type = array( 'post_type', 'taxonomy', 'custom' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
	 * Database fields to use.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
	 * @see Walker::$db_fields
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
	 * @todo Decouple this.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
	 * @var array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    34
	public $db_fields = array( 'parent' => 'menu_item_parent', 'id' => 'db_id' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
	 * Starts the list before the elements are added.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
	 * @see Walker::start_lvl()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
	 * @param string $output Passed by reference. Used to append additional content.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
	 * @param int    $depth  Depth of menu item. Used for padding.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
	 * @param array  $args   An array of arguments. @see wp_nav_menu()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    47
	public function start_lvl( &$output, $depth = 0, $args = array() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
		$indent = str_repeat("\t", $depth);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
		$output .= "\n$indent<ul class=\"sub-menu\">\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
	 * Ends the list of after the elements are added.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
	 * @see Walker::end_lvl()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
	 * @param string $output Passed by reference. Used to append additional content.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
	 * @param int    $depth  Depth of menu item. Used for padding.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
	 * @param array  $args   An array of arguments. @see wp_nav_menu()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    63
	public function end_lvl( &$output, $depth = 0, $args = array() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
		$indent = str_repeat("\t", $depth);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
		$output .= "$indent</ul>\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
	 * Start the element output.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
	 * @see Walker::start_el()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
	 * @param string $output Passed by reference. Used to append additional content.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
	 * @param object $item   Menu item data object.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
	 * @param int    $depth  Depth of menu item. Used for padding.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
	 * @param array  $args   An array of arguments. @see wp_nav_menu()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
	 * @param int    $id     Current item ID.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    81
	public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
		$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
		$classes = empty( $item->classes ) ? array() : (array) $item->classes;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
		$classes[] = 'menu-item-' . $item->ID;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
		/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    88
		 * Filter the CSS class(es) applied to a menu item's list item element.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
		 * @since 3.0.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    91
		 * @since 4.1.0 The `$depth` parameter was added.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
		 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    93
		 * @param array  $classes The CSS classes that are applied to the menu item's `<li>` element.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
		 * @param object $item    The current menu item.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    95
		 * @param array  $args    An array of {@see wp_nav_menu()} arguments.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    96
		 * @param int    $depth   Depth of menu item. Used for padding.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
		 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    98
		$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args, $depth ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
		$class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
		/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   102
		 * Filter the ID applied to a menu item's list item element.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
		 * @since 3.0.1
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   105
		 * @since 4.1.0 The `$depth` parameter was added.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
		 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   107
		 * @param string $menu_id The ID that is applied to the menu item's `<li>` element.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   108
		 * @param object $item    The current menu item.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   109
		 * @param array  $args    An array of {@see wp_nav_menu()} arguments.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   110
		 * @param int    $depth   Depth of menu item. Used for padding.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
		 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   112
		$id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args, $depth );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
		$id = $id ? ' id="' . esc_attr( $id ) . '"' : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   115
		$output .= $indent . '<li' . $id . $class_names .'>';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
		$atts = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
		$atts['title']  = ! empty( $item->attr_title ) ? $item->attr_title : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
		$atts['target'] = ! empty( $item->target )     ? $item->target     : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
		$atts['rel']    = ! empty( $item->xfn )        ? $item->xfn        : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
		$atts['href']   = ! empty( $item->url )        ? $item->url        : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
		/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   124
		 * Filter the HTML attributes applied to a menu item's anchor element.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
		 * @since 3.6.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   127
		 * @since 4.1.0 The `$depth` parameter was added.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
		 * @param array $atts {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   130
		 *     The HTML attributes applied to the menu item's `<a>` element, empty strings are ignored.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
		 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   132
		 *     @type string $title  Title attribute.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   133
		 *     @type string $target Target attribute.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
		 *     @type string $rel    The rel attribute.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
		 *     @type string $href   The href attribute.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
		 * }
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   137
		 * @param object $item  The current menu item.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   138
		 * @param array  $args  An array of {@see wp_nav_menu()} arguments.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   139
		 * @param int    $depth Depth of menu item. Used for padding.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
		 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   141
		$atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args, $depth );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
		$attributes = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
		foreach ( $atts as $attr => $value ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
			if ( ! empty( $value ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
				$value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
				$attributes .= ' ' . $attr . '="' . $value . '"';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
		$item_output = $args->before;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
		$item_output .= '<a'. $attributes .'>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
		/** This filter is documented in wp-includes/post-template.php */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
		$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
		$item_output .= '</a>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
		$item_output .= $args->after;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
		/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
		 * Filter a menu item's starting output.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
		 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   161
		 * The menu item's starting output only includes `$args->before`, the opening `<a>`,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   162
		 * the menu item's title, the closing `</a>`, and `$args->after`. Currently, there is
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   163
		 * no filter for modifying the opening and closing `<li>` for a menu item.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
		 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
		 * @param string $item_output The menu item's starting HTML output.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
		 * @param object $item        Menu item data object.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
		 * @param int    $depth       Depth of menu item. Used for padding.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   170
		 * @param array  $args        An array of {@see wp_nav_menu()} arguments.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
		 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
		$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
	 * Ends the element output, if needed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
	 * @see Walker::end_el()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
	 * @param string $output Passed by reference. Used to append additional content.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
	 * @param object $item   Page data object. Not used.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
	 * @param int    $depth  Depth of page. Not Used.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
	 * @param array  $args   An array of arguments. @see wp_nav_menu()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   187
	public function end_el( &$output, $item, $depth = 0, $args = array() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
		$output .= "</li>\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
} // Walker_Nav_Menu
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
 * Displays a navigation menu.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   198
 * @param array $args {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   199
 *     Optional. Array of nav menu arguments.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   200
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   201
 *     @type string        $menu            Desired menu. Accepts (matching in order) id, slug, name. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   202
 *     @type string        $menu_class      CSS class to use for the ul element which forms the menu. Default 'menu'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   203
 *     @type string        $menu_id         The ID that is applied to the ul element which forms the menu.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   204
 *                                          Default is the menu slug, incremented.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   205
 *     @type string        $container       Whether to wrap the ul, and what to wrap it with. Default 'div'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   206
 *     @type string        $container_class Class that is applied to the container. Default 'menu-{menu slug}-container'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   207
 *     @type string        $container_id    The ID that is applied to the container. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   208
 *     @type callback|bool $fallback_cb     If the menu doesn't exists, a callback function will fire.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   209
 *                                          Default is 'wp_page_menu'. Set to false for no fallback.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   210
 *     @type string        $before          Text before the link text. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   211
 *     @type string        $after           Text after the link text. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   212
 *     @type string        $link_before     Text before the link. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   213
 *     @type string        $link_after      Text after the link. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   214
 *     @type bool          $echo            Whether to echo the menu or return it. Default true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   215
 *     @type int           $depth           How many levels of the hierarchy are to be included. 0 means all. Default 0.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   216
 *     @type object        $walker          Instance of a custom walker class. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   217
 *     @type string        $theme_location  Theme location to be used. Must be registered with register_nav_menu()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   218
 *                                          in order to be selectable by the user.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   219
 *     @type string        $items_wrap      How the list items should be wrapped. Default is a ul with an id and class.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   220
 *                                          Uses printf() format with numbered placeholders.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   221
 * }
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   222
 * @return mixed 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
   223
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
function wp_nav_menu( $args = array() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
	static $menu_id_slugs = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   227
	$defaults = array( 'menu' => '', 'container' => 'div', 'container_class' => '', 'container_id' => '', 'menu_class' => 'menu', 'menu_id' => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
	'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>',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
	'depth' => 0, 'walker' => '', 'theme_location' => '' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
	$args = wp_parse_args( $args, $defaults );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
	 * Filter the arguments used to display a navigation menu.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   237
	 * @see wp_nav_menu()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   238
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   239
	 * @param array $args Array of wp_nav_menu() arguments.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
	$args = apply_filters( 'wp_nav_menu_args', $args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
	$args = (object) $args;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   244
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   245
	 * Filter whether to short-circuit the wp_nav_menu() output.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   246
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   247
	 * Returning a non-null value to the filter will short-circuit
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   248
	 * wp_nav_menu(), echoing that value if $args->echo is true,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   249
	 * returning that value otherwise.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   250
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   251
	 * @since 3.9.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   252
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   253
	 * @see wp_nav_menu()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   254
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   255
	 * @param string|null $output Nav menu output to short-circuit with. Default null.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   256
	 * @param object      $args   An object containing wp_nav_menu() arguments.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   257
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   258
	$nav_menu = apply_filters( 'pre_wp_nav_menu', null, $args );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   259
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   260
	if ( null !== $nav_menu ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   261
		if ( $args->echo ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   262
			echo $nav_menu;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   263
			return;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   264
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   265
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   266
		return $nav_menu;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   267
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   268
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   269
	// Get the nav menu based on the requested menu
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   270
	$menu = wp_get_nav_menu_object( $args->menu );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
	// Get the nav menu based on the theme_location
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   273
	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
   274
		$menu = wp_get_nav_menu_object( $locations[ $args->theme_location ] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
	// 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
   277
	if ( ! $menu && !$args->theme_location ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
		$menus = wp_get_nav_menus();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
		foreach ( $menus as $menu_maybe ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
			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
   281
				$menu = $menu_maybe;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   282
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   286
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   287
	// If the menu exists, get its items.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   288
	if ( $menu && ! is_wp_error($menu) && !isset($menu_items) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   289
		$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
   290
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   291
	/*
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   292
	 * If no menu was found:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   293
	 *  - Fall back (if one was specified), or bail.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   294
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   295
	 * If no menu items were found:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   296
	 *  - Fall back, but only if no theme location was specified.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   297
	 *  - Otherwise, bail.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   298
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   299
	if ( ( !$menu || is_wp_error($menu) || ( isset($menu_items) && empty($menu_items) && !$args->theme_location ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   300
		&& $args->fallback_cb && is_callable( $args->fallback_cb ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   301
			return call_user_func( $args->fallback_cb, (array) $args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   302
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
	if ( ! $menu || is_wp_error( $menu ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   305
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   306
	$nav_menu = $items = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   307
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
	$show_container = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   309
	if ( $args->container ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
		/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   311
		 * Filter the list of HTML tags that are valid for use as menu containers.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   313
		 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   314
		 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   315
		 * @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
   316
		 *                    Default is array containing 'div' and 'nav'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   317
		 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   318
		$allowed_tags = apply_filters( 'wp_nav_menu_container_allowedtags', array( 'div', 'nav' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   319
		if ( in_array( $args->container, $allowed_tags ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   320
			$show_container = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   321
			$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
   322
			$id = $args->container_id ? ' id="' . esc_attr( $args->container_id ) . '"' : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   323
			$nav_menu .= '<'. $args->container . $id . $class . '>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   324
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   325
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   326
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   327
	// Set up the $menu_item variables
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   328
	_wp_menu_item_classes_by_context( $menu_items );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   329
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   330
	$sorted_menu_items = $menu_items_with_children = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   331
	foreach ( (array) $menu_items as $menu_item ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   332
		$sorted_menu_items[ $menu_item->menu_order ] = $menu_item;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   333
		if ( $menu_item->menu_item_parent )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   334
			$menu_items_with_children[ $menu_item->menu_item_parent ] = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   335
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   336
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   337
	// Add the menu-item-has-children class where applicable
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
	if ( $menu_items_with_children ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   339
		foreach ( $sorted_menu_items as &$menu_item ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   340
			if ( isset( $menu_items_with_children[ $menu_item->ID ] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   341
				$menu_item->classes[] = 'menu-item-has-children';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   342
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   343
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   344
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   345
	unset( $menu_items, $menu_item );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   348
	 * Filter the sorted list of menu item objects before generating the menu's HTML.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   349
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   350
	 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   351
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   352
	 * @param array  $sorted_menu_items The menu items, sorted by each menu item's menu order.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   353
	 * @param object $args              An object containing wp_nav_menu() arguments.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   354
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   355
	$sorted_menu_items = apply_filters( 'wp_nav_menu_objects', $sorted_menu_items, $args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   357
	$items .= walk_nav_menu_tree( $sorted_menu_items, $args->depth, $args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   358
	unset($sorted_menu_items);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   359
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   360
	// Attributes
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   361
	if ( ! empty( $args->menu_id ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   362
		$wrap_id = $args->menu_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   363
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   364
		$wrap_id = 'menu-' . $menu->slug;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   365
		while ( in_array( $wrap_id, $menu_id_slugs ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   366
			if ( preg_match( '#-(\d+)$#', $wrap_id, $matches ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   367
				$wrap_id = preg_replace('#-(\d+)$#', '-' . ++$matches[1], $wrap_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   368
			else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   369
				$wrap_id = $wrap_id . '-1';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   370
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   371
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   372
	$menu_id_slugs[] = $wrap_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   373
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   374
	$wrap_class = $args->menu_class ? $args->menu_class : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   375
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   376
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   377
	 * Filter the HTML list content for navigation menus.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   378
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   379
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   380
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   381
	 * @see wp_nav_menu()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   382
	 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   383
	 * @param string $items The HTML list content for the menu items.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   384
	 * @param object $args  An object containing wp_nav_menu() arguments.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   385
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
	$items = apply_filters( 'wp_nav_menu_items', $items, $args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   387
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   388
	 * Filter the HTML list content for a specific navigation menu.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   389
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   390
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   391
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   392
	 * @see wp_nav_menu()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   393
	 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   394
	 * @param string $items The HTML list content for the menu items.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   395
	 * @param object $args  An object containing wp_nav_menu() arguments.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   396
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   397
	$items = apply_filters( "wp_nav_menu_{$menu->slug}_items", $items, $args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   398
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   399
	// Don't print any markup if there are no items at this point.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   400
	if ( empty( $items ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   401
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   402
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   403
	$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
   404
	unset( $items );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   405
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   406
	if ( $show_container )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   407
		$nav_menu .= '</' . $args->container . '>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   408
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   409
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   410
	 * Filter the HTML content for navigation menus.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   411
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   412
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   413
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   414
	 * @see wp_nav_menu()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   415
	 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   416
	 * @param string $nav_menu The HTML content for the navigation menu.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   417
	 * @param object $args     An object containing wp_nav_menu() arguments.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   418
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   419
	$nav_menu = apply_filters( 'wp_nav_menu', $nav_menu, $args );
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 ( $args->echo )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   422
		echo $nav_menu;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   423
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   424
		return $nav_menu;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   425
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   426
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   427
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   428
 * Add the class property classes for the current context, if applicable.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   429
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   430
 * @access private
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   431
 * @since 3.0.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   432
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   433
 * @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
   434
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   435
function _wp_menu_item_classes_by_context( &$menu_items ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   436
	global $wp_query, $wp_rewrite;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   437
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   438
	$queried_object = $wp_query->get_queried_object();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   439
	$queried_object_id = (int) $wp_query->queried_object_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   440
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   441
	$active_object = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   442
	$active_ancestor_item_ids = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   443
	$active_parent_item_ids = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   444
	$active_parent_object_ids = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   445
	$possible_taxonomy_ancestors = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   446
	$possible_object_parents = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   447
	$home_page_id = (int) get_option( 'page_for_posts' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   448
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   449
	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
   450
		foreach ( (array) get_object_taxonomies( $queried_object->post_type ) as $taxonomy ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   451
			if ( is_taxonomy_hierarchical( $taxonomy ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   452
				$term_hierarchy = _get_term_hierarchy( $taxonomy );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   453
				$terms = wp_get_object_terms( $queried_object_id, $taxonomy, array( 'fields' => 'ids' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   454
				if ( is_array( $terms ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   455
					$possible_object_parents = array_merge( $possible_object_parents, $terms );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   456
					$term_to_ancestor = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   457
					foreach ( (array) $term_hierarchy as $anc => $descs ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   458
						foreach ( (array) $descs as $desc )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   459
							$term_to_ancestor[ $desc ] = $anc;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   460
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   461
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   462
					foreach ( $terms as $desc ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   463
						do {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   464
							$possible_taxonomy_ancestors[ $taxonomy ][] = $desc;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   465
							if ( isset( $term_to_ancestor[ $desc ] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   466
								$_desc = $term_to_ancestor[ $desc ];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   467
								unset( $term_to_ancestor[ $desc ] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   468
								$desc = $_desc;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   469
							} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   470
								$desc = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   471
							}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   472
						} while ( ! empty( $desc ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   473
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   474
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   475
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   476
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   477
	} elseif ( ! empty( $queried_object->taxonomy ) && is_taxonomy_hierarchical( $queried_object->taxonomy ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   478
		$term_hierarchy = _get_term_hierarchy( $queried_object->taxonomy );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   479
		$term_to_ancestor = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   480
		foreach ( (array) $term_hierarchy as $anc => $descs ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   481
			foreach ( (array) $descs as $desc )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   482
				$term_to_ancestor[ $desc ] = $anc;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   483
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   484
		$desc = $queried_object->term_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   485
		do {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   486
			$possible_taxonomy_ancestors[ $queried_object->taxonomy ][] = $desc;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   487
			if ( isset( $term_to_ancestor[ $desc ] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   488
				$_desc = $term_to_ancestor[ $desc ];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   489
				unset( $term_to_ancestor[ $desc ] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   490
				$desc = $_desc;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   491
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   492
				$desc = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   493
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   494
		} while ( ! empty( $desc ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   495
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   496
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   497
	$possible_object_parents = array_filter( $possible_object_parents );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   498
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   499
	$front_page_url = home_url();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   500
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   501
	foreach ( (array) $menu_items as $key => $menu_item ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   502
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   503
		$menu_items[$key]->current = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   504
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   505
		$classes = (array) $menu_item->classes;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   506
		$classes[] = 'menu-item';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   507
		$classes[] = 'menu-item-type-' . $menu_item->type;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   508
		$classes[] = 'menu-item-object-' . $menu_item->object;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   509
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   510
		// 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
   511
		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
   512
			$active_parent_object_ids[] = (int) $menu_item->object_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   513
			$active_parent_item_ids[] = (int) $menu_item->db_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   514
			$active_object = $queried_object->post_type;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   515
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   516
		// if the menu item corresponds to the currently-queried post or taxonomy object
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   517
		} elseif (
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   518
			$menu_item->object_id == $queried_object_id &&
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   519
			(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   520
				( ! 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
   521
				( 'post_type' == $menu_item->type && $wp_query->is_singular ) ||
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   522
				( '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
   523
			)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   524
		) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   525
			$classes[] = 'current-menu-item';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   526
			$menu_items[$key]->current = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   527
			$_anc_id = (int) $menu_item->db_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   528
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   529
			while(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   530
				( $_anc_id = get_post_meta( $_anc_id, '_menu_item_menu_item_parent', true ) ) &&
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   531
				! in_array( $_anc_id, $active_ancestor_item_ids )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   532
			) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   533
				$active_ancestor_item_ids[] = $_anc_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   534
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   535
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   536
			if ( 'post_type' == $menu_item->type && 'page' == $menu_item->object ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   537
				// Back compat classes for pages to match wp_page_menu()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   538
				$classes[] = 'page_item';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   539
				$classes[] = 'page-item-' . $menu_item->object_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   540
				$classes[] = 'current_page_item';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   541
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   542
			$active_parent_item_ids[] = (int) $menu_item->menu_item_parent;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   543
			$active_parent_object_ids[] = (int) $menu_item->post_parent;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   544
			$active_object = $menu_item->object;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   545
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   546
		// if the menu item corresponds to the currently-requested URL
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   547
		} elseif ( 'custom' == $menu_item->object ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   548
			$_root_relative_current = untrailingslashit( $_SERVER['REQUEST_URI'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   549
			$current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_root_relative_current );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   550
			$raw_item_url = strpos( $menu_item->url, '#' ) ? substr( $menu_item->url, 0, strpos( $menu_item->url, '#' ) ) : $menu_item->url;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   551
			$item_url = untrailingslashit( $raw_item_url );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   552
			$_indexless_current = untrailingslashit( preg_replace( '/' . preg_quote( $wp_rewrite->index, '/' ) . '$/', '', $current_url ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   553
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   554
			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
   555
				$classes[] = 'current-menu-item';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   556
				$menu_items[$key]->current = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   557
				$_anc_id = (int) $menu_item->db_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   558
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   559
				while(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   560
					( $_anc_id = get_post_meta( $_anc_id, '_menu_item_menu_item_parent', true ) ) &&
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   561
					! in_array( $_anc_id, $active_ancestor_item_ids )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   562
				) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   563
					$active_ancestor_item_ids[] = $_anc_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   564
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   565
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   566
				if ( in_array( home_url(), array( untrailingslashit( $current_url ), untrailingslashit( $_indexless_current ) ) ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   567
					// Back compat for home link to match wp_page_menu()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   568
					$classes[] = 'current_page_item';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   569
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   570
				$active_parent_item_ids[] = (int) $menu_item->menu_item_parent;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   571
				$active_parent_object_ids[] = (int) $menu_item->post_parent;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   572
				$active_object = $menu_item->object;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   573
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   574
			// give front page item current-menu-item class when extra query arguments involved
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   575
			} elseif ( $item_url == $front_page_url && is_front_page() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   576
				$classes[] = 'current-menu-item';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   577
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   578
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   579
			if ( untrailingslashit($item_url) == home_url() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   580
				$classes[] = 'menu-item-home';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   581
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   582
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   583
		// 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
   584
		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
   585
			$classes[] = 'current_page_parent';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   586
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   587
		$menu_items[$key]->classes = array_unique( $classes );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   588
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   589
	$active_ancestor_item_ids = array_filter( array_unique( $active_ancestor_item_ids ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   590
	$active_parent_item_ids = array_filter( array_unique( $active_parent_item_ids ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   591
	$active_parent_object_ids = array_filter( array_unique( $active_parent_object_ids ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   592
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   593
	// set parent's class
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   594
	foreach ( (array) $menu_items as $key => $parent_item ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   595
		$classes = (array) $parent_item->classes;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   596
		$menu_items[$key]->current_item_ancestor = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   597
		$menu_items[$key]->current_item_parent = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   598
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   599
		if (
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   600
			isset( $parent_item->type ) &&
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   601
			(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   602
				// ancestral post object
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   603
				(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   604
					'post_type' == $parent_item->type &&
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   605
					! empty( $queried_object->post_type ) &&
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   606
					is_post_type_hierarchical( $queried_object->post_type ) &&
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   607
					in_array( $parent_item->object_id, $queried_object->ancestors ) &&
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   608
					$parent_item->object != $queried_object->ID
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   609
				) ||
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   610
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   611
				// ancestral term
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   612
				(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   613
					'taxonomy' == $parent_item->type &&
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   614
					isset( $possible_taxonomy_ancestors[ $parent_item->object ] ) &&
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   615
					in_array( $parent_item->object_id, $possible_taxonomy_ancestors[ $parent_item->object ] ) &&
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   616
					(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   617
						! isset( $queried_object->term_id ) ||
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   618
						$parent_item->object_id != $queried_object->term_id
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   619
					)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   620
				)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   621
			)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   622
		) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   623
			$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
   624
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   625
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   626
		if ( in_array(  intval( $parent_item->db_id ), $active_ancestor_item_ids ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   627
			$classes[] = 'current-menu-ancestor';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   628
			$menu_items[$key]->current_item_ancestor = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   629
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   630
		if ( in_array( $parent_item->db_id, $active_parent_item_ids ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   631
			$classes[] = 'current-menu-parent';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   632
			$menu_items[$key]->current_item_parent = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   633
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   634
		if ( in_array( $parent_item->object_id, $active_parent_object_ids ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   635
			$classes[] = 'current-' . $active_object . '-parent';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   636
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   637
		if ( 'post_type' == $parent_item->type && 'page' == $parent_item->object ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   638
			// Back compat classes for pages to match wp_page_menu()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   639
			if ( in_array('current-menu-parent', $classes) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   640
				$classes[] = 'current_page_parent';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   641
			if ( in_array('current-menu-ancestor', $classes) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   642
				$classes[] = 'current_page_ancestor';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   643
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   644
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   645
		$menu_items[$key]->classes = array_unique( $classes );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   646
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   647
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   648
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   649
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   650
 * Retrieve the HTML list content for nav menu items.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   651
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   652
 * @uses Walker_Nav_Menu to create HTML list content.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   653
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   654
 * @see Walker::walk() for parameters and return description.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   655
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   656
function walk_nav_menu_tree( $items, $depth, $r ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   657
	$walker = ( empty($r->walker) ) ? new Walker_Nav_Menu : $r->walker;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   658
	$args = array( $items, $depth, $r );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   659
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   660
	return call_user_func_array( array($walker, 'walk'), $args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   661
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   662
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   663
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   664
 * Prevents a menu item ID from being used more than once.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   665
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   666
 * @since 3.0.1
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   667
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   668
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   669
function _nav_menu_item_id_use_once( $id, $item ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   670
	static $_used_ids = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   671
	if ( in_array( $item->ID, $_used_ids ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   672
		return '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   673
	$_used_ids[] = $item->ID;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   674
	return $id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   675
}