applyFilters( "area_general_conditions", conditions, area );
applyFilters( "area_general_conditions_{key}", conditions, area );
Filter the condition promise, during area initialization. This filter is called once per Area, right after the page loaded.
The dynamic part of the filter name is the sanitized Area key. See DiviAreaItem.theKey()
for details.
When all conditions are met, the trigger is initialized. When one condition fails, the trigger stays inactive for the current request.
Params
conditions
- A promise that resolve()s when all conditions are met, or reject()s when a condition is not met.
area
- The new area instance.
Returns
This filter must return a Promise!
Examples
// Randomly disable a trigger, with a 50% chance.
addAction("area_general_conditions", function(conditions, area) {
function customCheck(resolve, reject) {
if (Math.random() > 0.5) {
resolve();
} else {
reject("Optional reject reason");
}
}
conditions = conditions.then(() => new Promise(customCheck));
return conditions;
});
// Call a remove URL via Ajax to see if the trigger should be initialized.
addAction("area_general_conditions", function(conditions, area) {
function customAjaxCheck(resolve, reject) {
fetch('/wp-admin/admin-ajax.php?action=test')
.then(function(response) {
return response.json()
})
.then(function(json) {
if (json.success) {
resolve();
} else {
reject("Ajax check failed");
}
});
}
conditions = conditions.then(() => new Promise(customAjaxCheck));
return conditions;
});
Notes
No notes