When asking for help with code, please post your
actual code or at least, if you really insist on writing new code to post as an example, code you've verified actually works. The code you posted (a) has a syntax error because of the extra } on line 6 and (b) doesn't actually do anything anyway.
That said, you should really avoid doing what you're doing, since you automatically taint everything already in the popup (thus preventing the use of menu entries to target the unit, set your focus, etc.) and most likely the entire dropdown menu system for the entire default UI (and all addons that use it). If you want suggestions on what you should do instead, you'll have to post more details about what you're actually trying to do (eg. what you want the menu entries to do).
If you don't care about breaking dropdown menus for the whole UI, and want to go ahead with what you're doing:
#1 -- Don't overwrite the UnitPopupMenus["PLAYER"] table, as other addons may also be adding stuff to it. Just add your extra entries to the one that already exists. If you want to add them somewhere other than at the end, pass the optional position arg to
table.insert to insert them at specific positions in the list.
#2 -- Use
hooksecurefunc on the
UnitPopup_HideButtons function to control the visibility of your custom menu entries each time the menu is shown.
#3 -- While the default UI handles changing other properties of each menu entry (eg. different text, disabled but still visible) in
UnitPopup_Show, you
should not do this, or your changes will be made
after the menu entries have been rendered into the UI, and won't actually affect anything until the
next time the menu is shown. Do that stuff in your UnitPopup_HideButtons hook (#2 above).