[ 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          $new_menu_locations = array();
 320          if ( isset( $_POST['menu-locations'] ) ) {
 321              $new_menu_locations = array_map( 'absint', $_POST['menu-locations'] );
 322              $menu_locations     = array_merge( $menu_locations, $new_menu_locations );
 323          }
 324  
 325          // Add Menu.
 326          if ( 0 === $nav_menu_selected_id ) {
 327              $new_menu_title = trim( esc_html( $_POST['menu-name'] ) );
 328  
 329              if ( $new_menu_title ) {
 330                  $_nav_menu_selected_id = wp_update_nav_menu_object( 0, array( 'menu-name' => $new_menu_title ) );
 331  
 332                  if ( is_wp_error( $_nav_menu_selected_id ) ) {
 333                      $messages[] = '<div id="message" class="error notice is-dismissible"><p>' . $_nav_menu_selected_id->get_error_message() . '</p></div>';
 334                  } else {
 335                      $_menu_object            = wp_get_nav_menu_object( $_nav_menu_selected_id );
 336                      $nav_menu_selected_id    = $_nav_menu_selected_id;
 337                      $nav_menu_selected_title = $_menu_object->name;
 338  
 339                      if ( isset( $_REQUEST['menu-item'] ) ) {
 340                          wp_save_nav_menu_items( $nav_menu_selected_id, absint( $_REQUEST['menu-item'] ) );
 341                      }
 342  
 343                      if ( isset( $_REQUEST['zero-menu-state'] ) || ! empty( $_POST['auto-add-pages'] ) ) {
 344                          // If there are menu items, add them.
 345                          wp_nav_menu_update_menu_items( $nav_menu_selected_id, $nav_menu_selected_title );
 346                      }
 347  
 348                      if ( isset( $_REQUEST['zero-menu-state'] ) ) {
 349                          // Auto-save nav_menu_locations.
 350                          $locations = get_nav_menu_locations();
 351  
 352                          foreach ( $locations as $location => $menu_id ) {
 353                                  $locations[ $location ] = $nav_menu_selected_id;
 354                                  break; // There should only be 1.
 355                          }
 356  
 357                          set_theme_mod( 'nav_menu_locations', $locations );
 358                      } elseif ( count( $new_menu_locations ) > 0 ) {
 359                          // If locations have been selected for the new menu, save those.
 360                          $locations = get_nav_menu_locations();
 361  
 362                          foreach ( array_keys( $new_menu_locations ) as $location ) {
 363                              $locations[ $location ] = $nav_menu_selected_id;
 364                          }
 365  
 366                          set_theme_mod( 'nav_menu_locations', $locations );
 367                      }
 368  
 369                      if ( isset( $_REQUEST['use-location'] ) ) {
 370                          $locations      = get_registered_nav_menus();
 371                          $menu_locations = get_nav_menu_locations();
 372  
 373                          if ( isset( $locations[ $_REQUEST['use-location'] ] ) ) {
 374                              $menu_locations[ $_REQUEST['use-location'] ] = $nav_menu_selected_id;
 375                          }
 376  
 377                          set_theme_mod( 'nav_menu_locations', $menu_locations );
 378                      }
 379  
 380                      wp_redirect( admin_url( 'nav-menus.php?menu=' . $_nav_menu_selected_id ) );
 381                      exit;
 382                  }
 383              } else {
 384                  $messages[] = '<div id="message" class="error notice is-dismissible"><p>' . __( 'Please enter a valid menu name.' ) . '</p></div>';
 385              }
 386  
 387              // Update existing menu.
 388          } else {
 389              // Remove menu locations that have been unchecked.
 390              foreach ( $locations as $location => $description ) {
 391                  if ( ( empty( $_POST['menu-locations'] ) || empty( $_POST['menu-locations'][ $location ] ) )
 392                      && isset( $menu_locations[ $location ] ) && $menu_locations[ $location ] === $nav_menu_selected_id
 393                  ) {
 394                      unset( $menu_locations[ $location ] );
 395                  }
 396              }
 397  
 398              // Set menu locations.
 399              set_theme_mod( 'nav_menu_locations', $menu_locations );
 400  
 401              $_menu_object = wp_get_nav_menu_object( $nav_menu_selected_id );
 402  
 403              $menu_title = trim( esc_html( $_POST['menu-name'] ) );
 404  
 405              if ( ! $menu_title ) {
 406                  $messages[] = '<div id="message" class="error notice is-dismissible"><p>' . __( 'Please enter a valid menu name.' ) . '</p></div>';
 407                  $menu_title = $_menu_object->name;
 408              }
 409  
 410              if ( ! is_wp_error( $_menu_object ) ) {
 411                  $_nav_menu_selected_id = wp_update_nav_menu_object( $nav_menu_selected_id, array( 'menu-name' => $menu_title ) );
 412  
 413                  if ( is_wp_error( $_nav_menu_selected_id ) ) {
 414                      $_menu_object = $_nav_menu_selected_id;
 415                      $messages[]   = '<div id="message" class="error notice is-dismissible"><p>' . $_nav_menu_selected_id->get_error_message() . '</p></div>';
 416                  } else {
 417                      $_menu_object            = wp_get_nav_menu_object( $_nav_menu_selected_id );
 418                      $nav_menu_selected_title = $_menu_object->name;
 419                  }
 420              }
 421  
 422              // Update menu items.
 423              if ( ! is_wp_error( $_menu_object ) ) {
 424                  $messages = array_merge( $messages, wp_nav_menu_update_menu_items( $_nav_menu_selected_id, $nav_menu_selected_title ) );
 425  
 426                  // If the menu ID changed, redirect to the new URL.
 427                  if ( $nav_menu_selected_id !== $_nav_menu_selected_id ) {
 428                      wp_redirect( admin_url( 'nav-menus.php?menu=' . (int) $_nav_menu_selected_id ) );
 429                      exit;
 430                  }
 431              }
 432          }
 433  
 434          break;
 435  
 436      case 'locations':
 437          if ( ! $num_locations ) {
 438              wp_redirect( admin_url( 'nav-menus.php' ) );
 439              exit;
 440          }
 441  
 442          add_filter( 'screen_options_show_screen', '__return_false' );
 443  
 444          if ( isset( $_POST['menu-locations'] ) ) {
 445              check_admin_referer( 'save-menu-locations' );
 446  
 447              $new_menu_locations = array_map( 'absint', $_POST['menu-locations'] );
 448              $menu_locations     = array_merge( $menu_locations, $new_menu_locations );
 449              // Set menu locations.
 450              set_theme_mod( 'nav_menu_locations', $menu_locations );
 451  
 452              $messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . __( 'Menu locations updated.' ) . '</p></div>';
 453          }
 454  
 455          break;
 456  }
 457  
 458  // Get all nav menus.
 459  $nav_menus  = wp_get_nav_menus();
 460  $menu_count = count( $nav_menus );
 461  
 462  // Are we on the add new screen?
 463  $add_new_screen = ( isset( $_GET['menu'] ) && 0 === (int) $_GET['menu'] ) ? true : false;
 464  
 465  $locations_screen = ( isset( $_GET['action'] ) && 'locations' === $_GET['action'] ) ? true : false;
 466  
 467  $page_count = wp_count_posts( 'page' );
 468  
 469  /*
 470   * If we have one theme location, and zero menus, we take them right
 471   * into editing their first menu.
 472   */
 473  if ( 1 === count( get_registered_nav_menus() ) && ! $add_new_screen
 474      && empty( $nav_menus ) && ! empty( $page_count->publish )
 475  ) {
 476      $one_theme_location_no_menus = true;
 477  } else {
 478      $one_theme_location_no_menus = false;
 479  }
 480  
 481  $nav_menus_l10n = array(
 482      'oneThemeLocationNoMenus' => $one_theme_location_no_menus,
 483      'moveUp'                  => __( 'Move up one' ),
 484      'moveDown'                => __( 'Move down one' ),
 485      'moveToTop'               => __( 'Move to the top' ),
 486      /* translators: %s: Previous item name. */
 487      'moveUnder'               => __( 'Move under %s' ),
 488      /* translators: %s: Previous item name. */
 489      'moveOutFrom'             => __( 'Move out from under %s' ),
 490      /* translators: %s: Previous item name. */
 491      'under'                   => __( 'Under %s' ),
 492      /* translators: %s: Previous item name. */
 493      'outFrom'                 => __( 'Out from under %s' ),
 494      /* translators: 1: Item name, 2: Item position, 3: Total number of items. */
 495      'menuFocus'               => __( '%1$s. Menu item %2$d of %3$d.' ),
 496      /* translators: 1: Item name, 2: Item position, 3: Parent item name. */
 497      'subMenuFocus'            => __( '%1$s. Sub item number %2$d under %3$s.' ),
 498      /* translators: %s: Item name. */
 499      'menuItemDeletion'        => __( 'item %s' ),
 500      /* translators: %s: Item name. */
 501      'itemsDeleted'            => __( 'Deleted menu item: %s.' ),
 502      'itemAdded'               => __( 'Menu item added' ),
 503      'itemRemoved'             => __( 'Menu item removed' ),
 504      'movedUp'                 => __( 'Menu item moved up' ),
 505      'movedDown'               => __( 'Menu item moved down' ),
 506      'movedTop'                => __( 'Menu item moved to the top' ),
 507      'movedLeft'               => __( 'Menu item moved out of submenu' ),
 508      'movedRight'              => __( 'Menu item is now a sub-item' ),
 509  );
 510  wp_localize_script( 'nav-menu', 'menus', $nav_menus_l10n );
 511  
 512  /*
 513   * Redirect to add screen if there are no menus and this users has either zero,
 514   * or more than 1 theme locations.
 515   */
 516  if ( 0 === $menu_count && ! $add_new_screen && ! $one_theme_location_no_menus ) {
 517      wp_redirect( admin_url( 'nav-menus.php?action=edit&menu=0' ) );
 518  }
 519  
 520  // Get recently edited nav menu.
 521  $recently_edited = absint( get_user_option( 'nav_menu_recently_edited' ) );
 522  if ( empty( $recently_edited ) && is_nav_menu( $nav_menu_selected_id ) ) {
 523      $recently_edited = $nav_menu_selected_id;
 524  }
 525  
 526  // Use $recently_edited if none are selected.
 527  if ( empty( $nav_menu_selected_id ) && ! isset( $_GET['menu'] ) && is_nav_menu( $recently_edited ) ) {
 528      $nav_menu_selected_id = $recently_edited;
 529  }
 530  
 531  // On deletion of menu, if another menu exists, show it.
 532  if ( ! $add_new_screen && $menu_count > 0 && isset( $_GET['action'] ) && 'delete' === $_GET['action'] ) {
 533      $nav_menu_selected_id = $nav_menus[0]->term_id;
 534  }
 535  
 536  // Set $nav_menu_selected_id to 0 if no menus.
 537  if ( $one_theme_location_no_menus ) {
 538      $nav_menu_selected_id = 0;
 539  } elseif ( empty( $nav_menu_selected_id ) && ! empty( $nav_menus ) && ! $add_new_screen ) {
 540      // If we have no selection yet, and we have menus, set to the first one in the list.
 541      $nav_menu_selected_id = $nav_menus[0]->term_id;
 542  }
 543  
 544  // Update the user's setting.
 545  if ( $nav_menu_selected_id !== $recently_edited && is_nav_menu( $nav_menu_selected_id ) ) {
 546      update_user_meta( $current_user->ID, 'nav_menu_recently_edited', $nav_menu_selected_id );
 547  }
 548  
 549  // If there's a menu, get its name.
 550  if ( ! $nav_menu_selected_title && is_nav_menu( $nav_menu_selected_id ) ) {
 551      $_menu_object            = wp_get_nav_menu_object( $nav_menu_selected_id );
 552      $nav_menu_selected_title = ! is_wp_error( $_menu_object ) ? $_menu_object->name : '';
 553  }
 554  
 555  // Generate truncated menu names.
 556  foreach ( (array) $nav_menus as $key => $_nav_menu ) {
 557      $nav_menus[ $key ]->truncated_name = wp_html_excerpt( $_nav_menu->name, 40, '&hellip;' );
 558  }
 559  
 560  // Retrieve menu locations.
 561  if ( current_theme_supports( 'menus' ) ) {
 562      $locations      = get_registered_nav_menus();
 563      $menu_locations = get_nav_menu_locations();
 564  }
 565  
 566  /*
 567   * Ensure the user will be able to scroll horizontally
 568   * by adding a class for the max menu depth.
 569   *
 570   * @global int $_wp_nav_menu_max_depth
 571   */
 572  global $_wp_nav_menu_max_depth;
 573  $_wp_nav_menu_max_depth = 0;
 574  
 575  // Calling wp_get_nav_menu_to_edit generates $_wp_nav_menu_max_depth.
 576  if ( is_nav_menu( $nav_menu_selected_id ) ) {
 577      $menu_items  = wp_get_nav_menu_items( $nav_menu_selected_id, array( 'post_status' => 'any' ) );
 578      $edit_markup = wp_get_nav_menu_to_edit( $nav_menu_selected_id );
 579  }
 580  
 581  /**
 582   * @global int $_wp_nav_menu_max_depth
 583   *
 584   * @param string $classes
 585   * @return string
 586   */
 587  function wp_nav_menu_max_depth( $classes ) {
 588      global $_wp_nav_menu_max_depth;
 589      return "$classes menu-max-depth-$_wp_nav_menu_max_depth";
 590  }
 591  
 592  add_filter( 'admin_body_class', 'wp_nav_menu_max_depth' );
 593  
 594  wp_nav_menu_setup();
 595  wp_initial_nav_menu_meta_boxes();
 596  
 597  if ( ! current_theme_supports( 'menus' ) && ! $num_locations ) {
 598      $messages[] = '<div id="message" class="updated"><p>' . sprintf(
 599          /* translators: %s: URL to Widgets screen. */
 600          __( '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.' ),
 601          admin_url( 'widgets.php' )
 602      ) . '</p></div>';
 603  }
 604  
 605  if ( ! $locations_screen ) : // Main tab.
 606      $overview  = '<p>' . __( 'This screen is used for managing your navigation menus.' ) . '</p>';
 607      $overview .= '<p>' . sprintf(
 608          /* translators: 1: URL to Widgets screen, 2 and 3: The names of the default themes. */
 609          __( '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.' ),
 610          admin_url( 'widgets.php' ),
 611          'Twenty Twenty',
 612          'Twenty Twenty-One'
 613      ) . '</p>';
 614      $overview .= '<p>' . __( 'From this screen you can:' ) . '</p>';
 615      $overview .= '<ul><li>' . __( 'Create, edit, and delete menus' ) . '</li>';
 616      $overview .= '<li>' . __( 'Add, organize, and modify individual menu items' ) . '</li></ul>';
 617  
 618      get_current_screen()->add_help_tab(
 619          array(
 620              'id'      => 'overview',
 621              'title'   => __( 'Overview' ),
 622              'content' => $overview,
 623          )
 624      );
 625  
 626      $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>';
 627      $menu_management .= '<ul><li>' . __( 'To edit an existing menu, <strong>choose a menu from the drop down and click Select</strong>' ) . '</li>';
 628      $menu_management .= '<li>' . __( 'If you have not yet created any menus, <strong>click the &#8217;create a new menu&#8217; link</strong> to get started' ) . '</li></ul>';
 629      $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>';
 630  
 631      get_current_screen()->add_help_tab(
 632          array(
 633              'id'      => 'menu-management',
 634              'title'   => __( 'Menu Management' ),
 635              'content' => $menu_management,
 636          )
 637      );
 638  
 639      $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>';
 640      $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>';
 641      $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>';
 642      $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>';
 643      $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>';
 644      $editing_menus .= '<li>' . __( 'Delete a menu item by <strong>expanding it and clicking the Remove link</strong>' ) . '</li></ul>';
 645  
 646      get_current_screen()->add_help_tab(
 647          array(
 648              'id'      => 'editing-menus',
 649              'title'   => __( 'Editing Menus' ),
 650              'content' => $editing_menus,
 651          )
 652      );
 653  else : // Locations tab.
 654      $locations_overview  = '<p>' . __( 'This screen is used for globally assigning menus to locations defined by your theme.' ) . '</p>';
 655      $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 are finished, <strong>click Save Changes</strong>' ) . '</li>';
 656      $locations_overview .= '<li>' . __( 'To edit a menu currently assigned to a theme location, <strong>click the adjacent &#8217;Edit&#8217; link</strong>' ) . '</li>';
 657      $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>';
 658  
 659      get_current_screen()->add_help_tab(
 660          array(
 661              'id'      => 'locations-overview',
 662              'title'   => __( 'Overview' ),
 663              'content' => $locations_overview,
 664          )
 665      );
 666  endif;
 667  
 668  get_current_screen()->set_help_sidebar(
 669      '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
 670      '<p>' . __( '<a href="https://wordpress.org/support/article/appearance-menus-screen/">Documentation on Menus</a>' ) . '</p>' .
 671      '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
 672  );
 673  
 674  // Get the admin header.
 675  require_once ABSPATH . 'wp-admin/admin-header.php';
 676  ?>
 677  <div class="wrap">
 678      <h1 class="wp-heading-inline"><?php esc_html_e( 'Menus' ); ?></h1>
 679      <?php
 680      if ( current_user_can( 'customize' ) ) :
 681          $focus = $locations_screen ? array( 'section' => 'menu_locations' ) : array( 'panel' => 'nav_menus' );
 682          printf(
 683              ' <a class="page-title-action hide-if-no-customize" href="%1$s">%2$s</a>',
 684              esc_url(
 685                  add_query_arg(
 686                      array(
 687                          array( 'autofocus' => $focus ),
 688                          'return' => urlencode( remove_query_arg( wp_removable_query_args(), wp_unslash( $_SERVER['REQUEST_URI'] ) ) ),
 689                      ),
 690                      admin_url( 'customize.php' )
 691                  )
 692              ),
 693              __( 'Manage with Live Preview' )
 694          );
 695      endif;
 696  
 697      $nav_tab_active_class = '';
 698      $nav_aria_current     = '';
 699  
 700      if ( ! isset( $_GET['action'] ) || isset( $_GET['action'] ) && 'locations' !== $_GET['action'] ) {
 701          $nav_tab_active_class = ' nav-tab-active';
 702          $nav_aria_current     = ' aria-current="page"';
 703      }
 704      ?>
 705  
 706      <hr class="wp-header-end">
 707  
 708      <nav class="nav-tab-wrapper wp-clearfix" aria-label="<?php esc_attr_e( 'Secondary menu' ); ?>">
 709          <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>
 710          <?php
 711          if ( $num_locations && $menu_count ) {
 712              $active_tab_class = '';
 713              $aria_current     = '';
 714  
 715              if ( $locations_screen ) {
 716                  $active_tab_class = ' nav-tab-active';
 717                  $aria_current     = ' aria-current="page"';
 718              }
 719              ?>
 720              <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>
 721              <?php
 722          }
 723          ?>
 724      </nav>
 725      <?php
 726      foreach ( $messages as $message ) :
 727          echo $message . "\n";
 728      endforeach;
 729      ?>
 730      <?php
 731      if ( $locations_screen ) :
 732          if ( 1 === $num_locations ) {
 733              echo '<p>' . __( 'Your theme supports one menu. Select which menu you would like to use.' ) . '</p>';
 734          } else {
 735              echo '<p>' . sprintf(
 736                  /* translators: %s: Number of menus. */
 737                  _n(
 738                      'Your theme supports %s menu. Select which menu appears in each location.',
 739                      'Your theme supports %s menus. Select which menu appears in each location.',
 740                      $num_locations
 741                  ),
 742                  number_format_i18n( $num_locations )
 743              ) . '</p>';
 744          }
 745          ?>
 746      <div id="menu-locations-wrap">
 747          <form method="post" action="<?php echo esc_url( add_query_arg( array( 'action' => 'locations' ), admin_url( 'nav-menus.php' ) ) ); ?>">
 748              <table class="widefat fixed" id="menu-locations-table">
 749                  <thead>
 750                  <tr>
 751                      <th scope="col" class="manage-column column-locations"><?php _e( 'Theme Location' ); ?></th>
 752                      <th scope="col" class="manage-column column-menus"><?php _e( 'Assigned Menu' ); ?></th>
 753                  </tr>
 754                  </thead>
 755                  <tbody class="menu-locations">
 756                  <?php foreach ( $locations as $_location => $_name ) { ?>
 757                      <tr class="menu-locations-row">
 758                          <td class="menu-location-title"><label for="locations-<?php echo $_location; ?>"><?php echo $_name; ?></label></td>
 759                          <td class="menu-location-menus">
 760                              <select name="menu-locations[<?php echo $_location; ?>]" id="locations-<?php echo $_location; ?>">
 761                                  <option value="0"><?php printf( '&mdash; %s &mdash;', esc_html__( 'Select a Menu' ) ); ?></option>
 762                                  <?php
 763                                  foreach ( $nav_menus as $menu ) :
 764                                      $data_orig = '';
 765                                      $selected  = isset( $menu_locations[ $_location ] ) && $menu_locations[ $_location ] === $menu->term_id;
 766  
 767                                      if ( $selected ) {
 768                                          $data_orig = 'data-orig="true"';
 769                                      }
 770                                      ?>
 771                                      <option <?php echo $data_orig; ?> <?php selected( $selected ); ?> value="<?php echo $menu->term_id; ?>">
 772                                          <?php echo wp_html_excerpt( $menu->name, 40, '&hellip;' ); ?>
 773                                      </option>
 774                                  <?php endforeach; ?>
 775                              </select>
 776                              <div class="locations-row-links">
 777                                  <?php if ( isset( $menu_locations[ $_location ] ) && 0 !== $menu_locations[ $_location ] ) : ?>
 778                                  <span class="locations-edit-menu-link">
 779                                      <a href="
 780                                      <?php
 781                                      echo esc_url(
 782                                          add_query_arg(
 783                                              array(
 784                                                  'action' => 'edit',
 785                                                  'menu'   => $menu_locations[ $_location ],
 786                                              ),
 787                                              admin_url( 'nav-menus.php' )
 788                                          )
 789                                      );
 790                                      ?>
 791                                      ">
 792                                          <span aria-hidden="true"><?php _ex( 'Edit', 'menu' ); ?></span><span class="screen-reader-text"><?php _e( 'Edit selected menu' ); ?></span>
 793                                      </a>
 794                                  </span>
 795                                  <?php endif; ?>
 796                                  <span class="locations-add-menu-link">
 797                                      <a href="
 798                                      <?php
 799                                      echo esc_url(
 800                                          add_query_arg(
 801                                              array(
 802                                                  'action' => 'edit',
 803                                                  'menu'   => 0,
 804                                                  'use-location' => $_location,
 805                                              ),
 806                                              admin_url( 'nav-menus.php' )
 807                                          )
 808                                      );
 809                                      ?>
 810                                      ">
 811                                          <?php _ex( 'Use new menu', 'menu' ); ?>
 812                                      </a>
 813                                  </span>
 814                              </div><!-- .locations-row-links -->
 815                          </td><!-- .menu-location-menus -->
 816                      </tr><!-- .menu-locations-row -->
 817                  <?php } // End foreach. ?>
 818                  </tbody>
 819              </table>
 820              <p class="button-controls wp-clearfix"><?php submit_button( __( 'Save Changes' ), 'primary left', 'nav-menu-locations', false ); ?></p>
 821              <?php wp_nonce_field( 'save-menu-locations' ); ?>
 822              <input type="hidden" name="menu" id="nav-menu-meta-object-id" value="<?php echo esc_attr( $nav_menu_selected_id ); ?>" />
 823          </form>
 824      </div><!-- #menu-locations-wrap -->
 825          <?php
 826          /**
 827           * Fires after the menu locations table is displayed.
 828           *
 829           * @since 3.6.0
 830           */
 831          do_action( 'after_menu_locations_table' );
 832          ?>
 833      <?php else : ?>
 834      <div class="manage-menus">
 835          <?php if ( $menu_count < 1 ) : ?>
 836          <span class="first-menu-message">
 837              <?php _e( 'Create your first menu below.' ); ?>
 838              <span class="screen-reader-text"><?php _e( 'Fill in the Menu Name and click the Create Menu button to create your first menu.' ); ?></span>
 839          </span><!-- /first-menu-message -->
 840          <?php elseif ( $menu_count < 2 ) : ?>
 841          <span class="add-edit-menu-action">
 842              <?php
 843              printf(
 844                  /* translators: %s: URL to create a new menu. */
 845                  __( 'Edit your menu below, or <a href="%s">create a new menu</a>. Do not forget to save your changes!' ),
 846                  esc_url(
 847                      add_query_arg(
 848                          array(
 849                              'action' => 'edit',
 850                              'menu'   => 0,
 851                          ),
 852                          admin_url( 'nav-menus.php' )
 853                      )
 854                  )
 855              );
 856              ?>
 857              <span class="screen-reader-text"><?php _e( 'Click the Save Menu button to save your changes.' ); ?></span>
 858          </span><!-- /add-edit-menu-action -->
 859          <?php else : ?>
 860              <form method="get" action="<?php echo esc_url( admin_url( 'nav-menus.php' ) ); ?>">
 861              <input type="hidden" name="action" value="edit" />
 862              <label for="select-menu-to-edit" class="selected-menu"><?php _e( 'Select a menu to edit:' ); ?></label>
 863              <select name="menu" id="select-menu-to-edit">
 864                  <?php if ( $add_new_screen ) : ?>
 865                      <option value="0" selected="selected"><?php _e( '&mdash; Select &mdash;' ); ?></option>
 866                  <?php endif; ?>
 867                  <?php foreach ( (array) $nav_menus as $_nav_menu ) : ?>
 868                      <option value="<?php echo esc_attr( $_nav_menu->term_id ); ?>" <?php selected( $_nav_menu->term_id, $nav_menu_selected_id ); ?>>
 869                          <?php
 870                          echo esc_html( $_nav_menu->truncated_name );
 871  
 872                          if ( ! empty( $menu_locations ) && in_array( $_nav_menu->term_id, $menu_locations, true ) ) {
 873                              $locations_assigned_to_this_menu = array();
 874  
 875                              foreach ( array_keys( $menu_locations, $_nav_menu->term_id, true ) as $menu_location_key ) {
 876                                  if ( isset( $locations[ $menu_location_key ] ) ) {
 877                                      $locations_assigned_to_this_menu[] = $locations[ $menu_location_key ];
 878                                  }
 879                              }
 880  
 881                              /**
 882                               * Filters the number of locations listed per menu in the drop-down select.
 883                               *
 884                               * @since 3.6.0
 885                               *
 886                               * @param int $locations Number of menu locations to list. Default 3.
 887                               */
 888                              $locations_listed_per_menu = absint( apply_filters( 'wp_nav_locations_listed_per_menu', 3 ) );
 889  
 890                              $assigned_locations = array_slice( $locations_assigned_to_this_menu, 0, $locations_listed_per_menu );
 891  
 892                              // Adds ellipses following the number of locations defined in $assigned_locations.
 893                              if ( ! empty( $assigned_locations ) ) {
 894                                  printf(
 895                                      ' (%1$s%2$s)',
 896                                      implode( ', ', $assigned_locations ),
 897                                      count( $locations_assigned_to_this_menu ) > count( $assigned_locations ) ? ' &hellip;' : ''
 898                                  );
 899                              }
 900                          }
 901                          ?>
 902                      </option>
 903                  <?php endforeach; ?>
 904              </select>
 905              <span class="submit-btn"><input type="submit" class="button" value="<?php esc_attr_e( 'Select' ); ?>"></span>
 906              <span class="add-new-menu-action">
 907                  <?php
 908                  printf(
 909                      /* translators: %s: URL to create a new menu. */
 910                      __( 'or <a href="%s">create a new menu</a>. Do not forget to save your changes!' ),
 911                      esc_url(
 912                          add_query_arg(
 913                              array(
 914                                  'action' => 'edit',
 915                                  'menu'   => 0,
 916                              ),
 917                              admin_url( 'nav-menus.php' )
 918                          )
 919                      )
 920                  );
 921                  ?>
 922                  <span class="screen-reader-text"><?php _e( 'Click the Save Menu button to save your changes.' ); ?></span>
 923              </span><!-- /add-new-menu-action -->
 924          </form>
 925              <?php
 926          endif;
 927  
 928          $metabox_holder_disabled_class = '';
 929  
 930          if ( isset( $_GET['menu'] ) && 0 === (int) $_GET['menu'] ) {
 931              $metabox_holder_disabled_class = ' metabox-holder-disabled';
 932          }
 933          ?>
 934      </div><!-- /manage-menus -->
 935      <div id="nav-menus-frame" class="wp-clearfix">
 936      <div id="menu-settings-column" class="metabox-holder<?php echo $metabox_holder_disabled_class; ?>">
 937  
 938          <div class="clear"></div>
 939  
 940          <form id="nav-menu-meta" class="nav-menu-meta" method="post" enctype="multipart/form-data">
 941              <input type="hidden" name="menu" id="nav-menu-meta-object-id" value="<?php echo esc_attr( $nav_menu_selected_id ); ?>" />
 942              <input type="hidden" name="action" value="add-menu-item" />
 943              <?php wp_nonce_field( 'add-menu_item', 'menu-settings-column-nonce' ); ?>
 944              <h2><?php _e( 'Add menu items' ); ?></h2>
 945              <?php do_accordion_sections( 'nav-menus', 'side', null ); ?>
 946          </form>
 947  
 948      </div><!-- /#menu-settings-column -->
 949      <div id="menu-management-liquid">
 950          <div id="menu-management">
 951              <form id="update-nav-menu" method="post" enctype="multipart/form-data">
 952                  <h2><?php _e( 'Menu structure' ); ?></h2>
 953                  <div class="menu-edit">
 954                      <input type="hidden" name="nav-menu-data">
 955                      <?php
 956                      wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
 957                      wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
 958                      wp_nonce_field( 'update-nav_menu', 'update-nav-menu-nonce' );
 959  
 960                      $menu_name_aria_desc = $add_new_screen ? ' aria-describedby="menu-name-desc"' : '';
 961  
 962                      if ( $one_theme_location_no_menus ) {
 963                          $menu_name_val = 'value="' . esc_attr( 'Menu 1' ) . '"';
 964                          ?>
 965                          <input type="hidden" name="zero-menu-state" value="true" />
 966                          <?php
 967                      } else {
 968                          $menu_name_val = 'value="' . esc_attr( $nav_menu_selected_title ) . '"';
 969                      }
 970                      ?>
 971                      <input type="hidden" name="action" value="update" />
 972                      <input type="hidden" name="menu" id="menu" value="<?php echo esc_attr( $nav_menu_selected_id ); ?>" />
 973                      <div id="nav-menu-header">
 974                          <div class="major-publishing-actions wp-clearfix">
 975                              <label class="menu-name-label" for="menu-name"><?php _e( 'Menu Name' ); ?></label>
 976                              <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; ?> />
 977                              <div class="publishing-action">
 978                                  <?php submit_button( empty( $nav_menu_selected_id ) ? __( 'Create Menu' ) : __( 'Save Menu' ), 'primary large menu-save', 'save_menu', false, array( 'id' => 'save_menu_header' ) ); ?>
 979                              </div><!-- END .publishing-action -->
 980                          </div><!-- END .major-publishing-actions -->
 981                      </div><!-- END .nav-menu-header -->
 982                      <div id="post-body">
 983                          <div id="post-body-content" class="wp-clearfix">
 984                              <?php if ( ! $add_new_screen ) : ?>
 985                                  <?php
 986                                  $hide_style = '';
 987  
 988                                  if ( isset( $menu_items ) && 0 === count( $menu_items ) ) {
 989                                      $hide_style = 'style="display: none;"';
 990                                  }
 991  
 992                                  if ( $one_theme_location_no_menus ) {
 993                                      $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.' );
 994                                  } else {
 995                                      $starter_copy = __( 'Drag the items into the order you prefer. Click the arrow on the right of the item to reveal additional configuration options.' );
 996                                  }
 997                                  ?>
 998                                  <div class="drag-instructions post-body-plain" <?php echo $hide_style; ?>>
 999                                      <p><?php echo $starter_copy; ?></p>
