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