Add a function to be called after execution of a secure function. Allows one to "post-hook" a secure function without tainting the original.

The original function will still be called, but the function supplied will be called after the original, with the same arguments. Return values from the supplied function are discarded. Note that there is no API to remove a hook from a function: any hooks applied will remain in place until the UI is reloaded.

Only allows hooking of functions named by a global variable; to hook a script handler on a Frame object, see Frame:HookScript().

See also Secure execution utility functions.


hooksecurefunc([table,] "function", hookfunc)


  • table - A table object that contains the function to be hooked (table)
  • function - The name of the function to be hooked (string)
  • hookfunc - The function to be called each time the original function is called (function)


-- Keep a counter of how many times your character has jumped, and display in chat
local counter = 0
local function hook_JumpOrAscendStart(...)
  counter = counter + 1
  ChatFrame1:AddMessage("Boing! Boing! - " .. counter .. " jumps.")
hooksecurefunc("JumpOrAscendStart", hook_JumpOrAscendStart)
-- Hook GameTooltip:SetAction() to display how many spell casts you can make
-- It does this by scanning the second line of the tooltip, and matching
-- it against the pattern "(%d+) " .. MANA, where MANA is the global string for
-- "Mana" in the current locale.
local function hook_SetAction(self, ...)
  -- The second line of the tooltip is getglobal(self:GetName().."TextLeft2")
  local line = _G[self:GetName() .. "TextLeft2"]
  local text = line:GetText() or ""
  local manaCost = text:match("(%d+) " .. MANA)
  if manaCost then
    -- Convert the mana cost to a number
    manaCost = tostring(manaCost)
    -- Get the player's current mana, and calculate the numnber of casts
    local mana = UnitMana("player")
    local numCasts = math.floor(mana / manaCost)
    -- Add the line to the tooltip, colored blue
    self:AddLine("You can cast this spell " .. numCasts .. " times", 0.4, 0.4, 1.0)
    -- Call this to ensure the tooltip is properly resized
hooksecurefunc(GameTooltip, "SetAction", hook_SetAction)