Javascript Hooks
To register javascript hooks, use the WPD.Hooks javascript object methods addFilter and removeFilter
1
/**
2
* Adds a callback function to a specific programmatically triggered tag (hook)
3
*
4
* @param tag - the hook name
5
* @param callback - the callback function variable name
6
* @param priority - (optional) default=10
7
* @param scope - (optional) function scope. When a function is executed within an object scope, the object variable should be passed.
8
*/
9
WPD.Hooks.addFilter = function( tag, callback, priority, scope )
10
11
/**
12
* Removes a callback function from a hook
13
*
14
* @param tag - the hook name
15
* @param callback - the callback function variable
16
*/
17
WPD.Hooks.removeFilter= function( tag, callback )
Copied!

Usage

1
// Add regular function
2
let func1 = funtion(arg1, arg2) {
3
return 'my value';
4
}
5
WPD.Hooks.addFilter('hook_name', func1);
6
7
// Add an object method, with reference to "this" inside the method
8
let myObject = {
9
'myValue': 'my value',
10
'myFunction': function(arg1, arg2) {
11
return this.myValue;
12
}
13
};
14
WPD.Hooks.addFilter('hook_name', myObject.myFunction, 10, myObject);
15
16
// Anonymous function
17
WPD.Hooks.addFilter('hook_name', function(arg1, arg2){
18
return 'my value';
19
});
20
21
// To remove all hooks
22
WPD.Hooks.removeFilter('hook_name');
Copied!

List of Hooks

Copy link