Triggers a filter event, allowing event subscribers to modify the specified data object. Each subscribed callback will be executed in order in a blocking/synchronous way.
Name | Type | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
opts | object | The options object. Properties
|
- Since
- 3.0.1
- Source
Returns the filtered data object.
- Type:
- object
import { filter } from "@gravityforms/utils";
async function Example() {
let filteredData = 'hello';
filteredData = await filter( { event: 'gform/example/event_name', data: filteredData } );
};
// elsewhere in the codebase
addFilter( 'gform/example/event_name', ( data ) => {
data = 'hello again!';
return data;
}, 11 );
Requires
- module:assign
Methods
(inner) addAsyncFilter(event, callable, priority) → {void}
Adds an async callback function to a filter event.
Name | Type | Description |
---|---|---|
event | string | The event name. |
callable | function | The callback function to be executed. The callback function takes a 'data' parameter as argument that can be of any type (depends on the event being fired). Defaults to 10. |
priority | int | The filter priority. This determines the execution order. Lower priority filters execute first. |
- Since
- 3.0.1
- Source
- Type:
- void
import { addAsyncFilter } from "@gravityforms/utils";
function Example() {
addAsyncFilter( 'gform/example/event_name', async function ( data ) {
data = 'filtered data';
return data;
}, 10 );
};
// elsewhere in the codebase
let filteredData = 'hello';
filteredData = await filter( { event: 'gform/example/event_name', data: filteredData } );*
(inner) addFilter(event, callable, priority, isAsync) → {void}
Adds a callback function to a filter event.
Name | Type | Description |
---|---|---|
event | string | The event name. |
callable | function | The callback function to be executed. The callback function takes a 'data' parameter as argument that can be of any type (depends on the event being fired). Defaults to 10. |
priority | int | The filter priority. This determines the execution order. Lower priority filters execute first. |
isAsync | boolean | Wether or not the callable parameter is an async function. Defaults to false. |
- Since
- 3.0.1
- Source
- Type:
- void
import { addFilter } from "@gravityforms/utils";
function Example() {
addFilter( 'gform/example/event_name', function ( data ) {
data = 'filtered data';
return data;
} );
};
// elsewhere in the codebase
let filteredData = 'hello';
filteredData = await filter( { event: 'gform/example/event_name', data: filteredData } );*
(inner) removeFilter(event, priority, tag) → {void}
Removes a callback function from the list of filters.
Name | Type | Description |
---|---|---|
event | string | The event name. |
priority | int | The filter priority. Removes filters of this priority. If ommitted, filters of any priority will be removed. |
tag | string | Removes functions of this tag. If ommitted, functions of any tag will be removed. Tag is formatted as 'event-name_function-index'. |
- Since
- 3.0.1
- Source
- Type:
- void
import { removeFilter } from "@gravityforms/utils";
function Example() {
// removes all filters that are subscribed to 'gform/example/event_name' and that have priority 10.
removeFilter( 'gform/example/event_name', 10);
};