Changeset 37640 for trunk/src/wp-includes/nav-menu-template.php
- Timestamp:
- 06/06/2016 03:17:46 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/nav-menu-template.php
r37639 r37640 1 1 <?php 2 2 /** 3 * Nav igation Menu template functions3 * Nav Menu API: Template functions 4 4 * 5 5 * @package WordPress … … 8 8 */ 9 9 10 /** 11 * Create HTML list of nav menu items. 12 * 13 * @since 3.0.0 14 * @uses Walker 15 */ 16 class Walker_Nav_Menu extends Walker { 17 /** 18 * What the class handles. 19 * 20 * @since 3.0.0 21 * @access public 22 * @var string 23 * 24 * @see Walker::$tree_type 25 */ 26 public $tree_type = array( 'post_type', 'taxonomy', 'custom' ); 27 28 /** 29 * Database fields to use. 30 * 31 * @since 3.0.0 32 * @access public 33 * @todo Decouple this. 34 * @var array 35 * 36 * @see Walker::$db_fields 37 */ 38 public $db_fields = array( 'parent' => 'menu_item_parent', 'id' => 'db_id' ); 39 40 /** 41 * Starts the list before the elements are added. 42 * 43 * @since 3.0.0 44 * 45 * @see Walker::start_lvl() 46 * 47 * @param string $output Passed by reference. Used to append additional content. 48 * @param int $depth Depth of menu item. Used for padding. 49 * @param array $args An array of wp_nav_menu() arguments. 50 */ 51 public function start_lvl( &$output, $depth = 0, $args = array() ) { 52 $indent = str_repeat("\t", $depth); 53 $output .= "\n$indent<ul class=\"sub-menu\">\n"; 54 } 55 56 /** 57 * Ends the list of after the elements are added. 58 * 59 * @since 3.0.0 60 * 61 * @see Walker::end_lvl() 62 * 63 * @param string $output Passed by reference. Used to append additional content. 64 * @param int $depth Depth of menu item. Used for padding. 65 * @param array $args An array of wp_nav_menu() arguments. 66 */ 67 public function end_lvl( &$output, $depth = 0, $args = array() ) { 68 $indent = str_repeat("\t", $depth); 69 $output .= "$indent</ul>\n"; 70 } 71 72 /** 73 * Starts the element output. 74 * 75 * @since 3.0.0 76 * @since 4.4.0 The {@see 'nav_menu_item_args'} filter was added. 77 * 78 * @see Walker::start_el() 79 * 80 * @param string $output Passed by reference. Used to append additional content. 81 * @param object $item Menu item data object. 82 * @param int $depth Depth of menu item. Used for padding. 83 * @param array $args An array of wp_nav_menu() arguments. 84 * @param int $id Current item ID. 85 */ 86 public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { 87 $indent = ( $depth ) ? str_repeat( "\t", $depth ) : ''; 88 89 $classes = empty( $item->classes ) ? array() : (array) $item->classes; 90 $classes[] = 'menu-item-' . $item->ID; 91 92 /** 93 * Filters the arguments for a single nav menu item. 94 * 95 * @since 4.4.0 96 * 97 * @param array $args An array of arguments. 98 * @param object $item Menu item data object. 99 * @param int $depth Depth of menu item. Used for padding. 100 */ 101 $args = apply_filters( 'nav_menu_item_args', $args, $item, $depth ); 102 103 /** 104 * Filters the CSS class(es) applied to a menu item's list item element. 105 * 106 * @since 3.0.0 107 * @since 4.1.0 The `$depth` parameter was added. 108 * 109 * @param array $classes The CSS classes that are applied to the menu item's `<li>` element. 110 * @param object $item The current menu item. 111 * @param array $args An array of wp_nav_menu() arguments. 112 * @param int $depth Depth of menu item. Used for padding. 113 */ 114 $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args, $depth ) ); 115 $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : ''; 116 117 /** 118 * Filters the ID applied to a menu item's list item element. 119 * 120 * @since 3.0.1 121 * @since 4.1.0 The `$depth` parameter was added. 122 * 123 * @param string $menu_id The ID that is applied to the menu item's `<li>` element. 124 * @param object $item The current menu item. 125 * @param array $args An array of wp_nav_menu() arguments. 126 * @param int $depth Depth of menu item. Used for padding. 127 */ 128 $id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args, $depth ); 129 $id = $id ? ' id="' . esc_attr( $id ) . '"' : ''; 130 131 $output .= $indent . '<li' . $id . $class_names .'>'; 132 133 $atts = array(); 134 $atts['title'] = ! empty( $item->attr_title ) ? $item->attr_title : ''; 135 $atts['target'] = ! empty( $item->target ) ? $item->target : ''; 136 $atts['rel'] = ! empty( $item->xfn ) ? $item->xfn : ''; 137 $atts['href'] = ! empty( $item->url ) ? $item->url : ''; 138 139 /** 140 * Filters the HTML attributes applied to a menu item's anchor element. 141 * 142 * @since 3.6.0 143 * @since 4.1.0 The `$depth` parameter was added. 144 * 145 * @param array $atts { 146 * The HTML attributes applied to the menu item's `<a>` element, empty strings are ignored. 147 * 148 * @type string $title Title attribute. 149 * @type string $target Target attribute. 150 * @type string $rel The rel attribute. 151 * @type string $href The href attribute. 152 * } 153 * @param object $item The current menu item. 154 * @param array $args An array of wp_nav_menu() arguments. 155 * @param int $depth Depth of menu item. Used for padding. 156 */ 157 $atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args, $depth ); 158 159 $attributes = ''; 160 foreach ( $atts as $attr => $value ) { 161 if ( ! empty( $value ) ) { 162 $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value ); 163 $attributes .= ' ' . $attr . '="' . $value . '"'; 164 } 165 } 166 167 /** This filter is documented in wp-includes/post-template.php */ 168 $title = apply_filters( 'the_title', $item->title, $item->ID ); 169 170 /** 171 * Filters a menu item's title. 172 * 173 * @since 4.4.0 174 * 175 * @param string $title The menu item's title. 176 * @param object $item The current menu item. 177 * @param array $args An array of wp_nav_menu() arguments. 178 * @param int $depth Depth of menu item. Used for padding. 179 */ 180 $title = apply_filters( 'nav_menu_item_title', $title, $item, $args, $depth ); 181 182 $item_output = $args->before; 183 $item_output .= '<a'. $attributes .'>'; 184 $item_output .= $args->link_before . $title . $args->link_after; 185 $item_output .= '</a>'; 186 $item_output .= $args->after; 187 188 /** 189 * Filters a menu item's starting output. 190 * 191 * The menu item's starting output only includes `$args->before`, the opening `<a>`, 192 * the menu item's title, the closing `</a>`, and `$args->after`. Currently, there is 193 * no filter for modifying the opening and closing `<li>` for a menu item. 194 * 195 * @since 3.0.0 196 * 197 * @param string $item_output The menu item's starting HTML output. 198 * @param object $item Menu item data object. 199 * @param int $depth Depth of menu item. Used for padding. 200 * @param array $args An array of wp_nav_menu() arguments. 201 */ 202 $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ); 203 } 204 205 /** 206 * Ends the element output, if needed. 207 * 208 * @since 3.0.0 209 * 210 * @see Walker::end_el() 211 * 212 * @param string $output Passed by reference. Used to append additional content. 213 * @param object $item Page data object. Not used. 214 * @param int $depth Depth of page. Not Used. 215 * @param array $args An array of wp_nav_menu() arguments. 216 */ 217 public function end_el( &$output, $item, $depth = 0, $args = array() ) { 218 $output .= "</li>\n"; 219 } 220 221 } // Walker_Nav_Menu 10 /** Walker_Nav_Menu class */ 11 require_once ABSPATH . WPINC . '/class-walker-nav-menu.php'; 222 12 223 13 /**
Note: See TracChangeset
for help on using the changeset viewer.