GPT:
/**
* 判断一个菜单项是否为二级菜单
*
* @param string $menu_item_id 菜单项的 ID
* @return bool
*/
function is_menu_item_secondary ($menu_item_id) {
// 获取菜单对象
$menu = wp_get_nav_menu_object ($menu_item_id);
// 获取菜单项的祖先项
$ancestors = get_post_ancestors ($menu_item_id);
// 如果祖先项数组不为空且第一个祖先项的父菜单与当前菜单的 ID 相同,则是二级菜单
if (!empty ($ancestors) && isset ($menu->term_id) && $ancestors[0] == $menu->term_id) {
return true;
}
return false;
}