Changeset 54973
- Timestamp:
- 12/14/2022 10:52:11 PM (21 months ago)
- Location:
- trunk/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/nav-menus.php
r54834 r54973 118 118 $parent_data = (array) $parent_object; 119 119 $menu_item_data['menu_item_parent'] = $parent_data['menu_item_parent']; 120 121 // Reset invalid `menu_item_parent`. 122 $menu_item_data = _wp_reset_invalid_menu_item_parent( $menu_item_data ); 123 120 124 update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] ); 121 125 } … … 127 131 128 132 $menu_item_data['menu_item_parent'] = $next_item_data['ID']; 133 134 // Reset invalid `menu_item_parent`. 135 $menu_item_data = _wp_reset_invalid_menu_item_parent( $menu_item_data ); 136 129 137 update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] ); 130 138 … … 138 146 ) { 139 147 $menu_item_data['menu_item_parent'] = (int) get_post_meta( $menu_item_data['menu_item_parent'], '_menu_item_menu_item_parent', true ); 148 149 // Reset invalid `menu_item_parent`. 150 $menu_item_data = _wp_reset_invalid_menu_item_parent( $menu_item_data ); 151 140 152 update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] ); 141 153 } … … 248 260 // Just make it a child of the previous; keep the order. 249 261 $menu_item_data['menu_item_parent'] = (int) $orders_to_dbids[ $dbids_to_orders[ $menu_item_id ] - 1 ]; 262 263 // Reset invalid `menu_item_parent`. 264 $menu_item_data = _wp_reset_invalid_menu_item_parent( $menu_item_data ); 265 250 266 update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] ); 251 267 wp_update_post( $menu_item_data ); -
trunk/src/wp-includes/nav-menu-template.php
r54891 r54973 200 200 $menu_items_with_children = array(); 201 201 foreach ( (array) $menu_items as $menu_item ) { 202 // Fix invalid `menu_item_parent`. See: https://core.trac.wordpress.org/ticket/56926. 203 if ( (int) $menu_item->ID === (int) $menu_item->menu_item_parent ) { 204 $menu_item->menu_item_parent = 0; 205 } 206 202 207 $sorted_menu_items[ $menu_item->menu_order ] = $menu_item; 203 208 $menu_items_tree[ $menu_item->ID ] = $menu_item->menu_item_parent; -
trunk/src/wp-includes/nav-menu.php
r54891 r54973 563 563 564 564 $menu_item_db_id = (int) $menu_item_db_id; 565 566 // Reset invalid `menu_item_parent`. 567 if ( (int) $args['menu-item-parent-id'] === $menu_item_db_id ) { 568 $args['menu-item-parent-id'] = 0; 569 } 565 570 566 571 update_post_meta( $menu_item_db_id, '_menu_item_type', sanitize_key( $args['menu-item-type'] ) ); … … 1274 1279 return $new_nav_menu_locations; 1275 1280 } 1281 1282 /** 1283 * Prevents menu items from being their own parent. 1284 * 1285 * Resets menu_item_parent to 0 when the parent is set to the item itself. 1286 * For use before saving `_menu_item_menu_item_parent` in nav-menus.php. 1287 * 1288 * @since 6.1.2 1289 * @access private 1290 * 1291 * @param array $menu_item_data The menu item data array. 1292 * @return array The menu item data with reset menu_item_parent. 1293 */ 1294 function _wp_reset_invalid_menu_item_parent( $menu_item_data ) { 1295 if ( ! is_array( $menu_item_data ) ) { 1296 return $menu_item_data; 1297 } 1298 1299 if ( 1300 ! empty( $menu_item_data['ID'] ) && 1301 ! empty( $menu_item_data['menu_item_parent'] ) && 1302 (int) $menu_item_data['ID'] === (int) $menu_item_data['menu_item_parent'] 1303 ) { 1304 $menu_item_data['menu_item_parent'] = 0; 1305 } 1306 1307 return $menu_item_data; 1308 }
Note: See TracChangeset
for help on using the changeset viewer.