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 */ 13require_once __DIR__ . '/admin.php'; 14 15// Load all the nav menu interface functions. 16require_once ABSPATH . 'wp-admin/includes/nav-menu.php'; 17 18if ( ! 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. 23if ( ! 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 31wp_enqueue_script( 'nav-menu' ); 32 33if ( 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 60switch ( $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 */ 473if ( 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); 503wp_localize_script( 'nav-menu', 'menus', $nav_menus_l10n ); 504 505/* 506 * Redirect to add screen if there are no menus and this users has either zero, 507 * or more than 1 theme locations. 508 */ 509if ( 0 === $menu_count && ! $add_new_screen && ! $one_theme_location_no_menus ) { 510 wp_redirect( admin_url( 'nav-menus.php?action=edit&menu=0' ) ); 511} 512 513// Get recently edited nav menu. 514$recently_edited = absint( get_user_option( 'nav_menu_recently_edited' ) ); 515if ( empty( $recently_edited ) && is_nav_menu( $nav_menu_selected_id ) ) { 516 $recently_edited = $nav_menu_selected_id; 517} 518 519// Use $recently_edited if none are selected. 520if ( empty( $nav_menu_selected_id ) && ! isset( $_GET['menu'] ) && is_nav_menu( $recently_edited ) ) { 521 $nav_menu_selected_id = $recently_edited; 522} 523 524// On deletion of menu, if another menu exists, show it. 525if ( ! $add_new_screen && $menu_count > 0 && isset( $_GET['action'] ) && 'delete' === $_GET['action'] ) { 526 $nav_menu_selected_id = $nav_menus[0]->term_id; 527} 528 529// Set $nav_menu_selected_id to 0 if no menus. 530if ( $one_theme_location_no_menus ) { 531 $nav_menu_selected_id = 0; 532} elseif ( empty( $nav_menu_selected_id ) && ! empty( $nav_menus ) && ! $add_new_screen ) { 533 // If we have no selection yet, and we have menus, set to the first one in the list. 534 $nav_menu_selected_id = $nav_menus[0]->term_id; 535} 536 537// Update the user's setting. 538if ( $nav_menu_selected_id !== $recently_edited && is_nav_menu( $nav_menu_selected_id ) ) { 539 update_user_meta( $current_user->ID, 'nav_menu_recently_edited', $nav_menu_selected_id ); 540} 541 542// If there's a menu, get its name. 543if ( ! $nav_menu_selected_title && is_nav_menu( $nav_menu_selected_id ) ) { 544 $_menu_object = wp_get_nav_menu_object( $nav_menu_selected_id ); 545 $nav_menu_selected_title = ! is_wp_error( $_menu_object ) ? $_menu_object->name : ''; 546} 547 548// Generate truncated menu names. 549foreach ( (array) $nav_menus as $key => $_nav_menu ) { 550 $nav_menus[ $key ]->truncated_name = wp_html_excerpt( $_nav_menu->name, 40, '…' ); 551} 552 553// Retrieve menu locations. 554if ( current_theme_supports( 'menus' ) ) { 555 $locations = get_registered_nav_menus(); 556 $menu_locations = get_nav_menu_locations(); 557} 558 559/* 560 * Ensure the user will be able to scroll horizontally 561 * by adding a class for the max menu depth. 562 * 563 * @global int $_wp_nav_menu_max_depth 564 */ 565global $_wp_nav_menu_max_depth; 566$_wp_nav_menu_max_depth = 0; 567 568// Calling wp_get_nav_menu_to_edit generates $_wp_nav_menu_max_depth. 569if ( is_nav_menu( $nav_menu_selected_id ) ) { 570 $menu_items = wp_get_nav_menu_items( $nav_menu_selected_id, array( 'post_status' => 'any' ) ); 571 $edit_markup = wp_get_nav_menu_to_edit( $nav_menu_selected_id ); 572} 573 574/** 575 * @global int $_wp_nav_menu_max_depth 576 * 577 * @param string $classes 578 * @return string 579 */ 580function wp_nav_menu_max_depth( $classes ) { 581 global $_wp_nav_menu_max_depth; 582 return "$classes menu-max-depth-$_wp_nav_menu_max_depth"; 583} 584 585add_filter( 'admin_body_class', 'wp_nav_menu_max_depth' ); 586 587wp_nav_menu_setup(); 588wp_initial_nav_menu_meta_boxes(); 589 590if ( ! current_theme_supports( 'menus' ) && ! $num_locations ) { 591 $messages[] = '<div id="message" class="updated"><p>' . sprintf( 592 /* translators: %s: URL to Widgets screen. */ 593 __( 'Your theme does not natively support menus, but you can use them in sidebars by adding a “Navigation Menu” widget on the <a href="%s">Widgets</a> screen.' ), 594 admin_url( 'widgets.php' ) 595 ) . '</p></div>'; 596} 597 598if ( ! $locations_screen ) : // Main tab. 599 $overview = '<p>' . __( 'This screen is used for managing your navigation menus.' ) . '</p>'; 600 $overview .= '<p>' . sprintf( 601 /* translators: 1: URL to Widgets screen, 2 and 3: The names of the default themes. */ 602 __( 'Menus can be displayed in locations defined by your theme, even used in sidebars by adding a “Navigation Menu” 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.' ), 603 admin_url( 'widgets.php' ), 604 'Twenty Twenty', 605 'Twenty Twenty-One' 606 ) . '</p>'; 607 $overview .= '<p>' . __( 'From this screen you can:' ) . '</p>'; 608 $overview .= '<ul><li>' . __( 'Create, edit, and delete menus' ) . '</li>'; 609 $overview .= '<li>' . __( 'Add, organize, and modify individual menu items' ) . '</li></ul>'; 610 611 get_current_screen()->add_help_tab( 612 array( 613 'id' => 'overview', 614 'title' => __( 'Overview' ), 615 'content' => $overview, 616 ) 617 ); 618 619 $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>'; 620 $menu_management .= '<ul><li>' . __( 'To edit an existing menu, <strong>choose a menu from the drop down and click Select</strong>' ) . '</li>'; 621 $menu_management .= '<li>' . __( 'If you haven’t yet created any menus, <strong>click the ’create a new menu’ link</strong> to get started' ) . '</li></ul>'; 622 $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>'; 623 624 get_current_screen()->add_help_tab( 625 array( 626 'id' => 'menu-management', 627 'title' => __( 'Menu Management' ), 628 'content' => $menu_management, 629 ) 630 ); 631 632 $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>'; 633 $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>'; 634 $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>'; 635 $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>'; 636 $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>'; 637 $editing_menus .= '<li>' . __( 'Delete a menu item by <strong>expanding it and clicking the Remove link</strong>' ) . '</li></ul>'; 638 639 get_current_screen()->add_help_tab( 640 array( 641 'id' => 'editing-menus', 642 'title' => __( 'Editing Menus' ), 643 'content' => $editing_menus, 644 ) 645 ); 646else : // Locations tab. 647 $locations_overview = '<p>' . __( 'This screen is used for globally assigning menus to locations defined by your theme.' ) . '</p>'; 648 $locations_overview .= '<ul><li>' . __( 'To assign menus to one or more theme locations, <strong>select a menu from each location’s drop down.</strong> When you’re finished, <strong>click Save Changes</strong>' ) . '</li>'; 649 $locations_overview .= '<li>' . __( 'To edit a menu currently assigned to a theme location, <strong>click the adjacent ’Edit’ link</strong>' ) . '</li>'; 650 $locations_overview .= '<li>' . __( 'To add a new menu instead of assigning an existing one, <strong>click the ’Use new menu’ link</strong>. Your new menu will be automatically assigned to that theme location' ) . '</li></ul>'; 651 652 get_current_screen()->add_help_tab( 653 array( 654 'id' => 'locations-overview', 655 'title' => __( 'Overview' ), 656 'content' => $locations_overview, 657 ) 658 ); 659endif; 660 661get_current_screen()->set_help_sidebar( 662 '<p><strong>' . __( 'For more information:' ) . '</strong></p>' . 663 '<p>' . __( '<a href="https://wordpress.org/support/article/appearance-menus-screen/">Documentation on Menus</a>' ) . '</p>' . 664 '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>' 665); 666 667// Get the admin header. 668require_once ABSPATH . 'wp-admin/admin-header.php'; 669?> 670<div class="wrap"> 671 <h1 class="wp-heading-inline"><?php esc_html_e( 'Menus' ); ?></h1> 672 <?php 673 if ( current_user_can( 'customize' ) ) : 674 $focus = $locations_screen ? array( 'section' => 'menu_locations' ) : array( 'panel' => 'nav_menus' ); 675 printf( 676 ' <a class="page-title-action hide-if-no-customize" href="%1$s">%2$s</a>', 677 esc_url( 678 add_query_arg( 679 array( 680 array( 'autofocus' => $focus ), 681 'return' => urlencode( remove_query_arg( wp_removable_query_args(), wp_unslash( $_SERVER['REQUEST_URI'] ) ) ), 682 ), 683 admin_url( 'customize.php' ) 684 ) 685 ), 686 __( 'Manage with Live Preview' ) 687 ); 688 endif; 689 690 $nav_tab_active_class = ''; 691 $nav_aria_current = ''; 692 693 if ( ! isset( $_GET['action'] ) || isset( $_GET['action'] ) && 'locations' !== $_GET['action'] ) { 694 $nav_tab_active_class = ' nav-tab-active'; 695 $nav_aria_current = ' aria-current="page"'; 696 } 697 ?> 698 699 <hr class="wp-header-end"> 700 701 <nav class="nav-tab-wrapper wp-clearfix" aria-label="<?php esc_attr_e( 'Secondary menu' ); ?>"> 702 <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> 703 <?php 704 if ( $num_locations && $menu_count ) { 705 $active_tab_class = ''; 706 $aria_current = ''; 707 708 if ( $locations_screen ) { 709 $active_tab_class = ' nav-tab-active'; 710 $aria_current = ' aria-current="page"'; 711 } 712 ?> 713 <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> 714 <?php 715 } 716 ?> 717 </nav> 718 <?php 719 foreach ( $messages as $message ) : 720 echo $message . "\n"; 721 endforeach; 722 ?> 723 <?php 724 if ( $locations_screen ) : 725 if ( 1 === $num_locations ) { 726 echo '<p>' . __( 'Your theme supports one menu. Select which menu you would like to use.' ) . '</p>'; 727 } else { 728 echo '<p>' . sprintf( 729 /* translators: %s: Number of menus. */ 730 _n( 731 'Your theme supports %s menu. Select which menu appears in each location.', 732 'Your theme supports %s menus. Select which menu appears in each location.', 733 $num_locations 734 ), 735 number_format_i18n( $num_locations ) 736 ) . '</p>'; 737 } 738 ?> 739 <div id="menu-locations-wrap"> 740 <form method="post" action="<?php echo esc_url( add_query_arg( array( 'action' => 'locations' ), admin_url( 'nav-menus.php' ) ) ); ?>"> 741 <table class="widefat fixed" id="menu-locations-table"> 742 <thead> 743 <tr> 744 <th scope="col" class="manage-column column-locations"><?php _e( 'Theme Location' ); ?></th> 745 <th scope="col" class="manage-column column-menus"><?php _e( 'Assigned Menu' ); ?></th> 746 </tr> 747 </thead> 748 <tbody class="menu-locations"> 749 <?php foreach ( $locations as $_location => $_name ) { ?> 750 <tr class="menu-locations-row"> 751 <td class="menu-location-title"><label for="locations-<?php echo $_location; ?>"><?php echo $_name; ?></label></td> 752 <td class="menu-location-menus"> 753 <select name="menu-locations[<?php echo $_location; ?>]" id="locations-<?php echo $_location; ?>"> 754 <option value="0"><?php printf( '— %s —', esc_html__( 'Select a Menu' ) ); ?></option> 755 <?php 756 foreach ( $nav_menus as $menu ) : 757 $data_orig = ''; 758 $selected = isset( $menu_locations[ $_location ] ) && $menu_locations[ $_location ] === $menu->term_id; 759 760 if ( $selected ) { 761 $data_orig = 'data-orig="true"'; 762 } 763 ?> 764 <option <?php echo $data_orig; ?> <?php selected( $selected ); ?> value="<?php echo $menu->term_id; ?>"> 765 <?php echo wp_html_excerpt( $menu->name, 40, '…' ); ?> 766 </option> 767 <?php endforeach; ?> 768 </select> 769 <div class="locations-row-links"> 770 <?php if ( isset( $menu_locations[ $_location ] ) && 0 !== $menu_locations[ $_location ] ) : ?> 771 <span class="locations-edit-menu-link"> 772 <a href=" 773 <?php 774 echo esc_url( 775 add_query_arg( 776 array( 777 'action' => 'edit', 778 'menu' => $menu_locations[ $_location ], 779 ), 780 admin_url( 'nav-menus.php' ) 781 ) 782 ); 783 ?> 784 "> 785 <span aria-hidden="true"><?php _ex( 'Edit', 'menu' ); ?></span><span class="screen-reader-text"><?php _e( 'Edit selected menu' ); ?></span> 786 </a> 787 </span> 788 <?php endif; ?> 789 <span class="locations-add-menu-link"> 790 <a href=" 791 <?php 792 echo esc_url( 793 add_query_arg( 794 array( 795 'action' => 'edit', 796 'menu' => 0, 797 'use-location' => $_location, 798 ), 799 admin_url( 'nav-menus.php' ) 800 ) 801 ); 802 ?> 803 "> 804 <?php _ex( 'Use new menu', 'menu' ); ?> 805 </a> 806 </span> 807 </div><!-- .locations-row-links --> 808 </td><!-- .menu-location-menus --> 809 </tr><!-- .menu-locations-row --> 810 <?php } // End foreach. ?> 811 </tbody> 812 </table> 813 <p class="button-controls wp-clearfix"><?php submit_button( __( 'Save Changes' ), 'primary left', 'nav-menu-locations', false ); ?></p> 814 <?php wp_nonce_field( 'save-menu-locations' ); ?> 815 <input type="hidden" name="menu" id="nav-menu-meta-object-id" value="<?php echo esc_attr( $nav_menu_selected_id ); ?>" /> 816 </form> 817 </div><!-- #menu-locations-wrap --> 818 <?php 819 /** 820 * Fires after the menu locations table is displayed. 821 * 822 * @since 3.6.0 823 */ 824 do_action( 'after_menu_locations_table' ); 825 ?> 826 <?php else : ?> 827 <div class="manage-menus"> 828 <?php if ( $menu_count < 1 ) : ?> 829 <span class="first-menu-message"> 830 <?php _e( 'Create your first menu below.' ); ?> 831 <span class="screen-reader-text"><?php _e( 'Fill in the Menu Name and click the Create Menu button to create your first menu.' ); ?></span> 832 </span><!-- /first-menu-message --> 833 <?php elseif ( $menu_count < 2 ) : ?> 834 <span class="add-edit-menu-action"> 835 <?php 836 printf( 837 /* translators: %s: URL to create a new menu. */ 838 __( 'Edit your menu below, or <a href="%s">create a new menu</a>. Don’t forget to save your changes!' ), 839 esc_url( 840 add_query_arg( 841 array( 842 'action' => 'edit', 843 'menu' => 0, 844 ), 845 admin_url( 'nav-menus.php' ) 846 ) 847 ) 848 ); 849 ?> 850 <span class="screen-reader-text"><?php _e( 'Click the Save Menu button to save your changes.' ); ?></span> 851 </span><!-- /add-edit-menu-action --> 852 <?php else : ?> 853 <form method="get" action="<?php echo esc_url( admin_url( 'nav-menus.php' ) ); ?>"> 854 <input type="hidden" name="action" value="edit" /> 855 <label for="select-menu-to-edit" class="selected-menu"><?php _e( 'Select a menu to edit:' ); ?></label> 856 <select name="menu" id="select-menu-to-edit"> 857 <?php if ( $add_new_screen ) : ?> 858 <option value="0" selected="selected"><?php _e( '— Select —' ); ?></option> 859 <?php endif; ?> 860 <?php foreach ( (array) $nav_menus as $_nav_menu ) : ?> 861 <option value="<?php echo esc_attr( $_nav_menu->term_id ); ?>" <?php selected( $_nav_menu->term_id, $nav_menu_selected_id ); ?>> 862 <?php 863 echo esc_html( $_nav_menu->truncated_name ); 864 865 if ( ! empty( $menu_locations ) && in_array( $_nav_menu->term_id, $menu_locations, true ) ) { 866 $locations_assigned_to_this_menu = array(); 867 868 foreach ( array_keys( $menu_locations, $_nav_menu->term_id, true ) as $menu_location_key ) { 869 if ( isset( $locations[ $menu_location_key ] ) ) { 870 $locations_assigned_to_this_menu[] = $locations[ $menu_location_key ]; 871 } 872 } 873 874 /** 875 * Filters the number of locations listed per menu in the drop-down select. 876 * 877 * @since 3.6.0 878 * 879 * @param int $locations Number of menu locations to list. Default 3. 880 */ 881 $locations_listed_per_menu = absint( apply_filters( 'wp_nav_locations_listed_per_menu', 3 ) ); 882 883 $assigned_locations = array_slice( $locations_assigned_to_this_menu, 0, $locations_listed_per_menu ); 884 885 // Adds ellipses following the number of locations defined in $assigned_locations. 886 if ( ! empty( $assigned_locations ) ) { 887 printf( 888 ' (%1$s%2$s)', 889 implode( ', ', $assigned_locations ), 890 count( $locations_assigned_to_this_menu ) > count( $assigned_locations ) ? ' …' : '' 891 ); 892 } 893 } 894 ?> 895 </option> 896 <?php endforeach; ?> 897 </select> 898 <span class="submit-btn"><input type="submit" class="button" value="<?php esc_attr_e( 'Select' ); ?>"></span> 899 <span class="add-new-menu-action"> 900 <?php 901 printf( 902 /* translators: %s: URL to create a new menu. */ 903 __( 'or <a href="%s">create a new menu</a>. Don’t forget to save your changes!' ), 904 esc_url( 905 add_query_arg( 906 array( 907 'action' => 'edit', 908 'menu' => 0, 909 ), 910 admin_url( 'nav-menus.php' ) 911 ) 912 ) 913 ); 914 ?> 915 <span class="screen-reader-text"><?php _e( 'Click the Save Menu button to save your changes.' ); ?></span> 916 </span><!-- /add-new-menu-action --> 917 </form> 918 <?php 919 endif; 920 921 $metabox_holder_disabled_class = ''; 922 923 if ( isset( $_GET['menu'] ) && 0 === (int) $_GET['menu'] ) { 924 $metabox_holder_disabled_class = ' metabox-holder-disabled'; 925 } 926 ?> 927 </div><!-- /manage-menus --> 928 <div id="nav-menus-frame" class="wp-clearfix"> 929 <div id="menu-settings-column" class="metabox-holder<?php echo $metabox_holder_disabled_class; ?>"> 930 931 <div class="clear"></div> 932 933 <form id="nav-menu-meta" class="nav-menu-meta" method="post" enctype="multipart/form-data"> 934 <input type="hidden" name="menu" id="nav-menu-meta-object-id" value="<?php echo esc_attr( $nav_menu_selected_id ); ?>" /> 935 <input type="hidden" name="action" value="add-menu-item" /> 936 <?php wp_nonce_field( 'add-menu_item', 'menu-settings-column-nonce' ); ?> 937 <h2><?php _e( 'Add menu items' ); ?></h2> 938 <?php do_accordion_sections( 'nav-menus', 'side', null ); ?> 939 </form> 940 941 </div><!-- /#menu-settings-column --> 942 <div id="menu-management-liquid"> 943 <div id="menu-management"> 944 <form id="update-nav-menu" method="post" enctype="multipart/form-data"> 945 <h2><?php _e( 'Menu structure' ); ?></h2> 946 <div class="menu-edit"> 947 <input type="hidden" name="nav-menu-data"> 948 <?php 949 wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); 950 wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); 951 wp_nonce_field( 'update-nav_menu', 'update-nav-menu-nonce' ); 952 953 $menu_name_aria_desc = $add_new_screen ? ' aria-describedby="menu-name-desc"' : ''; 954 955 if ( $one_theme_location_no_menus ) { 956 $menu_name_val = 'value="' . esc_attr( 'Menu 1' ) . '"'; 957 ?> 958 <input type="hidden" name="zero-menu-state" value="true" /> 959 <?php 960 } else { 961 $menu_name_val = 'value="' . esc_attr( $nav_menu_selected_title ) . '"'; 962 } 963 ?> 964 <input type="hidden" name="action" value="update" /> 965 <input type="hidden" name="menu" id="menu" value="<?php echo esc_attr( $nav_menu_selected_id ); ?>" /> 966 <div id="nav-menu-header"> 967 <div class="major-publishing-actions wp-clearfix"> 968 <label class="menu-name-label" for="menu-name"><?php _e( 'Menu Name' ); ?></label> 969 <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; ?> /> 970 <div class="publishing-action"> 971 <?php submit_button( empty( $nav_menu_selected_id ) ? __( 'Create Menu' ) : __( 'Save Menu' ), 'primary large menu-save', 'save_menu', false, array( 'id' => 'save_menu_header' ) ); ?> 972 </div><!-- END .publishing-action --> 973 </div><!-- END .major-publishing-actions --> 974 </div><!-- END .nav-menu-header --> 975 <div id="post-body"> 976 <div id="post-body-content" class="wp-clearfix"> 977 <?php if ( ! $add_new_screen ) : ?> 978 <?php 979 $hide_style = ''; 980 981 if ( isset( $menu_items ) && 0 === count( $menu_items ) ) { 982 $hide_style = 'style="display: none;"'; 983 } 984 985 if ( $one_theme_location_no_menus ) { 986 $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.' ); 987 } else { 988 $starter_copy = __( 'Drag the items into the order you prefer. Click the arrow on the right of the item to reveal additional configuration options.' ); 989 } 990 ?> 991 <div class="drag-instructions post-body-plain" <?php echo $hide_style; ?>> 992 <p><?php echo $starter_copy; ?></p> 993 </div> 994 995 <?php if ( ! $add_new_screen ) : ?> 996 <div id="nav-menu-bulk-actions-top" class="bulk-actions"> 997 <label class="bulk-select-button" for="bulk-select-switcher-top"> 998 <input type="checkbox" id="bulk-select-switcher-top" name="bulk-select-switcher-top" class="bulk-select-switcher"> 999 <span class="bulk-select-button-label"><?php _e( 'Bulk Select' ); ?></span> 1000 </label> 1001 </div> 1002 <?php endif; ?> 1003 1004 <?php 1005 if ( isset( $edit_markup ) && ! is_wp_error( $edit_markup ) ) { 1006 echo $edit_markup; 1007 } else { 1008 ?> 1009 <ul class="menu" id="menu-to-edit"></ul> 1010 <?php } ?> 1011 1012 <?php endif; ?> 1013 1014 <?php if ( $add_new_screen ) : ?> 1015 <p class="post-body-plain" id="menu-name-desc"><?php _e( 'Give your menu a name, then click Create Menu.' ); ?></p> 1016 <?php if ( isset( $_GET['use-location'] ) ) : ?> 1017 <input type="hidden" name="use-location" value="<?php echo esc_attr( $_GET['use-location'] ); ?>" /> 1018 <?php endif; ?> 1019 1020 <?php 1021 endif; 1022 1023 $no_menus_style = ''; 1024 1025 if ( $one_theme_location_no_menus ) { 1026 $no_menus_style = 'style="display: none;"'; 1027 } 1028 ?> 1029 1030 <?php if ( ! $add_new_screen ) : ?> 1031 <div id="nav-menu-bulk-actions-bottom" class="bulk-actions"> 1032 <label class="bulk-select-button" for="bulk-select-switcher-bottom"> 1033 <input type="checkbox" id="bulk-select-switcher-bottom" name="bulk-select-switcher-top" class="bulk-select-switcher"> 1034 <span class="bulk-select-button-label"><?php _e( 'Bulk Select' ); ?></span> 1035 </label> 1036 <input type="button" class="deletion menu-items-delete disabled" value="<?php _e( 'Remove Selected Items' ); ?>"> 1037 <div id="pending-menu-items-to-delete"> 1038 <p><?php _e( 'List of menu items selected for deletion:' ); ?></p> 1039 <ul></ul> 1040 </div> 1041 </div> 1042 <?php endif; ?> 1043 1044 <div class="menu-settings" <?php echo $no_menus_style; ?>> 1045 <h3><?php _e( 'Menu Settings' ); ?></h3> 1046 <?php 1047 if ( ! isset( $auto_add ) ) { 1048 $auto_add = get_option( 'nav_menu_options' ); 1049 1050 if ( ! isset( $auto_add['auto_add'] ) ) { 1051 $auto_add = false; 1052 } elseif ( false !== array_search( $nav_menu_selected_id, $auto_add['auto_add'], true ) ) { 1053 $auto_add = true; 1054 } else { 1055 $auto_add = false; 1056 } 1057 } 1058 ?> 1059 1060 <fieldset class="menu-settings-group auto-add-pages"> 1061 <legend class="menu-settings-group-name howto"><?php _e( 'Auto add pages' ); ?></legend> 1062 <div class="menu-settings-input checkbox-input"> 1063 <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> 1064 </div> 1065 </fieldset> 1066 1067 <?php if ( current_theme_supports( 'menus' ) ) : ?> 1068 1069 <fieldset class="menu-settings-group menu-theme-locations"> 1070 <legend class="menu-settings-group-name howto"><?php _e( 'Display location' ); ?></legend> 1071 <?php 1072 foreach ( $locations as $location => $description ) : 1073 $checked = false; 1074 1075 if ( isset( $menu_locations[ $location ] ) 1076 && 0 !== $nav_menu_selected_id 1077 && $menu_locations[ $location ] === $nav_menu_selected_id 1078 ) { 1079 $checked = true; 1080 } 1081 ?> 1082 <div class="menu-settings-input checkbox-input"> 1083 <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 ); ?>" /> 1084 <label for="locations-<?php echo esc_attr( $location ); ?>"><?php echo $description; ?></label> 1085 <?php if ( ! empty( $menu_locations[ $location ] ) && $menu_locations[ $location ] !== $nav_menu_selected_id ) : ?> 1086 <span class="theme-location-set"> 1087 <?php 1088 printf( 1089 /* translators: %s: Menu name. */ 1090 _x( '(Currently set to: %s)', 'menu location' ), 1091 wp_get_nav_menu_object( $menu_locations[ $location ] )->name 1092 ); 1093 ?> 1094 </span> 1095 <?php endif; ?> 1096 </div> 1097 <?php endforeach; ?> 1098 </fieldset> 1099 1100 <?php endif; ?> 1101 1102 </div> 1103 </div><!-- /#post-body-content --> 1104 </div><!-- /#post-body --> 1105 <div id="nav-menu-footer"> 1106 <div class="major-publishing-actions wp-clearfix"> 1107 <?php if ( $menu_count > 0 ) : ?> 1108 1109 <?php if ( $add_new_screen ) : ?> 1110 <span class="cancel-action"> 1111 <a class="submitcancel cancellation menu-cancel" href="<?php echo esc_url( admin_url( 'nav-menus.php' ) ); ?>"><?php _e( 'Cancel' ); ?></a> 1112 </span><!-- END .cancel-action --> 1113 <?php else : ?> 1114 <span class="delete-action"> 1115 <a class="submitdelete deletion menu-delete" href=" 1116 <?php 1117 echo esc_url( 1118 wp_nonce_url( 1119 add_query_arg( 1120 array( 1121 'action' => 'delete', 1122 'menu' => $nav_menu_selected_id, 1123 ), 1124 admin_url( 'nav-menus.php' ) 1125 ), 1126 'delete-nav_menu-' . $nav_menu_selected_id 1127 ) 1128 ); 1129 ?> 1130 "><?php _e( 'Delete Menu' ); ?></a> 1131 </span><!-- END .delete-action --> 1132 <?php endif; ?> 1133 1134 <?php endif; ?> 1135 <div class="publishing-action"> 1136 <?php submit_button( empty( $nav_menu_selected_id ) ? __( 'Create Menu' ) : __( 'Save Menu' ), 'primary large menu-save', 'save_menu', false, array( 'id' => 'save_menu_footer' ) ); ?> 1137 </div><!-- END .publishing-action --> 1138 </div><!-- END .major-publishing-actions --> 1139 </div><!-- /#nav-menu-footer --> 1140 </div><!-- /.menu-edit --> 1141 </form><!-- /#update-nav-menu --> 1142 </div><!-- /#menu-management --> 1143 </div><!-- /#menu-management-liquid --> 1144 </div><!-- /#nav-menus-frame --> 1145 <?php endif; ?> 1146</div><!-- /.wrap--> 1147<?php require_once ABSPATH . 'wp-admin/admin-footer.php'; ?> 1148