[ PHPXref.com ] [ Generated: Thu Aug 19 03:45:23 2010 ] [ WordPress 3.0.1 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

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 ( '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  // Permissions Check
  22  if ( ! current_user_can('edit_theme_options') )
  23      wp_die( __( 'Cheatin&#8217; uh?' ) );
  24  
  25  // Nav Menu CSS
  26  wp_admin_css( 'nav-menu' );
  27  
  28  // jQuery
  29  wp_enqueue_script( 'jquery' );
  30  wp_enqueue_script( 'jquery-ui-draggable' );
  31  wp_enqueue_script( 'jquery-ui-droppable' );
  32  wp_enqueue_script( 'jquery-ui-sortable' );
  33  
  34  // Nav Menu functions
  35  wp_enqueue_script( 'nav-menu' );
  36  
  37  // Metaboxes
  38  wp_enqueue_script( 'common' );
  39  wp_enqueue_script( 'wp-lists' );
  40  wp_enqueue_script( 'postbox' );
  41  
  42  // Container for any messages displayed to the user
  43  $messages = array();
  44  
  45  // Container that stores the name of the active menu
  46  $nav_menu_selected_title = '';
  47  
  48  // The menu id of the current menu being edited
  49  $nav_menu_selected_id = isset( $_REQUEST['menu'] ) ? (int) $_REQUEST['menu'] : 0;
  50  
  51  // Allowed actions: add, update, delete
  52  $action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : 'edit';
  53  
  54  switch ( $action ) {
  55      case 'add-menu-item':
  56          check_admin_referer( 'add-menu_item', 'menu-settings-column-nonce' );
  57          if ( isset( $_REQUEST['nav-menu-locations'] ) )
  58              set_theme_mod( 'nav_menu_locations', array_map( 'absint', $_REQUEST['menu-locations'] ) );
  59          elseif ( isset( $_REQUEST['menu-item'] ) )
  60              wp_save_nav_menu_items( $nav_menu_selected_id, $_REQUEST['menu-item'] );
  61          break;
  62      case 'move-down-menu-item' :
  63          // moving down a menu item is the same as moving up the next in order
  64          check_admin_referer( 'move-menu_item' );
  65          $menu_item_id = isset( $_REQUEST['menu-item'] ) ? (int) $_REQUEST['menu-item'] : 0;
  66          if ( is_nav_menu_item( $menu_item_id ) ) {
  67              $menus = isset( $_REQUEST['menu'] ) ? array( (int) $_REQUEST['menu'] ) : wp_get_object_terms( $menu_item_id, 'nav_menu', array( 'fields' => 'ids' ) );
  68              if ( ! is_wp_error( $menus ) && ! empty( $menus[0] ) ) {
  69                  $menu_id = (int) $menus[0];
  70                  $ordered_menu_items = wp_get_nav_menu_items( $menu_id );
  71                  $menu_item_data = (array) wp_setup_nav_menu_item( get_post( $menu_item_id ) );
  72  
  73                  // setup the data we need in one pass through the array of menu items
  74                  $dbids_to_orders = array();
  75                  $orders_to_dbids = array();
  76                  foreach( (array) $ordered_menu_items as $ordered_menu_item_object ) {
  77                      if ( isset( $ordered_menu_item_object->ID ) ) {
  78                          if ( isset( $ordered_menu_item_object->menu_order ) ) {
  79                              $dbids_to_orders[$ordered_menu_item_object->ID] = $ordered_menu_item_object->menu_order;
  80                              $orders_to_dbids[$ordered_menu_item_object->menu_order] = $ordered_menu_item_object->ID;
  81                          }
  82                      }
  83                  }
  84  
  85                  // get next in order
  86                  if (
  87                      isset( $orders_to_dbids[$dbids_to_orders[$menu_item_id] + 1] )
  88                  ) {
  89                      $next_item_id = $orders_to_dbids[$dbids_to_orders[$menu_item_id] + 1];
  90                      $next_item_data = (array) wp_setup_nav_menu_item( get_post( $next_item_id ) );
  91  
  92                      // if not siblings of same parent, bubble menu item up but keep order
  93                      if (
  94                          ! empty( $menu_item_data['menu_item_parent'] ) &&
  95                          (
  96                              empty( $next_item_data['menu_item_parent'] ) ||
  97                              $next_item_data['menu_item_parent'] != $menu_item_data['menu_item_parent']
  98                          )
  99                      ) {
 100  
 101                          $parent_db_id = in_array( $menu_item_data['menu_item_parent'], $orders_to_dbids ) ? (int) $menu_item_data['menu_item_parent'] : 0;
 102  
 103                          $parent_object = wp_setup_nav_menu_item( get_post( $parent_db_id ) );
 104  
 105                          if ( ! is_wp_error( $parent_object ) ) {
 106                              $parent_data = (array) $parent_object;
 107                              $menu_item_data['menu_item_parent'] = $parent_data['menu_item_parent'];
 108                              update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] );
 109  
 110                          }
 111  
 112                      // make menu item a child of its next sibling
 113                      } else {
 114                          $next_item_data['menu_order'] = $next_item_data['menu_order'] - 1;
 115                          $menu_item_data['menu_order'] = $menu_item_data['menu_order'] + 1;
 116  
 117                          $menu_item_data['menu_item_parent'] = $next_item_data['ID'];
 118                          update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] );
 119  
 120                          wp_update_post($menu_item_data);
 121                          wp_update_post($next_item_data);
 122                      }
 123  
 124  
 125                  // the item is last but still has a parent, so bubble up
 126                  } elseif (
 127                      ! empty( $menu_item_data['menu_item_parent'] ) &&
 128                      in_array( $menu_item_data['menu_item_parent'], $orders_to_dbids )
 129                  ) {
 130                      $menu_item_data['menu_item_parent'] = (int) get_post_meta( $menu_item_data['menu_item_parent'], '_menu_item_menu_item_parent', true);
 131                      update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] );
 132                  }
 133              }
 134          }
 135  
 136          break;
 137      case 'move-up-menu-item' :
 138          check_admin_referer( 'move-menu_item' );
 139          $menu_item_id = isset( $_REQUEST['menu-item'] ) ? (int) $_REQUEST['menu-item'] : 0;
 140          if ( is_nav_menu_item( $menu_item_id ) ) {
 141              $menus = isset( $_REQUEST['menu'] ) ? array( (int) $_REQUEST['menu'] ) : wp_get_object_terms( $menu_item_id, 'nav_menu', array( 'fields' => 'ids' ) );
 142              if ( ! is_wp_error( $menus ) && ! empty( $menus[0] ) ) {
 143                  $menu_id = (int) $menus[0];
 144                  $ordered_menu_items = wp_get_nav_menu_items( $menu_id );
 145                  $menu_item_data = (array) wp_setup_nav_menu_item( get_post( $menu_item_id ) );
 146  
 147                  // setup the data we need in one pass through the array of menu items
 148                  $dbids_to_orders = array();
 149                  $orders_to_dbids = array();
 150                  foreach( (array) $ordered_menu_items as $ordered_menu_item_object ) {
 151                      if ( isset( $ordered_menu_item_object->ID ) ) {
 152                          if ( isset( $ordered_menu_item_object->menu_order ) ) {
 153                              $dbids_to_orders[$ordered_menu_item_object->ID] = $ordered_menu_item_object->menu_order;
 154                              $orders_to_dbids[$ordered_menu_item_object->menu_order] = $ordered_menu_item_object->ID;
 155                          }
 156                      }
 157                  }
 158  
 159  
 160                  // if this menu item is not first
 161                  if ( ! empty( $dbids_to_orders[$menu_item_id] ) && ! empty( $orders_to_dbids[$dbids_to_orders[$menu_item_id] - 1] ) ) {
 162  
 163                      // if this menu item is a child of the previous
 164                      if (
 165                          ! empty( $menu_item_data['menu_item_parent'] ) &&
 166                          in_array( $menu_item_data['menu_item_parent'], array_keys( $dbids_to_orders ) ) &&
 167                          isset( $orders_to_dbids[$dbids_to_orders[$menu_item_id] - 1] ) &&
 168                          ( $menu_item_data['menu_item_parent'] == $orders_to_dbids[$dbids_to_orders[$menu_item_id] - 1] )
 169                      ) {
 170                          $parent_db_id = in_array( $menu_item_data['menu_item_parent'], $orders_to_dbids ) ? (int) $menu_item_data['menu_item_parent'] : 0;
 171                          $parent_object = wp_setup_nav_menu_item( get_post( $parent_db_id ) );
 172  
 173                          if ( ! is_wp_error( $parent_object ) ) {
 174                              $parent_data = (array) $parent_object;
 175  
 176                              // if there is something before the parent and parent a child of it, make menu item a child also of it
 177                              if (
 178                                  ! empty( $dbids_to_orders[$parent_db_id] ) &&
 179                                  ! empty( $orders_to_dbids[$dbids_to_orders[$parent_db_id] - 1] ) &&
 180                                  ! empty( $parent_data['menu_item_parent'] )
 181                              ) {
 182                                  $menu_item_data['menu_item_parent'] = $parent_data['menu_item_parent'];
 183  
 184                              // else if there is something before parent and parent not a child of it, make menu item a child of that something's parent
 185                              } elseif (
 186                                  ! empty( $dbids_to_orders[$parent_db_id] ) &&
 187                                  ! empty( $orders_to_dbids[$dbids_to_orders[$parent_db_id] - 1] )
 188                              ) {
 189                                  $_possible_parent_id = (int) get_post_meta( $orders_to_dbids[$dbids_to_orders[$parent_db_id] - 1], '_menu_item_menu_item_parent', true);
 190                                  if ( in_array( $_possible_parent_id, array_keys( $dbids_to_orders ) ) )
 191                                      $menu_item_data['menu_item_parent'] = $_possible_parent_id;
 192                                  else
 193                                      $menu_item_data['menu_item_parent'] = 0;
 194  
 195                              // else there isn't something before the parent
 196                              } else {
 197                                  $menu_item_data['menu_item_parent'] = 0;
 198                              }
 199  
 200                              // set former parent's [menu_order] to that of menu-item's
 201                              $parent_data['menu_order'] = $parent_data['menu_order'] + 1;
 202  
 203                              // set menu-item's [menu_order] to that of former parent
 204                              $menu_item_data['menu_order'] = $menu_item_data['menu_order'] - 1;
 205  
 206                              // save changes
 207                              update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] );
 208                              wp_update_post($menu_item_data);
 209                              wp_update_post($parent_data);
 210                          }
 211  
 212                      // else this menu item is not a child of the previous
 213                      } elseif (
 214                          empty( $menu_item_data['menu_order'] ) ||
 215                          empty( $menu_item_data['menu_item_parent'] ) ||
 216                          ! in_array( $menu_item_data['menu_item_parent'], array_keys( $dbids_to_orders ) ) ||
 217                          empty( $orders_to_dbids[$dbids_to_orders[$menu_item_id] - 1] ) ||
 218                          $orders_to_dbids[$dbids_to_orders[$menu_item_id] - 1] != $menu_item_data['menu_item_parent']
 219                      ) {
 220                          // just make it a child of the previous; keep the order
 221                          $menu_item_data['menu_item_parent'] = (int) $orders_to_dbids[$dbids_to_orders[$menu_item_id] - 1];
 222                          update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] );
 223                          wp_update_post($menu_item_data);
 224                      }
 225                  }
 226              }
 227          }
 228          break;
 229  
 230      case 'delete-menu-item':
 231          $menu_item_id = (int) $_REQUEST['menu-item'];
 232  
 233          check_admin_referer( 'delete-menu_item_' . $menu_item_id );
 234  
 235  
 236          if ( is_nav_menu_item( $menu_item_id ) && wp_delete_post( $menu_item_id, true ) )
 237              $messages[] = '<div id="message" class="updated"><p>' . __('The menu item has been successfully deleted.') . '</p></div>';
 238          break;
 239      case 'delete':
 240          check_admin_referer( 'delete-nav_menu-' . $nav_menu_selected_id );
 241  
 242          if ( is_nav_menu( $nav_menu_selected_id ) ) {
 243              $deleted_nav_menu = wp_get_nav_menu_object( $nav_menu_selected_id );
 244              $delete_nav_menu = wp_delete_nav_menu( $nav_menu_selected_id );
 245  
 246              if ( is_wp_error($delete_nav_menu) ) {
 247                  $messages[] = '<div id="message" class="error"><p>' . $delete_nav_menu->get_error_message() . '</p></div>';
 248              } else {
 249                  // Remove this menu from any locations.
 250                  $locations = get_theme_mod( 'nav_menu_locations' );
 251                  foreach ( (array) $locations as $location => $menu_id ) {
 252                      if ( $menu_id == $nav_menu_selected_id )
 253                          $locations[ $location ] = 0;
 254                  }
 255                  set_theme_mod( 'nav_menu_locations', $locations );
 256                  $messages[] = '<div id="message" class="updated"><p>' . __('The menu has been successfully deleted.') . '</p></div>';
 257                  // Select the next available menu
 258                  $nav_menu_selected_id = 0;
 259                  $_nav_menus = wp_get_nav_menus( array('orderby' => 'name') );
 260                  foreach( $_nav_menus as $index => $_nav_menu ) {
 261                      if ( strcmp( $_nav_menu->name, $deleted_nav_menu->name ) >= 0
 262                       || $index == count( $_nav_menus ) - 1 ) {
 263                          $nav_menu_selected_id = $_nav_menu->term_id;
 264                          break;
 265                      }
 266                  }
 267              }
 268              unset( $delete_nav_menu, $deleted_nav_menu, $_nav_menus );
 269          } else {
 270              // Reset the selected menu
 271              $nav_menu_selected_id = 0;
 272              unset( $_REQUEST['menu'] );
 273          }
 274          break;
 275  
 276      case 'update':
 277          check_admin_referer( 'update-nav_menu', 'update-nav-menu-nonce' );
 278  
 279          // Update menu theme locations
 280          if ( isset( $_POST['menu-locations'] ) )
 281              set_theme_mod( 'nav_menu_locations', array_map( 'absint', $_POST['menu-locations'] ) );
 282  
 283          // Add Menu
 284          if ( 0 == $nav_menu_selected_id ) {
 285              $new_menu_title = trim( esc_html( $_POST['menu-name'] ) );
 286  
 287              if ( $new_menu_title ) {
 288                  $_nav_menu_selected_id = wp_update_nav_menu_object( 0, array('menu-name' => $new_menu_title) );
 289  
 290                  if ( is_wp_error( $_nav_menu_selected_id ) ) {
 291                      $messages[] = '<div id="message" class="error"><p>' . $_nav_menu_selected_id->get_error_message() . '</p></div>';
 292                  } else {
 293                      $_menu_object = wp_get_nav_menu_object( $_nav_menu_selected_id );
 294                      $nav_menu_selected_id = $_nav_menu_selected_id;
 295                      $nav_menu_selected_title = $_menu_object->name;
 296                      $messages[] = '<div id="message" class="updated"><p>' . sprintf( __('The <strong>%s</strong> menu has been successfully created.'), $nav_menu_selected_title ) . '</p></div>';
 297                  }
 298              } else {
 299                  $messages[] = '<div id="message" class="error"><p>' . __('Please enter a valid menu name.') . '</p></div>';
 300              }
 301  
 302          // update existing menu
 303          } else {
 304  
 305              $_menu_object = wp_get_nav_menu_object( $nav_menu_selected_id );
 306  
 307              $menu_title = trim( esc_html( $_POST['menu-name'] ) );
 308              if ( ! $menu_title ) {
 309                  $messages[] = '<div id="message" class="error"><p>' . __('Please enter a valid menu name.') . '</p></div>';
 310                  $menu_title = $_menu_object->name;
 311              }
 312  
 313              if ( ! is_wp_error( $_menu_object ) ) {
 314                  $_nav_menu_selected_id = wp_update_nav_menu_object( $nav_menu_selected_id, array( 'menu-name' => $menu_title ) );
 315                  if ( is_wp_error( $_nav_menu_selected_id ) ) {
 316                      $_menu_object = $_nav_menu_selected_id;
 317                      $messages[] = '<div id="message" class="error"><p>' . $_nav_menu_selected_id->get_error_message() . '</p></div>';
 318                  } else {
 319                      $_menu_object = wp_get_nav_menu_object( $_nav_menu_selected_id );
 320                      $nav_menu_selected_title = $_menu_object->name;
 321                  }
 322              }
 323  
 324              // Update menu items
 325  
 326              if ( ! is_wp_error( $_menu_object ) ) {
 327                  $unsorted_menu_items = wp_get_nav_menu_items( $nav_menu_selected_id, array('orderby' => 'ID', 'output' => ARRAY_A, 'output_key' => 'ID', 'post_status' => 'draft,publish') );
 328                  $menu_items = array();
 329                  // Index menu items by db ID
 330                  foreach( $unsorted_menu_items as $_item )
 331                      $menu_items[$_item->db_id] = $_item;
 332  
 333                  $post_fields = array( 'menu-item-db-id', 'menu-item-object-id', 'menu-item-object', 'menu-item-parent-id', 'menu-item-position', 'menu-item-type', 'menu-item-title', 'menu-item-url', 'menu-item-description', 'menu-item-attr-title', 'menu-item-target', 'menu-item-classes', 'menu-item-xfn' );
 334                  wp_defer_term_counting(true);
 335                  // Loop through all the menu items' POST variables
 336                  if ( ! empty( $_POST['menu-item-db-id'] ) ) {
 337                      foreach( (array) $_POST['menu-item-db-id'] as $_key => $k ) {
 338  
 339                          // Menu item title can't be blank
 340                          if ( empty( $_POST['menu-item-title'][$_key] ) )
 341                              continue;
 342  
 343                          $args = array();
 344                          foreach ( $post_fields as $field )
 345                              $args[$field] = isset( $_POST[$field][$_key] ) ? $_POST[$field][$_key] : '';
 346  
 347                          $menu_item_db_id = wp_update_nav_menu_item( $nav_menu_selected_id, ( $_POST['menu-item-db-id'][$_key] != $_key ? 0 : $_key ), $args );
 348  
 349                          if ( is_wp_error( $menu_item_db_id ) )
 350                              $messages[] = '<div id="message" class="error"><p>' . $menu_item_db_id->get_error_message() . '</p></div>';
 351                          elseif ( isset( $menu_items[$menu_item_db_id] ) )
 352                              unset( $menu_items[$menu_item_db_id] );
 353                      }
 354                  }
 355  
 356                  // Remove menu items from the menu that weren't in $_POST
 357                  if ( ! empty( $menu_items ) ) {
 358                      foreach ( array_keys( $menu_items ) as $menu_item_id ) {
 359                          if ( is_nav_menu_item( $menu_item_id ) ) {
 360                              wp_delete_post( $menu_item_id );
 361                          }
 362                      }
 363                  }
 364  
 365                  // Store 'auto-add' pages.
 366                  $auto_add = ! empty( $_POST['auto-add-pages'] );
 367                  $nav_menu_option = (array) get_option( 'nav_menu_options' );
 368                  if ( ! isset( $nav_menu_option['auto_add'] ) )
 369                      $nav_menu_option['auto_add'] = array();
 370                  if ( $auto_add ) {
 371                      if ( ! in_array( $nav_menu_selected_id, $nav_menu_option['auto_add'] ) )
 372                          $nav_menu_option['auto_add'][] = $nav_menu_selected_id;
 373                  } else {
 374                      if ( false !== ( $key = array_search( $nav_menu_selected_id, $nav_menu_option['auto_add'] ) ) )
 375                          unset( $nav_menu_option['auto_add'][$key] );
 376                  }
 377                  // Remove nonexistent/deleted menus
 378                  $nav_menu_option['auto_add'] = array_intersect( $nav_menu_option['auto_add'], wp_get_nav_menus( array( 'fields' => 'ids' ) ) );
 379                  update_option( 'nav_menu_options', $nav_menu_option );
 380  
 381                  wp_defer_term_counting(false);
 382  
 383                  do_action( 'wp_update_nav_menu', $nav_menu_selected_id );
 384  
 385                  $messages[] = '<div id="message" class="updated"><p>' . sprintf( __('The <strong>%s</strong> menu has been updated.'), $nav_menu_selected_title ) . '</p></div>';
 386                  unset( $menu_items, $unsorted_menu_items );
 387              }
 388          }
 389          break;
 390  }
 391  
 392  // Get all nav menus
 393  $nav_menus = wp_get_nav_menus( array('orderby' => 'name') );
 394  
 395  // Get recently edited nav menu
 396  $recently_edited = (int) get_user_option( 'nav_menu_recently_edited' );
 397  
 398  // If there was no recently edited menu, and $nav_menu_selected_id is a nav menu, update recently edited menu.
 399  if ( !$recently_edited && is_nav_menu( $nav_menu_selected_id ) ) {
 400      $recently_edited = $nav_menu_selected_id;
 401  
 402  // Else if $nav_menu_selected_id is not a menu and not requesting that we create a new menu, but $recently_edited is a menu, grab that one.
 403  } elseif ( 0 == $nav_menu_selected_id && ! isset( $_REQUEST['menu'] ) && is_nav_menu( $recently_edited ) ) {
 404      $nav_menu_selected_id = $recently_edited;
 405  
 406  // Else try to grab the first menu from the menus list
 407  } elseif ( 0 == $nav_menu_selected_id && ! isset( $_REQUEST['menu'] ) && ! empty($nav_menus) ) {
 408      $nav_menu_selected_id = $nav_menus[0]->term_id;
 409  }
 410  
 411  // Update the user's setting
 412  if ( $nav_menu_selected_id != $recently_edited && is_nav_menu( $nav_menu_selected_id ) )
 413      update_user_meta( $current_user->ID, 'nav_menu_recently_edited', $nav_menu_selected_id );
 414  
 415  // If there's a menu, get its name.
 416  if ( ! $nav_menu_selected_title && is_nav_menu( $nav_menu_selected_id ) ) {
 417      $_menu_object = wp_get_nav_menu_object( $nav_menu_selected_id );
 418      $nav_menu_selected_title = ! is_wp_error( $_menu_object ) ? $_menu_object->name : '';
 419  }
 420  
 421  // Generate truncated menu names
 422  foreach( (array) $nav_menus as $key => $_nav_menu ) {
 423      $_nav_menu->truncated_name = trim( wp_html_excerpt( $_nav_menu->name, 40 ) );
 424      if ( $_nav_menu->truncated_name != $_nav_menu->name )
 425          $_nav_menu->truncated_name .= '&hellip;';
 426  
 427      $nav_menus[$key]->truncated_name = $_nav_menu->truncated_name;
 428  }
 429  
 430  // Ensure the user will be able to scroll horizontally
 431  // by adding a class for the max menu depth.
 432  global $_wp_nav_menu_max_depth;
 433  $_wp_nav_menu_max_depth = 0;
 434  
 435  // Calling wp_get_nav_menu_to_edit generates $_wp_nav_menu_max_depth
 436  if ( is_nav_menu( $nav_menu_selected_id ) )
 437      $edit_markup = wp_get_nav_menu_to_edit( $nav_menu_selected_id  );
 438  
 439  function wp_nav_menu_max_depth() {
 440      global $_wp_nav_menu_max_depth;
 441      return "menu-max-depth-$_wp_nav_menu_max_depth";
 442  }
 443  
 444  add_action('admin_body_class','wp_nav_menu_max_depth');
 445  
 446  wp_nav_menu_setup();
 447  wp_initial_nav_menu_meta_boxes();
 448  
 449  if ( ! current_theme_supports( 'menus' ) && ! wp_get_nav_menus() )
 450      $messages[] = '<div id="message" class="updated"><p>' . __('The current theme does not natively support menus, but you can use the &#8220;Custom Menu&#8221; widget to add any menus you create here to the theme&#8217;s sidebar.') . '</p></div>';
 451  
 452  $help =  '<p>' . __('This feature is new in version 3.0; to use a custom menu in place of your theme&#8217;s default menus, support for this feature must be registered in the theme&#8217;s functions.php file. If your theme does not support the custom menus feature yet (the new default theme, Twenty Ten, does), you can learn about adding support yourself by following the below link.') . '</p>';
 453  $help .= '<p>' . __('You can create custom menus for your site. These menus may contain links to pages, categories, custom links or other content types (use the Screen Options tab to decide which ones to show on the screen). You can specify a different navigation label for a menu item as well as other attributes. You can create multiple menus. If your theme includes more than one menu, you can choose which custom menu to associate with each. You can also use custom menus in conjunction with the Custom Menus widget.') . '</p>';
 454  $help .= '<p>' . __('To create a new custom menu, click on the + tab, give the menu a name, and click Create Menu. Next, add menu items from the appropriate boxes. You&#8217;ll be able to edit the information for each menu item, and can drag and drop to put them in order. You can also drag a menu item a little to the right to make it a submenu, to create menus with hierarchy. You&#8217;ll see when the position of the drop target shifts over to create the nested placement. Don&#8217;t forget to click Save when you&#8217;re finished.') . '</p>';
 455  $help .= '<p><strong>' . __('For more information:') . '</strong></p>';
 456  $help .= '<p>' . __('<a href="http://codex.wordpress.org/Appearance_Menus_SubPanel" target="_blank">Menus Documentation</a>') . '</p>';
 457  $help .= '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>';
 458  
 459  add_contextual_help($current_screen, $help);
 460  
 461  // Get the admin header
 462  require_once ( 'admin-header.php' );
 463  ?>
 464  <div class="wrap">
 465      <?php screen_icon(); ?>
 466      <h2><?php esc_html_e('Menus'); ?></h2>
 467      <?php
 468      foreach( $messages as $message ) :
 469          echo $message . "\n";
 470      endforeach;
 471      ?>
 472      <div id="nav-menus-frame">
 473      <div id="menu-settings-column" class="metabox-holder<?php if ( !$nav_menu_selected_id ) { echo ' metabox-holder-disabled'; } ?>">
 474  
 475          <form id="nav-menu-meta" action="<?php echo admin_url( 'nav-menus.php' ); ?>" class="nav-menu-meta" method="post" enctype="multipart/form-data">
 476              <input type="hidden" name="menu" id="nav-menu-meta-object-id" value="<?php echo esc_attr( $nav_menu_selected_id ); ?>" />
 477              <input type="hidden" name="action" value="add-menu-item" />
 478              <?php wp_nonce_field( 'add-menu_item', 'menu-settings-column-nonce' ); ?>
 479              <?php do_meta_boxes( 'nav-menus', 'side', null ); ?>
 480          </form>
 481  
 482      </div><!-- /#menu-settings-column -->
 483      <div id="menu-management-liquid">
 484          <div id="menu-management">
 485              <div id="select-nav-menu-container" class="hide-if-js">
 486                  <form id="select-nav-menu" action="">
 487                      <strong><label for="select-nav-menu"><?php esc_html_e( 'Select Menu:' ); ?></label></strong>
 488                      <select class="select-nav-menu" name="menu">
 489                          <?php foreach( (array) $nav_menus as $_nav_menu ) : ?>
 490                              <option value="<?php echo esc_attr($_nav_menu->term_id) ?>" <?php selected($nav_menu_selected_id, $_nav_menu->term_id); ?>>
 491                                  <?php echo esc_html( $_nav_menu->truncated_name ); ?>
 492                              </option>
 493                          <?php endforeach; ?>
 494                          <option value="0"><?php esc_html_e('Add New Menu'); ?></option>
 495                      </select>
 496                      <input type="hidden" name="action" value="edit" />
 497                      <input class="button-secondary" name="select_menu" type="submit" value="<?php esc_attr_e('Select'); ?>" />
 498                  </form>
 499              </div>
 500              <div class="nav-tabs-wrapper">
 501              <div class="nav-tabs">
 502                  <?php
 503                  foreach( (array) $nav_menus as $_nav_menu ) :
 504                      if ( $nav_menu_selected_id == $_nav_menu->term_id ) : ?><span class="nav-tab nav-tab-active">
 505                              <?php echo esc_html( $_nav_menu->truncated_name ); ?>
 506                          </span><?php else : ?><a href="<?php
 507                              echo esc_url(add_query_arg(
 508                                  array(
 509                                      'action' => 'edit',
 510                                      'menu' => $_nav_menu->term_id,
 511                                  ),
 512                                  admin_url( 'nav-menus.php' )
 513                              ));
 514                          ?>" class="nav-tab hide-if-no-js">
 515                              <?php echo esc_html( $_nav_menu->truncated_name ); ?>
 516                          </a><?php endif;
 517                  endforeach;
 518                  if ( 0 == $nav_menu_selected_id ) : ?><span class="nav-tab menu-add-new nav-tab-active">
 519                      <?php printf( '<abbr title="%s">+</abbr>', esc_html__( 'Add menu' ) ); ?>
 520                  </span><?php else : ?><a href="<?php
 521                      echo esc_url(add_query_arg(
 522                          array(
 523                              'action' => 'edit',
 524                              'menu' => 0,
 525                          ),
 526                          admin_url( 'nav-menus.php' )
 527                      ));
 528                  ?>" class="nav-tab menu-add-new">
 529                      <?php printf( '<abbr title="%s">+</abbr>', esc_html__( 'Add menu' ) ); ?>
 530                  </a><?php endif; ?>
 531              </div>
 532              </div>
 533              <div class="menu-edit">
 534                  <form id="update-nav-menu" action="<?php echo admin_url( 'nav-menus.php' ); ?>" method="post" enctype="multipart/form-data">
 535                      <div id="nav-menu-header">
 536                          <div id="submitpost" class="submitbox">
 537                              <div class="major-publishing-actions">
 538                                  <label class="menu-name-label howto open-label" for="menu-name">
 539                                      <span><?php _e('Menu Name'); ?></span>
 540                                      <input name="menu-name" id="menu-name" type="text" class="menu-name regular-text menu-item-textbox input-with-default-title" title="<?php esc_attr_e('Enter menu name here'); ?>" value="<?php echo esc_attr( $nav_menu_selected_title  ); ?>" />
 541                                  </label>
 542                                  <?php if ( !empty( $nav_menu_selected_id ) ) :
 543                                      if ( ! isset( $auto_add ) ) {
 544                                          $auto_add = get_option( 'nav_menu_options' );
 545                                          if ( ! isset( $auto_add['auto_add'] ) )
 546                                              $auto_add = false;
 547                                          elseif ( false !== array_search( $nav_menu_selected_id, $auto_add['auto_add'] ) )
 548                                              $auto_add = true;
 549                                          else
 550                                              $auto_add = false;
 551                                      }
 552                                  ?>
 553                                  <div class="auto-add-pages">
 554                                      <label class="howto"><input type="checkbox"<?php checked( $auto_add ); ?> name="auto-add-pages" value="1" /> <?php printf( __('Automatically add new top-level pages' ), esc_url( admin_url( 'edit.php?post_type=page' ) ) ); ?></label>
 555                                  </div>
 556                                  <?php endif; ?>
 557                                  <br class="clear" />
 558                                  <div class="publishing-action">
 559                                      <input class="button-primary menu-save" name="save_menu" type="submit" value="<?php empty($nav_menu_selected_id) ? esc_attr_e('Create Menu') : esc_attr_e('Save Menu'); ?>" />
 560                                  </div><!-- END .publishing-action -->
 561  
 562                                  <?php if ( ! empty( $nav_menu_selected_id ) ) : ?>
 563                                  <div class="delete-action">
 564                                      <a class="submitdelete deletion menu-delete" href="<?php echo esc_url( wp_nonce_url( admin_url('nav-menus.php?action=delete&amp;menu=' . $nav_menu_selected_id), 'delete-nav_menu-' . $nav_menu_selected_id ) ); ?>"><?php _e('Delete Menu'); ?></a>
 565                                  </div><!-- END .delete-action -->
 566                                  <?php endif; ?>
 567                              </div><!-- END .major-publishing-actions -->
 568                          </div><!-- END #submitpost .submitbox -->
 569                          <?php
 570                          wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
 571                          wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
 572                          wp_nonce_field( 'update-nav_menu', 'update-nav-menu-nonce' );
 573                          ?>
 574                          <input type="hidden" name="action" value="update" />
 575                          <input type="hidden" name="menu" id="menu" value="<?php echo esc_attr( $nav_menu_selected_id ); ?>" />
 576                      </div><!-- END #nav-menu-header -->
 577                      <div id="post-body">
 578                          <div id="post-body-content">
 579                              <?php
 580                              if ( isset( $edit_markup ) ) {
 581                                  if ( ! is_wp_error( $edit_markup ) )
 582                                      echo $edit_markup;
 583                              } else if ( empty( $nav_menu_selected_id ) ) {
 584                                  echo '<div class="post-body-plain">';
 585                                  echo '<p>' . __('To create a custom menu, give it a name above and click Create Menu. Then choose items like pages, categories or custom links from the left column to add to this menu.') . '</p>';
 586                                  echo '<p>' . __('After you have added your items, drag and drop to put them in the order you want. You can also click each item to reveal additional configuration options.') . '</p>';
 587                                  echo '<p>' . __('When you have finished building your custom menu, make sure you click the Save Menu button.') . '</p>';
 588                                  echo '</div>';
 589                              }
 590                              ?>
 591                          </div><!-- /#post-body-content -->
 592                      </div><!-- /#post-body -->
 593                  </form><!-- /#update-nav-menu -->
 594              </div><!-- /.menu-edit -->
 595          </div><!-- /#menu-management -->
 596      </div><!-- /#menu-management-liquid -->
 597      </div><!-- /#nav-menus-frame -->
 598  </div><!-- /.wrap-->
 599  
 600  
 601  <?php include ( 'admin-footer.php' ); ?>


[ Powered by PHPXref - Served by Debian GNU/Linux ]