[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-admin/ -> nav-menus.php (source)

   1  <?php
   2  /**
   3   * WordPress Administration for Navigation Menus
   4   * Interface functions
   5   *
   6   * @version 2.0.0
   7   *
   8   * @package WordPress
   9   * @subpackage Administration
  10   */
  11  
  12  /** Load WordPress Administration Bootstrap */
  13  require_once  __DIR__ . '/admin.php';
  14  
  15  // Load all the nav menu interface functions.
  16  require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
  17  
  18  if ( ! current_theme_supports( 'menus' ) && ! current_theme_supports( 'widgets' ) ) {
  19      wp_die( __( 'Your theme does not support navigation menus or widgets.' ) );
  20  }
  21  
  22  // Permissions check.
  23  if ( ! current_user_can( 'edit_theme_options' ) ) {
  24      wp_die(
  25          '<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
  26          '<p>' . __( 'Sorry, you are not allowed to edit theme options on this site.' ) . '</p>',
  27          403
  28      );
  29  }
  30  
  31  wp_enqueue_script( 'nav-menu' );
  32  
  33  if ( wp_is_mobile() ) {
  34      wp_enqueue_script( 'jquery-touch-punch' );
  35  }
  36  
  37  // Container for any messages displayed to the user.
  38  $messages = array();
  39  
  40  // Container that stores the name of the active menu.
  41  $nav_menu_selected_title = '';
  42  
  43  // The menu id of the current menu being edited.
  44  $nav_menu_selected_id = isset( $_REQUEST['menu'] ) ? (int) $_REQUEST['menu'] : 0;
  45  
  46  // Get existing menu locations assignments.
  47  $locations      = get_registered_nav_menus();
  48  $menu_locations = get_nav_menu_locations();
  49  $num_locations  = count( array_keys( $locations ) );
  50  
  51  // Allowed actions: add, update, delete.
  52  $action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : 'edit';
  53  
  54  /*
  55   * If a JSON blob of navigation menu data is found, expand it and inject it
  56   * into `$_POST` to avoid PHP `max_input_vars` limitations. See #14134.
  57   */
  58  _wp_expand_nav_menu_post_data();
  59  
  60  switch ( $action ) {
  61      case 'add-menu-item':
  62          check_admin_referer( 'add-menu_item', 'menu-settings-column-nonce' );
  63  
  64          if ( isset( $_REQUEST['nav-menu-locations'] ) ) {
  65              set_theme_mod( 'nav_menu_locations', array_map( 'absint', $_REQUEST['menu-locations'] ) );
  66          } elseif ( isset( $_REQUEST['menu-item'] ) ) {
  67              wp_save_nav_menu_items( $nav_menu_selected_id, $_REQUEST['menu-item'] );
  68          }
  69  
  70          break;
  71  
  72      case 'move-down-menu-item':
  73          // Moving down a menu item is the same as moving up the next in order.
  74          check_admin_referer( 'move-menu_item' );
  75  
  76          $menu_item_id = isset( $_REQUEST['menu-item'] ) ? (int) $_REQUEST['menu-item'] : 0;
  77  
  78          if ( is_nav_menu_item( $menu_item_id ) ) {
  79              $menus = isset( $_REQUEST['menu'] ) ? array( (int) $_REQUEST['menu'] ) : wp_get_object_terms( $menu_item_id, 'nav_menu', array( 'fields' => 'ids' ) );
  80  
  81              if ( ! is_wp_error( $menus ) && ! empty( $menus[0] ) ) {
  82                  $menu_id            = (int) $menus[0];
  83                  $ordered_menu_items = wp_get_nav_menu_items( $menu_id );
  84                  $menu_item_data     = (array) wp_setup_nav_menu_item( get_post( $menu_item_id ) );
  85  
  86                  // Set up the data we need in one pass through the array of menu items.
  87                  $dbids_to_orders = array();
  88                  $orders_to_dbids = array();
  89  
  90                  foreach ( (array) $ordered_menu_items as $ordered_menu_item_object ) {
  91                      if ( isset( $ordered_menu_item_object->ID ) ) {
  92                          if ( isset( $ordered_menu_item_object->menu_order ) ) {
  93                              $dbids_to_orders[ $ordered_menu_item_object->ID ]         = $ordered_menu_item_object->menu_order;
  94                              $orders_to_dbids[ $ordered_menu_item_object->menu_order ] = $ordered_menu_item_object->ID;
  95                          }
  96                      }
  97                  }
  98  
  99                  // Get next in order.
 100                  if ( isset( $orders_to_dbids[ $dbids_to_orders[ $menu_item_id ] + 1 ] ) ) {
 101                      $next_item_id   = $orders_to_dbids[ $dbids_to_orders[ $menu_item_id ] + 1 ];
 102                      $next_item_data = (array) wp_setup_nav_menu_item( get_post( $next_item_id ) );
 103  
 104                      // If not siblings of same parent, bubble menu item up but keep order.
 105                      if ( ! empty( $menu_item_data['menu_item_parent'] )
 106                          && ( empty( $next_item_data['menu_item_parent'] )
 107                              || (int) $next_item_data['menu_item_parent'] !== (int) $menu_item_data['menu_item_parent'] )
 108                      ) {
 109                          if ( in_array( (int) $menu_item_data['menu_item_parent'], $orders_to_dbids, true ) ) {
 110                              $parent_db_id = (int) $menu_item_data['menu_item_parent'];
 111                          } else {
 112                              $parent_db_id = 0;
 113                          }
 114  
 115                          $parent_object = wp_setup_nav_menu_item( get_post( $parent_db_id ) );
 116  
 117                          if ( ! is_wp_error( $parent_object ) ) {
 118                              $parent_data                        = (array) $parent_object;
 119                              $menu_item_data['menu_item_parent'] = $parent_data['menu_item_parent'];
 120                              update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] );
 121                          }
 122  
 123                          // Make menu item a child of its next sibling.
 124                      } else {
 125                          $next_item_data['menu_order'] = $next_item_data['menu_order'] - 1;
 126                          $menu_item_data['menu_order'] = $menu_item_data['menu_order'] + 1;
 127  
 128                          $menu_item_data['menu_item_parent'] = $next_item_data['ID'];
 129                          update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] );
 130  
 131                          wp_update_post( $menu_item_data );
 132                          wp_update_post( $next_item_data );
 133                      }
 134  
 135                      // The item is last but still has a parent, so bubble up.
 136                  } elseif ( ! empty( $menu_item_data['menu_item_parent'] )
 137                      && in_array( (int) $menu_item_data['menu_item_parent'], $orders_to_dbids, true )
 138                  ) {
 139                      $menu_item_data['menu_item_parent'] = (int) get_post_meta( $menu_item_data['menu_item_parent'], '_menu_item_menu_item_parent', true );
 140                      update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] );
 141                  }
 142              }
 143          }
 144  
 145          break;
 146  
 147      case 'move-up-menu-item':
 148          check_admin_referer( 'move-menu_item' );
 149  
 150          $menu_item_id = isset( $_REQUEST['menu-item'] ) ? (int) $_REQUEST['menu-item'] : 0;
 151  
 152          if ( is_nav_menu_item( $menu_item_id ) ) {
 153              if ( isset( $_REQUEST['menu'] ) ) {
 154                  $menus = array( (int) $_REQUEST['menu'] );
 155              } else {
 156                  $menus = wp_get_object_terms( $menu_item_id, 'nav_menu', array( 'fields' => 'ids' ) );
 157              }
 158  
 159              if ( ! is_wp_error( $menus ) && ! empty( $menus[0] ) ) {
 160                  $menu_id            = (int) $menus[0];
 161                  $ordered_menu_items = wp_get_nav_menu_items( $menu_id );
 162                  $menu_item_data     = (array) wp_setup_nav_menu_item( get_post( $menu_item_id ) );
 163  
 164                  // Set up the data we need in one pass through the array of menu items.
 165                  $dbids_to_orders = array();
 166                  $orders_to_dbids = array();
 167  
 168                  foreach ( (array) $ordered_menu_items as $ordered_menu_item_object ) {
 169                      if ( isset( $ordered_menu_item_object->ID ) ) {
 170                          if ( isset( $ordered_menu_item_object->menu_order ) ) {
 171                              $dbids_to_orders[ $ordered_menu_item_object->ID ]         = $ordered_menu_item_object->menu_order;
 172                              $orders_to_dbids[ $ordered_menu_item_object->menu_order ] = $ordered_menu_item_object->ID;
 173                          }
 174                      }
 175                  }
 176  
 177                  // If this menu item is not first.
 178                  if ( ! empty( $dbids_to_orders[ $menu_item_id ] )
 179                      && ! empty( $orders_to_dbids[ $dbids_to_orders[ $menu_item_id ] - 1 ] )
 180                  ) {
 181  
 182                      // If this menu item is a child of the previous.
 183                      if ( ! empty( $menu_item_data['menu_item_parent'] )
 184                          && in_array( (int) $menu_item_data['menu_item_parent'], array_keys( $dbids_to_orders ), true )
 185                          && isset( $orders_to_dbids[ $dbids_to_orders[ $menu_item_id ] - 1 ] )
 186                          && ( (int) $menu_item_data['menu_item_parent'] === $orders_to_dbids[ $dbids_to_orders[ $menu_item_id ] - 1 ] )
 187                      ) {
 188                          if ( in_array( (int) $menu_item_data['menu_item_parent'], $orders_to_dbids, true ) ) {
 189                              $parent_db_id = (int) $menu_item_data['menu_item_parent'];
 190                          } else {
 191                              $parent_db_id = 0;
 192                          }
 193  
 194                          $parent_object = wp_setup_nav_menu_item( get_post( $parent_db_id ) );
 195  
 196                          if ( ! is_wp_error( $parent_object ) ) {
 197                              $parent_data = (array) $parent_object;
 198  
 199                              /*
 200                               * If there is something before the parent and parent a child of it,
 201                               * make menu item a child also of it.
 202                               */
 203                              if ( ! empty( $dbids_to_orders[ $parent_db_id ] )
 204                                  && ! empty( $orders_to_dbids[ $dbids_to_orders[ $parent_db_id ] - 1 ] )
 205                                  && ! empty( $parent_data['menu_item_parent'] )
 206                              ) {
 207                                  $menu_item_data['menu_item_parent'] = $parent_data['menu_item_parent'];
 208  
 209                                  /*
 210                                  * Else if there is something before parent and parent not a child of it,
 211                                  * make menu item a child of that something's parent
 212                                  */
 213                              } elseif ( ! empty( $dbids_to_orders[ $parent_db_id ] )
 214                                  && ! empty( $orders_to_dbids[ $dbids_to_orders[ $parent_db_id ] - 1 ] )
 215                              ) {
 216                                  $_possible_parent_id = (int) get_post_meta( $orders_to_dbids[ $dbids_to_orders[ $parent_db_id ] - 1 ], '_menu_item_menu_item_parent', true );
 217  
 218                                  if ( in_array( $_possible_parent_id, array_keys( $dbids_to_orders ), true ) ) {
 219                                      $menu_item_data['menu_item_parent'] = $_possible_parent_id;
 220                                  } else {
 221                                      $menu_item_data['menu_item_parent'] = 0;
 222                                  }
 223  
 224                                  // Else there isn't something before the parent.
 225                              } else {
 226                                  $menu_item_data['menu_item_parent'] = 0;
 227                              }
 228  
 229                              // Set former parent's [menu_order] to that of menu-item's.
 230                              $parent_data['menu_order'] = $parent_data['menu_order'] + 1;
 231  
 232                              // Set menu-item's [menu_order] to that of former parent.
 233                              $menu_item_data['menu_order'] = $menu_item_data['menu_order'] - 1;
 234  
 235                              // Save changes.
 236                              update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] );
 237                              wp_update_post( $menu_item_data );
 238                              wp_update_post( $parent_data );
 239                          }
 240  
 241                          // Else this menu item is not a child of the previous.
 242                      } elseif ( empty( $menu_item_data['menu_order'] )
 243                          || empty( $menu_item_data['menu_item_parent'] )
 244                          || ! in_array( (int) $menu_item_data['menu_item_parent'], array_keys( $dbids_to_orders ), true )
 245                          || empty( $orders_to_dbids[ $dbids_to_orders[ $menu_item_id ] - 1 ] )
 246                          || $orders_to_dbids[ $dbids_to_orders[ $menu_item_id ] - 1 ] !== (int) $menu_item_data['menu_item_parent']
 247                      ) {
 248                          // Just make it a child of the previous; keep the order.
 249                          $menu_item_data['menu_item_parent'] = (int) $orders_to_dbids[ $dbids_to_orders[ $menu_item_id ] - 1 ];
 250                          update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] );
 251                          wp_update_post( $menu_item_data );
 252                      }
 253                  }
 254              }
 255          }
 256  
 257          break;
 258  
 259      case 'delete-menu-item':
 260          $menu_item_id = (int) $_REQUEST['menu-item'];
 261  
 262          check_admin_referer( 'delete-menu_item_' . $menu_item_id );
 263  
 264          if ( is_nav_menu_item( $menu_item_id ) && wp_delete_post( $menu_item_id, true ) ) {
 265              $messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . __( 'The menu item has been successfully deleted.' ) . '</p></div>';
 266          }
 267  
 268          break;
 269  
 270      case 'delete':
 271          check_admin_referer( 'delete-nav_menu-' . $nav_menu_selected_id );
 272  
 273          if ( is_nav_menu( $nav_menu_selected_id ) ) {
 274              $deletion = wp_delete_nav_menu( $nav_menu_selected_id );
 275          } else {
 276              // Reset the selected menu.
 277              $nav_menu_selected_id = 0;
 278              unset( $_REQUEST['menu'] );
 279          }
 280  
 281          if ( ! isset( $deletion ) ) {
 282              break;
 283          }
 284  
 285          if ( is_wp_error( $deletion ) ) {
 286              $messages[] = '<div id="message" class="error notice is-dismissible"><p>' . $deletion->get_error_message() . '</p></div>';
 287          } else {
 288              $messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . __( 'The menu has been successfully deleted.' ) . '</p></div>';
 289          }
 290  
 291          break;
 292  
 293      case 'delete_menus':
 294          check_admin_referer( 'nav_menus_bulk_actions' );
 295  
 296          foreach ( $_REQUEST['delete_menus'] as $menu_id_to_delete ) {
 297              if ( ! is_nav_menu( $menu_id_to_delete ) ) {
 298                  continue;
 299              }
 300  
 301              $deletion = wp_delete_nav_menu( $menu_id_to_delete );
 302  
 303              if ( is_wp_error( $deletion ) ) {
 304                  $messages[]     = '<div id="message" class="error notice is-dismissible"><p>' . $deletion->get_error_message() . '</p></div>';
 305                  $deletion_error = true;
 306              }
 307          }
 308  
 309          if ( empty( $deletion_error ) ) {
 310              $messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . __( 'Selected menus have been successfully deleted.' ) . '</p></div>';
 311          }
 312  
 313          break;
 314  
 315      case 'update':
 316          check_admin_referer( 'update-nav_menu', 'update-nav-menu-nonce' );
 317  
 318          // Merge new and existing menu locations if any new ones are set.
 319          if ( isset( $_POST['menu-locations'] ) ) {
 320              $new_menu_locations = array_map( 'absint', $_POST['menu-locations'] );
 321              $menu_locations     = array_merge( $menu_locations, $new_menu_locations );
 322          }
 323  
 324          // Add Menu.
 325          if ( 0 === $nav_menu_selected_id ) {
 326              $new_menu_title = trim( esc_html( $_POST['menu-name'] ) );
 327  
 328              if ( $new_menu_title ) {
 329                  $_nav_menu_selected_id = wp_update_nav_menu_object( 0, array( 'menu-name' => $new_menu_title ) );
 330  
 331                  if ( is_wp_error( $_nav_menu_selected_id ) ) {
 332                      $messages[] = '<div id="message" class="error notice is-dismissible"><p>' . $_nav_menu_selected_id->get_error_message() . '</p></div>';
 333                  } else {
 334                      $_menu_object            = wp_get_nav_menu_object( $_nav_menu_selected_id );
 335                      $nav_menu_selected_id    = $_nav_menu_selected_id;
 336                      $nav_menu_selected_title = $_menu_object->name;
 337  
 338                      if ( isset( $_REQUEST['menu-item'] ) ) {
 339                          wp_save_nav_menu_items( $nav_menu_selected_id, absint( $_REQUEST['menu-item'] ) );
 340                      }
 341  
 342                      if ( isset( $_REQUEST['zero-menu-state'] ) || ! empty( $_POST['auto-add-pages'] ) ) {
 343                          // If there are menu items, add them.
 344                          wp_nav_menu_update_menu_items( $nav_menu_selected_id, $nav_menu_selected_title );
 345                      }
 346  
 347                      if ( isset( $_REQUEST['zero-menu-state'] ) ) {
 348                          // Auto-save nav_menu_locations.
 349                          $locations = get_nav_menu_locations();
 350  
 351                          foreach ( $locations as $location => $menu_id ) {
 352                                  $locations[ $location ] = $nav_menu_selected_id;
 353                                  break; // There should only be 1.
 354                          }
 355  
 356                          set_theme_mod( 'nav_menu_locations', $locations );
 357                      }
 358  
 359                      if ( isset( $_REQUEST['use-location'] ) ) {
 360                          $locations      = get_registered_nav_menus();
 361                          $menu_locations = get_nav_menu_locations();
 362  
 363                          if ( isset( $locations[ $_REQUEST['use-location'] ] ) ) {
 364                              $menu_locations[ $_REQUEST['use-location'] ] = $nav_menu_selected_id;
 365                          }
 366  
 367                          set_theme_mod( 'nav_menu_locations', $menu_locations );
 368                      }
 369  
 370                      wp_redirect( admin_url( 'nav-menus.php?menu=' . $_nav_menu_selected_id ) );
 371                      exit;
 372                  }
 373              } else {
 374                  $messages[] = '<div id="message" class="error notice is-dismissible"><p>' . __( 'Please enter a valid menu name.' ) . '</p></div>';
 375              }
 376  
 377              // Update existing menu.
 378          } else {
 379              // Remove menu locations that have been unchecked.
 380              foreach ( $locations as $location => $description ) {
 381                  if ( ( empty( $_POST['menu-locations'] ) || empty( $_POST['menu-locations'][ $location ] ) )
 382                      && isset( $menu_locations[ $location ] ) && $menu_locations[ $location ] === $nav_menu_selected_id
 383                  ) {
 384                      unset( $menu_locations[ $location ] );
 385                  }
 386              }
 387  
 388              // Set menu locations.
 389              set_theme_mod( 'nav_menu_locations', $menu_locations );
 390  
 391              $_menu_object = wp_get_nav_menu_object( $nav_menu_selected_id );
 392  
 393              $menu_title = trim( esc_html( $_POST['menu-name'] ) );
 394  
 395              if ( ! $menu_title ) {
 396                  $messages[] = '<div id="message" class="error notice is-dismissible"><p>' . __( 'Please enter a valid menu name.' ) . '</p></div>';
 397                  $menu_title = $_menu_object->name;
 398              }
 399  
 400              if ( ! is_wp_error( $_menu_object ) ) {
 401                  $_nav_menu_selected_id = wp_update_nav_menu_object( $nav_menu_selected_id, array( 'menu-name' => $menu_title ) );
 402  
 403                  if ( is_wp_error( $_nav_menu_selected_id ) ) {
 404                      $_menu_object = $_nav_menu_selected_id;
 405                      $messages[]   = '<div id="message" class="error notice is-dismissible"><p>' . $_nav_menu_selected_id->get_error_message() . '</p></div>';
 406                  } else {
 407                      $_menu_object            = wp_get_nav_menu_object( $_nav_menu_selected_id );
 408                      $nav_menu_selected_title = $_menu_object->name;
 409                  }
 410              }
 411  
 412              // Update menu items.
 413              if ( ! is_wp_error( $_menu_object ) ) {
 414                  $messages = array_merge( $messages, wp_nav_menu_update_menu_items( $_nav_menu_selected_id, $nav_menu_selected_title ) );
 415  
 416                  // If the menu ID changed, redirect to the new URL.
 417                  if ( $nav_menu_selected_id !== $_nav_menu_selected_id ) {
 418                      wp_redirect( admin_url( 'nav-menus.php?menu=' . (int) $_nav_menu_selected_id ) );
 419                      exit;
 420                  }
 421              }
 422          }
 423  
 424          break;
 425  
 426      case 'locations':
 427          if ( ! $num_locations ) {
 428              wp_redirect( admin_url( 'nav-menus.php' ) );
 429              exit;
 430          }
 431  
 432          add_filter( 'screen_options_show_screen', '__return_false' );
 433  
 434          if ( isset( $_POST['menu-locations'] ) ) {
 435              check_admin_referer( 'save-menu-locations' );
 436  
 437              $new_menu_locations = array_map( 'absint', $_POST['menu-locations'] );
 438              $menu_locations     = array_merge( $menu_locations, $new_menu_locations );
 439              // Set menu locations.
 440              set_theme_mod( 'nav_menu_locations', $menu_locations );
 441  
 442              $messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . __( 'Menu locations updated.' ) . '</p></div>';
 443          }
 444  
 445          break;
 446  }
 447  
 448  // Get all nav menus.
 449  $nav_menus  = wp_get_nav_menus();
 450  $menu_count = count( $nav_menus );
 451  
 452  // Are we on the add new screen?
 453  $add_new_screen = ( isset( $_GET['menu'] ) && 0 === (int) $_GET['menu'] ) ? true : false;
 454  
 455  $locations_screen = ( isset( $_GET['action'] ) && 'locations' === $_GET['action'] ) ? true : false;
 456  
 457  $page_count = wp_count_posts( 'page' );
 458  
 459  /*
 460   * If we have one theme location, and zero menus, we take them right
 461   * into editing their first menu.
 462   */
 463  if ( 1 === count( get_registered_nav_menus() ) && ! $add_new_screen
 464      && empty( $nav_menus ) && ! empty( $page_count->publish )
 465  ) {
 466      $one_theme_location_no_menus = true;
 467  } else {
 468      $one_theme_location_no_menus = false;
 469  }
 470  
 471  $nav_menus_l10n = array(
 472      'oneThemeLocationNoMenus' => $one_theme_location_no_menus,
 473      'moveUp'                  => __( 'Move up one' ),
 474      'moveDown'                => __( 'Move down one' ),
 475      'moveToTop'               => __( 'Move to the top' ),
 476      /* translators: %s: Previous item name. */
 477      'moveUnder'               => __( 'Move under %s' ),
 478      /* translators: %s: Previous item name. */
 479      'moveOutFrom'             => __( 'Move out from under %s' ),
 480      /* translators: %s: Previous item name. */
 481      'under'                   => __( 'Under %s' ),
 482      /* translators: %s: Previous item name. */
 483      'outFrom'                 => __( 'Out from under %s' ),
 484      /* translators: 1: Item name, 2: Item position, 3: Total number of items. */
 485      'menuFocus'               => __( '%1$s. Menu item %2$d of %3$d.' ),
 486      /* translators: 1: Item name, 2: Item position, 3: Parent item name. */
 487      'subMenuFocus'            => __( '%1$s. Sub item number %2$d under %3$s.' ),
 488      /* translators: %s: Item name. */
 489      'menuItemDeletion'        => __( 'item %s' ),
 490      /* translators: %s: Item name. */
 491      'itemsDeleted'            => __( 'Deleted menu item: %s.' ),
 492  );
 493  wp_localize_script( 'nav-menu', 'menus', $nav_menus_l10n );
 494  
 495  /*
 496   * Redirect to add screen if there are no menus and this users has either zero,
 497   * or more than 1 theme locations.
 498   */
 499  if ( 0 === $menu_count && ! $add_new_screen && ! $one_theme_location_no_menus ) {
 500      wp_redirect( admin_url( 'nav-menus.php?action=edit&menu=0' ) );
 501  }
 502  
 503  // Get recently edited nav menu.
 504  $recently_edited = absint( get_user_option( 'nav_menu_recently_edited' ) );
 505  if ( empty( $recently_edited ) && is_nav_menu( $nav_menu_selected_id ) ) {
 506      $recently_edited = $nav_menu_selected_id;
 507  }
 508  
 509  // Use $recently_edited if none are selected.
 510  if ( empty( $nav_menu_selected_id ) && ! isset( $_GET['menu'] ) && is_nav_menu( $recently_edited ) ) {
 511      $nav_menu_selected_id = $recently_edited;
 512  }
 513  
 514  // On deletion of menu, if another menu exists, show it.
 515  if ( ! $add_new_screen && $menu_count > 0 && isset( $_GET['action'] ) && 'delete' === $_GET['action'] ) {
 516      $nav_menu_selected_id = $nav_menus[0]->term_id;
 517  }
 518  
 519  // Set $nav_menu_selected_id to 0 if no menus.
 520  if ( $one_theme_location_no_menus ) {
 521      $nav_menu_selected_id = 0;
 522  } elseif ( empty( $nav_menu_selected_id ) && ! empty( $nav_menus ) && ! $add_new_screen ) {
 523      // If we have no selection yet, and we have menus, set to the first one in the list.
 524      $nav_menu_selected_id = $nav_menus[0]->term_id;
 525  }
 526  
 527  // Update the user's setting.
 528  if ( $nav_menu_selected_id !== $recently_edited && is_nav_menu( $nav_menu_selected_id ) ) {
 529      update_user_meta( $current_user->ID, 'nav_menu_recently_edited', $nav_menu_selected_id );
 530  }
 531  
 532  // If there's a menu, get its name.
 533  if ( ! $nav_menu_selected_title && is_nav_menu( $nav_menu_selected_id ) ) {
 534      $_menu_object            = wp_get_nav_menu_object( $nav_menu_selected_id );
 535      $nav_menu_selected_title = ! is_wp_error( $_menu_object ) ? $_menu_object->name : '';
 536  }
 537  
 538  // Generate truncated menu names.
 539  foreach ( (array) $nav_menus as $key => $_nav_menu ) {
 540      $nav_menus[ $key ]->truncated_name = wp_html_excerpt( $_nav_menu->name, 40, '&hellip;' );
 541  }
 542  
 543  // Retrieve menu locations.
 544  if ( current_theme_supports( 'menus' ) ) {
 545      $locations      = get_registered_nav_menus();
 546      $menu_locations = get_nav_menu_locations();
 547  }
 548  
 549  /*
 550   * Ensure the user will be able to scroll horizontally
 551   * by adding a class for the max menu depth.
 552   *
 553   * @global int $_wp_nav_menu_max_depth
 554   */
 555  global $_wp_nav_menu_max_depth;
 556  $_wp_nav_menu_max_depth = 0;
 557  
 558  // Calling wp_get_nav_menu_to_edit generates $_wp_nav_menu_max_depth.
 559  if ( is_nav_menu( $nav_menu_selected_id ) ) {
 560      $menu_items  = wp_get_nav_menu_items( $nav_menu_selected_id, array( 'post_status' => 'any' ) );
 561      $edit_markup = wp_get_nav_menu_to_edit( $nav_menu_selected_id );
 562  }
 563  
 564  /**
 565   * @global int $_wp_nav_menu_max_depth
 566   *
 567   * @param string $classes
 568   * @return string
 569   */
 570  function wp_nav_menu_max_depth( $classes ) {
 571      global $_wp_nav_menu_max_depth;
 572      return "$classes menu-max-depth-$_wp_nav_menu_max_depth";
 573  }
 574  
 575  add_filter( 'admin_body_class', 'wp_nav_menu_max_depth' );
 576  
 577  wp_nav_menu_setup();
 578  wp_initial_nav_menu_meta_boxes();
 579  
 580  if ( ! current_theme_supports( 'menus' ) && ! $num_locations ) {
 581      $messages[] = '<div id="message" class="updated"><p>' . sprintf(
 582          /* translators: %s: URL to Widgets screen. */
 583          __( 'Your theme does not natively support menus, but you can use them in sidebars by adding a &#8220;Navigation Menu&#8221; widget on the <a href="%s">Widgets</a> screen.' ),
 584          admin_url( 'widgets.php' )
 585      ) . '</p></div>';
 586  }
 587  
 588  if ( ! $locations_screen ) : // Main tab.
 589      $overview  = '<p>' . __( 'This screen is used for managing your navigation menus.' ) . '</p>';
 590      $overview .= '<p>' . sprintf(
 591          /* translators: 1: URL to Widgets screen, 2 and 3: The names of the default themes. */
 592          __( 'Menus can be displayed in locations defined by your theme, even used in sidebars by adding a &#8220;Navigation Menu&#8221; widget on the <a href="%1$s">Widgets</a> screen. If your theme does not support the navigation menus feature (the default themes, %2$s and %3$s, do), you can learn about adding this support by following the Documentation link to the side.' ),
 593          admin_url( 'widgets.php' ),
 594          'Twenty Twenty',
 595          'Twenty Twenty-One'
 596      ) . '</p>';
 597      $overview .= '<p>' . __( 'From this screen you can:' ) . '</p>';
 598      $overview .= '<ul><li>' . __( 'Create, edit, and delete menus' ) . '</li>';
 599      $overview .= '<li>' . __( 'Add, organize, and modify individual menu items' ) . '</li></ul>';
 600  
 601      get_current_screen()->add_help_tab(
 602          array(
 603              'id'      => 'overview',
 604              'title'   => __( 'Overview' ),
 605              'content' => $overview,
 606          )
 607      );
 608  
 609      $menu_management  = '<p>' . __( 'The menu management box at the top of the screen is used to control which menu is opened in the editor below.' ) . '</p>';
 610      $menu_management .= '<ul><li>' . __( 'To edit an existing menu, <strong>choose a menu from the drop down and click Select</strong>' ) . '</li>';
 611      $menu_management .= '<li>' . __( 'If you haven&#8217;t yet created any menus, <strong>click the &#8217;create a new menu&#8217; link</strong> to get started' ) . '</li></ul>';
 612      $menu_management .= '<p>' . __( 'You can assign theme locations to individual menus by <strong>selecting the desired settings</strong> at the bottom of the menu editor. To assign menus to all theme locations at once, <strong>visit the Manage Locations tab</strong> at the top of the screen.' ) . '</p>';
 613  
 614      get_current_screen()->add_help_tab(
 615          array(
 616              'id'      => 'menu-management',
 617              'title'   => __( 'Menu Management' ),
 618              'content' => $menu_management,
 619          )
 620      );
 621  
 622      $editing_menus  = '<p>' . __( 'Each navigation menu may contain a mix of links to pages, categories, custom URLs or other content types. Menu links are added by selecting items from the expanding boxes in the left-hand column below.' ) . '</p>';
 623      $editing_menus .= '<p>' . __( '<strong>Clicking the arrow to the right of any menu item</strong> in the editor will reveal a standard group of settings. Additional settings such as link target, CSS classes, link relationships, and link descriptions can be enabled and disabled via the Screen Options tab.' ) . '</p>';
 624      $editing_menus .= '<ul><li>' . __( 'Add one or several items at once by <strong>selecting the checkbox next to each item and clicking Add to Menu</strong>' ) . '</li>';
 625      $editing_menus .= '<li>' . __( 'To add a custom link, <strong>expand the Custom Links section, enter a URL and link text, and click Add to Menu</strong>' ) . '</li>';
 626      $editing_menus .= '<li>' . __( 'To reorganize menu items, <strong>drag and drop items with your mouse or use your keyboard</strong>. Drag or move a menu item a little to the right to make it a submenu' ) . '</li>';
 627      $editing_menus .= '<li>' . __( 'Delete a menu item by <strong>expanding it and clicking the Remove link</strong>' ) . '</li></ul>';
 628  
 629      get_current_screen()->add_help_tab(
 630          array(
 631              'id'      => 'editing-menus',
 632              'title'   => __( 'Editing Menus' ),
 633              'content' => $editing_menus,
 634          )
 635      );
 636  else : // Locations tab.
 637      $locations_overview  = '<p>' . __( 'This screen is used for globally assigning menus to locations defined by your theme.' ) . '</p>';
 638      $locations_overview .= '<ul><li>' . __( 'To assign menus to one or more theme locations, <strong>select a menu from each location&#8217;s drop down.</strong> When you&#8217;re finished, <strong>click Save Changes</strong>' ) . '</li>';
 639      $locations_overview .= '<li>' . __( 'To edit a menu currently assigned to a theme location, <strong>click the adjacent &#8217;Edit&#8217; link</strong>' ) . '</li>';
 640      $locations_overview .= '<li>' . __( 'To add a new menu instead of assigning an existing one, <strong>click the &#8217;Use new menu&#8217; link</strong>. Your new menu will be automatically assigned to that theme location' ) . '</li></ul>';
 641  
 642      get_current_screen()->add_help_tab(
 643          array(
 644              'id'      => 'locations-overview',
 645              'title'   => __( 'Overview' ),
 646              'content' => $locations_overview,
 647          )
 648      );
 649  endif;
 650  
 651  get_current_screen()->set_help_sidebar(
 652      '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
 653      '<p>' . __( '<a href="https://wordpress.org/support/article/appearance-menus-screen/">Documentation on Menus</a>' ) . '</p>' .
 654      '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
 655  );
 656  
 657  // Get the admin header.
 658  require_once ABSPATH . 'wp-admin/admin-header.php';
 659  ?>
 660  <div class="wrap">
 661      <h1 class="wp-heading-inline"><?php esc_html_e( 'Menus' ); ?></h1>
 662      <?php
 663      if ( current_user_can( 'customize' ) ) :
 664          $focus = $locations_screen ? array( 'section' => 'menu_locations' ) : array( 'panel' => 'nav_menus' );
 665          printf(
 666              ' <a class="page-title-action hide-if-no-customize" href="%1$s">%2$s</a>',
 667              esc_url(
 668                  add_query_arg(
 669                      array(
 670                          array( 'autofocus' => $focus ),
 671                          'return' => urlencode( remove_query_arg( wp_removable_query_args(), wp_unslash( $_SERVER['REQUEST_URI'] ) ) ),
 672                      ),
 673                      admin_url( 'customize.php' )
 674                  )
 675              ),
 676              __( 'Manage with Live Preview' )
 677          );
 678      endif;
 679  
 680      $nav_tab_active_class = '';
 681      $nav_aria_current     = '';
 682  
 683      if ( ! isset( $_GET['action'] ) || isset( $_GET['action'] ) && 'locations' !== $_GET['action'] ) {
 684          $nav_tab_active_class = ' nav-tab-active';
 685          $nav_aria_current     = ' aria-current="page"';
 686      }
 687      ?>
 688  
 689      <hr class="wp-header-end">
 690  
 691      <nav class="nav-tab-wrapper wp-clearfix" aria-label="<?php esc_attr_e( 'Secondary menu' ); ?>">
 692          <a href="<?php echo esc_url( admin_url( 'nav-menus.php' ) ); ?>" class="nav-tab<?php echo $nav_tab_active_class; ?>"<?php echo $nav_aria_current; ?>><?php esc_html_e( 'Edit Menus' ); ?></a>
 693          <?php
 694          if ( $num_locations && $menu_count ) {
 695              $active_tab_class = '';
 696              $aria_current     = '';
 697  
 698              if ( $locations_screen ) {
 699                  $active_tab_class = ' nav-tab-active';
 700                  $aria_current     = ' aria-current="page"';
 701              }
 702              ?>
 703              <a href="<?php echo esc_url( add_query_arg( array( 'action' => 'locations' ), admin_url( 'nav-menus.php' ) ) ); ?>" class="nav-tab<?php echo $active_tab_class; ?>"<?php echo $aria_current; ?>><?php esc_html_e( 'Manage Locations' ); ?></a>
 704              <?php
 705          }
 706          ?>
 707      </nav>
 708      <?php
 709      foreach ( $messages as $message ) :
 710          echo $message . "\n";
 711      endforeach;
 712      ?>
 713      <?php
 714      if ( $locations_screen ) :
 715          if ( 1 === $num_locations ) {
 716              echo '<p>' . __( 'Your theme supports one menu. Select which menu you would like to use.' ) . '</p>';
 717          } else {
 718              echo '<p>' . sprintf(
 719                  /* translators: %s: Number of menus. */
 720                  _n(
 721                      'Your theme supports %s menu. Select which menu appears in each location.',
 722                      'Your theme supports %s menus. Select which menu appears in each location.',
 723                      $num_locations
 724                  ),
 725                  number_format_i18n( $num_locations )
 726              ) . '</p>';
 727          }
 728          ?>
 729      <div id="menu-locations-wrap">
 730          <form method="post" action="<?php echo esc_url( add_query_arg( array( 'action' => 'locations' ), admin_url( 'nav-menus.php' ) ) ); ?>">
 731              <table class="widefat fixed" id="menu-locations-table">
 732                  <thead>
 733                  <tr>
 734                      <th scope="col" class="manage-column column-locations"><?php _e( 'Theme Location' ); ?></th>
 735                      <th scope="col" class="manage-column column-menus"><?php _e( 'Assigned Menu' ); ?></th>
 736                  </tr>
 737                  </thead>
 738                  <tbody class="menu-locations">
 739                  <?php foreach ( $locations as $_location => $_name ) { ?>
 740                      <tr class="menu-locations-row">
 741                          <td class="menu-location-title"><label for="locations-<?php echo $_location; ?>"><?php echo $_name; ?></label></td>
 742                          <td class="menu-location-menus">
 743                              <select name="menu-locations[<?php echo $_location; ?>]" id="locations-<?php echo $_location; ?>">
 744                                  <option value="0"><?php printf( '&mdash; %s &mdash;', esc_html__( 'Select a Menu' ) ); ?></option>
 745                                  <?php
 746                                  foreach ( $nav_menus as $menu ) :
 747                                      $data_orig = '';
 748                                      $selected  = isset( $menu_locations[ $_location ] ) && $menu_locations[ $_location ] === $menu->term_id;
 749  
 750                                      if ( $selected ) {
 751                                          $data_orig = 'data-orig="true"';
 752                                      }
 753                                      ?>
 754                                      <option <?php echo $data_orig; ?> <?php selected( $selected ); ?> value="<?php echo $menu->term_id; ?>">
 755                                          <?php echo wp_html_excerpt( $menu->name, 40, '&hellip;' ); ?>
 756                                      </option>
 757                                  <?php endforeach; ?>
 758                              </select>
 759                              <div class="locations-row-links">
 760                                  <?php if ( isset( $menu_locations[ $_location ] ) && 0 !== $menu_locations[ $_location ] ) : ?>
 761                                  <span class="locations-edit-menu-link">
 762                                      <a href="
 763                                      <?php
 764                                      echo esc_url(
 765                                          add_query_arg(
 766                                              array(
 767                                                  'action' => 'edit',
 768                                                  'menu'   => $menu_locations[ $_location ],
 769                                              ),
 770                                              admin_url( 'nav-menus.php' )
 771                                          )
 772                                      );
 773                                      ?>
 774                                      ">
 775                                          <span aria-hidden="true"><?php _ex( 'Edit', 'menu' ); ?></span><span class="screen-reader-text"><?php _e( 'Edit selected menu' ); ?></span>
 776                                      </a>
 777                                  </span>
 778                                  <?php endif; ?>
 779                                  <span class="locations-add-menu-link">
 780                                      <a href="
 781                                      <?php
 782                                      echo esc_url(
 783                                          add_query_arg(
 784                                              array(
 785                                                  'action' => 'edit',
 786                                                  'menu'   => 0,
 787                                                  'use-location' => $_location,
 788                                              ),
 789                                              admin_url( 'nav-menus.php' )
 790                                          )
 791                                      );
 792                                      ?>
 793                                      ">
 794                                          <?php _ex( 'Use new menu', 'menu' ); ?>
 795                                      </a>
 796                                  </span>
 797                              </div><!-- .locations-row-links -->
 798                          </td><!-- .menu-location-menus -->
 799                      </tr><!-- .menu-locations-row -->
 800                  <?php } // End foreach. ?>
 801                  </tbody>
 802              </table>
 803              <p class="button-controls wp-clearfix"><?php submit_button( __( 'Save Changes' ), 'primary left', 'nav-menu-locations', false ); ?></p>
 804              <?php wp_nonce_field( 'save-menu-locations' ); ?>
 805              <input type="hidden" name="menu" id="nav-menu-meta-object-id" value="<?php echo esc_attr( $nav_menu_selected_id ); ?>" />
 806          </form>
 807      </div><!-- #menu-locations-wrap -->
 808          <?php
 809          /**
 810           * Fires after the menu locations table is displayed.
 811           *
 812           * @since 3.6.0
 813           */
 814          do_action( 'after_menu_locations_table' );
 815          ?>
 816      <?php else : ?>
 817      <div class="manage-menus">
 818          <?php if ( $menu_count < 1 ) : ?>
 819          <span class="first-menu-message">
 820              <?php _e( 'Create your first menu below.' ); ?>
 821              <span class="screen-reader-text"><?php _e( 'Fill in the Menu Name and click the Create Menu button to create your first menu.' ); ?></span>
 822          </span><!-- /first-menu-message -->
 823          <?php elseif ( $menu_count < 2 ) : ?>
 824          <span class="add-edit-menu-action">
 825              <?php
 826              printf(
 827                  /* translators: %s: URL to create a new menu. */
 828                  __( 'Edit your menu below, or <a href="%s">create a new menu</a>. Don&#8217;t forget to save your changes!' ),
 829                  esc_url(
 830                      add_query_arg(
 831                          array(
 832                              'action' => 'edit',
 833                              'menu'   => 0,
 834                          ),
 835                          admin_url( 'nav-menus.php' )
 836                      )
 837                  )
 838              );
 839              ?>
 840              <span class="screen-reader-text"><?php _e( 'Click the Save Menu button to save your changes.' ); ?></span>
 841          </span><!-- /add-edit-menu-action -->
 842          <?php else : ?>
 843              <form method="get" action="<?php echo esc_url( admin_url( 'nav-menus.php' ) ); ?>">
 844              <input type="hidden" name="action" value="edit" />
 845              <label for="select-menu-to-edit" class="selected-menu"><?php _e( 'Select a menu to edit:' ); ?></label>
 846              <select name="menu" id="select-menu-to-edit">
 847                  <?php if ( $add_new_screen ) : ?>
 848                      <option value="0" selected="selected"><?php _e( '&mdash; Select &mdash;' ); ?></option>
 849                  <?php endif; ?>
 850                  <?php foreach ( (array) $nav_menus as $_nav_menu ) : ?>
 851                      <option value="<?php echo esc_attr( $_nav_menu->term_id ); ?>" <?php selected( $_nav_menu->term_id, $nav_menu_selected_id ); ?>>
 852                          <?php
 853                          echo esc_html( $_nav_menu->truncated_name );
 854  
 855                          if ( ! empty( $menu_locations ) && in_array( $_nav_menu->term_id, $menu_locations, true ) ) {
 856                              $locations_assigned_to_this_menu = array();
 857  
 858                              foreach ( array_keys( $menu_locations, $_nav_menu->term_id, true ) as $menu_location_key ) {
 859                                  if ( isset( $locations[ $menu_location_key ] ) ) {
 860                                      $locations_assigned_to_this_menu[] = $locations[ $menu_location_key ];
 861                                  }
 862                              }
 863  
 864                              /**
 865                               * Filters the number of locations listed per menu in the drop-down select.
 866                               *
 867                               * @since 3.6.0
 868                               *
 869                               * @param int $locations Number of menu locations to list. Default 3.
 870                               */
 871                              $locations_listed_per_menu = absint( apply_filters( 'wp_nav_locations_listed_per_menu', 3 ) );
 872  
 873                              $assigned_locations = array_slice( $locations_assigned_to_this_menu, 0, $locations_listed_per_menu );
 874  
 875                              // Adds ellipses following the number of locations defined in $assigned_locations.
 876                              if ( ! empty( $assigned_locations ) ) {
 877                                  printf(
 878                                      ' (%1$s%2$s)',
 879                                      implode( ', ', $assigned_locations ),
 880                                      count( $locations_assigned_to_this_menu ) > count( $assigned_locations ) ? ' &hellip;' : ''
 881                                  );
 882                              }
 883                          }
 884                          ?>
 885                      </option>
 886                  <?php endforeach; ?>
 887              </select>
 888              <span class="submit-btn"><input type="submit" class="button" value="<?php esc_attr_e( 'Select' ); ?>"></span>
 889              <span class="add-new-menu-action">
 890                  <?php
 891                  printf(
 892                      /* translators: %s: URL to create a new menu. */
 893                      __( 'or <a href="%s">create a new menu</a>. Don&#8217;t forget to save your changes!' ),
 894                      esc_url(
 895                          add_query_arg(
 896                              array(
 897                                  'action' => 'edit',
 898                                  'menu'   => 0,
 899                              ),
 900                              admin_url( 'nav-menus.php' )
 901                          )
 902                      )
 903                  );
 904                  ?>
 905                  <span class="screen-reader-text"><?php _e( 'Click the Save Menu button to save your changes.' ); ?></span>
 906              </span><!-- /add-new-menu-action -->
 907          </form>
 908              <?php
 909          endif;
 910  
 911          $metabox_holder_disabled_class = '';
 912  
 913          if ( isset( $_GET['menu'] ) && 0 === (int) $_GET['menu'] ) {
 914              $metabox_holder_disabled_class = ' metabox-holder-disabled';
 915          }
 916          ?>
 917      </div><!-- /manage-menus -->
 918      <div id="nav-menus-frame" class="wp-clearfix">
 919      <div id="menu-settings-column" class="metabox-holder<?php echo $metabox_holder_disabled_class; ?>">
 920  
 921          <div class="clear"></div>
 922  
 923          <form id="nav-menu-meta" class="nav-menu-meta" method="post" enctype="multipart/form-data">
 924              <input type="hidden" name="menu" id="nav-menu-meta-object-id" value="<?php echo esc_attr( $nav_menu_selected_id ); ?>" />
 925              <input type="hidden" name="action" value="add-menu-item" />
 926              <?php wp_nonce_field( 'add-menu_item', 'menu-settings-column-nonce' ); ?>
 927              <h2><?php _e( 'Add menu items' ); ?></h2>
 928              <?php do_accordion_sections( 'nav-menus', 'side', null ); ?>
 929          </form>
 930  
 931      </div><!-- /#menu-settings-column -->
 932      <div id="menu-management-liquid">
 933          <div id="menu-management">
 934              <form id="update-nav-menu" method="post" enctype="multipart/form-data">
 935                  <h2><?php _e( 'Menu structure' ); ?></h2>
 936                  <div class="menu-edit">
 937                      <input type="hidden" name="nav-menu-data">
 938                      <?php
 939                      wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
 940                      wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
 941                      wp_nonce_field( 'update-nav_menu', 'update-nav-menu-nonce' );
 942  
 943                      $menu_name_aria_desc = $add_new_screen ? ' aria-describedby="menu-name-desc"' : '';
 944  
 945                      if ( $one_theme_location_no_menus ) {
 946                          $menu_name_val = 'value="' . esc_attr( 'Menu 1' ) . '"';
 947                          ?>
 948                          <input type="hidden" name="zero-menu-state" value="true" />
 949                          <?php
 950                      } else {
 951                          $menu_name_val = 'value="' . esc_attr( $nav_menu_selected_title ) . '"';
 952                      }
 953                      ?>
 954                      <input type="hidden" name="action" value="update" />
 955                      <input type="hidden" name="menu" id="menu" value="<?php echo esc_attr( $nav_menu_selected_id ); ?>" />
 956                      <div id="nav-menu-header">
 957                          <div class="major-publishing-actions wp-clearfix">
 958                              <label class="menu-name-label" for="menu-name"><?php _e( 'Menu Name' ); ?></label>
 959                              <input name="menu-name" id="menu-name" type="text" class="menu-name regular-text menu-item-textbox form-required" required="required" <?php echo $menu_name_val . $menu_name_aria_desc; ?> />
 960                              <div class="publishing-action">
 961                                  <?php submit_button( empty( $nav_menu_selected_id ) ? __( 'Create Menu' ) : __( 'Save Menu' ), 'primary large menu-save', 'save_menu', false, array( 'id' => 'save_menu_header' ) ); ?>
 962                              </div><!-- END .publishing-action -->
 963                          </div><!-- END .major-publishing-actions -->
 964                      </div><!-- END .nav-menu-header -->
 965                      <div id="post-body">
 966                          <div id="post-body-content" class="wp-clearfix">
 967                              <?php if ( ! $add_new_screen ) : ?>
 968                                  <?php
 969                                  $hide_style = '';
 970  
 971                                  if ( isset( $menu_items ) && 0 === count( $menu_items ) ) {
 972                                      $hide_style = 'style="display: none;"';
 973                                  }
 974  
 975                                  if ( $one_theme_location_no_menus ) {
 976                                      $starter_copy = __( 'Edit your default menu by adding or removing items. Drag the items into the order you prefer. Click Create Menu to save your changes.' );
 977                                  } else {
 978                                      $starter_copy = __( 'Drag the items into the order you prefer. Click the arrow on the right of the item to reveal additional configuration options.' );
 979                                  }
 980                                  ?>
 981                                  <div class="drag-instructions post-body-plain" <?php echo $hide_style; ?>>
 982                                      <p><?php echo $starter_copy; ?></p>
 983                                  </div>
 984                                  <div id="nav-menu-bulk-actions-top" class="bulk-actions">
 985                                      <label class="bulk-select-button" for="bulk-select-switcher-top">
 986                                          <input type="checkbox" id="bulk-select-switcher-top" name="bulk-select-switcher-top" class="bulk-select-switcher">
 987                                          <span class="bulk-select-button-label"><?php _e( 'Bulk Select' ); ?></span>
 988                                      </label>
 989                                  </div>
 990                                  <?php
 991                                  if ( isset( $edit_markup ) && ! is_wp_error( $edit_markup ) ) {
 992                                      echo $edit_markup;
 993                                  } else {
 994                                      ?>
 995                                      <ul class="menu" id="menu-to-edit"></ul>
 996                                  <?php } ?>
 997  
 998                              <?php endif; ?>
 999  
