_wp_reset_invalid_menu_item_parent( array $menu_item_data ): array

In this article

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

Prevents menu items from being their own parent.

Description

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.

Parameters

$menu_item_dataarrayrequired
The menu item data array.

Return

array The menu item data with reset menu_item_parent.

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;
}

Changelog

VersionDescription
6.2.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.