SecureUnitButtonTemplate is one of the SecureTemplates introduced in Patch 2.0. It's purpose is to allow creation of unit frames, executing certain protected actions from secure code in response to clicks.
This template's behavior differs only slightly from SecureActionButtonTemplate, and can be thought of as a special case. The only difference is in how the menu function is handled: the template allows spells currently being targeted to be cancelled before calling the menu function.
Supporting API Edit
FrameXML defines a convenience method to interact with this template: SecureUnitButton_OnLoad(self, unit, menufunc)
- Frame - frame inheriting from SecureUnitButtonTemplate.
- String - unit this unit frame is showing/acting on.
- Function - menu function to show when the frame is right clicked.
The function sets a limited number of attributes on a frame to make it behave like the default unit frames: left clicks target the unit, and right clicks open the menu by calling menuFunc(self, unit, button).
Another useful function is RegisterUnitWatch(frame), which controls the visibility of a protected frame based on whether the unit specified by the frame's "unit" attribute exists.
Supported Attributes Edit
The template supports all of the attributes supported by SecureActionButtonTemplate, and behaves in similar fashion. There is a single special case: if the value of the modified attribute "type" is "menu" (with no unit remapping performed), the OnClick cancels any spell being targeted and calls menuFunc().
Some attributes may be used to enable automatic vehicle unit remapping for the frame: making the player frame behave as a vehicle frame, and a pet frame behave as a player frame when the player is in a vehicle.