Changeset 29206 for trunk/src/wp-admin/nav-menus.php
- Timestamp:
- 07/17/2014 09:13:53 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/nav-menus.php
r28205 r29206 54 54 break; 55 55 case 'move-down-menu-item' : 56 // moving down a menu item is the same as moving up the next in order 56 57 // Moving down a menu item is the same as moving up the next in order. 57 58 check_admin_referer( 'move-menu_item' ); 58 59 $menu_item_id = isset( $_REQUEST['menu-item'] ) ? (int) $_REQUEST['menu-item'] : 0; … … 64 65 $menu_item_data = (array) wp_setup_nav_menu_item( get_post( $menu_item_id ) ); 65 66 66 // set up the data we need in one pass through the array of menu items67 // Set up the data we need in one pass through the array of menu items. 67 68 $dbids_to_orders = array(); 68 69 $orders_to_dbids = array(); … … 76 77 } 77 78 78 // get next in order79 // Get next in order. 79 80 if ( 80 81 isset( $orders_to_dbids[$dbids_to_orders[$menu_item_id] + 1] ) … … 83 84 $next_item_data = (array) wp_setup_nav_menu_item( get_post( $next_item_id ) ); 84 85 85 // if not siblings of same parent, bubble menu item up but keep order86 // If not siblings of same parent, bubble menu item up but keep order. 86 87 if ( 87 88 ! empty( $menu_item_data['menu_item_parent'] ) && … … 103 104 } 104 105 105 // make menu item a child of its next sibling106 // Make menu item a child of its next sibling. 106 107 } else { 107 108 $next_item_data['menu_order'] = $next_item_data['menu_order'] - 1; … … 115 116 } 116 117 117 // the item is last but still has a parent, so bubble up118 // The item is last but still has a parent, so bubble up. 118 119 } elseif ( 119 120 ! empty( $menu_item_data['menu_item_parent'] ) && … … 137 138 $menu_item_data = (array) wp_setup_nav_menu_item( get_post( $menu_item_id ) ); 138 139 139 // set up the data we need in one pass through the array of menu items140 // Set up the data we need in one pass through the array of menu items. 140 141 $dbids_to_orders = array(); 141 142 $orders_to_dbids = array(); … … 149 150 } 150 151 151 // if this menu item is not first152 // If this menu item is not first. 152 153 if ( ! empty( $dbids_to_orders[$menu_item_id] ) && ! empty( $orders_to_dbids[$dbids_to_orders[$menu_item_id] - 1] ) ) { 153 154 154 // if this menu item is a child of the previous155 // If this menu item is a child of the previous. 155 156 if ( 156 157 ! empty( $menu_item_data['menu_item_parent'] ) && … … 165 166 $parent_data = (array) $parent_object; 166 167 167 // if there is something before the parent and parent a child of it, make menu item a child also of it 168 /* 169 * If there is something before the parent and parent a child of it, 170 * make menu item a child also of it. 171 */ 168 172 if ( 169 173 ! empty( $dbids_to_orders[$parent_db_id] ) && … … 173 177 $menu_item_data['menu_item_parent'] = $parent_data['menu_item_parent']; 174 178 175 // else if there is something before parent and parent not a child of it, make menu item a child of that something's parent 179 /* 180 * Else if there is something before parent and parent not a child of it, 181 * make menu item a child of that something's parent 182 */ 176 183 } elseif ( 177 184 ! empty( $dbids_to_orders[$parent_db_id] ) && … … 184 191 $menu_item_data['menu_item_parent'] = 0; 185 192 186 // else there isn't something before the parent193 // Else there isn't something before the parent. 187 194 } else { 188 195 $menu_item_data['menu_item_parent'] = 0; 189 196 } 190 197 191 // set former parent's [menu_order] to that of menu-item's198 // Set former parent's [menu_order] to that of menu-item's. 192 199 $parent_data['menu_order'] = $parent_data['menu_order'] + 1; 193 200 194 // set menu-item's [menu_order] to that of former parent201 // Set menu-item's [menu_order] to that of former parent. 195 202 $menu_item_data['menu_order'] = $menu_item_data['menu_order'] - 1; 196 203 197 // save changes204 // Save changes. 198 205 update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] ); 199 206 wp_update_post($menu_item_data); … … 201 208 } 202 209 203 // else this menu item is not a child of the previous210 // Else this menu item is not a child of the previous. 204 211 } elseif ( 205 212 empty( $menu_item_data['menu_order'] ) || … … 209 216 $orders_to_dbids[$dbids_to_orders[$menu_item_id] - 1] != $menu_item_data['menu_item_parent'] 210 217 ) { 211 // just make it a child of the previous; keep the order218 // Just make it a child of the previous; keep the order. 212 219 $menu_item_data['menu_item_parent'] = (int) $orders_to_dbids[$dbids_to_orders[$menu_item_id] - 1]; 213 220 update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] ); … … 233 240 $deletion = wp_delete_nav_menu( $nav_menu_selected_id ); 234 241 } else { 235 // Reset the selected menu 242 // Reset the selected menu. 236 243 $nav_menu_selected_id = 0; 237 244 unset( $_REQUEST['menu'] ); … … 267 274 check_admin_referer( 'update-nav_menu', 'update-nav-menu-nonce' ); 268 275 269 // Remove menu locations that have been unchecked 276 // Remove menu locations that have been unchecked. 270 277 foreach ( $locations as $location => $description ) { 271 278 if ( ( empty( $_POST['menu-locations'] ) || empty( $_POST['menu-locations'][ $location ] ) ) && isset( $menu_locations[ $location ] ) && $menu_locations[ $location ] == $nav_menu_selected_id ) … … 273 280 } 274 281 275 // Merge new and existing menu locations if any new ones are set 282 // Merge new and existing menu locations if any new ones are set. 276 283 if ( isset( $_POST['menu-locations'] ) ) { 277 284 $new_menu_locations = array_map( 'absint', $_POST['menu-locations'] ); … … 279 286 } 280 287 281 // Set menu locations 288 // Set menu locations. 282 289 set_theme_mod( 'nav_menu_locations', $menu_locations ); 283 290 284 // Add Menu 291 // Add Menu. 285 292 if ( 0 == $nav_menu_selected_id ) { 286 293 $new_menu_title = trim( esc_html( $_POST['menu-name'] ) ); … … 315 322 set_theme_mod( 'nav_menu_locations', $menu_locations ); 316 323 } 324 317 325 // $messages[] = '<div id="message" class="updated"><p>' . sprintf( __( '<strong>%s</strong> has been created.' ), $nav_menu_selected_title ) . '</p></div>'; 318 326 wp_redirect( admin_url( 'nav-menus.php?menu=' . $_nav_menu_selected_id ) ); … … 323 331 } 324 332 325 // Update existing menu 333 // Update existing menu. 326 334 } else { 327 335 … … 345 353 } 346 354 347 // Update menu items 355 // Update menu items. 348 356 if ( ! is_wp_error( $_menu_object ) ) { 349 357 $messages = array_merge( $messages, wp_nav_menu_update_menu_items( $nav_menu_selected_id, $nav_menu_selected_title ) ); … … 372 380 } 373 381 374 // Get all nav menus 382 // Get all nav menus. 375 383 $nav_menus = wp_get_nav_menus( array('orderby' => 'name') ); 376 384 $menu_count = count( $nav_menus ); … … 381 389 $locations_screen = ( isset( $_GET['action'] ) && 'locations' == $_GET['action'] ) ? true : false; 382 390 383 // If we have one theme location, and zero menus, we take them right into editing their first menu 391 /* 392 * If we have one theme location, and zero menus, we take them right 393 * into editing their first menu. 394 */ 384 395 $page_count = wp_count_posts( 'page' ); 385 396 $one_theme_location_no_menus = ( 1 == count( get_registered_nav_menus() ) && ! $add_new_screen && empty( $nav_menus ) && ! empty( $page_count->publish ) ) ? true : false; … … 405 416 wp_localize_script( 'nav-menu', 'menus', $nav_menus_l10n ); 406 417 407 // Redirect to add screen if there are no menus and this users has either zero, or more than 1 theme locations 418 /* 419 * Redirect to add screen if there are no menus and this users has either zero, 420 * or more than 1 theme locations. 421 */ 408 422 if ( 0 == $menu_count && ! $add_new_screen && ! $one_theme_location_no_menus ) 409 423 wp_redirect( admin_url( 'nav-menus.php?action=edit&menu=0' ) ); 410 424 411 // Get recently edited nav menu 425 // Get recently edited nav menu. 412 426 $recently_edited = absint( get_user_option( 'nav_menu_recently_edited' ) ); 413 427 if ( empty( $recently_edited ) && is_nav_menu( $nav_menu_selected_id ) ) 414 428 $recently_edited = $nav_menu_selected_id; 415 429 416 // Use $recently_edited if none are selected 430 // Use $recently_edited if none are selected. 417 431 if ( empty( $nav_menu_selected_id ) && ! isset( $_GET['menu'] ) && is_nav_menu( $recently_edited ) ) 418 432 $nav_menu_selected_id = $recently_edited; 419 433 420 // On deletion of menu, if another menu exists, show it 434 // On deletion of menu, if another menu exists, show it. 421 435 if ( ! $add_new_screen && 0 < $menu_count && isset( $_GET['action'] ) && 'delete' == $_GET['action'] ) 422 436 $nav_menu_selected_id = $nav_menus[0]->term_id; 423 437 424 // Set $nav_menu_selected_id to 0 if no menus 438 // Set $nav_menu_selected_id to 0 if no menus. 425 439 if ( $one_theme_location_no_menus ) { 426 440 $nav_menu_selected_id = 0; 427 441 } elseif ( empty( $nav_menu_selected_id ) && ! empty( $nav_menus ) && ! $add_new_screen ) { 428 // if we have no selection yet, and we have menus, set to the first one in the list 442 // if we have no selection yet, and we have menus, set to the first one in the list. 429 443 $nav_menu_selected_id = $nav_menus[0]->term_id; 430 444 } 431 445 432 // Update the user's setting 446 // Update the user's setting. 433 447 if ( $nav_menu_selected_id != $recently_edited && is_nav_menu( $nav_menu_selected_id ) ) 434 448 update_user_meta( $current_user->ID, 'nav_menu_recently_edited', $nav_menu_selected_id ); … … 440 454 } 441 455 442 // Generate truncated menu names 456 // Generate truncated menu names. 443 457 foreach( (array) $nav_menus as $key => $_nav_menu ) { 444 458 $nav_menus[$key]->truncated_name = wp_html_excerpt( $_nav_menu->name, 40, '…' ); 445 459 } 446 460 447 // Retrieve menu locations 461 // Retrieve menu locations. 448 462 if ( current_theme_supports( 'menus' ) ) { 449 463 $locations = get_registered_nav_menus(); … … 451 465 } 452 466 453 // Ensure the user will be able to scroll horizontally 454 // by adding a class for the max menu depth. 467 /* 468 * Ensure the user will be able to scroll horizontally 469 * by adding a class for the max menu depth. 470 */ 455 471 global $_wp_nav_menu_max_depth; 456 472 $_wp_nav_menu_max_depth = 0; 457 473 458 // Calling wp_get_nav_menu_to_edit generates $_wp_nav_menu_max_depth 474 // Calling wp_get_nav_menu_to_edit generates $_wp_nav_menu_max_depth. 459 475 if ( is_nav_menu( $nav_menu_selected_id ) ) { 460 476 $menu_items = wp_get_nav_menu_items( $nav_menu_selected_id, array( 'post_status' => 'any' ) ); … … 511 527 'content' => $editing_menus 512 528 ) ); 513 else : // Locations Tab 529 else : // Locations Tab. 514 530 $locations_overview = '<p>' . __( 'This screen is used for globally assigning menus to locations defined by your theme.' ) . '</p>'; 515 531 $locations_overview .= '<ul><li>' . __( 'To assign menus to one or more theme locations, <strong>select a menu from each location’s drop down.</strong> When you’re finished, <strong>click Save Changes</strong>' ) . '</li>'; … … 530 546 ); 531 547 532 // Get the admin header 548 // Get the admin header. 533 549 require_once( ABSPATH . 'wp-admin/admin-header.php' ); 534 550 ?> … … 645 661 $assigned_locations = array_slice( $locations_assigned_to_this_menu, 0, absint( apply_filters( 'wp_nav_locations_listed_per_menu', 3 ) ) ); 646 662 647 // Adds ellipses following the number of locations defined in $assigned_locations 663 // Adds ellipses following the number of locations defined in $assigned_locations. 648 664 if ( ! empty( $assigned_locations ) ) { 649 665 printf( ' (%1$s%2$s)',
Note: See TracChangeset
for help on using the changeset viewer.