I think this is the best way to go:
Code:
testButton:SetScript("OnClick", function()
if InCombatLockdown() then
-- If you are using an addon that has removed WorldMapFrame from UIPanelWindows,
-- we are able to hide WorldMapFrame for you here.
-- If not, hiding the map will result in ToggleGameMenu() not working any more,
-- because WorldMapFrame will still be listed in UIParent's FramePositionDelegate.
if not UIPanelWindows["WorldMapFrame"] then
WorldMapFrame:Hide()
end
else
HideUIPanel(WorldMapFrame)
end
end)