Changeset 34168 for trunk/src/wp-admin/includes/nav-menu.php
- Timestamp:
- 09/15/2015 04:01:30 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/nav-menu.php
r33998 r34168 1 1 <?php 2 2 3 /** 4 * Create HTML list of nav menu input items. 5 * 6 * @package WordPress 7 * @since 3.0.0 8 * @uses Walker_Nav_Menu 9 */ 10 class Walker_Nav_Menu_Edit extends Walker_Nav_Menu { 11 /** 12 * Starts the list before the elements are added. 13 * 14 * @see Walker_Nav_Menu::start_lvl() 15 * 16 * @since 3.0.0 17 * 18 * @param string $output Passed by reference. 19 * @param int $depth Depth of menu item. Used for padding. 20 * @param array $args Not used. 21 */ 22 public function start_lvl( &$output, $depth = 0, $args = array() ) {} 23 24 /** 25 * Ends the list of after the elements are added. 26 * 27 * @see Walker_Nav_Menu::end_lvl() 28 * 29 * @since 3.0.0 30 * 31 * @param string $output Passed by reference. 32 * @param int $depth Depth of menu item. Used for padding. 33 * @param array $args Not used. 34 */ 35 public function end_lvl( &$output, $depth = 0, $args = array() ) {} 36 37 /** 38 * Start the element output. 39 * 40 * @see Walker_Nav_Menu::start_el() 41 * @since 3.0.0 42 * 43 * @global int $_wp_nav_menu_max_depth 44 * 45 * @param string $output Passed by reference. Used to append additional content. 46 * @param object $item Menu item data object. 47 * @param int $depth Depth of menu item. Used for padding. 48 * @param array $args Not used. 49 * @param int $id Not used. 50 */ 51 public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { 52 global $_wp_nav_menu_max_depth; 53 $_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth; 54 55 ob_start(); 56 $item_id = esc_attr( $item->ID ); 57 $removed_args = array( 58 'action', 59 'customlink-tab', 60 'edit-menu-item', 61 'menu-item', 62 'page-tab', 63 '_wpnonce', 64 ); 65 66 $original_title = ''; 67 if ( 'taxonomy' == $item->type ) { 68 $original_title = get_term_field( 'name', $item->object_id, $item->object, 'raw' ); 69 if ( is_wp_error( $original_title ) ) 70 $original_title = false; 71 } elseif ( 'post_type' == $item->type ) { 72 $original_object = get_post( $item->object_id ); 73 $original_title = get_the_title( $original_object->ID ); 74 } 75 76 $classes = array( 77 'menu-item menu-item-depth-' . $depth, 78 'menu-item-' . esc_attr( $item->object ), 79 'menu-item-edit-' . ( ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? 'active' : 'inactive'), 80 ); 81 82 $title = $item->title; 83 84 if ( ! empty( $item->_invalid ) ) { 85 $classes[] = 'menu-item-invalid'; 86 /* translators: %s: title of menu item which is invalid */ 87 $title = sprintf( __( '%s (Invalid)' ), $item->title ); 88 } elseif ( isset( $item->post_status ) && 'draft' == $item->post_status ) { 89 $classes[] = 'pending'; 90 /* translators: %s: title of menu item in draft status */ 91 $title = sprintf( __('%s (Pending)'), $item->title ); 92 } 93 94 $title = ( ! isset( $item->label ) || '' == $item->label ) ? $title : $item->label; 95 96 $submenu_text = ''; 97 if ( 0 == $depth ) 98 $submenu_text = 'style="display: none;"'; 99 100 ?> 101 <li id="menu-item-<?php echo $item_id; ?>" class="<?php echo implode(' ', $classes ); ?>"> 102 <div class="menu-item-bar"> 103 <div class="menu-item-handle"> 104 <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> 105 <span class="item-controls"> 106 <span class="item-type"><?php echo esc_html( $item->type_label ); ?></span> 107 <span class="item-order hide-if-js"> 108 <a href="<?php 109 echo wp_nonce_url( 110 add_query_arg( 111 array( 112 'action' => 'move-up-menu-item', 113 'menu-item' => $item_id, 114 ), 115 remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) ) 116 ), 117 'move-menu_item' 118 ); 119 ?>" class="item-move-up"><abbr title="<?php esc_attr_e('Move up'); ?>">↑</abbr></a> 120 | 121 <a href="<?php 122 echo wp_nonce_url( 123 add_query_arg( 124 array( 125 'action' => 'move-down-menu-item', 126 'menu-item' => $item_id, 127 ), 128 remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) ) 129 ), 130 'move-menu_item' 131 ); 132 ?>" class="item-move-down"><abbr title="<?php esc_attr_e('Move down'); ?>">↓</abbr></a> 133 </span> 134 <a class="item-edit" id="edit-<?php echo $item_id; ?>" title="<?php esc_attr_e('Edit Menu Item'); ?>" href="<?php 135 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 ) ) ); 136 ?>"><?php _e( 'Edit Menu Item' ); ?></a> 137 </span> 138 </div> 139 </div> 140 141 <div class="menu-item-settings" id="menu-item-settings-<?php echo $item_id; ?>"> 142 <?php if ( 'custom' == $item->type ) : ?> 143 <p class="field-url description description-wide"> 144 <label for="edit-menu-item-url-<?php echo $item_id; ?>"> 145 <?php _e( 'URL' ); ?><br /> 146 <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 ); ?>" /> 147 </label> 148 </p> 149 <?php endif; ?> 150 <p class="description description-wide"> 151 <label for="edit-menu-item-title-<?php echo $item_id; ?>"> 152 <?php _e( 'Navigation Label' ); ?><br /> 153 <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 ); ?>" /> 154 </label> 155 </p> 156 <p class="field-title-attribute description description-wide"> 157 <label for="edit-menu-item-attr-title-<?php echo $item_id; ?>"> 158 <?php _e( 'Title Attribute' ); ?><br /> 159 <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 ); ?>" /> 160 </label> 161 </p> 162 <p class="field-link-target description"> 163 <label for="edit-menu-item-target-<?php echo $item_id; ?>"> 164 <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' ); ?> /> 165 <?php _e( 'Open link in a new tab' ); ?> 166 </label> 167 </p> 168 <p class="field-css-classes description description-thin"> 169 <label for="edit-menu-item-classes-<?php echo $item_id; ?>"> 170 <?php _e( 'CSS Classes (optional)' ); ?><br /> 171 <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 ) ); ?>" /> 172 </label> 173 </p> 174 <p class="field-xfn description description-thin"> 175 <label for="edit-menu-item-xfn-<?php echo $item_id; ?>"> 176 <?php _e( 'Link Relationship (XFN)' ); ?><br /> 177 <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 ); ?>" /> 178 </label> 179 </p> 180 <p class="field-description description description-wide"> 181 <label for="edit-menu-item-description-<?php echo $item_id; ?>"> 182 <?php _e( 'Description' ); ?><br /> 183 <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> 184 <span class="description"><?php _e('The description will be displayed in the menu if the current theme supports it.'); ?></span> 185 </label> 186 </p> 187 188 <p class="field-move hide-if-no-js description description-wide"> 189 <label> 190 <span><?php _e( 'Move' ); ?></span> 191 <a href="#" class="menus-move menus-move-up" data-dir="up"><?php _e( 'Up one' ); ?></a> 192 <a href="#" class="menus-move menus-move-down" data-dir="down"><?php _e( 'Down one' ); ?></a> 193 <a href="#" class="menus-move menus-move-left" data-dir="left"></a> 194 <a href="#" class="menus-move menus-move-right" data-dir="right"></a> 195 <a href="#" class="menus-move menus-move-top" data-dir="top"><?php _e( 'To the top' ); ?></a> 196 </label> 197 </p> 198 199 <div class="menu-item-actions description-wide submitbox"> 200 <?php if ( 'custom' != $item->type && $original_title !== false ) : ?> 201 <p class="link-to-original"> 202 <?php printf( __('Original: %s'), '<a href="' . esc_attr( $item->url ) . '">' . esc_html( $original_title ) . '</a>' ); ?> 203 </p> 204 <?php endif; ?> 205 <a class="item-delete submitdelete deletion" id="delete-<?php echo $item_id; ?>" href="<?php 206 echo wp_nonce_url( 207 add_query_arg( 208 array( 209 'action' => 'delete-menu-item', 210 'menu-item' => $item_id, 211 ), 212 admin_url( 'nav-menus.php' ) 213 ), 214 'delete-menu_item_' . $item_id 215 ); ?>"><?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' ) ) ); 216 ?>#menu-item-settings-<?php echo $item_id; ?>"><?php _e('Cancel'); ?></a> 217 </div> 218 219 <input class="menu-item-data-db-id" type="hidden" name="menu-item-db-id[<?php echo $item_id; ?>]" value="<?php echo $item_id; ?>" /> 220 <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 ); ?>" /> 221 <input class="menu-item-data-object" type="hidden" name="menu-item-object[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object ); ?>" /> 222 <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 ); ?>" /> 223 <input class="menu-item-data-position" type="hidden" name="menu-item-position[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_order ); ?>" /> 224 <input class="menu-item-data-type" type="hidden" name="menu-item-type[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->type ); ?>" /> 225 </div><!-- .menu-item-settings--> 226 <ul class="menu-item-transport"></ul> 227 <?php 228 $output .= ob_get_clean(); 229 } 230 231 } // Walker_Nav_Menu_Edit 232 233 /** 234 * Create HTML list of nav menu input items. 235 * 236 * @since 3.0.0 237 * @uses Walker_Nav_Menu 238 */ 239 class Walker_Nav_Menu_Checklist extends Walker_Nav_Menu { 240 /** 241 * 242 * @param array $fields 243 */ 244 public function __construct( $fields = false ) { 245 if ( $fields ) { 246 $this->db_fields = $fields; 247 } 248 } 249 250 /** 251 * Starts the list before the elements are added. 252 * 253 * @see Walker_Nav_Menu::start_lvl() 254 * 255 * @since 3.0.0 256 * 257 * @param string $output Passed by reference. Used to append additional content. 258 * @param int $depth Depth of page. Used for padding. 259 * @param array $args Not used. 260 */ 261 public function start_lvl( &$output, $depth = 0, $args = array() ) { 262 $indent = str_repeat( "\t", $depth ); 263 $output .= "\n$indent<ul class='children'>\n"; 264 } 265 266 /** 267 * Ends the list of after the elements are added. 268 * 269 * @see Walker_Nav_Menu::end_lvl() 270 * 271 * @since 3.0.0 272 * 273 * @param string $output Passed by reference. Used to append additional content. 274 * @param int $depth Depth of page. Used for padding. 275 * @param array $args Not used. 276 */ 277 public function end_lvl( &$output, $depth = 0, $args = array() ) { 278 $indent = str_repeat( "\t", $depth ); 279 $output .= "\n$indent</ul>"; 280 } 281 282 /** 283 * Start the element output. 284 * 285 * @see Walker_Nav_Menu::start_el() 286 * 287 * @since 3.0.0 288 * 289 * @global int $_nav_menu_placeholder 290 * 291 * @param string $output Passed by reference. Used to append additional content. 292 * @param object $item Menu item data object. 293 * @param int $depth Depth of menu item. Used for padding. 294 * @param array $args Not used. 295 * @param int $id Not used. 296 */ 297 public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { 298 global $_nav_menu_placeholder; 299 300 $_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? intval($_nav_menu_placeholder) - 1 : -1; 301 $possible_object_id = isset( $item->post_type ) && 'nav_menu_item' == $item->post_type ? $item->object_id : $_nav_menu_placeholder; 302 $possible_db_id = ( ! empty( $item->ID ) ) && ( 0 < $possible_object_id ) ? (int) $item->ID : 0; 303 304 $indent = ( $depth ) ? str_repeat( "\t", $depth ) : ''; 305 306 $output .= $indent . '<li>'; 307 $output .= '<label class="menu-item-title">'; 308 $output .= '<input type="checkbox" class="menu-item-checkbox'; 309 310 if ( ! empty( $item->front_or_home ) ) 311 $output .= ' add-to-top'; 312 313 $output .= '" name="menu-item[' . $possible_object_id . '][menu-item-object-id]" value="'. esc_attr( $item->object_id ) .'" /> '; 314 315 if ( ! empty( $item->label ) ) { 316 $title = $item->label; 317 } elseif ( isset( $item->post_type ) ) { 318 /** This filter is documented in wp-includes/post-template.php */ 319 $title = apply_filters( 'the_title', $item->post_title, $item->ID ); 320 if ( ! empty( $item->front_or_home ) && _x( 'Home', 'nav menu home label' ) !== $title ) 321 $title = sprintf( _x( 'Home: %s', 'nav menu front page title' ), $title ); 322 } 323 324 $output .= isset( $title ) ? esc_html( $title ) : esc_html( $item->title ); 325 $output .= '</label>'; 326 327 // Menu item hidden fields 328 $output .= '<input type="hidden" class="menu-item-db-id" name="menu-item[' . $possible_object_id . '][menu-item-db-id]" value="' . $possible_db_id . '" />'; 329 $output .= '<input type="hidden" class="menu-item-object" name="menu-item[' . $possible_object_id . '][menu-item-object]" value="'. esc_attr( $item->object ) .'" />'; 330 $output .= '<input type="hidden" class="menu-item-parent-id" name="menu-item[' . $possible_object_id . '][menu-item-parent-id]" value="'. esc_attr( $item->menu_item_parent ) .'" />'; 331 $output .= '<input type="hidden" class="menu-item-type" name="menu-item[' . $possible_object_id . '][menu-item-type]" value="'. esc_attr( $item->type ) .'" />'; 332 $output .= '<input type="hidden" class="menu-item-title" name="menu-item[' . $possible_object_id . '][menu-item-title]" value="'. esc_attr( $item->title ) .'" />'; 333 $output .= '<input type="hidden" class="menu-item-url" name="menu-item[' . $possible_object_id . '][menu-item-url]" value="'. esc_attr( $item->url ) .'" />'; 334 $output .= '<input type="hidden" class="menu-item-target" name="menu-item[' . $possible_object_id . '][menu-item-target]" value="'. esc_attr( $item->target ) .'" />'; 335 $output .= '<input type="hidden" class="menu-item-attr_title" name="menu-item[' . $possible_object_id . '][menu-item-attr_title]" value="'. esc_attr( $item->attr_title ) .'" />'; 336 $output .= '<input type="hidden" class="menu-item-classes" name="menu-item[' . $possible_object_id . '][menu-item-classes]" value="'. esc_attr( implode( ' ', $item->classes ) ) .'" />'; 337 $output .= '<input type="hidden" class="menu-item-xfn" name="menu-item[' . $possible_object_id . '][menu-item-xfn]" value="'. esc_attr( $item->xfn ) .'" />'; 338 } 339 340 } // Walker_Nav_Menu_Checklist 3 /** Walker_Nav_Menu_Edit class */ 4 require_once( ABSPATH . 'wp-admin/includes/class-walker-nav-menu-edit.php' ); 5 6 /** Walker_Nav_Menu_Checklist class */ 7 require_once( ABSPATH . 'wp-admin/includes/class-walker-nav-menu-checklist.php' ); 341 8 342 9 /**
Note: See TracChangeset
for help on using the changeset viewer.