1000                              <?php if ( $add_new_screen ) : ?>
1001                                  <p class="post-body-plain" id="menu-name-desc"><?php _e( 'Give your menu a name, then click Create Menu.' ); ?></p>
1002                                  <?php if ( isset( $_GET['use-location'] ) ) : ?>
1003                                      <input type="hidden" name="use-location" value="<?php echo esc_attr( $_GET['use-location'] ); ?>" />
1004                                  <?php endif; ?>
1005  
1006                                  <?php
1007                              endif;
1008  
1009                              $no_menus_style = '';
1010  
1011                              if ( $one_theme_location_no_menus ) {
1012                                  $no_menus_style = 'style="display: none;"';
1013                              }
1014                              ?>
1015                              <div id="nav-menu-bulk-actions-bottom" class="bulk-actions">
1016                                  <label class="bulk-select-button" for="bulk-select-switcher-bottom">
1017                                      <input type="checkbox" id="bulk-select-switcher-bottom" name="bulk-select-switcher-top" class="bulk-select-switcher">
1018                                      <span class="bulk-select-button-label"><?php _e( 'Bulk Select' ); ?></span>
1019                                  </label>
1020                                  <input type="button" class="deletion menu-items-delete disabled" value="<?php _e( 'Remove Selected Items' ); ?>">
1021                                  <div id="pending-menu-items-to-delete">
1022                                      <p><?php _e( 'List of menu items selected for deletion:' ); ?></p>
1023                                      <ul></ul>
1024                                  </div>
1025                              </div>
1026                              <div class="menu-settings" <?php echo $no_menus_style; ?>>
1027                                  <h3><?php _e( 'Menu Settings' ); ?></h3>
1028                                  <?php
1029                                  if ( ! isset( $auto_add ) ) {
1030                                      $auto_add = get_option( 'nav_menu_options' );
1031  
1032                                      if ( ! isset( $auto_add['auto_add'] ) ) {
1033                                          $auto_add = false;
1034                                      } elseif ( false !== array_search( $nav_menu_selected_id, $auto_add['auto_add'], true ) ) {
1035                                          $auto_add = true;
1036                                      } else {
1037                                          $auto_add = false;
1038                                      }
1039                                  }
1040                                  ?>
1041  
1042                                  <fieldset class="menu-settings-group auto-add-pages">
1043                                      <legend class="menu-settings-group-name howto"><?php _e( 'Auto add pages' ); ?></legend>
1044                                      <div class="menu-settings-input checkbox-input">
1045                                          <input type="checkbox"<?php checked( $auto_add ); ?> name="auto-add-pages" id="auto-add-pages" value="1" /> <label for="auto-add-pages"><?php printf( __( 'Automatically add new top-level pages to this menu' ), esc_url( admin_url( 'edit.php?post_type=page' ) ) ); ?></label>
1046                                      </div>
1047                                  </fieldset>
1048  
1049                                  <?php if ( current_theme_supports( 'menus' ) ) : ?>
1050  
1051                                      <fieldset class="menu-settings-group menu-theme-locations">
1052                                          <legend class="menu-settings-group-name howto"><?php _e( 'Display location' ); ?></legend>
1053                                          <?php
1054                                          foreach ( $locations as $location => $description ) :
1055                                              $checked = false;
1056  
1057                                              if ( isset( $menu_locations[ $location ] )
1058                                                      && 0 !== $nav_menu_selected_id
1059                                                      && $menu_locations[ $location ] === $nav_menu_selected_id
1060                                              ) {
1061                                                      $checked = true;
1062                                              }
1063                                              ?>
1064                                              <div class="menu-settings-input checkbox-input">
1065                                                  <input type="checkbox"<?php checked( $checked ); ?> name="menu-locations[<?php echo esc_attr( $location ); ?>]" id="locations-<?php echo esc_attr( $location ); ?>" value="<?php echo esc_attr( $nav_menu_selected_id ); ?>" />
1066                                                  <label for="locations-<?php echo esc_attr( $location ); ?>"><?php echo $description; ?></label>
1067                                                  <?php if ( ! empty( $menu_locations[ $location ] ) && $menu_locations[ $location ] !== $nav_menu_selected_id ) : ?>
1068                                                      <span class="theme-location-set">
1069                                                      <?php
1070                                                          printf(
1071                                                              /* translators: %s: Menu name. */
1072                                                              _x( '(Currently set to: %s)', 'menu location' ),
1073                                                              wp_get_nav_menu_object( $menu_locations[ $location ] )->name
1074                                                          );
1075                                                      ?>
1076                                                      </span>
1077                                                  <?php endif; ?>
1078                                              </div>
1079                                          <?php endforeach; ?>
1080                                      </fieldset>
1081  
1082                                  <?php endif; ?>
1083  
1084                              </div>
1085                          </div><!-- /#post-body-content -->
1086                      </div><!-- /#post-body -->
1087                      <div id="nav-menu-footer">
1088                          <div class="major-publishing-actions wp-clearfix">
1089                              <?php if ( $menu_count > 0 ) : ?>
1090  
1091                                  <?php if ( $add_new_screen ) : ?>
1092                                  <span class="cancel-action">
1093                                      <a class="submitcancel cancellation menu-cancel" href="<?php echo esc_url( admin_url( 'nav-menus.php' ) ); ?>"><?php _e( 'Cancel' ); ?></a>
1094                                  </span><!-- END .cancel-action -->
1095                                  <?php else : ?>
1096                                  <span class="delete-action">
1097                                      <a class="submitdelete deletion menu-delete" href="
1098                                      <?php
1099                                      echo esc_url(
1100                                          wp_nonce_url(
1101                                              add_query_arg(
1102                                                  array(
1103                                                      'action' => 'delete',
1104                                                      'menu' => $nav_menu_selected_id,
1105                                                  ),
1106                                                  admin_url( 'nav-menus.php' )
1107                                              ),
1108                                              'delete-nav_menu-' . $nav_menu_selected_id
1109                                          )
1110                                      );
1111                                      ?>
1112                                      "><?php _e( 'Delete Menu' ); ?></a>
1113                                  </span><!-- END .delete-action -->
1114                                  <?php endif; ?>
1115  
1116                              <?php endif; ?>
1117                              <div class="publishing-action">
1118                                  <?php submit_button( empty( $nav_menu_selected_id ) ? __( 'Create Menu' ) : __( 'Save Menu' ), 'primary large menu-save', 'save_menu', false, array( 'id' => 'save_menu_footer' ) ); ?>
1119                              </div><!-- END .publishing-action -->
1120                          </div><!-- END .major-publishing-actions -->
1121                      </div><!-- /#nav-menu-footer -->
1122                  </div><!-- /.menu-edit -->
1123              </form><!-- /#update-nav-menu -->
1124          </div><!-- /#menu-management -->
1125      </div><!-- /#menu-management-liquid -->
1126      </div><!-- /#nav-menus-frame -->
1127      <?php endif; ?>
1128  </div><!-- /.wrap-->
1129  <?php require_once ABSPATH . 'wp-admin/admin-footer.php'; ?>


Generated: Mon Aug 2 01:00:04 2021 Cross-referenced by PHPXref 0.7.1