To register javascript hooks, use the WPD.Hooks javascript object methods addFilter and removeFilter
/** * Adds a callback function to a specific programmatically triggered tag (hook) * * @param tag - the hook name * @param callback - the callback function variable name * @param priority - (optional) default=10 * @param scope - (optional) function scope. When a function is executed within an object scope, the object variable should be passed. */WPD.Hooks.addFilter=function( tag, callback, priority, scope )/** * Removes a callback function from a hook * * @param tag - the hook name * @param callback - the callback function variable */WPD.Hooks.removeFilter= function( tag, callback )
Usage
// Add regular functionlet func1 =funtion(arg1, arg2) { return 'my value';}WPD.Hooks.addFilter('hook_name', func1);// Add an object method, with reference to "this" inside the methodlet myObject = {'myValue':'my value','myFunction':function(arg1, arg2) {returnthis.myValue; }};WPD.Hooks.addFilter('hook_name', myObject.myFunction,10, myObject);// Anonymous functionWPD.Hooks.addFilter('hook_name',function(arg1, arg2){return'my value';});// To remove all hooksWPD.Hooks.removeFilter('hook_name');