1000                                  </div>
1001  
1002                                  <?php if ( ! $add_new_screen ) : ?>
1003                                      <div id="nav-menu-bulk-actions-top" class="bulk-actions">
1004                                          <label class="bulk-select-button" for="bulk-select-switcher-top">
1005                                              <input type="checkbox" id="bulk-select-switcher-top" name="bulk-select-switcher-top" class="bulk-select-switcher">
1006                                              <span class="bulk-select-button-label"><?php _e( 'Bulk Select' ); ?></span>
1007                                          </label>
1008                                      </div>
1009                                  <?php endif; ?>
1010  
1011                                  <?php
1012                                  if ( isset( $edit_markup ) && ! is_wp_error( $edit_markup ) ) {
1013                                      echo $edit_markup;
1014                                  } else {
1015                                      ?>
1016                                      <ul class="menu" id="menu-to-edit"></ul>
1017                                  <?php } ?>
1018  
1019                              <?php endif; ?>
1020  
1021                              <?php if ( $add_new_screen ) : ?>
1022                                  <p class="post-body-plain" id="menu-name-desc"><?php _e( 'Give your menu a name, then click Create Menu.' ); ?></p>
1023                                  <?php if ( isset( $_GET['use-location'] ) ) : ?>
1024                                      <input type="hidden" name="use-location" value="<?php echo esc_attr( $_GET['use-location'] ); ?>" />
1025                                  <?php endif; ?>
1026  
1027                                  <?php
1028                              endif;
1029  
1030                              $no_menus_style = '';
1031  
1032                              if ( $one_theme_location_no_menus ) {
1033                                  $no_menus_style = 'style="display: none;"';
1034                              }
1035                              ?>
1036  
1037                              <?php if ( ! $add_new_screen ) : ?>
1038                                  <div id="nav-menu-bulk-actions-bottom" class="bulk-actions">
1039                                      <label class="bulk-select-button" for="bulk-select-switcher-bottom">
1040                                          <input type="checkbox" id="bulk-select-switcher-bottom" name="bulk-select-switcher-top" class="bulk-select-switcher">
1041                                          <span class="bulk-select-button-label"><?php _e( 'Bulk Select' ); ?></span>
1042                                      </label>
1043                                      <input type="button" class="deletion menu-items-delete disabled" value="<?php _e( 'Remove Selected Items' ); ?>">
1044                                      <div id="pending-menu-items-to-delete">
1045                                          <p><?php _e( 'List of menu items selected for deletion:' ); ?></p>
1046                                          <ul></ul>
1047                                      </div>
1048                                  </div>
1049                              <?php endif; ?>
1050  
1051                              <div class="menu-settings" <?php echo $no_menus_style; ?>>
1052                                  <h3><?php _e( 'Menu Settings' ); ?></h3>
1053                                  <?php
1054                                  if ( ! isset( $auto_add ) ) {
1055                                      $auto_add = get_option( 'nav_menu_options' );
1056  
1057                                      if ( ! isset( $auto_add['auto_add'] ) ) {
1058                                          $auto_add = false;
1059                                      } elseif ( false !== array_search( $nav_menu_selected_id, $auto_add['auto_add'], true ) ) {
1060                                          $auto_add = true;
1061                                      } else {
1062                                          $auto_add = false;
1063                                      }
1064                                  }
1065                                  ?>
1066  
1067                                  <fieldset class="menu-settings-group auto-add-pages">
1068                                      <legend class="menu-settings-group-name howto"><?php _e( 'Auto add pages' ); ?></legend>
1069                                      <div class="menu-settings-input checkbox-input">
1070                                          <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>
1071                                      </div>
1072                                  </fieldset>
1073  
1074                                  <?php if ( current_theme_supports( 'menus' ) ) : ?>
1075  
1076                                      <fieldset class="menu-settings-group menu-theme-locations">
1077                                          <legend class="menu-settings-group-name howto"><?php _e( 'Display location' ); ?></legend>
1078                                          <?php
1079                                          foreach ( $locations as $location => $description ) :
1080                                              $checked = false;
1081  
1082                                              if ( isset( $menu_locations[ $location ] )
1083                                                      && 0 !== $nav_menu_selected_id
1084                                                      && $menu_locations[ $location ] === $nav_menu_selected_id
1085                                              ) {
1086                                                      $checked = true;
1087                                              }
1088                                              ?>
1089                                              <div class="menu-settings-input checkbox-input">
1090                                                  <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 ); ?>" />
1091                                                  <label for="locations-<?php echo esc_attr( $location ); ?>"><?php echo $description; ?></label>
1092                                                  <?php if ( ! empty( $menu_locations[ $location ] ) && $menu_locations[ $location ] !== $nav_menu_selected_id ) : ?>
1093                                                      <span class="theme-location-set">
1094                                                      <?php
1095                                                          printf(
1096                                                              /* translators: %s: Menu name. */
1097                                                              _x( '(Currently set to: %s)', 'menu location' ),
1098                                                              wp_get_nav_menu_object( $menu_locations[ $location ] )->name
1099                                                          );
1100                                                      ?>
1101                                                      </span>
1102                                                  <?php endif; ?>
1103                                              </div>
1104                                          <?php endforeach; ?>
1105                                      </fieldset>
1106  
1107                                  <?php endif; ?>
1108  
1109                              </div>
1110                          </div><!-- /#post-body-content -->
1111                      </div><!-- /#post-body -->
1112                      <div id="nav-menu-footer">
1113                          <div class="major-publishing-actions wp-clearfix">
1114                              <?php if ( $menu_count > 0 ) : ?>
1115  
1116                                  <?php if ( $add_new_screen ) : ?>
1117                                  <span class="cancel-action">
1118                                      <a class="submitcancel cancellation menu-cancel" href="<?php echo esc_url( admin_url( 'nav-menus.php' ) ); ?>"><?php _e( 'Cancel' ); ?></a>
1119                                  </span><!-- END .cancel-action -->
1120                                  <?php else : ?>
1121                                  <span class="delete-action">
1122                                      <a class="submitdelete deletion menu-delete" href="
1123                                      <?php
1124                                      echo esc_url(
1125                                          wp_nonce_url(
1126                                              add_query_arg(
1127                                                  array(
1128                                                      'action' => 'delete',
1129                                                      'menu' => $nav_menu_selected_id,
1130                                                  ),
1131                                                  admin_url( 'nav-menus.php' )
1132                                              ),
1133                                              'delete-nav_menu-' . $nav_menu_selected_id
1134                                          )
1135                                      );
1136                                      ?>
1137                                      "><?php _e( 'Delete Menu' ); ?></a>
1138                                  </span><!-- END .delete-action -->
1139                                  <?php endif; ?>
1140  
1141                              <?php endif; ?>
1142                              <div class="publishing-action">
1143                                  <?php submit_button( empty( $nav_menu_selected_id ) ? __( 'Create Menu' ) : __( 'Save Menu' ), 'primary large menu-save', 'save_menu', false, array( 'id' => 'save_menu_footer' ) ); ?>
1144                              </div><!-- END .publishing-action -->
1145                          </div><!-- END .major-publishing-actions -->
1146                      </div><!-- /#nav-menu-footer -->
1147                  </div><!-- /.menu-edit -->
1148              </form><!-- /#update-nav-menu -->
1149          </div><!-- /#menu-management -->
1150      </div><!-- /#menu-management-liquid -->
1151      </div><!-- /#nav-menus-frame -->
1152      <?php endif; ?>
1153  </div><!-- /.wrap-->
1154  <?php require_once ABSPATH . 'wp-admin/admin-footer.php'; ?>


Generated: Wed May 25 01:00:02 2022 Cross-referenced by PHPXref 0.7.1