Changeset 51739 for trunk/src/wp-includes/class-walker-nav-menu.php
- Timestamp:
- 09/08/2021 03:35:32 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-walker-nav-menu.php
r50823 r51739 107 107 * @since 3.0.0 108 108 * @since 4.4.0 The {@see 'nav_menu_item_args'} filter was added. 109 * @since 5.9.0 Renamed `$item` to `$data_object` to match parent class for PHP 8 named parameter support. 109 110 * 110 111 * @see Walker::start_el() 111 112 * 112 * @param string $output Used to append additional content (passed by reference). 113 * @param WP_Post $item Menu item data object. 114 * @param int $depth Depth of menu item. Used for padding. 115 * @param stdClass $args An object of wp_nav_menu() arguments. 116 * @param int $id Current item ID. 117 */ 118 public function start_el( &$output, $item, $depth = 0, $args = null, $id = 0 ) { 113 * @param string $output Used to append additional content (passed by reference). 114 * @param WP_Post $data_object Menu item data object. 115 * @param int $depth Depth of menu item. Used for padding. 116 * @param stdClass $args An object of wp_nav_menu() arguments. 117 * @param int $id Current item ID. 118 */ 119 public function start_el( &$output, $data_object, $depth = 0, $args = null, $id = 0 ) { 120 // Restores the more descriptive, specific name for use within this method. 121 $menu_item = $data_object; 122 119 123 if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) { 120 124 $t = ''; … … 126 130 $indent = ( $depth ) ? str_repeat( $t, $depth ) : ''; 127 131 128 $classes = empty( $ item->classes ) ? array() : (array) $item->classes;129 $classes[] = 'menu-item-' . $ item->ID;132 $classes = empty( $menu_item->classes ) ? array() : (array) $menu_item->classes; 133 $classes[] = 'menu-item-' . $menu_item->ID; 130 134 131 135 /** … … 134 138 * @since 4.4.0 135 139 * 136 * @param stdClass $args An object of wp_nav_menu() arguments.137 * @param WP_Post $ itemMenu item data object.138 * @param int $depth Depth of menu item. Used for padding.139 */ 140 $args = apply_filters( 'nav_menu_item_args', $args, $ item, $depth );140 * @param stdClass $args An object of wp_nav_menu() arguments. 141 * @param WP_Post $menu_item Menu item data object. 142 * @param int $depth Depth of menu item. Used for padding. 143 */ 144 $args = apply_filters( 'nav_menu_item_args', $args, $menu_item, $depth ); 141 145 142 146 /** … … 146 150 * @since 4.1.0 The `$depth` parameter was added. 147 151 * 148 * @param string[] $classes Array of the CSS classes that are applied to the menu item's `<li>` element.149 * @param WP_Post $ item The current menu item.150 * @param stdClass $args An object of wp_nav_menu() arguments.151 * @param int $depth Depth of menu item. Used for padding.152 */ 153 $class_names = implode( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $ item, $args, $depth ) );152 * @param string[] $classes Array of the CSS classes that are applied to the menu item's `<li>` element. 153 * @param WP_Post $menu_item The current menu item object. 154 * @param stdClass $args An object of wp_nav_menu() arguments. 155 * @param int $depth Depth of menu item. Used for padding. 156 */ 157 $class_names = implode( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $menu_item, $args, $depth ) ); 154 158 $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : ''; 155 159 … … 160 164 * @since 4.1.0 The `$depth` parameter was added. 161 165 * 162 * @param string $menu_id The ID that is applied to the menu item's `<li>` element.163 * @param WP_Post $ itemThe current menu item.164 * @param stdClass $args An object of wp_nav_menu() arguments.165 * @param int $depth Depth of menu item. Used for padding.166 */ 167 $id = apply_filters( 'nav_menu_item_id', 'menu-item-' . $ item->ID, $item, $args, $depth );166 * @param string $menu_id The ID that is applied to the menu item's `<li>` element. 167 * @param WP_Post $menu_item The current menu item. 168 * @param stdClass $args An object of wp_nav_menu() arguments. 169 * @param int $depth Depth of menu item. Used for padding. 170 */ 171 $id = apply_filters( 'nav_menu_item_id', 'menu-item-' . $menu_item->ID, $menu_item, $args, $depth ); 168 172 $id = $id ? ' id="' . esc_attr( $id ) . '"' : ''; 169 173 … … 171 175 172 176 $atts = array(); 173 $atts['title'] = ! empty( $ item->attr_title ) ? $item->attr_title : '';174 $atts['target'] = ! empty( $ item->target ) ? $item->target : '';175 if ( '_blank' === $ item->target && empty( $item->xfn ) ) {177 $atts['title'] = ! empty( $menu_item->attr_title ) ? $menu_item->attr_title : ''; 178 $atts['target'] = ! empty( $menu_item->target ) ? $menu_item->target : ''; 179 if ( '_blank' === $menu_item->target && empty( $menu_item->xfn ) ) { 176 180 $atts['rel'] = 'noopener'; 177 181 } else { 178 $atts['rel'] = $ item->xfn;179 } 180 $atts['href'] = ! empty( $ item->url ) ? $item->url : '';181 $atts['aria-current'] = $ item->current ? 'page' : '';182 $atts['rel'] = $menu_item->xfn; 183 } 184 $atts['href'] = ! empty( $menu_item->url ) ? $menu_item->url : ''; 185 $atts['aria-current'] = $menu_item->current ? 'page' : ''; 182 186 183 187 /** … … 196 200 * @type string $aria-current The aria-current attribute. 197 201 * } 198 * @param WP_Post $ item The current menu item.199 * @param stdClass $args An object of wp_nav_menu() arguments.200 * @param int $depth Depth of menu item. Used for padding.201 */ 202 $atts = apply_filters( 'nav_menu_link_attributes', $atts, $ item, $args, $depth );202 * @param WP_Post $menu_item The current menu item object. 203 * @param stdClass $args An object of wp_nav_menu() arguments. 204 * @param int $depth Depth of menu item. Used for padding. 205 */ 206 $atts = apply_filters( 'nav_menu_link_attributes', $atts, $menu_item, $args, $depth ); 203 207 204 208 $attributes = ''; … … 211 215 212 216 /** This filter is documented in wp-includes/post-template.php */ 213 $title = apply_filters( 'the_title', $ item->title, $item->ID );217 $title = apply_filters( 'the_title', $menu_item->title, $menu_item->ID ); 214 218 215 219 /** … … 218 222 * @since 4.4.0 219 223 * 220 * @param string $title The menu item's title.221 * @param WP_Post $ item The current menu item.222 * @param stdClass $args An object of wp_nav_menu() arguments.223 * @param int $depth Depth of menu item. Used for padding.224 */ 225 $title = apply_filters( 'nav_menu_item_title', $title, $ item, $args, $depth );224 * @param string $title The menu item's title. 225 * @param WP_Post $menu_item The current menu item object. 226 * @param stdClass $args An object of wp_nav_menu() arguments. 227 * @param int $depth Depth of menu item. Used for padding. 228 */ 229 $title = apply_filters( 'nav_menu_item_title', $title, $menu_item, $args, $depth ); 226 230 227 231 $item_output = $args->before; … … 241 245 * 242 246 * @param string $item_output The menu item's starting HTML output. 243 * @param WP_Post $ itemMenu item data object.247 * @param WP_Post $menu_item Menu item data object. 244 248 * @param int $depth Depth of menu item. Used for padding. 245 249 * @param stdClass $args An object of wp_nav_menu() arguments. 246 250 */ 247 $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $ item, $depth, $args );251 $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $menu_item, $depth, $args ); 248 252 } 249 253
Note: See TracChangeset
for help on using the changeset viewer.