44 /** |
44 /** |
45 * Start the element output. |
45 * Start the element output. |
46 * |
46 * |
47 * @see Walker_Nav_Menu::start_el() |
47 * @see Walker_Nav_Menu::start_el() |
48 * @since 3.0.0 |
48 * @since 3.0.0 |
|
49 * @since 5.9.0 Renamed `$item` to `$data_object` and `$id` to `$current_object_id` |
|
50 * to match parent class for PHP 8 named parameter support. |
49 * |
51 * |
50 * @global int $_wp_nav_menu_max_depth |
52 * @global int $_wp_nav_menu_max_depth |
51 * |
53 * |
52 * @param string $output Used to append additional content (passed by reference). |
54 * @param string $output Used to append additional content (passed by reference). |
53 * @param WP_Post $item Menu item data object. |
55 * @param WP_Post $data_object Menu item data object. |
54 * @param int $depth Depth of menu item. Used for padding. |
56 * @param int $depth Depth of menu item. Used for padding. |
55 * @param stdClass $args Not used. |
57 * @param stdClass $args Not used. |
56 * @param int $id Not used. |
58 * @param int $current_object_id Optional. ID of the current menu item. Default 0. |
57 */ |
59 */ |
58 public function start_el( &$output, $item, $depth = 0, $args = null, $id = 0 ) { |
60 public function start_el( &$output, $data_object, $depth = 0, $args = null, $current_object_id = 0 ) { |
59 global $_wp_nav_menu_max_depth; |
61 global $_wp_nav_menu_max_depth; |
|
62 |
|
63 // Restores the more descriptive, specific name for use within this method. |
|
64 $menu_item = $data_object; |
60 $_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth; |
65 $_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth; |
61 |
66 |
62 ob_start(); |
67 ob_start(); |
63 $item_id = esc_attr( $item->ID ); |
68 $item_id = esc_attr( $menu_item->ID ); |
64 $removed_args = array( |
69 $removed_args = array( |
65 'action', |
70 'action', |
66 'customlink-tab', |
71 'customlink-tab', |
67 'edit-menu-item', |
72 'edit-menu-item', |
68 'menu-item', |
73 'menu-item', |
70 '_wpnonce', |
75 '_wpnonce', |
71 ); |
76 ); |
72 |
77 |
73 $original_title = false; |
78 $original_title = false; |
74 |
79 |
75 if ( 'taxonomy' === $item->type ) { |
80 if ( 'taxonomy' === $menu_item->type ) { |
76 $original_object = get_term( (int) $item->object_id, $item->object ); |
81 $original_object = get_term( (int) $menu_item->object_id, $menu_item->object ); |
77 if ( $original_object && ! is_wp_error( $original_object ) ) { |
82 if ( $original_object && ! is_wp_error( $original_object ) ) { |
78 $original_title = $original_object->name; |
83 $original_title = $original_object->name; |
79 } |
84 } |
80 } elseif ( 'post_type' === $item->type ) { |
85 } elseif ( 'post_type' === $menu_item->type ) { |
81 $original_object = get_post( $item->object_id ); |
86 $original_object = get_post( $menu_item->object_id ); |
82 if ( $original_object ) { |
87 if ( $original_object ) { |
83 $original_title = get_the_title( $original_object->ID ); |
88 $original_title = get_the_title( $original_object->ID ); |
84 } |
89 } |
85 } elseif ( 'post_type_archive' === $item->type ) { |
90 } elseif ( 'post_type_archive' === $menu_item->type ) { |
86 $original_object = get_post_type_object( $item->object ); |
91 $original_object = get_post_type_object( $menu_item->object ); |
87 if ( $original_object ) { |
92 if ( $original_object ) { |
88 $original_title = $original_object->labels->archives; |
93 $original_title = $original_object->labels->archives; |
89 } |
94 } |
90 } |
95 } |
91 |
96 |
92 $classes = array( |
97 $classes = array( |
93 'menu-item menu-item-depth-' . $depth, |
98 'menu-item menu-item-depth-' . $depth, |
94 'menu-item-' . esc_attr( $item->object ), |
99 'menu-item-' . esc_attr( $menu_item->object ), |
95 'menu-item-edit-' . ( ( isset( $_GET['edit-menu-item'] ) && $item_id === $_GET['edit-menu-item'] ) ? 'active' : 'inactive' ), |
100 'menu-item-edit-' . ( ( isset( $_GET['edit-menu-item'] ) && $item_id === $_GET['edit-menu-item'] ) ? 'active' : 'inactive' ), |
96 ); |
101 ); |
97 |
102 |
98 $title = $item->title; |
103 $title = $menu_item->title; |
99 |
104 |
100 if ( ! empty( $item->_invalid ) ) { |
105 if ( ! empty( $menu_item->_invalid ) ) { |
101 $classes[] = 'menu-item-invalid'; |
106 $classes[] = 'menu-item-invalid'; |
102 /* translators: %s: Title of an invalid menu item. */ |
107 /* translators: %s: Title of an invalid menu item. */ |
103 $title = sprintf( __( '%s (Invalid)' ), $item->title ); |
108 $title = sprintf( __( '%s (Invalid)' ), $menu_item->title ); |
104 } elseif ( isset( $item->post_status ) && 'draft' === $item->post_status ) { |
109 } elseif ( isset( $menu_item->post_status ) && 'draft' === $menu_item->post_status ) { |
105 $classes[] = 'pending'; |
110 $classes[] = 'pending'; |
106 /* translators: %s: Title of a menu item in draft status. */ |
111 /* translators: %s: Title of a menu item in draft status. */ |
107 $title = sprintf( __( '%s (Pending)' ), $item->title ); |
112 $title = sprintf( __( '%s (Pending)' ), $menu_item->title ); |
108 } |
113 } |
109 |
114 |
110 $title = ( ! isset( $item->label ) || '' === $item->label ) ? $title : $item->label; |
115 $title = ( ! isset( $menu_item->label ) || '' === $menu_item->label ) ? $title : $menu_item->label; |
111 |
116 |
112 $submenu_text = ''; |
117 $submenu_text = ''; |
113 if ( 0 === $depth ) { |
118 if ( 0 === $depth ) { |
114 $submenu_text = 'style="display: none;"'; |
119 $submenu_text = 'style="display: none;"'; |
115 } |
120 } |
183 </span> |
188 </span> |
184 </div> |
189 </div> |
185 </div> |
190 </div> |
186 |
191 |
187 <div class="menu-item-settings wp-clearfix" id="menu-item-settings-<?php echo $item_id; ?>"> |
192 <div class="menu-item-settings wp-clearfix" id="menu-item-settings-<?php echo $item_id; ?>"> |
188 <?php if ( 'custom' === $item->type ) : ?> |
193 <?php if ( 'custom' === $menu_item->type ) : ?> |
189 <p class="field-url description description-wide"> |
194 <p class="field-url description description-wide"> |
190 <label for="edit-menu-item-url-<?php echo $item_id; ?>"> |
195 <label for="edit-menu-item-url-<?php echo $item_id; ?>"> |
191 <?php _e( 'URL' ); ?><br /> |
196 <?php _e( 'URL' ); ?><br /> |
192 <input type="text" id="edit-menu-item-url-<?php echo $item_id; ?>" class="widefat code edit-menu-item-url" name="menu-item-url[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->url ); ?>" /> |
197 <input type="text" id="edit-menu-item-url-<?php echo $item_id; ?>" class="widefat code edit-menu-item-url" name="menu-item-url[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $menu_item->url ); ?>" /> |
193 </label> |
198 </label> |
194 </p> |
199 </p> |
195 <?php endif; ?> |
200 <?php endif; ?> |
196 <p class="description description-wide"> |
201 <p class="description description-wide"> |
197 <label for="edit-menu-item-title-<?php echo $item_id; ?>"> |
202 <label for="edit-menu-item-title-<?php echo $item_id; ?>"> |
198 <?php _e( 'Navigation Label' ); ?><br /> |
203 <?php _e( 'Navigation Label' ); ?><br /> |
199 <input type="text" id="edit-menu-item-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-title" name="menu-item-title[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->title ); ?>" /> |
204 <input type="text" id="edit-menu-item-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-title" name="menu-item-title[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $menu_item->title ); ?>" /> |
200 </label> |
205 </label> |
201 </p> |
206 </p> |
202 <p class="field-title-attribute field-attr-title description description-wide"> |
207 <p class="field-title-attribute field-attr-title description description-wide"> |
203 <label for="edit-menu-item-attr-title-<?php echo $item_id; ?>"> |
208 <label for="edit-menu-item-attr-title-<?php echo $item_id; ?>"> |
204 <?php _e( 'Title Attribute' ); ?><br /> |
209 <?php _e( 'Title Attribute' ); ?><br /> |
205 <input type="text" id="edit-menu-item-attr-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-attr-title" name="menu-item-attr-title[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->post_excerpt ); ?>" /> |
210 <input type="text" id="edit-menu-item-attr-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-attr-title" name="menu-item-attr-title[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $menu_item->post_excerpt ); ?>" /> |
206 </label> |
211 </label> |
207 </p> |
212 </p> |
208 <p class="field-link-target description"> |
213 <p class="field-link-target description"> |
209 <label for="edit-menu-item-target-<?php echo $item_id; ?>"> |
214 <label for="edit-menu-item-target-<?php echo $item_id; ?>"> |
210 <input type="checkbox" id="edit-menu-item-target-<?php echo $item_id; ?>" value="_blank" name="menu-item-target[<?php echo $item_id; ?>]"<?php checked( $item->target, '_blank' ); ?> /> |
215 <input type="checkbox" id="edit-menu-item-target-<?php echo $item_id; ?>" value="_blank" name="menu-item-target[<?php echo $item_id; ?>]"<?php checked( $menu_item->target, '_blank' ); ?> /> |
211 <?php _e( 'Open link in a new tab' ); ?> |
216 <?php _e( 'Open link in a new tab' ); ?> |
212 </label> |
217 </label> |
213 </p> |
218 </p> |
214 <p class="field-css-classes description description-thin"> |
219 <p class="field-css-classes description description-thin"> |
215 <label for="edit-menu-item-classes-<?php echo $item_id; ?>"> |
220 <label for="edit-menu-item-classes-<?php echo $item_id; ?>"> |
216 <?php _e( 'CSS Classes (optional)' ); ?><br /> |
221 <?php _e( 'CSS Classes (optional)' ); ?><br /> |
217 <input type="text" id="edit-menu-item-classes-<?php echo $item_id; ?>" class="widefat code edit-menu-item-classes" name="menu-item-classes[<?php echo $item_id; ?>]" value="<?php echo esc_attr( implode( ' ', $item->classes ) ); ?>" /> |
222 <input type="text" id="edit-menu-item-classes-<?php echo $item_id; ?>" class="widefat code edit-menu-item-classes" name="menu-item-classes[<?php echo $item_id; ?>]" value="<?php echo esc_attr( implode( ' ', $menu_item->classes ) ); ?>" /> |
218 </label> |
223 </label> |
219 </p> |
224 </p> |
220 <p class="field-xfn description description-thin"> |
225 <p class="field-xfn description description-thin"> |
221 <label for="edit-menu-item-xfn-<?php echo $item_id; ?>"> |
226 <label for="edit-menu-item-xfn-<?php echo $item_id; ?>"> |
222 <?php _e( 'Link Relationship (XFN)' ); ?><br /> |
227 <?php _e( 'Link Relationship (XFN)' ); ?><br /> |
223 <input type="text" id="edit-menu-item-xfn-<?php echo $item_id; ?>" class="widefat code edit-menu-item-xfn" name="menu-item-xfn[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->xfn ); ?>" /> |
228 <input type="text" id="edit-menu-item-xfn-<?php echo $item_id; ?>" class="widefat code edit-menu-item-xfn" name="menu-item-xfn[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $menu_item->xfn ); ?>" /> |
224 </label> |
229 </label> |
225 </p> |
230 </p> |
226 <p class="field-description description description-wide"> |
231 <p class="field-description description description-wide"> |
227 <label for="edit-menu-item-description-<?php echo $item_id; ?>"> |
232 <label for="edit-menu-item-description-<?php echo $item_id; ?>"> |
228 <?php _e( 'Description' ); ?><br /> |
233 <?php _e( 'Description' ); ?><br /> |
229 <textarea id="edit-menu-item-description-<?php echo $item_id; ?>" class="widefat edit-menu-item-description" rows="3" cols="20" name="menu-item-description[<?php echo $item_id; ?>]"><?php echo esc_html( $item->description ); // textarea_escaped ?></textarea> |
234 <textarea id="edit-menu-item-description-<?php echo $item_id; ?>" class="widefat edit-menu-item-description" rows="3" cols="20" name="menu-item-description[<?php echo $item_id; ?>]"><?php echo esc_html( $menu_item->description ); // textarea_escaped ?></textarea> |
230 <span class="description"><?php _e( 'The description will be displayed in the menu if the current theme supports it.' ); ?></span> |
235 <span class="description"><?php _e( 'The description will be displayed in the menu if the active theme supports it.' ); ?></span> |
231 </label> |
236 </label> |
232 </p> |
237 </p> |
233 |
238 |
234 <?php |
239 <?php |
235 /** |
240 /** |
236 * Fires just before the move buttons of a nav menu item in the menu editor. |
241 * Fires just before the move buttons of a nav menu item in the menu editor. |
237 * |
242 * |
238 * @since 5.4.0 |
243 * @since 5.4.0 |
239 * |
244 * |
240 * @param int $item_id Menu item ID. |
245 * @param string $item_id Menu item ID as a numeric string. |
241 * @param WP_Post $item Menu item data object. |
246 * @param WP_Post $menu_item Menu item data object. |
242 * @param int $depth Depth of menu item. Used for padding. |
247 * @param int $depth Depth of menu item. Used for padding. |
243 * @param stdClass $args An object of menu item arguments. |
248 * @param stdClass|null $args An object of menu item arguments. |
244 * @param int $id Nav menu ID. |
249 * @param int $current_object_id Nav menu ID. |
245 */ |
250 */ |
246 do_action( 'wp_nav_menu_item_custom_fields', $item_id, $item, $depth, $args, $id ); |
251 do_action( 'wp_nav_menu_item_custom_fields', $item_id, $menu_item, $depth, $args, $current_object_id ); |
247 ?> |
252 ?> |
248 |
253 |
249 <fieldset class="field-move hide-if-no-js description description-wide"> |
254 <fieldset class="field-move hide-if-no-js description description-wide"> |
250 <span class="field-move-visual-label" aria-hidden="true"><?php _e( 'Move' ); ?></span> |
255 <span class="field-move-visual-label" aria-hidden="true"><?php _e( 'Move' ); ?></span> |
251 <button type="button" class="button-link menus-move menus-move-up" data-dir="up"><?php _e( 'Up one' ); ?></button> |
256 <button type="button" class="button-link menus-move menus-move-up" data-dir="up"><?php _e( 'Up one' ); ?></button> |
301 ); |
306 ); |
302 ?> |
307 ?> |
303 </div> |
308 </div> |
304 |
309 |
305 <input class="menu-item-data-db-id" type="hidden" name="menu-item-db-id[<?php echo $item_id; ?>]" value="<?php echo $item_id; ?>" /> |
310 <input class="menu-item-data-db-id" type="hidden" name="menu-item-db-id[<?php echo $item_id; ?>]" value="<?php echo $item_id; ?>" /> |
306 <input class="menu-item-data-object-id" type="hidden" name="menu-item-object-id[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object_id ); ?>" /> |
311 <input class="menu-item-data-object-id" type="hidden" name="menu-item-object-id[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $menu_item->object_id ); ?>" /> |
307 <input class="menu-item-data-object" type="hidden" name="menu-item-object[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object ); ?>" /> |
312 <input class="menu-item-data-object" type="hidden" name="menu-item-object[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $menu_item->object ); ?>" /> |
308 <input class="menu-item-data-parent-id" type="hidden" name="menu-item-parent-id[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_item_parent ); ?>" /> |
313 <input class="menu-item-data-parent-id" type="hidden" name="menu-item-parent-id[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $menu_item->menu_item_parent ); ?>" /> |
309 <input class="menu-item-data-position" type="hidden" name="menu-item-position[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_order ); ?>" /> |
314 <input class="menu-item-data-position" type="hidden" name="menu-item-position[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $menu_item->menu_order ); ?>" /> |
310 <input class="menu-item-data-type" type="hidden" name="menu-item-type[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->type ); ?>" /> |
315 <input class="menu-item-data-type" type="hidden" name="menu-item-type[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $menu_item->type ); ?>" /> |
311 </div><!-- .menu-item-settings--> |
316 </div><!-- .menu-item-settings--> |
312 <ul class="menu-item-transport"></ul> |
317 <ul class="menu-item-transport"></ul> |
313 <?php |
318 <?php |
314 $output .= ob_get_clean(); |
319 $output .= ob_get_clean(); |
315 } |
320 } |