Changeset 42343 for trunk/src/wp-admin/nav-menus.php
- Timestamp:
- 11/30/2017 11:09:33 PM (8 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-admin/nav-menus.php (modified) (55 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/nav-menus.php
r42217 r42343 16 16 require_once( ABSPATH . 'wp-admin/includes/nav-menu.php' ); 17 17 18 if ( ! current_theme_supports( 'menus' ) && ! current_theme_supports( 'widgets' ) ) 18 if ( ! current_theme_supports( 'menus' ) && ! current_theme_supports( 'widgets' ) ) { 19 19 wp_die( __( 'Your theme does not support navigation menus or widgets.' ) ); 20 } 20 21 21 22 // Permissions Check … … 30 31 wp_enqueue_script( 'nav-menu' ); 31 32 32 if ( wp_is_mobile() ) 33 if ( wp_is_mobile() ) { 33 34 wp_enqueue_script( 'jquery-touch-punch' ); 35 } 34 36 35 37 // Container for any messages displayed to the user … … 43 45 44 46 // Get existing menu locations assignments 45 $locations = get_registered_nav_menus();47 $locations = get_registered_nav_menus(); 46 48 $menu_locations = get_nav_menu_locations(); 47 $num_locations = count( array_keys( $locations ) );49 $num_locations = count( array_keys( $locations ) ); 48 50 49 51 // Allowed actions: add, update, delete … … 59 61 case 'add-menu-item': 60 62 check_admin_referer( 'add-menu_item', 'menu-settings-column-nonce' ); 61 if ( isset( $_REQUEST['nav-menu-locations'] ) ) 63 if ( isset( $_REQUEST['nav-menu-locations'] ) ) { 62 64 set_theme_mod( 'nav_menu_locations', array_map( 'absint', $_REQUEST['menu-locations'] ) ); 63 elseif ( isset( $_REQUEST['menu-item'] ) )65 } elseif ( isset( $_REQUEST['menu-item'] ) ) { 64 66 wp_save_nav_menu_items( $nav_menu_selected_id, $_REQUEST['menu-item'] ); 67 } 65 68 break; 66 case 'move-down-menu-item' : 67 69 case 'move-down-menu-item': 68 70 // Moving down a menu item is the same as moving up the next in order. 69 71 check_admin_referer( 'move-menu_item' ); … … 72 74 $menus = isset( $_REQUEST['menu'] ) ? array( (int) $_REQUEST['menu'] ) : wp_get_object_terms( $menu_item_id, 'nav_menu', array( 'fields' => 'ids' ) ); 73 75 if ( ! is_wp_error( $menus ) && ! empty( $menus[0] ) ) { 74 $menu_id = (int) $menus[0];76 $menu_id = (int) $menus[0]; 75 77 $ordered_menu_items = wp_get_nav_menu_items( $menu_id ); 76 $menu_item_data = (array) wp_setup_nav_menu_item( get_post( $menu_item_id ) );78 $menu_item_data = (array) wp_setup_nav_menu_item( get_post( $menu_item_id ) ); 77 79 78 80 // Set up the data we need in one pass through the array of menu items. … … 82 84 if ( isset( $ordered_menu_item_object->ID ) ) { 83 85 if ( isset( $ordered_menu_item_object->menu_order ) ) { 84 $dbids_to_orders[ $ordered_menu_item_object->ID]= $ordered_menu_item_object->menu_order;85 $orders_to_dbids[ $ordered_menu_item_object->menu_order] = $ordered_menu_item_object->ID;86 $dbids_to_orders[ $ordered_menu_item_object->ID ] = $ordered_menu_item_object->menu_order; 87 $orders_to_dbids[ $ordered_menu_item_object->menu_order ] = $ordered_menu_item_object->ID; 86 88 } 87 89 } … … 90 92 // Get next in order. 91 93 if ( 92 isset( $orders_to_dbids[ $dbids_to_orders[$menu_item_id] + 1] )94 isset( $orders_to_dbids[ $dbids_to_orders[ $menu_item_id ] + 1 ] ) 93 95 ) { 94 $next_item_id = $orders_to_dbids[$dbids_to_orders[$menu_item_id] + 1];96 $next_item_id = $orders_to_dbids[ $dbids_to_orders[ $menu_item_id ] + 1 ]; 95 97 $next_item_data = (array) wp_setup_nav_menu_item( get_post( $next_item_id ) ); 96 98 … … 109 111 110 112 if ( ! is_wp_error( $parent_object ) ) { 111 $parent_data = (array) $parent_object;113 $parent_data = (array) $parent_object; 112 114 $menu_item_data['menu_item_parent'] = $parent_data['menu_item_parent']; 113 115 update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] ); … … 115 117 } 116 118 117 // Make menu item a child of its next sibling.119 // Make menu item a child of its next sibling. 118 120 } else { 119 121 $next_item_data['menu_order'] = $next_item_data['menu_order'] - 1; … … 123 125 update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] ); 124 126 125 wp_update_post( $menu_item_data);126 wp_update_post( $next_item_data);127 wp_update_post( $menu_item_data ); 128 wp_update_post( $next_item_data ); 127 129 } 128 130 129 // The item is last but still has a parent, so bubble up.131 // The item is last but still has a parent, so bubble up. 130 132 } elseif ( 131 133 ! empty( $menu_item_data['menu_item_parent'] ) && 132 134 in_array( $menu_item_data['menu_item_parent'], $orders_to_dbids ) 133 135 ) { 134 $menu_item_data['menu_item_parent'] = (int) get_post_meta( $menu_item_data['menu_item_parent'], '_menu_item_menu_item_parent', true );136 $menu_item_data['menu_item_parent'] = (int) get_post_meta( $menu_item_data['menu_item_parent'], '_menu_item_menu_item_parent', true ); 135 137 update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] ); 136 138 } … … 139 141 140 142 break; 141 case 'move-up-menu-item' :143 case 'move-up-menu-item': 142 144 check_admin_referer( 'move-menu_item' ); 143 145 $menu_item_id = isset( $_REQUEST['menu-item'] ) ? (int) $_REQUEST['menu-item'] : 0; … … 145 147 $menus = isset( $_REQUEST['menu'] ) ? array( (int) $_REQUEST['menu'] ) : wp_get_object_terms( $menu_item_id, 'nav_menu', array( 'fields' => 'ids' ) ); 146 148 if ( ! is_wp_error( $menus ) && ! empty( $menus[0] ) ) { 147 $menu_id = (int) $menus[0];149 $menu_id = (int) $menus[0]; 148 150 $ordered_menu_items = wp_get_nav_menu_items( $menu_id ); 149 $menu_item_data = (array) wp_setup_nav_menu_item( get_post( $menu_item_id ) );151 $menu_item_data = (array) wp_setup_nav_menu_item( get_post( $menu_item_id ) ); 150 152 151 153 // Set up the data we need in one pass through the array of menu items. … … 155 157 if ( isset( $ordered_menu_item_object->ID ) ) { 156 158 if ( isset( $ordered_menu_item_object->menu_order ) ) { 157 $dbids_to_orders[ $ordered_menu_item_object->ID]= $ordered_menu_item_object->menu_order;158 $orders_to_dbids[ $ordered_menu_item_object->menu_order] = $ordered_menu_item_object->ID;159 $dbids_to_orders[ $ordered_menu_item_object->ID ] = $ordered_menu_item_object->menu_order; 160 $orders_to_dbids[ $ordered_menu_item_object->menu_order ] = $ordered_menu_item_object->ID; 159 161 } 160 162 } … … 162 164 163 165 // If this menu item is not first. 164 if ( ! empty( $dbids_to_orders[ $menu_item_id] ) && ! empty( $orders_to_dbids[$dbids_to_orders[$menu_item_id] - 1] ) ) {166 if ( ! empty( $dbids_to_orders[ $menu_item_id ] ) && ! empty( $orders_to_dbids[ $dbids_to_orders[ $menu_item_id ] - 1 ] ) ) { 165 167 166 168 // If this menu item is a child of the previous. … … 168 170 ! empty( $menu_item_data['menu_item_parent'] ) && 169 171 in_array( $menu_item_data['menu_item_parent'], array_keys( $dbids_to_orders ) ) && 170 isset( $orders_to_dbids[ $dbids_to_orders[$menu_item_id] - 1] ) &&171 ( $menu_item_data['menu_item_parent'] == $orders_to_dbids[ $dbids_to_orders[$menu_item_id] - 1] )172 isset( $orders_to_dbids[ $dbids_to_orders[ $menu_item_id ] - 1 ] ) && 173 ( $menu_item_data['menu_item_parent'] == $orders_to_dbids[ $dbids_to_orders[ $menu_item_id ] - 1 ] ) 172 174 ) { 173 $parent_db_id = in_array( $menu_item_data['menu_item_parent'], $orders_to_dbids ) ? (int) $menu_item_data['menu_item_parent'] : 0;175 $parent_db_id = in_array( $menu_item_data['menu_item_parent'], $orders_to_dbids ) ? (int) $menu_item_data['menu_item_parent'] : 0; 174 176 $parent_object = wp_setup_nav_menu_item( get_post( $parent_db_id ) ); 175 177 … … 182 184 */ 183 185 if ( 184 ! empty( $dbids_to_orders[ $parent_db_id] ) &&185 ! empty( $orders_to_dbids[ $dbids_to_orders[$parent_db_id] - 1] ) &&186 ! empty( $dbids_to_orders[ $parent_db_id ] ) && 187 ! empty( $orders_to_dbids[ $dbids_to_orders[ $parent_db_id ] - 1 ] ) && 186 188 ! empty( $parent_data['menu_item_parent'] ) 187 189 ) { 188 190 $menu_item_data['menu_item_parent'] = $parent_data['menu_item_parent']; 189 191 190 /*191 * Else if there is something before parent and parent not a child of it,192 * make menu item a child of that something's parent193 */192 /* 193 * Else if there is something before parent and parent not a child of it, 194 * make menu item a child of that something's parent 195 */ 194 196 } elseif ( 195 ! empty( $dbids_to_orders[ $parent_db_id] ) &&196 ! empty( $orders_to_dbids[ $dbids_to_orders[$parent_db_id] - 1] )197 ! empty( $dbids_to_orders[ $parent_db_id ] ) && 198 ! empty( $orders_to_dbids[ $dbids_to_orders[ $parent_db_id ] - 1 ] ) 197 199 ) { 198 $_possible_parent_id = (int) get_post_meta( $orders_to_dbids[ $dbids_to_orders[$parent_db_id] - 1], '_menu_item_menu_item_parent', true);199 if ( in_array( $_possible_parent_id, array_keys( $dbids_to_orders ) ) ) 200 $_possible_parent_id = (int) get_post_meta( $orders_to_dbids[ $dbids_to_orders[ $parent_db_id ] - 1 ], '_menu_item_menu_item_parent', true ); 201 if ( in_array( $_possible_parent_id, array_keys( $dbids_to_orders ) ) ) { 200 202 $menu_item_data['menu_item_parent'] = $_possible_parent_id; 201 else203 } else { 202 204 $menu_item_data['menu_item_parent'] = 0; 203 204 // Else there isn't something before the parent. 205 } 206 207 // Else there isn't something before the parent. 205 208 } else { 206 209 $menu_item_data['menu_item_parent'] = 0; … … 215 218 // Save changes. 216 219 update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] ); 217 wp_update_post( $menu_item_data);218 wp_update_post( $parent_data);220 wp_update_post( $menu_item_data ); 221 wp_update_post( $parent_data ); 219 222 } 220 223 221 // Else this menu item is not a child of the previous.224 // Else this menu item is not a child of the previous. 222 225 } elseif ( 223 226 empty( $menu_item_data['menu_order'] ) || 224 227 empty( $menu_item_data['menu_item_parent'] ) || 225 228 ! in_array( $menu_item_data['menu_item_parent'], array_keys( $dbids_to_orders ) ) || 226 empty( $orders_to_dbids[ $dbids_to_orders[$menu_item_id] - 1] ) ||227 $orders_to_dbids[ $dbids_to_orders[$menu_item_id] - 1] != $menu_item_data['menu_item_parent']229 empty( $orders_to_dbids[ $dbids_to_orders[ $menu_item_id ] - 1 ] ) || 230 $orders_to_dbids[ $dbids_to_orders[ $menu_item_id ] - 1 ] != $menu_item_data['menu_item_parent'] 228 231 ) { 229 232 // Just make it a child of the previous; keep the order. 230 $menu_item_data['menu_item_parent'] = (int) $orders_to_dbids[ $dbids_to_orders[$menu_item_id] - 1];233 $menu_item_data['menu_item_parent'] = (int) $orders_to_dbids[ $dbids_to_orders[ $menu_item_id ] - 1 ]; 231 234 update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] ); 232 wp_update_post( $menu_item_data);235 wp_update_post( $menu_item_data ); 233 236 } 234 237 } … … 242 245 check_admin_referer( 'delete-menu_item_' . $menu_item_id ); 243 246 244 if ( is_nav_menu_item( $menu_item_id ) && wp_delete_post( $menu_item_id, true ) ) 245 $messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . __('The menu item has been successfully deleted.') . '</p></div>'; 247 if ( is_nav_menu_item( $menu_item_id ) && wp_delete_post( $menu_item_id, true ) ) { 248 $messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . __( 'The menu item has been successfully deleted.' ) . '</p></div>'; 249 } 246 250 break; 247 251 … … 256 260 } 257 261 258 if ( ! isset( $deletion ) ) 262 if ( ! isset( $deletion ) ) { 259 263 break; 260 261 if ( is_wp_error( $deletion ) ) 264 } 265 266 if ( is_wp_error( $deletion ) ) { 262 267 $messages[] = '<div id="message" class="error notice is-dismissible"><p>' . $deletion->get_error_message() . '</p></div>'; 263 else268 } else { 264 269 $messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . __( 'The menu has been successfully deleted.' ) . '</p></div>'; 270 } 265 271 break; 266 272 … … 268 274 check_admin_referer( 'nav_menus_bulk_actions' ); 269 275 foreach ( $_REQUEST['delete_menus'] as $menu_id_to_delete ) { 270 if ( ! is_nav_menu( $menu_id_to_delete ) ) 276 if ( ! is_nav_menu( $menu_id_to_delete ) ) { 271 277 continue; 278 } 272 279 273 280 $deletion = wp_delete_nav_menu( $menu_id_to_delete ); 274 281 if ( is_wp_error( $deletion ) ) { 275 $messages[] = '<div id="message" class="error notice is-dismissible"><p>' . $deletion->get_error_message() . '</p></div>';282 $messages[] = '<div id="message" class="error notice is-dismissible"><p>' . $deletion->get_error_message() . '</p></div>'; 276 283 $deletion_error = true; 277 284 } 278 285 } 279 286 280 if ( empty( $deletion_error ) ) 287 if ( empty( $deletion_error ) ) { 281 288 $messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . __( 'Selected menus have been successfully deleted.' ) . '</p></div>'; 289 } 282 290 break; 283 291 … … 287 295 // Remove menu locations that have been unchecked. 288 296 foreach ( $locations as $location => $description ) { 289 if ( ( empty( $_POST['menu-locations'] ) || empty( $_POST['menu-locations'][ $location ] ) ) && isset( $menu_locations[ $location ] ) && $menu_locations[ $location ] == $nav_menu_selected_id ) 297 if ( ( empty( $_POST['menu-locations'] ) || empty( $_POST['menu-locations'][ $location ] ) ) && isset( $menu_locations[ $location ] ) && $menu_locations[ $location ] == $nav_menu_selected_id ) { 290 298 unset( $menu_locations[ $location ] ); 299 } 291 300 } 292 301 … … 294 303 if ( isset( $_POST['menu-locations'] ) ) { 295 304 $new_menu_locations = array_map( 'absint', $_POST['menu-locations'] ); 296 $menu_locations = array_merge( $menu_locations, $new_menu_locations );305 $menu_locations = array_merge( $menu_locations, $new_menu_locations ); 297 306 } 298 307 … … 305 314 306 315 if ( $new_menu_title ) { 307 $_nav_menu_selected_id = wp_update_nav_menu_object( 0, array( 'menu-name' => $new_menu_title) );316 $_nav_menu_selected_id = wp_update_nav_menu_object( 0, array( 'menu-name' => $new_menu_title ) ); 308 317 309 318 if ( is_wp_error( $_nav_menu_selected_id ) ) { 310 319 $messages[] = '<div id="message" class="error notice is-dismissible"><p>' . $_nav_menu_selected_id->get_error_message() . '</p></div>'; 311 320 } else { 312 $_menu_object = wp_get_nav_menu_object( $_nav_menu_selected_id );313 $nav_menu_selected_id = $_nav_menu_selected_id;321 $_menu_object = wp_get_nav_menu_object( $_nav_menu_selected_id ); 322 $nav_menu_selected_id = $_nav_menu_selected_id; 314 323 $nav_menu_selected_title = $_menu_object->name; 315 if ( isset( $_REQUEST['menu-item'] ) ) 324 if ( isset( $_REQUEST['menu-item'] ) ) { 316 325 wp_save_nav_menu_items( $nav_menu_selected_id, absint( $_REQUEST['menu-item'] ) ); 326 } 317 327 if ( isset( $_REQUEST['zero-menu-state'] ) ) { 318 328 // If there are menu items, add them … … 327 337 } 328 338 if ( isset( $_REQUEST['use-location'] ) ) { 329 $locations = get_registered_nav_menus();339 $locations = get_registered_nav_menus(); 330 340 $menu_locations = get_nav_menu_locations(); 331 if ( isset( $locations[ $_REQUEST['use-location'] ] ) ) 341 if ( isset( $locations[ $_REQUEST['use-location'] ] ) ) { 332 342 $menu_locations[ $_REQUEST['use-location'] ] = $nav_menu_selected_id; 343 } 333 344 set_theme_mod( 'nav_menu_locations', $menu_locations ); 334 345 } … … 342 353 } 343 354 344 // Update existing menu.355 // Update existing menu. 345 356 } else { 346 357 … … 357 368 if ( is_wp_error( $_nav_menu_selected_id ) ) { 358 369 $_menu_object = $_nav_menu_selected_id; 359 $messages[] = '<div id="message" class="error notice is-dismissible"><p>' . $_nav_menu_selected_id->get_error_message() . '</p></div>';370 $messages[] = '<div id="message" class="error notice is-dismissible"><p>' . $_nav_menu_selected_id->get_error_message() . '</p></div>'; 360 371 } else { 361 $_menu_object = wp_get_nav_menu_object( $_nav_menu_selected_id );372 $_menu_object = wp_get_nav_menu_object( $_nav_menu_selected_id ); 362 373 $nav_menu_selected_title = $_menu_object->name; 363 374 } … … 388 399 389 400 $new_menu_locations = array_map( 'absint', $_POST['menu-locations'] ); 390 $menu_locations = array_merge( $menu_locations, $new_menu_locations );401 $menu_locations = array_merge( $menu_locations, $new_menu_locations ); 391 402 // Set menu locations 392 403 set_theme_mod( 'nav_menu_locations', $menu_locations ); … … 398 409 399 410 // Get all nav menus. 400 $nav_menus = wp_get_nav_menus();411 $nav_menus = wp_get_nav_menus(); 401 412 $menu_count = count( $nav_menus ); 402 413 … … 410 421 * into editing their first menu. 411 422 */ 412 $page_count = wp_count_posts( 'page' );423 $page_count = wp_count_posts( 'page' ); 413 424 $one_theme_location_no_menus = ( 1 == count( get_registered_nav_menus() ) && ! $add_new_screen && empty( $nav_menus ) && ! empty( $page_count->publish ) ) ? true : false; 414 425 415 426 $nav_menus_l10n = array( 416 427 'oneThemeLocationNoMenus' => $one_theme_location_no_menus, 417 'moveUp' => __( 'Move up one' ),418 'moveDown' => __( 'Move down one' ),419 'moveToTop' => __( 'Move to the top' ),428 'moveUp' => __( 'Move up one' ), 429 'moveDown' => __( 'Move down one' ), 430 'moveToTop' => __( 'Move to the top' ), 420 431 /* translators: %s: previous item name */ 421 'moveUnder' => __( 'Move under %s' ),432 'moveUnder' => __( 'Move under %s' ), 422 433 /* translators: %s: previous item name */ 423 'moveOutFrom' => __( 'Move out from under %s' ),434 'moveOutFrom' => __( 'Move out from under %s' ), 424 435 /* translators: %s: previous item name */ 425 'under' => __( 'Under %s' ),436 'under' => __( 'Under %s' ), 426 437 /* translators: %s: previous item name */ 427 'outFrom' => __( 'Out from under %s' ),438 'outFrom' => __( 'Out from under %s' ), 428 439 /* translators: 1: item name, 2: item position, 3: total number of items */ 429 'menuFocus' => __( '%1$s. Menu item %2$d of %3$d.' ),440 'menuFocus' => __( '%1$s. Menu item %2$d of %3$d.' ), 430 441 /* translators: 1: item name, 2: item position, 3: parent item name */ 431 'subMenuFocus' => __( '%1$s. Sub item number %2$d under %3$s.' ),442 'subMenuFocus' => __( '%1$s. Sub item number %2$d under %3$s.' ), 432 443 ); 433 444 wp_localize_script( 'nav-menu', 'menus', $nav_menus_l10n ); … … 437 448 * or more than 1 theme locations. 438 449 */ 439 if ( 0 == $menu_count && ! $add_new_screen && ! $one_theme_location_no_menus ) 450 if ( 0 == $menu_count && ! $add_new_screen && ! $one_theme_location_no_menus ) { 440 451 wp_redirect( admin_url( 'nav-menus.php?action=edit&menu=0' ) ); 452 } 441 453 442 454 // Get recently edited nav menu. 443 455 $recently_edited = absint( get_user_option( 'nav_menu_recently_edited' ) ); 444 if ( empty( $recently_edited ) && is_nav_menu( $nav_menu_selected_id ) ) 456 if ( empty( $recently_edited ) && is_nav_menu( $nav_menu_selected_id ) ) { 445 457 $recently_edited = $nav_menu_selected_id; 458 } 446 459 447 460 // Use $recently_edited if none are selected. 448 if ( empty( $nav_menu_selected_id ) && ! isset( $_GET['menu'] ) && is_nav_menu( $recently_edited ) ) 461 if ( empty( $nav_menu_selected_id ) && ! isset( $_GET['menu'] ) && is_nav_menu( $recently_edited ) ) { 449 462 $nav_menu_selected_id = $recently_edited; 463 } 450 464 451 465 // On deletion of menu, if another menu exists, show it. 452 if ( ! $add_new_screen && 0 < $menu_count && isset( $_GET['action'] ) && 'delete' == $_GET['action'] ) 466 if ( ! $add_new_screen && 0 < $menu_count && isset( $_GET['action'] ) && 'delete' == $_GET['action'] ) { 453 467 $nav_menu_selected_id = $nav_menus[0]->term_id; 468 } 454 469 455 470 // Set $nav_menu_selected_id to 0 if no menus. … … 462 477 463 478 // Update the user's setting. 464 if ( $nav_menu_selected_id != $recently_edited && is_nav_menu( $nav_menu_selected_id ) ) 479 if ( $nav_menu_selected_id != $recently_edited && is_nav_menu( $nav_menu_selected_id ) ) { 465 480 update_user_meta( $current_user->ID, 'nav_menu_recently_edited', $nav_menu_selected_id ); 481 } 466 482 467 483 // If there's a menu, get its name. 468 484 if ( ! $nav_menu_selected_title && is_nav_menu( $nav_menu_selected_id ) ) { 469 $_menu_object = wp_get_nav_menu_object( $nav_menu_selected_id );485 $_menu_object = wp_get_nav_menu_object( $nav_menu_selected_id ); 470 486 $nav_menu_selected_title = ! is_wp_error( $_menu_object ) ? $_menu_object->name : ''; 471 487 } … … 473 489 // Generate truncated menu names. 474 490 foreach ( (array) $nav_menus as $key => $_nav_menu ) { 475 $nav_menus[ $key]->truncated_name = wp_html_excerpt( $_nav_menu->name, 40, '…' );491 $nav_menus[ $key ]->truncated_name = wp_html_excerpt( $_nav_menu->name, 40, '…' ); 476 492 } 477 493 478 494 // Retrieve menu locations. 479 495 if ( current_theme_supports( 'menus' ) ) { 480 $locations = get_registered_nav_menus();496 $locations = get_registered_nav_menus(); 481 497 $menu_locations = get_nav_menu_locations(); 482 498 } … … 493 509 // Calling wp_get_nav_menu_to_edit generates $_wp_nav_menu_max_depth. 494 510 if ( is_nav_menu( $nav_menu_selected_id ) ) { 495 $menu_items = wp_get_nav_menu_items( $nav_menu_selected_id, array( 'post_status' => 'any' ) );511 $menu_items = wp_get_nav_menu_items( $nav_menu_selected_id, array( 'post_status' => 'any' ) ); 496 512 $edit_markup = wp_get_nav_menu_to_edit( $nav_menu_selected_id ); 497 513 } 498 514 499 515 /** 500 *501 516 * @global int $_wp_nav_menu_max_depth 502 517 * … … 509 524 } 510 525 511 add_filter( 'admin_body_class', 'wp_nav_menu_max_depth');526 add_filter( 'admin_body_class', 'wp_nav_menu_max_depth' ); 512 527 513 528 wp_nav_menu_setup(); 514 529 wp_initial_nav_menu_meta_boxes(); 515 530 516 if ( ! current_theme_supports( 'menus' ) && ! $num_locations ) 531 if ( ! current_theme_supports( 'menus' ) && ! $num_locations ) { 517 532 $messages[] = '<div id="message" class="updated"><p>' . sprintf( __( 'Your theme does not natively support menus, but you can use them in sidebars by adding a “Navigation Menu” widget on the <a href="%s">Widgets</a> screen.' ), admin_url( 'widgets.php' ) ) . '</p></div>'; 533 } 518 534 519 535 if ( ! $locations_screen ) : // Main tab 520 $overview = '<p>' . __( 'This screen is used for managing your navigation menus.' ) . '</p>';536 $overview = '<p>' . __( 'This screen is used for managing your navigation menus.' ) . '</p>'; 521 537 /* translators: 1: Widgets admin screen URL, 2 and 3: The name of the default themes */ 522 538 $overview .= '<p>' . sprintf( __( 'Menus can be displayed in locations defined by your theme, even used in sidebars by adding a “Navigation Menu” widget on the <a href="%1$s">Widgets</a> screen. If your theme does not support the navigation menus feature (the default themes, %2$s and %3$s, do), you can learn about adding this support by following the Documentation link to the side.' ), admin_url( 'widgets.php' ), 'Twenty Sixteen', 'Twenty Seventeen' ) . '</p>'; … … 525 541 $overview .= '<li>' . __( 'Add, organize, and modify individual menu items' ) . '</li></ul>'; 526 542 527 get_current_screen()->add_help_tab( array( 528 'id' => 'overview', 529 'title' => __( 'Overview' ), 530 'content' => $overview 531 ) ); 543 get_current_screen()->add_help_tab( 544 array( 545 'id' => 'overview', 546 'title' => __( 'Overview' ), 547 'content' => $overview, 548 ) 549 ); 532 550 533 551 $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>'; … … 536 554 $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>'; 537 555 538 get_current_screen()->add_help_tab( array( 539 'id' => 'menu-management', 540 'title' => __( 'Menu Management' ), 541 'content' => $menu_management 542 ) ); 556 get_current_screen()->add_help_tab( 557 array( 558 'id' => 'menu-management', 559 'title' => __( 'Menu Management' ), 560 'content' => $menu_management, 561 ) 562 ); 543 563 544 564 $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>'; 545 565 $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>'; 546 566 $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>'; 547 $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>';567 $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>'; 548 568 $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>'; 549 569 $editing_menus .= '<li>' . __( 'Delete a menu item by <strong>expanding it and clicking the Remove link</strong>' ) . '</li></ul>'; 550 570 551 get_current_screen()->add_help_tab( array( 552 'id' => 'editing-menus', 553 'title' => __( 'Editing Menus' ), 554 'content' => $editing_menus 555 ) ); 571 get_current_screen()->add_help_tab( 572 array( 573 'id' => 'editing-menus', 574 'title' => __( 'Editing Menus' ), 575 'content' => $editing_menus, 576 ) 577 ); 556 578 else : // Locations Tab. 557 579 $locations_overview = '<p>' . __( 'This screen is used for globally assigning menus to locations defined by your theme.' ) . '</p>'; … … 560 582 $locations_overview .= '<li>' . __( 'To add a new menu instead of assigning an existing one, <strong>click the ’Use new menu’ link</strong>. Your new menu will be automatically assigned to that theme location' ) . '</li></ul>'; 561 583 562 get_current_screen()->add_help_tab( array( 563 'id' => 'locations-overview', 564 'title' => __( 'Overview' ), 565 'content' => $locations_overview 566 ) ); 584 get_current_screen()->add_help_tab( 585 array( 586 'id' => 'locations-overview', 587 'title' => __( 'Overview' ), 588 'content' => $locations_overview, 589 ) 590 ); 567 591 endif; 568 592 569 593 get_current_screen()->set_help_sidebar( 570 '<p><strong>' . __( 'For more information:') . '</strong></p>' .571 '<p>' . __( '<a href="https://codex.wordpress.org/Appearance_Menus_Screen">Documentation on Menus</a>') . '</p>' .572 '<p>' . __( '<a href="https://wordpress.org/support/">Support Forums</a>') . '</p>'594 '<p><strong>' . __( 'For more information:' ) . '</strong></p>' . 595 '<p>' . __( '<a href="https://codex.wordpress.org/Appearance_Menus_Screen">Documentation on Menus</a>' ) . '</p>' . 596 '<p>' . __( '<a href="https://wordpress.org/support/">Support Forums</a>' ) . '</p>' 573 597 ); 574 598 … … 583 607 printf( 584 608 ' <a class="page-title-action hide-if-no-customize" href="%1$s">%2$s</a>', 585 esc_url( add_query_arg( array( 586 array( 'autofocus' => $focus ), 587 'return' => urlencode( remove_query_arg( wp_removable_query_args(), wp_unslash( $_SERVER['REQUEST_URI'] ) ) ), 588 ), admin_url( 'customize.php' ) ) ), 609 esc_url( 610 add_query_arg( 611 array( 612 array( 'autofocus' => $focus ), 613 'return' => urlencode( remove_query_arg( wp_removable_query_args(), wp_unslash( $_SERVER['REQUEST_URI'] ) ) ), 614 ), admin_url( 'customize.php' ) 615 ) 616 ), 589 617 __( 'Manage with Live Preview' ) 590 618 ); … … 602 630 <a href="<?php echo admin_url( 'nav-menus.php' ); ?>" class="nav-tab<?php echo $nav_tab_active_class; ?>"><?php esc_html_e( 'Edit Menus' ); ?></a> 603 631 <?php if ( $num_locations && $menu_count ) : ?> 604 <a href="<?php echo esc_url( add_query_arg( array( 'action' => 'locations' ), admin_url( 'nav-menus.php' ) ) ); ?>" class="nav-tab<?php if ( $locations_screen ) echo ' nav-tab-active'; ?>"><?php esc_html_e( 'Manage Locations' ); ?></a> 632 <a href="<?php echo esc_url( add_query_arg( array( 'action' => 'locations' ), admin_url( 'nav-menus.php' ) ) ); ?>" class="nav-tab 633 <?php 634 if ( $locations_screen ) { 635 echo ' nav-tab-active';} 636 ?> 637 "><?php esc_html_e( 'Manage Locations' ); ?></a> 605 638 <?php 606 639 endif; … … 617 650 echo '<p>' . __( 'Your theme supports one menu. Select which menu you would like to use.' ) . '</p>'; 618 651 } else { 619 echo '<p>' . sprintf( _n( 'Your theme supports %s menu. Select which menu appears in each location.', 'Your theme supports %s menus. Select which menu appears in each location.', $num_locations ), number_format_i18n( $num_locations ) ) . '</p>';652 echo '<p>' . sprintf( _n( 'Your theme supports %s menu. Select which menu appears in each location.', 'Your theme supports %s menus. Select which menu appears in each location.', $num_locations ), number_format_i18n( $num_locations ) ) . '</p>'; 620 653 } 621 654 ?> … … 637 670 <option value="0"><?php printf( '— %s —', esc_html__( 'Select a Menu' ) ); ?></option> 638 671 <?php 639 foreach ( $nav_menus as $menu ) :640 $data_orig = '';641 $selected = isset( $menu_locations[$_location] ) && $menu_locations[$_location] == $menu->term_id;642 if ( $selected ) {643 $data_orig = 'data-orig="true"';644 }645 ?>672 foreach ( $nav_menus as $menu ) : 673 $data_orig = ''; 674 $selected = isset( $menu_locations[ $_location ] ) && $menu_locations[ $_location ] == $menu->term_id; 675 if ( $selected ) { 676 $data_orig = 'data-orig="true"'; 677 } 678 ?> 646 679 <option <?php echo $data_orig; ?> <?php selected( $selected ); ?> value="<?php echo $menu->term_id; ?>"> 647 680 <?php echo wp_html_excerpt( $menu->name, 40, '…' ); ?> … … 652 685 <?php if ( isset( $menu_locations[ $_location ] ) && 0 != $menu_locations[ $_location ] ) : ?> 653 686 <span class="locations-edit-menu-link"> 654 <a href="<?php echo esc_url( add_query_arg( array( 'action' => 'edit', 'menu' => $menu_locations[$_location] ), admin_url( 'nav-menus.php' ) ) ); ?>"> 687 <a href=" 688 <?php 689 echo esc_url( 690 add_query_arg( 691 array( 692 'action' => 'edit', 693 'menu' => $menu_locations[ $_location ], 694 ), admin_url( 'nav-menus.php' ) 695 ) 696 ); 697 ?> 698 "> 655 699 <span aria-hidden="true"><?php _ex( 'Edit', 'menu' ); ?></span><span class="screen-reader-text"><?php _e( 'Edit selected menu' ); ?></span> 656 700 </a> … … 658 702 <?php endif; ?> 659 703 <span class="locations-add-menu-link"> 660 <a href="<?php echo esc_url( add_query_arg( array( 'action' => 'edit', 'menu' => 0, 'use-location' => $_location ), admin_url( 'nav-menus.php' ) ) ); ?>"> 704 <a href=" 705 <?php 706 echo esc_url( 707 add_query_arg( 708 array( 709 'action' => 'edit', 710 'menu' => 0, 711 'use-location' => $_location, 712 ), admin_url( 'nav-menus.php' ) 713 ) 714 ); 715 ?> 716 "> 661 717 <?php _ex( 'Use new menu', 'menu' ); ?> 662 718 </a> … … 679 735 * @since 3.6.0 680 736 */ 681 do_action( 'after_menu_locations_table' ); ?> 737 do_action( 'after_menu_locations_table' ); 738 ?> 682 739 <?php else : ?> 683 740 <div class="manage-menus"> 684 <?php if ( $menu_count < 2 ) : ?>741 <?php if ( $menu_count < 2 ) : ?> 685 742 <span class="add-edit-menu-action"> 686 <?php printf( __( 'Edit your menu below, or <a href="%s">create a new menu</a>.' ), esc_url( add_query_arg( array( 'action' => 'edit', 'menu' => 0 ), admin_url( 'nav-menus.php' ) ) ) ); ?> 743 <?php 744 printf( 745 __( 'Edit your menu below, or <a href="%s">create a new menu</a>.' ), esc_url( 746 add_query_arg( 747 array( 748 'action' => 'edit', 749 'menu' => 0, 750 ), admin_url( 'nav-menus.php' ) 751 ) 752 ) 753 ); 754 ?> 687 755 </span><!-- /add-edit-menu-action --> 688 756 <?php else : ?> … … 697 765 <option value="<?php echo esc_attr( $_nav_menu->term_id ); ?>" <?php selected( $_nav_menu->term_id, $nav_menu_selected_id ); ?>> 698 766 <?php 699 echo esc_html( $_nav_menu->truncated_name ) ;767 echo esc_html( $_nav_menu->truncated_name ); 700 768 701 769 if ( ! empty( $menu_locations ) && in_array( $_nav_menu->term_id, $menu_locations ) ) { … … 718 786 // Adds ellipses following the number of locations defined in $assigned_locations. 719 787 if ( ! empty( $assigned_locations ) ) { 720 printf( ' (%1$s%2$s)', 788 printf( 789 ' (%1$s%2$s)', 721 790 implode( ', ', $assigned_locations ), 722 791 count( $locations_assigned_to_this_menu ) > count( $assigned_locations ) ? ' …' : '' … … 730 799 <span class="submit-btn"><input type="submit" class="button" value="<?php esc_attr_e( 'Select' ); ?>"></span> 731 800 <span class="add-new-menu-action"> 732 <?php printf( __( 'or <a href="%s">create a new menu</a>.' ), esc_url( add_query_arg( array( 'action' => 'edit', 'menu' => 0 ), admin_url( 'nav-menus.php' ) ) ) ); ?> 801 <?php 802 printf( 803 __( 'or <a href="%s">create a new menu</a>.' ), esc_url( 804 add_query_arg( 805 array( 806 'action' => 'edit', 807 'menu' => 0, 808 ), admin_url( 'nav-menus.php' ) 809 ) 810 ) 811 ); 812 ?> 733 813 </span><!-- /add-new-menu-action --> 734 814 </form> … … 737 817 738 818 $metabox_holder_disabled_class = ''; 739 if ( isset( $_GET['menu'] ) && '0' == $_GET['menu'] ) {740 $metabox_holder_disabled_class = ' metabox-holder-disabled';741 }819 if ( isset( $_GET['menu'] ) && '0' == $_GET['menu'] ) { 820 $metabox_holder_disabled_class = ' metabox-holder-disabled'; 821 } 742 822 ?> 743 823 </div><!-- /manage-menus --> … … 760 840 <?php 761 841 $new_screen_class = ''; 762 if ( $add_new_screen ) {763 $new_screen_class = 'blank-slate';764 }842 if ( $add_new_screen ) { 843 $new_screen_class = 'blank-slate'; 844 } 765 845 ?> 766 846 <div class="menu-edit <?php echo $new_screen_class; ?>"> … … 777 857 ?> 778 858 <input type="hidden" name="zero-menu-state" value="true" /> 779 <?php } else { 859 <?php 860 } else { 780 861 $menu_name_val = 'value="' . esc_attr( $nav_menu_selected_title ) . '"'; 781 } ?> 782 <input type="hidden" name="action" value="update" /> 862 } 863 ?> 864 <input type="hidden" name="action" value="update" /> 783 865 <input type="hidden" name="menu" id="menu" value="<?php echo esc_attr( $nav_menu_selected_id ); ?>" /> 784 866 <div id="nav-menu-header"> … … 797 879 <?php 798 880 $hide_style = ''; 799 if ( isset( $menu_items ) && 0 == count( $menu_items ) ) {800 $hide_style = 'style="display: none;"';801 }881 if ( isset( $menu_items ) && 0 == count( $menu_items ) ) { 882 $hide_style = 'style="display: none;"'; 883 } 802 884 $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.' ); 803 885 ?> … … 822 904 823 905 $no_menus_style = ''; 824 if ( $one_theme_location_no_menus ) {825 $no_menus_style = 'style="display: none;"';826 }906 if ( $one_theme_location_no_menus ) { 907 $no_menus_style = 'style="display: none;"'; 908 } 827 909 ?> 828 910 <div class="menu-settings" <?php echo $no_menus_style; ?>> … … 831 913 if ( ! isset( $auto_add ) ) { 832 914 $auto_add = get_option( 'nav_menu_options' ); 833 if ( ! isset( $auto_add['auto_add'] ) ) 915 if ( ! isset( $auto_add['auto_add'] ) ) { 834 916 $auto_add = false; 835 elseif ( false !== array_search( $nav_menu_selected_id, $auto_add['auto_add'] ) )917 } elseif ( false !== array_search( $nav_menu_selected_id, $auto_add['auto_add'] ) ) { 836 918 $auto_add = true; 837 else919 } else { 838 920 $auto_add = false; 839 } ?> 921 } 922 } 923 ?> 840 924 841 925 <fieldset class="menu-settings-group auto-add-pages"> 842 926 <legend class="menu-settings-group-name howto"><?php _e( 'Auto add pages' ); ?></legend> 843 927 <div class="menu-settings-input checkbox-input"> 844 <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>928 <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> 845 929 </div> 846 930 </fieldset> … … 855 939 <label for="locations-<?php echo esc_attr( $location ); ?>"><?php echo $description; ?></label> 856 940 <?php if ( ! empty( $menu_locations[ $location ] ) && $menu_locations[ $location ] != $nav_menu_selected_id ) : ?> 857 <span class="theme-location-set"><?php 941 <span class="theme-location-set"> 942 <?php 858 943 /* translators: %s: menu name */ 859 printf( _x( '(Currently set to: %s)', 'menu location' ), 944 printf( 945 _x( '(Currently set to: %s)', 'menu location' ), 860 946 wp_get_nav_menu_object( $menu_locations[ $location ] )->name 861 947 ); 862 ?></span> 948 ?> 949 </span> 863 950 <?php endif; ?> 864 951 </div> … … 875 962 <?php if ( 0 != $menu_count && ! $add_new_screen ) : ?> 876 963 <span class="delete-action"> 877 <a class="submitdelete deletion menu-delete" href="<?php echo esc_url( wp_nonce_url( add_query_arg( array( 'action' => 'delete', 'menu' => $nav_menu_selected_id ), admin_url( 'nav-menus.php' ) ), 'delete-nav_menu-' . $nav_menu_selected_id) ); ?>"><?php _e('Delete Menu'); ?></a> 964 <a class="submitdelete deletion menu-delete" href=" 965 <?php 966 echo esc_url( 967 wp_nonce_url( 968 add_query_arg( 969 array( 970 'action' => 'delete', 971 'menu' => $nav_menu_selected_id, 972 ), admin_url( 'nav-menus.php' ) 973 ), 'delete-nav_menu-' . $nav_menu_selected_id 974 ) 975 ); 976 ?> 977 "><?php _e( 'Delete Menu' ); ?></a> 878 978 </span><!-- END .delete-action --> 879 979 <?php endif; ?>
Note: See TracChangeset
for help on using the changeset viewer.