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