nav-menus.php 43 KB

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