[ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Navigation Menu API: Walker_Nav_Menu_Edit class 4 * 5 * @package WordPress 6 * @subpackage Administration 7 * @since 4.4.0 8 */ 9 10 /** 11 * Create HTML list of nav menu input items. 12 * 13 * @since 3.0.0 14 * 15 * @see Walker_Nav_Menu 16 */ 17 class Walker_Nav_Menu_Edit extends Walker_Nav_Menu { 18 /** 19 * Starts the list before the elements are added. 20 * 21 * @see Walker_Nav_Menu::start_lvl() 22 * 23 * @since 3.0.0 24 * 25 * @param string $output Passed by reference. 26 * @param int $depth Depth of menu item. Used for padding. 27 * @param stdClass $args Not used. 28 */ 29 public function start_lvl( &$output, $depth = 0, $args = null ) {} 30 31 /** 32 * Ends the list of after the elements are added. 33 * 34 * @see Walker_Nav_Menu::end_lvl() 35 * 36 * @since 3.0.0 37 * 38 * @param string $output Passed by reference. 39 * @param int $depth Depth of menu item. Used for padding. 40 * @param stdClass $args Not used. 41 */ 42 public function end_lvl( &$output, $depth = 0, $args = null ) {} 43 44 /** 45 * Start the element output. 46 * 47 * @see Walker_Nav_Menu::start_el() 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. 51 * 52 * @global int $_wp_nav_menu_max_depth 53 * 54 * @param string $output Used to append additional content (passed by reference). 55 * @param WP_Post $data_object Menu item data object. 56 * @param int $depth Depth of menu item. Used for padding. 57 * @param stdClass $args Not used. 58 * @param int $current_object_id Optional. ID of the current menu item. Default 0. 59 */ 60 public function start_el( &$output, $data_object, $depth = 0, $args = null, $current_object_id = 0 ) { 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; 65 66 $_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth; 67 68 ob_start(); 69 $item_id = esc_attr( $menu_item->ID ); 70 $removed_args = array( 71 'action', 72 'customlink-tab', 73 'edit-menu-item', 74 'menu-item', 75 'page-tab', 76 '_wpnonce', 77 ); 78 79 $original_title = false; 80 81 if ( 'taxonomy' === $menu_item->type ) { 82 $original_object = get_term( (int) $menu_item->object_id, $menu_item->object ); 83 if ( $original_object && ! is_wp_error( $original_object ) ) { 84 $original_title = $original_object->name; 85 } 86 } elseif ( 'post_type' === $menu_item->type ) { 87 $original_object = get_post( $menu_item->object_id ); 88 if ( $original_object ) { 89 $original_title = get_the_title( $original_object->ID ); 90 } 91 } elseif ( 'post_type_archive' === $menu_item->type ) { 92 $original_object = get_post_type_object( $menu_item->object ); 93 if ( $original_object ) { 94 $original_title = $original_object->labels->archives; 95 } 96 } 97 98 $classes = array( 99 'menu-item menu-item-depth-' . $depth, 100 'menu-item-' . esc_attr( $menu_item->object ), 101 'menu-item-edit-' . ( ( isset( $_GET['edit-menu-item'] ) && $item_id === $_GET['edit-menu-item'] ) ? 'active' : 'inactive' ), 102 ); 103 104 $title = $menu_item->title; 105 106 if ( ! empty( $menu_item->_invalid ) ) { 107 $classes[] = 'menu-item-invalid'; 108 /* translators: %s: Title of an invalid menu item. */ 109 $title = sprintf( __( '%s (Invalid)' ), $menu_item->title ); 110 } elseif ( isset( $menu_item->post_status ) && 'draft' === $menu_item->post_status ) { 111 $classes[] = 'pending'; 112 /* translators: %s: Title of a menu item in draft status. */ 113 $title = sprintf( __( '%s (Pending)' ), $menu_item->title ); 114 } 115 116 $title = ( ! isset( $menu_item->label ) || '' === $menu_item->label ) ? $title : $menu_item->label; 117 118 $submenu_text = ''; 119 if ( 0 === $depth ) { 120 $submenu_text = 'style="display: none;"'; 121 } 122 123 ?> 124 <li id="menu-item-<?php echo $item_id; ?>" class="<?php echo implode( ' ', $classes ); ?>"> 125 <div class="menu-item-bar"> 126 <div class="menu-item-handle"> 127 <label class="item-title" for="menu-item-checkbox-<?php echo $item_id; ?>"> 128 <input id="menu-item-checkbox-<?php echo $item_id; ?>" type="checkbox" class="menu-item-checkbox" data-menu-item-id="<?php echo $item_id; ?>" disabled="disabled" /> 129 <span class="menu-item-title"><?php echo esc_html( $title ); ?></span> 130 <span class="is-submenu" <?php echo $submenu_text; ?>><?php _e( 'sub item' ); ?></span> 131 </label> 132 <span class="item-controls"> 133 <span class="item-type"><?php echo esc_html( $menu_item->type_label ); ?></span> 134 <span class="item-order hide-if-js"> 135 <?php 136 printf( 137 '<a href="%s" class="item-move-up" aria-label="%s">↑</a>', 138 wp_nonce_url( 139 add_query_arg( 140 array( 141 'action' => 'move-up-menu-item', 142 'menu-item' => $item_id, 143 ), 144 remove_query_arg( $removed_args, admin_url( 'nav-menus.php' ) ) 145 ), 146 'move-menu_item' 147 ), 148 esc_attr__( 'Move up' ) 149 ); 150 ?> 151 | 152 <?php 153 printf( 154 '<a href="%s" class="item-move-down" aria-label="%s">↓</a>', 155 wp_nonce_url( 156 add_query_arg( 157 array( 158 'action' => 'move-down-menu-item', 159 'menu-item' => $item_id, 160 ), 161 remove_query_arg( $removed_args, admin_url( 'nav-menus.php' ) ) 162 ), 163 'move-menu_item' 164 ), 165 esc_attr__( 'Move down' ) 166 ); 167 ?> 168 </span> 169 <?php 170 if ( isset( $_GET['edit-menu-item'] ) && $item_id === $_GET['edit-menu-item'] ) { 171 $edit_url = admin_url( 'nav-menus.php' ); 172 } else { 173 $edit_url = add_query_arg( 174 array( 175 'edit-menu-item' => $item_id, 176 ), 177 remove_query_arg( $removed_args, admin_url( 'nav-menus.php#menu-item-settings-' . $item_id ) ) 178 ); 179 } 180 181 printf( 182 '<a class="item-edit" id="edit-%s" href="%s" aria-label="%s"><span class="screen-reader-text">%s</span></a>', 183 $item_id, 184 esc_url( $edit_url ), 185 esc_attr__( 'Edit menu item' ), 186 /* translators: Hidden accessibility text. */ 187 __( 'Edit' ) 188 ); 189 ?> 190 </span> 191 </div> 192 </div> 193 194 <div class="menu-item-settings wp-clearfix" id="menu-item-settings-<?php echo $item_id; ?>"> 195 <?php if ( 'custom' === $menu_item->type ) : ?> 196 <p class="field-url description description-wide"> 197 <label for="edit-menu-item-url-<?php echo $item_id; ?>"> 198 <?php _e( 'URL' ); ?><br /> 199 <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 ); ?>" /> 200 </label> 201 </p> 202 <?php endif; ?> 203 <p class="description description-wide"> 204 <label for="edit-menu-item-title-<?php echo $item_id; ?>"> 205 <?php _e( 'Navigation Label' ); ?><br /> 206 <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 ); ?>" /> 207 </label> 208 </p> 209 <p class="field-title-attribute field-attr-title description description-wide"> 210 <label for="edit-menu-item-attr-title-<?php echo $item_id; ?>"> 211 <?php _e( 'Title Attribute' ); ?><br /> 212 <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 ); ?>" /> 213 </label> 214 </p> 215 <p class="field-link-target description"> 216 <label for="edit-menu-item-target-<?php echo $item_id; ?>"> 217 <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' ); ?> /> 218 <?php _e( 'Open link in a new tab' ); ?> 219 </label> 220 </p> 221 <div class="description-group"> 222 <p class="field-css-classes description description-thin"> 223 <label for="edit-menu-item-classes-<?php echo $item_id; ?>"> 224 <?php _e( 'CSS Classes (optional)' ); ?><br /> 225 <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 ) ); ?>" /> 226 </label> 227 </p> 228 <p class="field-xfn description description-thin"> 229 <label for="edit-menu-item-xfn-<?php echo $item_id; ?>"> 230 <?php _e( 'Link Relationship (XFN)' ); ?><br /> 231 <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 ); ?>" /> 232 </label> 233 </p> 234 </div> 235 <p class="field-description description description-wide"> 236 <label for="edit-menu-item-description-<?php echo $item_id; ?>"> 237 <?php _e( 'Description' ); ?><br /> 238 <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> 239 <span class="description"><?php _e( 'The description will be displayed in the menu if the active theme supports it.' ); ?></span> 240 </label> 241 </p> 242 243 <?php 244 /** 245 * Update parent and order of menu item using select inputs. 246 * 247 * @since 6.7.0 248 */ 249 ?> 250 251 <div class="field-move-combo description-group"> 252 <p class="description description-wide"> 253 <label for="edit-menu-item-parent-<?php echo $item_id; ?>"> 254 <?php _e( 'Menu Parent' ); ?> 255 </label> 256 <select class="edit-menu-item-parent widefat" id="edit-menu-item-parent-<?php echo $item_id; ?>" name="menu-item-parent[<?php echo $item_id; ?>]"> 257 </select> 258 </p> 259 <p class="description description-wide"> 260 <label for="edit-menu-item-order-<?php echo $item_id; ?>"> 261 <?php _e( 'Menu Order' ); ?> 262 </label> 263 <select class="edit-menu-item-order widefat" id="edit-menu-item-order-<?php echo $item_id; ?>" name="menu-item-order[<?php echo $item_id; ?>]"> 264 </select> 265 </p> 266 </div> 267 268 <?php 269 /** 270 * Fires just before the move buttons of a nav menu item in the menu editor. 271 * 272 * @since 5.4.0 273 * 274 * @param string $item_id Menu item ID as a numeric string. 275 * @param WP_Post $menu_item Menu item data object. 276 * @param int $depth Depth of menu item. Used for padding. 277 * @param stdClass|null $args An object of menu item arguments. 278 * @param int $current_object_id Nav menu ID. 279 */ 280 do_action( 'wp_nav_menu_item_custom_fields', $item_id, $menu_item, $depth, $args, $current_object_id ); 281 ?> 282 283 <fieldset class="field-move hide-if-no-js description description-wide"> 284 <span class="field-move-visual-label" aria-hidden="true"><?php _e( 'Move' ); ?></span> 285 <button type="button" class="button-link menus-move menus-move-up" data-dir="up"><?php _e( 'Up one' ); ?></button> 286 <button type="button" class="button-link menus-move menus-move-down" data-dir="down"><?php _e( 'Down one' ); ?></button> 287 <button type="button" class="button-link menus-move menus-move-left" data-dir="left"></button> 288 <button type="button" class="button-link menus-move menus-move-right" data-dir="right"></button> 289 <button type="button" class="button-link menus-move menus-move-top" data-dir="top"><?php _e( 'To the top' ); ?></button> 290 </fieldset> 291 292 <div class="menu-item-actions description-wide submitbox"> 293 <?php if ( 'custom' !== $menu_item->type && false !== $original_title ) : ?> 294 <p class="link-to-original"> 295 <?php 296 /* translators: %s: Link to menu item's original object. */ 297 printf( __( 'Original: %s' ), '<a href="' . esc_url( $menu_item->url ) . '">' . esc_html( $original_title ) . '</a>' ); 298 ?> 299 </p> 300 <?php endif; ?> 301 302 <?php 303 printf( 304 '<a class="item-delete submitdelete deletion" id="delete-%s" href="%s">%s</a>', 305 $item_id, 306 wp_nonce_url( 307 add_query_arg( 308 array( 309 'action' => 'delete-menu-item', 310 'menu-item' => $item_id, 311 ), 312 admin_url( 'nav-menus.php' ) 313 ), 314 'delete-menu_item_' . $item_id 315 ), 316 __( 'Remove' ) 317 ); 318 ?> 319 <span class="meta-sep hide-if-no-js"> | </span> 320 <?php 321 printf( 322 '<a class="item-cancel submitcancel hide-if-no-js" id="cancel-%s" href="%s#menu-item-settings-%s">%s</a>', 323 $item_id, 324 esc_url( 325 add_query_arg( 326 array( 327 'edit-menu-item' => $item_id, 328 'cancel' => time(), 329 ), 330 admin_url( 'nav-menus.php' ) 331 ) 332 ), 333 $item_id, 334 __( 'Cancel' ) 335 ); 336 ?> 337 </div> 338 339 <input class="menu-item-data-db-id" type="hidden" name="menu-item-db-id[<?php echo $item_id; ?>]" value="<?php echo $item_id; ?>" /> 340 <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 ); ?>" /> 341 <input class="menu-item-data-object" type="hidden" name="menu-item-object[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $menu_item->object ); ?>" /> 342 <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 ); ?>" /> 343 <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 ); ?>" /> 344 <input class="menu-item-data-type" type="hidden" name="menu-item-type[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $menu_item->type ); ?>" /> 345 </div><!-- .menu-item-settings--> 346 <ul class="menu-item-transport"></ul> 347 <?php 348 $output .= ob_get_clean(); 349 } 350 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated : Thu Nov 21 08:20:01 2024 | Cross-referenced by PHPXref |