Edit File by line
/home/barbar84/public_h.../wp-admin
File: nav-menus.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* WordPress Administration for Navigation Menus
[2] Fix | Delete
* Interface functions
[3] Fix | Delete
*
[4] Fix | Delete
* @version 2.0.0
[5] Fix | Delete
*
[6] Fix | Delete
* @package WordPress
[7] Fix | Delete
* @subpackage Administration
[8] Fix | Delete
*/
[9] Fix | Delete
[10] Fix | Delete
/** Load WordPress Administration Bootstrap */
[11] Fix | Delete
require_once __DIR__ . '/admin.php';
[12] Fix | Delete
[13] Fix | Delete
// Load all the nav menu interface functions.
[14] Fix | Delete
require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
[15] Fix | Delete
[16] Fix | Delete
if ( ! current_theme_supports( 'menus' ) && ! current_theme_supports( 'widgets' ) ) {
[17] Fix | Delete
wp_die( __( 'Your theme does not support navigation menus or widgets.' ) );
[18] Fix | Delete
}
[19] Fix | Delete
[20] Fix | Delete
// Permissions check.
[21] Fix | Delete
if ( ! current_user_can( 'edit_theme_options' ) ) {
[22] Fix | Delete
wp_die(
[23] Fix | Delete
'<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
[24] Fix | Delete
'<p>' . __( 'Sorry, you are not allowed to edit theme options on this site.' ) . '</p>',
[25] Fix | Delete
403
[26] Fix | Delete
);
[27] Fix | Delete
}
[28] Fix | Delete
[29] Fix | Delete
wp_enqueue_script( 'nav-menu' );
[30] Fix | Delete
[31] Fix | Delete
if ( wp_is_mobile() ) {
[32] Fix | Delete
wp_enqueue_script( 'jquery-touch-punch' );
[33] Fix | Delete
}
[34] Fix | Delete
[35] Fix | Delete
// Container for any messages displayed to the user.
[36] Fix | Delete
$messages = array();
[37] Fix | Delete
[38] Fix | Delete
// Container that stores the name of the active menu.
[39] Fix | Delete
$nav_menu_selected_title = '';
[40] Fix | Delete
[41] Fix | Delete
// The menu id of the current menu being edited.
[42] Fix | Delete
$nav_menu_selected_id = isset( $_REQUEST['menu'] ) ? (int) $_REQUEST['menu'] : 0;
[43] Fix | Delete
[44] Fix | Delete
// Get existing menu locations assignments.
[45] Fix | Delete
$locations = get_registered_nav_menus();
[46] Fix | Delete
$menu_locations = get_nav_menu_locations();
[47] Fix | Delete
$num_locations = count( array_keys( $locations ) );
[48] Fix | Delete
[49] Fix | Delete
// Allowed actions: add, update, delete.
[50] Fix | Delete
$action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : 'edit';
[51] Fix | Delete
[52] Fix | Delete
/*
[53] Fix | Delete
* If a JSON blob of navigation menu data is found, expand it and inject it
[54] Fix | Delete
* into `$_POST` to avoid PHP `max_input_vars` limitations. See #14134.
[55] Fix | Delete
*/
[56] Fix | Delete
_wp_expand_nav_menu_post_data();
[57] Fix | Delete
[58] Fix | Delete
switch ( $action ) {
[59] Fix | Delete
case 'add-menu-item':
[60] Fix | Delete
check_admin_referer( 'add-menu_item', 'menu-settings-column-nonce' );
[61] Fix | Delete
[62] Fix | Delete
if ( isset( $_REQUEST['nav-menu-locations'] ) ) {
[63] Fix | Delete
set_theme_mod( 'nav_menu_locations', array_map( 'absint', $_REQUEST['menu-locations'] ) );
[64] Fix | Delete
} elseif ( isset( $_REQUEST['menu-item'] ) ) {
[65] Fix | Delete
wp_save_nav_menu_items( $nav_menu_selected_id, $_REQUEST['menu-item'] );
[66] Fix | Delete
}
[67] Fix | Delete
[68] Fix | Delete
break;
[69] Fix | Delete
[70] Fix | Delete
case 'move-down-menu-item':
[71] Fix | Delete
// Moving down a menu item is the same as moving up the next in order.
[72] Fix | Delete
check_admin_referer( 'move-menu_item' );
[73] Fix | Delete
[74] Fix | Delete
$menu_item_id = isset( $_REQUEST['menu-item'] ) ? (int) $_REQUEST['menu-item'] : 0;
[75] Fix | Delete
[76] Fix | Delete
if ( is_nav_menu_item( $menu_item_id ) ) {
[77] Fix | Delete
$menus = isset( $_REQUEST['menu'] ) ? array( (int) $_REQUEST['menu'] ) : wp_get_object_terms( $menu_item_id, 'nav_menu', array( 'fields' => 'ids' ) );
[78] Fix | Delete
[79] Fix | Delete
if ( ! is_wp_error( $menus ) && ! empty( $menus[0] ) ) {
[80] Fix | Delete
$menu_id = (int) $menus[0];
[81] Fix | Delete
$ordered_menu_items = wp_get_nav_menu_items( $menu_id );
[82] Fix | Delete
$menu_item_data = (array) wp_setup_nav_menu_item( get_post( $menu_item_id ) );
[83] Fix | Delete
[84] Fix | Delete
// Set up the data we need in one pass through the array of menu items.
[85] Fix | Delete
$dbids_to_orders = array();
[86] Fix | Delete
$orders_to_dbids = array();
[87] Fix | Delete
[88] Fix | Delete
foreach ( (array) $ordered_menu_items as $ordered_menu_item_object ) {
[89] Fix | Delete
if ( isset( $ordered_menu_item_object->ID ) ) {
[90] Fix | Delete
if ( isset( $ordered_menu_item_object->menu_order ) ) {
[91] Fix | Delete
$dbids_to_orders[ $ordered_menu_item_object->ID ] = $ordered_menu_item_object->menu_order;
[92] Fix | Delete
$orders_to_dbids[ $ordered_menu_item_object->menu_order ] = $ordered_menu_item_object->ID;
[93] Fix | Delete
}
[94] Fix | Delete
}
[95] Fix | Delete
}
[96] Fix | Delete
[97] Fix | Delete
// Get next in order.
[98] Fix | Delete
if ( isset( $orders_to_dbids[ $dbids_to_orders[ $menu_item_id ] + 1 ] ) ) {
[99] Fix | Delete
$next_item_id = $orders_to_dbids[ $dbids_to_orders[ $menu_item_id ] + 1 ];
[100] Fix | Delete
$next_item_data = (array) wp_setup_nav_menu_item( get_post( $next_item_id ) );
[101] Fix | Delete
[102] Fix | Delete
// If not siblings of same parent, bubble menu item up but keep order.
[103] Fix | Delete
if ( ! empty( $menu_item_data['menu_item_parent'] )
[104] Fix | Delete
&& ( empty( $next_item_data['menu_item_parent'] )
[105] Fix | Delete
|| (int) $next_item_data['menu_item_parent'] !== (int) $menu_item_data['menu_item_parent'] )
[106] Fix | Delete
) {
[107] Fix | Delete
if ( in_array( (int) $menu_item_data['menu_item_parent'], $orders_to_dbids, true ) ) {
[108] Fix | Delete
$parent_db_id = (int) $menu_item_data['menu_item_parent'];
[109] Fix | Delete
} else {
[110] Fix | Delete
$parent_db_id = 0;
[111] Fix | Delete
}
[112] Fix | Delete
[113] Fix | Delete
$parent_object = wp_setup_nav_menu_item( get_post( $parent_db_id ) );
[114] Fix | Delete
[115] Fix | Delete
if ( ! is_wp_error( $parent_object ) ) {
[116] Fix | Delete
$parent_data = (array) $parent_object;
[117] Fix | Delete
$menu_item_data['menu_item_parent'] = $parent_data['menu_item_parent'];
[118] Fix | Delete
update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] );
[119] Fix | Delete
}
[120] Fix | Delete
[121] Fix | Delete
// Make menu item a child of its next sibling.
[122] Fix | Delete
} else {
[123] Fix | Delete
$next_item_data['menu_order'] = $next_item_data['menu_order'] - 1;
[124] Fix | Delete
$menu_item_data['menu_order'] = $menu_item_data['menu_order'] + 1;
[125] Fix | Delete
[126] Fix | Delete
$menu_item_data['menu_item_parent'] = $next_item_data['ID'];
[127] Fix | Delete
update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] );
[128] Fix | Delete
[129] Fix | Delete
wp_update_post( $menu_item_data );
[130] Fix | Delete
wp_update_post( $next_item_data );
[131] Fix | Delete
}
[132] Fix | Delete
[133] Fix | Delete
// The item is last but still has a parent, so bubble up.
[134] Fix | Delete
} elseif ( ! empty( $menu_item_data['menu_item_parent'] )
[135] Fix | Delete
&& in_array( (int) $menu_item_data['menu_item_parent'], $orders_to_dbids, true )
[136] Fix | Delete
) {
[137] Fix | Delete
$menu_item_data['menu_item_parent'] = (int) get_post_meta( $menu_item_data['menu_item_parent'], '_menu_item_menu_item_parent', true );
[138] Fix | Delete
update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] );
[139] Fix | Delete
}
[140] Fix | Delete
}
[141] Fix | Delete
}
[142] Fix | Delete
[143] Fix | Delete
break;
[144] Fix | Delete
[145] Fix | Delete
case 'move-up-menu-item':
[146] Fix | Delete
check_admin_referer( 'move-menu_item' );
[147] Fix | Delete
[148] Fix | Delete
$menu_item_id = isset( $_REQUEST['menu-item'] ) ? (int) $_REQUEST['menu-item'] : 0;
[149] Fix | Delete
[150] Fix | Delete
if ( is_nav_menu_item( $menu_item_id ) ) {
[151] Fix | Delete
if ( isset( $_REQUEST['menu'] ) ) {
[152] Fix | Delete
$menus = array( (int) $_REQUEST['menu'] );
[153] Fix | Delete
} else {
[154] Fix | Delete
$menus = wp_get_object_terms( $menu_item_id, 'nav_menu', array( 'fields' => 'ids' ) );
[155] Fix | Delete
}
[156] Fix | Delete
[157] Fix | Delete
if ( ! is_wp_error( $menus ) && ! empty( $menus[0] ) ) {
[158] Fix | Delete
$menu_id = (int) $menus[0];
[159] Fix | Delete
$ordered_menu_items = wp_get_nav_menu_items( $menu_id );
[160] Fix | Delete
$menu_item_data = (array) wp_setup_nav_menu_item( get_post( $menu_item_id ) );
[161] Fix | Delete
[162] Fix | Delete
// Set up the data we need in one pass through the array of menu items.
[163] Fix | Delete
$dbids_to_orders = array();
[164] Fix | Delete
$orders_to_dbids = array();
[165] Fix | Delete
[166] Fix | Delete
foreach ( (array) $ordered_menu_items as $ordered_menu_item_object ) {
[167] Fix | Delete
if ( isset( $ordered_menu_item_object->ID ) ) {
[168] Fix | Delete
if ( isset( $ordered_menu_item_object->menu_order ) ) {
[169] Fix | Delete
$dbids_to_orders[ $ordered_menu_item_object->ID ] = $ordered_menu_item_object->menu_order;
[170] Fix | Delete
$orders_to_dbids[ $ordered_menu_item_object->menu_order ] = $ordered_menu_item_object->ID;
[171] Fix | Delete
}
[172] Fix | Delete
}
[173] Fix | Delete
}
[174] Fix | Delete
[175] Fix | Delete
// If this menu item is not first.
[176] Fix | Delete
if ( ! empty( $dbids_to_orders[ $menu_item_id ] )
[177] Fix | Delete
&& ! empty( $orders_to_dbids[ $dbids_to_orders[ $menu_item_id ] - 1 ] )
[178] Fix | Delete
) {
[179] Fix | Delete
[180] Fix | Delete
// If this menu item is a child of the previous.
[181] Fix | Delete
if ( ! empty( $menu_item_data['menu_item_parent'] )
[182] Fix | Delete
&& in_array( (int) $menu_item_data['menu_item_parent'], array_keys( $dbids_to_orders ), true )
[183] Fix | Delete
&& isset( $orders_to_dbids[ $dbids_to_orders[ $menu_item_id ] - 1 ] )
[184] Fix | Delete
&& ( (int) $menu_item_data['menu_item_parent'] === $orders_to_dbids[ $dbids_to_orders[ $menu_item_id ] - 1 ] )
[185] Fix | Delete
) {
[186] Fix | Delete
if ( in_array( (int) $menu_item_data['menu_item_parent'], $orders_to_dbids, true ) ) {
[187] Fix | Delete
$parent_db_id = (int) $menu_item_data['menu_item_parent'];
[188] Fix | Delete
} else {
[189] Fix | Delete
$parent_db_id = 0;
[190] Fix | Delete
}
[191] Fix | Delete
[192] Fix | Delete
$parent_object = wp_setup_nav_menu_item( get_post( $parent_db_id ) );
[193] Fix | Delete
[194] Fix | Delete
if ( ! is_wp_error( $parent_object ) ) {
[195] Fix | Delete
$parent_data = (array) $parent_object;
[196] Fix | Delete
[197] Fix | Delete
/*
[198] Fix | Delete
* If there is something before the parent and parent a child of it,
[199] Fix | Delete
* make menu item a child also of it.
[200] Fix | Delete
*/
[201] Fix | Delete
if ( ! empty( $dbids_to_orders[ $parent_db_id ] )
[202] Fix | Delete
&& ! empty( $orders_to_dbids[ $dbids_to_orders[ $parent_db_id ] - 1 ] )
[203] Fix | Delete
&& ! empty( $parent_data['menu_item_parent'] )
[204] Fix | Delete
) {
[205] Fix | Delete
$menu_item_data['menu_item_parent'] = $parent_data['menu_item_parent'];
[206] Fix | Delete
[207] Fix | Delete
/*
[208] Fix | Delete
* Else if there is something before parent and parent not a child of it,
[209] Fix | Delete
* make menu item a child of that something's parent
[210] Fix | Delete
*/
[211] Fix | Delete
} elseif ( ! empty( $dbids_to_orders[ $parent_db_id ] )
[212] Fix | Delete
&& ! empty( $orders_to_dbids[ $dbids_to_orders[ $parent_db_id ] - 1 ] )
[213] Fix | Delete
) {
[214] Fix | Delete
$_possible_parent_id = (int) get_post_meta( $orders_to_dbids[ $dbids_to_orders[ $parent_db_id ] - 1 ], '_menu_item_menu_item_parent', true );
[215] Fix | Delete
[216] Fix | Delete
if ( in_array( $_possible_parent_id, array_keys( $dbids_to_orders ), true ) ) {
[217] Fix | Delete
$menu_item_data['menu_item_parent'] = $_possible_parent_id;
[218] Fix | Delete
} else {
[219] Fix | Delete
$menu_item_data['menu_item_parent'] = 0;
[220] Fix | Delete
}
[221] Fix | Delete
[222] Fix | Delete
// Else there isn't something before the parent.
[223] Fix | Delete
} else {
[224] Fix | Delete
$menu_item_data['menu_item_parent'] = 0;
[225] Fix | Delete
}
[226] Fix | Delete
[227] Fix | Delete
// Set former parent's [menu_order] to that of menu-item's.
[228] Fix | Delete
$parent_data['menu_order'] = $parent_data['menu_order'] + 1;
[229] Fix | Delete
[230] Fix | Delete
// Set menu-item's [menu_order] to that of former parent.
[231] Fix | Delete
$menu_item_data['menu_order'] = $menu_item_data['menu_order'] - 1;
[232] Fix | Delete
[233] Fix | Delete
// Save changes.
[234] Fix | Delete
update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] );
[235] Fix | Delete
wp_update_post( $menu_item_data );
[236] Fix | Delete
wp_update_post( $parent_data );
[237] Fix | Delete
}
[238] Fix | Delete
[239] Fix | Delete
// Else this menu item is not a child of the previous.
[240] Fix | Delete
} elseif ( empty( $menu_item_data['menu_order'] )
[241] Fix | Delete
|| empty( $menu_item_data['menu_item_parent'] )
[242] Fix | Delete
|| ! in_array( (int) $menu_item_data['menu_item_parent'], array_keys( $dbids_to_orders ), true )
[243] Fix | Delete
|| empty( $orders_to_dbids[ $dbids_to_orders[ $menu_item_id ] - 1 ] )
[244] Fix | Delete
|| $orders_to_dbids[ $dbids_to_orders[ $menu_item_id ] - 1 ] !== (int) $menu_item_data['menu_item_parent']
[245] Fix | Delete
) {
[246] Fix | Delete
// Just make it a child of the previous; keep the order.
[247] Fix | Delete
$menu_item_data['menu_item_parent'] = (int) $orders_to_dbids[ $dbids_to_orders[ $menu_item_id ] - 1 ];
[248] Fix | Delete
update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] );
[249] Fix | Delete
wp_update_post( $menu_item_data );
[250] Fix | Delete
}
[251] Fix | Delete
}
[252] Fix | Delete
}
[253] Fix | Delete
}
[254] Fix | Delete
[255] Fix | Delete
break;
[256] Fix | Delete
[257] Fix | Delete
case 'delete-menu-item':
[258] Fix | Delete
$menu_item_id = (int) $_REQUEST['menu-item'];
[259] Fix | Delete
[260] Fix | Delete
check_admin_referer( 'delete-menu_item_' . $menu_item_id );
[261] Fix | Delete
[262] Fix | Delete
if ( is_nav_menu_item( $menu_item_id ) && wp_delete_post( $menu_item_id, true ) ) {
[263] Fix | Delete
$messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . __( 'The menu item has been successfully deleted.' ) . '</p></div>';
[264] Fix | Delete
}
[265] Fix | Delete
[266] Fix | Delete
break;
[267] Fix | Delete
[268] Fix | Delete
case 'delete':
[269] Fix | Delete
check_admin_referer( 'delete-nav_menu-' . $nav_menu_selected_id );
[270] Fix | Delete
[271] Fix | Delete
if ( is_nav_menu( $nav_menu_selected_id ) ) {
[272] Fix | Delete
$deletion = wp_delete_nav_menu( $nav_menu_selected_id );
[273] Fix | Delete
} else {
[274] Fix | Delete
// Reset the selected menu.
[275] Fix | Delete
$nav_menu_selected_id = 0;
[276] Fix | Delete
unset( $_REQUEST['menu'] );
[277] Fix | Delete
}
[278] Fix | Delete
[279] Fix | Delete
if ( ! isset( $deletion ) ) {
[280] Fix | Delete
break;
[281] Fix | Delete
}
[282] Fix | Delete
[283] Fix | Delete
if ( is_wp_error( $deletion ) ) {
[284] Fix | Delete
$messages[] = '<div id="message" class="error notice is-dismissible"><p>' . $deletion->get_error_message() . '</p></div>';
[285] Fix | Delete
} else {
[286] Fix | Delete
$messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . __( 'The menu has been successfully deleted.' ) . '</p></div>';
[287] Fix | Delete
}
[288] Fix | Delete
[289] Fix | Delete
break;
[290] Fix | Delete
[291] Fix | Delete
case 'delete_menus':
[292] Fix | Delete
check_admin_referer( 'nav_menus_bulk_actions' );
[293] Fix | Delete
[294] Fix | Delete
foreach ( $_REQUEST['delete_menus'] as $menu_id_to_delete ) {
[295] Fix | Delete
if ( ! is_nav_menu( $menu_id_to_delete ) ) {
[296] Fix | Delete
continue;
[297] Fix | Delete
}
[298] Fix | Delete
[299] Fix | Delete
$deletion = wp_delete_nav_menu( $menu_id_to_delete );
[300] Fix | Delete
[301] Fix | Delete
if ( is_wp_error( $deletion ) ) {
[302] Fix | Delete
$messages[] = '<div id="message" class="error notice is-dismissible"><p>' . $deletion->get_error_message() . '</p></div>';
[303] Fix | Delete
$deletion_error = true;
[304] Fix | Delete
}
[305] Fix | Delete
}
[306] Fix | Delete
[307] Fix | Delete
if ( empty( $deletion_error ) ) {
[308] Fix | Delete
$messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . __( 'Selected menus have been successfully deleted.' ) . '</p></div>';
[309] Fix | Delete
}
[310] Fix | Delete
[311] Fix | Delete
break;
[312] Fix | Delete
[313] Fix | Delete
case 'update':
[314] Fix | Delete
check_admin_referer( 'update-nav_menu', 'update-nav-menu-nonce' );
[315] Fix | Delete
[316] Fix | Delete
// Merge new and existing menu locations if any new ones are set.
[317] Fix | Delete
if ( isset( $_POST['menu-locations'] ) ) {
[318] Fix | Delete
$new_menu_locations = array_map( 'absint', $_POST['menu-locations'] );
[319] Fix | Delete
$menu_locations = array_merge( $menu_locations, $new_menu_locations );
[320] Fix | Delete
}
[321] Fix | Delete
[322] Fix | Delete
// Add Menu.
[323] Fix | Delete
if ( 0 === $nav_menu_selected_id ) {
[324] Fix | Delete
$new_menu_title = trim( esc_html( $_POST['menu-name'] ) );
[325] Fix | Delete
[326] Fix | Delete
if ( $new_menu_title ) {
[327] Fix | Delete
$_nav_menu_selected_id = wp_update_nav_menu_object( 0, array( 'menu-name' => $new_menu_title ) );
[328] Fix | Delete
[329] Fix | Delete
if ( is_wp_error( $_nav_menu_selected_id ) ) {
[330] Fix | Delete
$messages[] = '<div id="message" class="error notice is-dismissible"><p>' . $_nav_menu_selected_id->get_error_message() . '</p></div>';
[331] Fix | Delete
} else {
[332] Fix | Delete
$_menu_object = wp_get_nav_menu_object( $_nav_menu_selected_id );
[333] Fix | Delete
$nav_menu_selected_id = $_nav_menu_selected_id;
[334] Fix | Delete
$nav_menu_selected_title = $_menu_object->name;
[335] Fix | Delete
[336] Fix | Delete
if ( isset( $_REQUEST['menu-item'] ) ) {
[337] Fix | Delete
wp_save_nav_menu_items( $nav_menu_selected_id, absint( $_REQUEST['menu-item'] ) );
[338] Fix | Delete
}
[339] Fix | Delete
[340] Fix | Delete
if ( isset( $_REQUEST['zero-menu-state'] ) || ! empty( $_POST['auto-add-pages'] ) ) {
[341] Fix | Delete
// If there are menu items, add them.
[342] Fix | Delete
wp_nav_menu_update_menu_items( $nav_menu_selected_id, $nav_menu_selected_title );
[343] Fix | Delete
}
[344] Fix | Delete
[345] Fix | Delete
if ( isset( $_REQUEST['zero-menu-state'] ) ) {
[346] Fix | Delete
// Auto-save nav_menu_locations.
[347] Fix | Delete
$locations = get_nav_menu_locations();
[348] Fix | Delete
[349] Fix | Delete
foreach ( $locations as $location => $menu_id ) {
[350] Fix | Delete
$locations[ $location ] = $nav_menu_selected_id;
[351] Fix | Delete
break; // There should only be 1.
[352] Fix | Delete
}
[353] Fix | Delete
[354] Fix | Delete
set_theme_mod( 'nav_menu_locations', $locations );
[355] Fix | Delete
}
[356] Fix | Delete
[357] Fix | Delete
if ( isset( $_REQUEST['use-location'] ) ) {
[358] Fix | Delete
$locations = get_registered_nav_menus();
[359] Fix | Delete
$menu_locations = get_nav_menu_locations();
[360] Fix | Delete
[361] Fix | Delete
if ( isset( $locations[ $_REQUEST['use-location'] ] ) ) {
[362] Fix | Delete
$menu_locations[ $_REQUEST['use-location'] ] = $nav_menu_selected_id;
[363] Fix | Delete
}
[364] Fix | Delete
[365] Fix | Delete
set_theme_mod( 'nav_menu_locations', $menu_locations );
[366] Fix | Delete
}
[367] Fix | Delete
[368] Fix | Delete
wp_redirect( admin_url( 'nav-menus.php?menu=' . $_nav_menu_selected_id ) );
[369] Fix | Delete
exit;
[370] Fix | Delete
}
[371] Fix | Delete
} else {
[372] Fix | Delete
$messages[] = '<div id="message" class="error notice is-dismissible"><p>' . __( 'Please enter a valid menu name.' ) . '</p></div>';
[373] Fix | Delete
}
[374] Fix | Delete
[375] Fix | Delete
// Update existing menu.
[376] Fix | Delete
} else {
[377] Fix | Delete
// Remove menu locations that have been unchecked.
[378] Fix | Delete
foreach ( $locations as $location => $description ) {
[379] Fix | Delete
if ( ( empty( $_POST['menu-locations'] ) || empty( $_POST['menu-locations'][ $location ] ) )
[380] Fix | Delete
&& isset( $menu_locations[ $location ] ) && $menu_locations[ $location ] === $nav_menu_selected_id
[381] Fix | Delete
) {
[382] Fix | Delete
unset( $menu_locations[ $location ] );
[383] Fix | Delete
}
[384] Fix | Delete
}
[385] Fix | Delete
[386] Fix | Delete
// Set menu locations.
[387] Fix | Delete
set_theme_mod( 'nav_menu_locations', $menu_locations );
[388] Fix | Delete
[389] Fix | Delete
$_menu_object = wp_get_nav_menu_object( $nav_menu_selected_id );
[390] Fix | Delete
[391] Fix | Delete
$menu_title = trim( esc_html( $_POST['menu-name'] ) );
[392] Fix | Delete
[393] Fix | Delete
if ( ! $menu_title ) {
[394] Fix | Delete
$messages[] = '<div id="message" class="error notice is-dismissible"><p>' . __( 'Please enter a valid menu name.' ) . '</p></div>';
[395] Fix | Delete
$menu_title = $_menu_object->name;
[396] Fix | Delete
}
[397] Fix | Delete
[398] Fix | Delete
if ( ! is_wp_error( $_menu_object ) ) {
[399] Fix | Delete
$_nav_menu_selected_id = wp_update_nav_menu_object( $nav_menu_selected_id, array( 'menu-name' => $menu_title ) );
[400] Fix | Delete
[401] Fix | Delete
if ( is_wp_error( $_nav_menu_selected_id ) ) {
[402] Fix | Delete
$_menu_object = $_nav_menu_selected_id;
[403] Fix | Delete
$messages[] = '<div id="message" class="error notice is-dismissible"><p>' . $_nav_menu_selected_id->get_error_message() . '</p></div>';
[404] Fix | Delete
} else {
[405] Fix | Delete
$_menu_object = wp_get_nav_menu_object( $_nav_menu_selected_id );
[406] Fix | Delete
$nav_menu_selected_title = $_menu_object->name;
[407] Fix | Delete
}
[408] Fix | Delete
}
[409] Fix | Delete
[410] Fix | Delete
// Update menu items.
[411] Fix | Delete
if ( ! is_wp_error( $_menu_object ) ) {
[412] Fix | Delete
$messages = array_merge( $messages, wp_nav_menu_update_menu_items( $_nav_menu_selected_id, $nav_menu_selected_title ) );
[413] Fix | Delete
[414] Fix | Delete
// If the menu ID changed, redirect to the new URL.
[415] Fix | Delete
if ( $nav_menu_selected_id !== $_nav_menu_selected_id ) {
[416] Fix | Delete
wp_redirect( admin_url( 'nav-menus.php?menu=' . (int) $_nav_menu_selected_id ) );
[417] Fix | Delete
exit;
[418] Fix | Delete
}
[419] Fix | Delete
}
[420] Fix | Delete
}
[421] Fix | Delete
[422] Fix | Delete
break;
[423] Fix | Delete
[424] Fix | Delete
case 'locations':
[425] Fix | Delete
if ( ! $num_locations ) {
[426] Fix | Delete
wp_redirect( admin_url( 'nav-menus.php' ) );
[427] Fix | Delete
exit;
[428] Fix | Delete
}
[429] Fix | Delete
[430] Fix | Delete
add_filter( 'screen_options_show_screen', '__return_false' );
[431] Fix | Delete
[432] Fix | Delete
if ( isset( $_POST['menu-locations'] ) ) {
[433] Fix | Delete
check_admin_referer( 'save-menu-locations' );
[434] Fix | Delete
[435] Fix | Delete
$new_menu_locations = array_map( 'absint', $_POST['menu-locations'] );
[436] Fix | Delete
$menu_locations = array_merge( $menu_locations, $new_menu_locations );
[437] Fix | Delete
// Set menu locations.
[438] Fix | Delete
set_theme_mod( 'nav_menu_locations', $menu_locations );
[439] Fix | Delete
[440] Fix | Delete
$messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . __( 'Menu locations updated.' ) . '</p></div>';
[441] Fix | Delete
}
[442] Fix | Delete
[443] Fix | Delete
break;
[444] Fix | Delete
}
[445] Fix | Delete
[446] Fix | Delete
// Get all nav menus.
[447] Fix | Delete
$nav_menus = wp_get_nav_menus();
[448] Fix | Delete
$menu_count = count( $nav_menus );
[449] Fix | Delete
[450] Fix | Delete
// Are we on the add new screen?
[451] Fix | Delete
$add_new_screen = ( isset( $_GET['menu'] ) && 0 === (int) $_GET['menu'] ) ? true : false;
[452] Fix | Delete
[453] Fix | Delete
$locations_screen = ( isset( $_GET['action'] ) && 'locations' === $_GET['action'] ) ? true : false;
[454] Fix | Delete
[455] Fix | Delete
$page_count = wp_count_posts( 'page' );
[456] Fix | Delete
[457] Fix | Delete
/*
[458] Fix | Delete
* If we have one theme location, and zero menus, we take them right
[459] Fix | Delete
* into editing their first menu.
[460] Fix | Delete
*/
[461] Fix | Delete
if ( 1 === count( get_registered_nav_menus() ) && ! $add_new_screen
[462] Fix | Delete
&& empty( $nav_menus ) && ! empty( $page_count->publish )
[463] Fix | Delete
) {
[464] Fix | Delete
$one_theme_location_no_menus = true;
[465] Fix | Delete
} else {
[466] Fix | Delete
$one_theme_location_no_menus = false;
[467] Fix | Delete
}
[468] Fix | Delete
[469] Fix | Delete
$nav_menus_l10n = array(
[470] Fix | Delete
'oneThemeLocationNoMenus' => $one_theme_location_no_menus,
[471] Fix | Delete
'moveUp' => __( 'Move up one' ),
[472] Fix | Delete
'moveDown' => __( 'Move down one' ),
[473] Fix | Delete
'moveToTop' => __( 'Move to the top' ),
[474] Fix | Delete
/* translators: %s: Previous item name. */
[475] Fix | Delete
'moveUnder' => __( 'Move under %s' ),
[476] Fix | Delete
/* translators: %s: Previous item name. */
[477] Fix | Delete
'moveOutFrom' => __( 'Move out from under %s' ),
[478] Fix | Delete
/* translators: %s: Previous item name. */
[479] Fix | Delete
'under' => __( 'Under %s' ),
[480] Fix | Delete
/* translators: %s: Previous item name. */
[481] Fix | Delete
'outFrom' => __( 'Out from under %s' ),
[482] Fix | Delete
/* translators: 1: Item name, 2: Item position, 3: Total number of items. */
[483] Fix | Delete
'menuFocus' => __( '%1$s. Menu item %2$d of %3$d.' ),
[484] Fix | Delete
/* translators: 1: Item name, 2: Item position, 3: Parent item name. */
[485] Fix | Delete
'subMenuFocus' => __( '%1$s. Sub item number %2$d under %3$s.' ),
[486] Fix | Delete
);
[487] Fix | Delete
wp_localize_script( 'nav-menu', 'menus', $nav_menus_l10n );
[488] Fix | Delete
[489] Fix | Delete
/*
[490] Fix | Delete
* Redirect to add screen if there are no menus and this users has either zero,
[491] Fix | Delete
* or more than 1 theme locations.
[492] Fix | Delete
*/
[493] Fix | Delete
if ( 0 === $menu_count && ! $add_new_screen && ! $one_theme_location_no_menus ) {
[494] Fix | Delete
wp_redirect( admin_url( 'nav-menus.php?action=edit&menu=0' ) );
[495] Fix | Delete
}
[496] Fix | Delete
[497] Fix | Delete
// Get recently edited nav menu.
[498] Fix | Delete
$recently_edited = absint( get_user_option( 'nav_menu_recently_edited' ) );
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function