Walker_Nav_Menu_Edit

Create HTML list of nav menu input items.

Defined (1)

The class is defined in the following location(s).

/wp-admin/includes/class-walker-nav-menu-edit.php  
  1. class Walker_Nav_Menu_Edit extends Walker_Nav_Menu { 
  2. /** 
  3. * Starts the list before the elements are added. 
  4. * @see Walker_Nav_Menu::start_lvl() 
  5. * @since 3.0.0 
  6. * @param string $output Passed by reference. 
  7. * @param int $depth Depth of menu item. Used for padding. 
  8. * @param array $args Not used. 
  9. */ 
  10. public function start_lvl( &$output, $depth = 0, $args = array() ) {} 
  11.  
  12. /** 
  13. * Ends the list of after the elements are added. 
  14. * @see Walker_Nav_Menu::end_lvl() 
  15. * @since 3.0.0 
  16. * @param string $output Passed by reference. 
  17. * @param int $depth Depth of menu item. Used for padding. 
  18. * @param array $args Not used. 
  19. */ 
  20. public function end_lvl( &$output, $depth = 0, $args = array() ) {} 
  21.  
  22. /** 
  23. * Start the element output. 
  24. * @see Walker_Nav_Menu::start_el() 
  25. * @since 3.0.0 
  26. * @global int $_wp_nav_menu_max_depth 
  27. * @param string $output Passed by reference. Used to append additional content. 
  28. * @param object $item Menu item data object. 
  29. * @param int $depth Depth of menu item. Used for padding. 
  30. * @param array $args Not used. 
  31. * @param int $id Not used. 
  32. */ 
  33. public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { 
  34. global $_wp_nav_menu_max_depth; 
  35. $_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth; 
  36.  
  37. ob_start(); 
  38. $item_id = esc_attr( $item->ID ); 
  39. $removed_args = array( 
  40. 'action',  
  41. 'customlink-tab',  
  42. 'edit-menu-item',  
  43. 'menu-item',  
  44. 'page-tab',  
  45. '_wpnonce',  
  46. ); 
  47.  
  48. $original_title = false; 
  49. if ( 'taxonomy' == $item->type ) { 
  50. $original_title = get_term_field( 'name', $item->object_id, $item->object, 'raw' ); 
  51. if ( is_wp_error( $original_title ) ) 
  52. $original_title = false; 
  53. } elseif ( 'post_type' == $item->type ) { 
  54. $original_object = get_post( $item->object_id ); 
  55. $original_title = get_the_title( $original_object->ID ); 
  56. } elseif ( 'post_type_archive' == $item->type ) { 
  57. $original_object = get_post_type_object( $item->object ); 
  58. if ( $original_object ) { 
  59. $original_title = $original_object->labels->archives; 
  60.  
  61. $classes = array( 
  62. 'menu-item menu-item-depth-' . $depth,  
  63. 'menu-item-' . esc_attr( $item->object ),  
  64. 'menu-item-edit-' . ( ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? 'active' : 'inactive'),  
  65. ); 
  66.  
  67. $title = $item->title; 
  68.  
  69. if ( ! empty( $item->_invalid ) ) { 
  70. $classes[] = 'menu-item-invalid'; 
  71. /** translators: %s: title of menu item which is invalid */ 
  72. $title = sprintf( __( '%s (Invalid)' ), $item->title ); 
  73. } elseif ( isset( $item->post_status ) && 'draft' == $item->post_status ) { 
  74. $classes[] = 'pending'; 
  75. /** translators: %s: title of menu item in draft status */ 
  76. $title = sprintf( __('%s (Pending)'), $item->title ); 
  77.  
  78. $title = ( ! isset( $item->label ) || '' == $item->label ) ? $title : $item->label; 
  79.  
  80. $submenu_text = ''; 
  81. if ( 0 == $depth ) 
  82. $submenu_text = 'style="display: none;"'; 
  83.  
  84. ?> 
  85. <li id="menu-item-<?php echo $item_id; ?>" class="<?php echo implode(' ', $classes ); ?>"> 
  86. <div class="menu-item-bar"> 
  87. <div class="menu-item-handle"> 
  88. <span class="item-title"><span class="menu-item-title"><?php echo esc_html( $title ); ?></span> <span class="is-submenu" <?php echo $submenu_text; ?>><?php _e( 'sub item' ); ?></span></span> 
  89. <span class="item-controls"> 
  90. <span class="item-type"><?php echo esc_html( $item->type_label ); ?></span> 
  91. <span class="item-order hide-if-js"> 
  92. <a href="<?php 
  93. echo wp_nonce_url( 
  94. add_query_arg( 
  95. array( 
  96. 'action' => 'move-up-menu-item',  
  97. 'menu-item' => $item_id,  
  98. ),  
  99. remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) ) 
  100. ),  
  101. 'move-menu_item' 
  102. ); 
  103. ?>" class="item-move-up" aria-label="<?php esc_attr_e( 'Move up' ) ?>">↑</a> 
  104. <a href="<?php 
  105. echo wp_nonce_url( 
  106. add_query_arg( 
  107. array( 
  108. 'action' => 'move-down-menu-item',  
  109. 'menu-item' => $item_id,  
  110. ),  
  111. remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) ) 
  112. ),  
  113. 'move-menu_item' 
  114. ); 
  115. ?>" class="item-move-down" aria-label="<?php esc_attr_e( 'Move down' ) ?>">↓</a> 
  116. </span> 
  117. <a class="item-edit" id="edit-<?php echo $item_id; ?>" href="<?php 
  118. echo ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? admin_url( 'nav-menus.php' ) : add_query_arg( 'edit-menu-item', $item_id, remove_query_arg( $removed_args, admin_url( 'nav-menus.php#menu-item-settings-' . $item_id ) ) ); 
  119. ?>" aria-label="<?php esc_attr_e( 'Edit menu item' ); ?>"><?php _e( 'Edit' ); ?></a> 
  120. </span> 
  121. </div> 
  122. </div> 
  123.  
  124. <div class="menu-item-settings wp-clearfix" id="menu-item-settings-<?php echo $item_id; ?>"> 
  125. <?php if ( 'custom' == $item->type ) : ?> 
  126. <p class="field-url description description-wide"> 
  127. <label for="edit-menu-item-url-<?php echo $item_id; ?>"> 
  128. <?php _e( 'URL' ); ?><br /> 
  129. <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 ); ?>" /> 
  130. </label> 
  131. </p> 
  132. <?php endif; ?> 
  133. <p class="description description-wide"> 
  134. <label for="edit-menu-item-title-<?php echo $item_id; ?>"> 
  135. <?php _e( 'Navigation Label' ); ?><br /> 
  136. <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 ); ?>" /> 
  137. </label> 
  138. </p> 
  139. <p class="field-title-attribute field-attr-title description description-wide"> 
  140. <label for="edit-menu-item-attr-title-<?php echo $item_id; ?>"> 
  141. <?php _e( 'Title Attribute' ); ?><br /> 
  142. <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 ); ?>" /> 
  143. </label> 
  144. </p> 
  145. <p class="field-link-target description"> 
  146. <label for="edit-menu-item-target-<?php echo $item_id; ?>"> 
  147. <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' ); ?> /> 
  148. <?php _e( 'Open link in a new tab' ); ?> 
  149. </label> 
  150. </p> 
  151. <p class="field-css-classes description description-thin"> 
  152. <label for="edit-menu-item-classes-<?php echo $item_id; ?>"> 
  153. <?php _e( 'CSS Classes (optional)' ); ?><br /> 
  154. <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 ) ); ?>" /> 
  155. </label> 
  156. </p> 
  157. <p class="field-xfn description description-thin"> 
  158. <label for="edit-menu-item-xfn-<?php echo $item_id; ?>"> 
  159. <?php _e( 'Link Relationship (XFN)' ); ?><br /> 
  160. <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 ); ?>" /> 
  161. </label> 
  162. </p> 
  163. <p class="field-description description description-wide"> 
  164. <label for="edit-menu-item-description-<?php echo $item_id; ?>"> 
  165. <?php _e( 'Description' ); ?><br /> 
  166. <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> 
  167. <span class="description"><?php _e('The description will be displayed in the menu if the current theme supports it.'); ?></span> 
  168. </label> 
  169. </p> 
  170.  
  171. <p class="field-move hide-if-no-js description description-wide"> 
  172. <label> 
  173. <span><?php _e( 'Move' ); ?></span> 
  174. <a href="#" class="menus-move menus-move-up" data-dir="up"><?php _e( 'Up one' ); ?></a> 
  175. <a href="#" class="menus-move menus-move-down" data-dir="down"><?php _e( 'Down one' ); ?></a> 
  176. <a href="#" class="menus-move menus-move-left" data-dir="left"></a> 
  177. <a href="#" class="menus-move menus-move-right" data-dir="right"></a> 
  178. <a href="#" class="menus-move menus-move-top" data-dir="top"><?php _e( 'To the top' ); ?></a> 
  179. </label> 
  180. </p> 
  181.  
  182. <div class="menu-item-actions description-wide submitbox"> 
  183. <?php if ( 'custom' != $item->type && $original_title !== false ) : ?> 
  184. <p class="link-to-original"> 
  185. <?php printf( __('Original: %s'), '<a href="' . esc_attr( $item->url ) . '">' . esc_html( $original_title ) . '</a>' ); ?> 
  186. </p> 
  187. <?php endif; ?> 
  188. <a class="item-delete submitdelete deletion" id="delete-<?php echo $item_id; ?>" href="<?php 
  189. echo wp_nonce_url( 
  190. add_query_arg( 
  191. array( 
  192. 'action' => 'delete-menu-item',  
  193. 'menu-item' => $item_id,  
  194. ),  
  195. admin_url( 'nav-menus.php' ) 
  196. ),  
  197. 'delete-menu_item_' . $item_id 
  198. ); ?>"><?php _e( 'Remove' ); ?></a> <span class="meta-sep hide-if-no-js"> | </span> <a class="item-cancel submitcancel hide-if-no-js" id="cancel-<?php echo $item_id; ?>" href="<?php echo esc_url( add_query_arg( array( 'edit-menu-item' => $item_id, 'cancel' => time() ), admin_url( 'nav-menus.php' ) ) ); 
  199. ?>#menu-item-settings-<?php echo $item_id; ?>"><?php _e('Cancel'); ?></a> 
  200. </div> 
  201.  
  202. <input class="menu-item-data-db-id" type="hidden" name="menu-item-db-id[<?php echo $item_id; ?>]" value="<?php echo $item_id; ?>" /> 
  203. <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 ); ?>" /> 
  204. <input class="menu-item-data-object" type="hidden" name="menu-item-object[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object ); ?>" /> 
  205. <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 ); ?>" /> 
  206. <input class="menu-item-data-position" type="hidden" name="menu-item-position[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_order ); ?>" /> 
  207. <input class="menu-item-data-type" type="hidden" name="menu-item-type[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->type ); ?>" /> 
  208. </div><!-- .menu-item-settings--> 
  209. <ul class="menu-item-transport"></ul> 
  210. <?php 
  211. $output .= ob_get_clean(); 
  212.  
  213. } // Walker_Nav_Menu_Edit