AI_Walker_Nav_Menu_Edit_Custom

/! This is a copy of Walker_Nav_Menu_Edit class in core.

Defined (1)

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

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