wpseek.com
A WordPress-centric search engine for devs and theme authors



_wp_reset_invalid_menu_item_parent › WordPress Function

Since6.1.2
Deprecatedn/a
_wp_reset_invalid_menu_item_parent ( $menu_item_data )
Access:
  • private
Parameters:
  • (array) $menu_item_data The menu item data array.
    Required: Yes
Returns:
  • (array) The menu item data with reset menu_item_parent.
Defined at:
Codex:

Prevents menu items from being their own parent.

Resets menu_item_parent to 0 when the parent is set to the item itself. For use before saving _menu_item_menu_item_parent in nav-menus.php.


Source

function _wp_reset_invalid_menu_item_parent( $menu_item_data ) {
	if ( ! is_array( $menu_item_data ) ) {
		return $menu_item_data;
	}

	if (
		! empty( $menu_item_data['ID'] ) &&
		! empty( $menu_item_data['menu_item_parent'] ) &&
		(int) $menu_item_data['ID'] === (int) $menu_item_data['menu_item_parent']
	) {
		$menu_item_data['menu_item_parent'] = 0;
	}

	return $menu_item_data;
}