Changeset 23810 for trunk/wp-admin/nav-menus.php
- Timestamp:
- 03/27/2013 11:46:08 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/nav-menus.php
r23807 r23810 37 37 // The menu id of the current menu being edited 38 38 $nav_menu_selected_id = isset( $_REQUEST['menu'] ) ? (int) $_REQUEST['menu'] : 0; 39 40 // Get existing menu locations assignments 41 $locations = get_registered_nav_menus(); 42 $menu_locations = get_nav_menu_locations(); 43 $num_locations = count( array_keys( $locations ) ); 39 44 40 45 // Allowed actions: add, update, delete … … 262 267 case 'update': 263 268 check_admin_referer( 'update-nav_menu', 'update-nav-menu-nonce' ); 264 265 // Get existing menu locations assignments266 $locations = get_registered_nav_menus();267 $menu_locations = get_nav_menu_locations();268 269 269 270 // Remove menu locations that have been unchecked … … 308 309 set_theme_mod( 'nav_menu_locations', $locations ); 309 310 } 310 $messages[] = '<div id="message" class="updated"><p>' . sprintf( __( '<strong>%s</strong> has been created.' ), $nav_menu_selected_title ) . '</p></div>'; 311 if ( isset( $_REQUEST['use-location'] ) ) { 312 $locations = get_theme_mod( 'nav_menu_locations' ); 313 if ( isset( $locations[$_REQUEST['use-location']] ) ) 314 $locations[$_REQUEST['use-location']] = $nav_menu_selected_id; 315 set_theme_mod( 'nav_menu_locations', $locations ); 316 } 317 // $messages[] = '<div id="message" class="updated"><p>' . sprintf( __( '<strong>%s</strong> has been created.' ), $nav_menu_selected_title ) . '</p></div>'; 318 wp_redirect( admin_url( 'nav-menus.php?menu=' . $_nav_menu_selected_id ) ); 319 exit(); 311 320 } 312 321 } else { … … 342 351 } 343 352 break; 353 case 'locations': 354 add_filter( 'screen_options_show_screen', '__return_false' ); 355 356 if ( isset( $_POST['menu-locations'] ) ) { 357 check_admin_referer( 'save-menu-locations' ); 358 359 $new_menu_locations = array_map( 'absint', $_POST['menu-locations'] ); 360 $menu_locations = array_merge( $menu_locations, $new_menu_locations ); 361 // Set menu locations 362 set_theme_mod( 'nav_menu_locations', $menu_locations ); 363 364 $messages[] = '<div id="message" class="updated"><p>' . __( 'Menu locations updated.' ) . '</p></div>'; 365 } 366 break; 344 367 } 345 368 … … 350 373 // Are we on the add new screen? 351 374 $add_new_screen = ( isset( $_GET['menu'] ) && 0 == $_GET['menu'] ) ? true : false; 375 376 $locations_screen = ( isset( $_GET['action'] ) && 'locations' == $_GET['action'] ) ? true : false; 352 377 353 378 // If we have one theme location, and zero menus, we take them right into editing their first menu … … 475 500 <div class="wrap"> 476 501 <?php screen_icon(); ?> 477 <h2><?php _e( 'Menus' ); ?> <a href="<?php echo esc_url( add_query_arg( array( 'action' => 'edit', 'menu' => 0, ), admin_url( 'nav-menus.php' ) ) ); ?>" class="add-new-h2"><?php _ex( 'Add New', 'menu' ); ?></a></h2> 502 <h2 class="nav-tab-wrapper"> 503 <a href="<?php echo admin_url( 'nav-menus.php' ); ?>" class="nav-tab<?php if ( ! isset( $_GET['action'] ) || isset( $_GET['action'] ) && 'locations' != $_GET['action'] ) echo ' nav-tab-active'; ?>"><?php esc_html_e( 'Edit Menus' ); ?></a> 504 <a href="<?php echo esc_url( add_query_arg( array( 'action' => 'locations' ), admin_url( 'nav-menus.php' ) ) ); ?>" class="nav-tab<?php if ( $locations_screen ) echo ' nav-tab-active'; ?>"><?php esc_html_e( 'Manage Locations' ); ?></a> 505 </h2> 478 506 <?php 479 507 foreach( $messages as $message ) : … … 481 509 endforeach; 482 510 ?> 511 <?php 512 if ( $locations_screen ) : 513 echo '<p>' . sprintf( _n( 'Your theme supports %s menu. Select which menu you would like to use below.', 'Your theme supports %s menus. Select a menu to use for each theme location below.', $num_locations ), number_format_i18n( $num_locations ) ) . '</p>'; 514 ?> 515 <div id="menu-locations-wrap"> 516 <form method="post" action="<?php echo esc_url( add_query_arg( array( 'action' => 'locations' ), admin_url( 'nav-menus.php' ) ) ); ?>"> 517 <table class="widefat fixed" cellspacing="0" id="menu-locations-table"> 518 <thead> 519 <tr> 520 <th scope="col" class="manage-column column-locations"><?php _e( 'Theme Location' ); ?></th> 521 <th scope="col" class="manage-column column-menus"><?php _e( 'Assigned Menu' ); ?></th> 522 </tr> 523 </thead> 524 <!--<tfoot> 525 <tr> 526 <th scope="col" class="manage-column column-locations"><?php _e( 'Theme Location' ); ?></th> 527 <th scope="col" class="manage-column column-menus"><?php _e( 'Assigned Menu' ); ?></th> 528 </tr> 529 </tfoot>--> 530 <tbody class="menu-locations"> 531 <?php foreach ( $locations as $_location => $_name ) { ?> 532 <tr id="menu-locations-row"> 533 <td class="menu-location-title"><strong><?php echo $_name; ?></strong></td> 534 <td class="menu-location-menus"> 535 <select name="menu-locations[<?php echo $_location; ?>]" id="locations-<?php echo $_location; ?>"> 536 <option value="0"><?php printf( '— %s —', esc_html__( 'Select a Menu' ) ); ?></option> 537 <?php foreach ( $nav_menus as $menu ) : ?> 538 <?php $selected = isset( $menu_locations[$_location] ) && $menu_locations[$_location] == $menu->term_id; ?> 539 <option <?php if ( $selected ) echo 'data-orig="true"'; ?> <?php selected( $selected ); ?> value="<?php echo $menu->term_id; ?>"> 540 <?php $truncated_name = wp_html_excerpt( $menu->name, 40 ); 541 echo $truncated_name == $menu->name ? $menu->name : trim( $truncated_name ) . '…'; ?> 542 </option> 543 <?php endforeach; ?> 544 </select> 545 <div class="locations-row-links"> 546 <?php if ( isset( $menu_locations[ $_location ] ) && 0 != $menu_locations[ $_location ] ) : ?> 547 <span class="locations-edit-menu-link"> 548 <a href="<?php echo esc_url( add_query_arg( array( 'action' => 'edit', 'menu' => $menu_locations[$_location] ), admin_url( 'nav-menus.php' ) ) ); ?>"> 549 <?php _ex( 'Edit', 'menu' ); ?> 550 </a> 551 </span> 552 <?php endif; ?> 553 <span class="locations-add-menu-link"> 554 <a href="<?php echo esc_url( add_query_arg( array( 'action' => 'edit', 'menu' => 0, 'use-location' => $_location ), admin_url( 'nav-menus.php' ) ) ); ?>"> 555 <?php _ex( 'Use new menu', 'menu' ); ?> 556 </a> 557 </span> 558 </div><!-- #locations-row-links --> 559 </td><!-- .menu-location-menus --> 560 </tr><!-- #menu-locations-row --> 561 <?php } // foreach ?> 562 </tbody> 563 </table> 564 <p class="button-controls"><?php submit_button( __( 'Save Changes' ), 'primary left', 'nav-menu-locations', false ); ?></p> 565 <?php wp_nonce_field( 'save-menu-locations' ); ?> 566 <input type="hidden" name="menu" id="nav-menu-meta-object-id" value="<?php echo esc_attr( $nav_menu_selected_id ); ?>" /> 567 </form> 568 </div><!-- #menu-locations-wrap --> 569 <?php do_action( 'after_menu_locations_table' ); ?> 570 <?php else : ?> 483 571 <div class="manage-menus"> 484 <?php if ( $menu_count < 2 ) : ?>572 <?php if ( $menu_count < 2 ) : ?> 485 573 <span class="add-edit-menu-action"> 486 574 <?php printf( __( 'Edit your menu below, or <a href="%s">create a new menu</a>.' ), esc_url( add_query_arg( array( 'action' => 'edit', 'menu' => 0 ), admin_url( 'nav-menus.php' ) ) ) ); ?> 487 575 </span><!-- /add-edit-menu-action --> 488 <?php else : ?>489 <form method="get" action="">576 <?php else : ?> 577 <form method="get" action="<?php echo admin_url( 'nav-menus.php' ); ?>"> 490 578 <input type="hidden" name="action" value="edit" /> 491 579 <label for="menu" class="selected-menu"><?php _e( 'Select a menu to edit:' ); ?></label> … … 579 667 <?php if ( $add_new_screen ) : ?> 580 668 <p class="post-body-plain"><?php _e( 'Give your menu a name above, then click Create Menu.' ); ?></p> 669 <?php if ( isset( $_GET['use-location'] ) ) : ?> 670 <input type="hidden" name="use-location" value="<?php echo esc_attr( $_GET['use-location'] ); ?>" /> 671 <?php endif; ?> 581 672 <?php endif; ?> 582 673 <div class="menu-settings" <?php if ( $one_theme_location_no_menus ) { ?>style="display: none;"<?php } ?>> … … 634 725 </div><!-- /#menu-management-liquid --> 635 726 </div><!-- /#nav-menus-frame --> 727 <?php endif; ?> 636 728 </div><!-- /.wrap--> 637 729 <?php include( './admin-footer.php' ); ?>
Note: See TracChangeset
for help on using the changeset viewer.