Нема описа

nav-menus.php 45KB

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