applyFilters( “area_general_conditions” )

  1. Home
  2. Knowledge Base
  3. Codex
  4. JS API
  5. JS Filters
  6. applyFilters( “area_general_conditions” )
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.

When all conditions are met, the trigger is initialized. When one condition fails, the trigger stays inactive for the current request.

Params

conditions
(Promise, required) A promise that resolve()s when all conditions are met, or reject()s when a condition is not met.
area
(DiviAreaItem, required) The new area instance.

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

Was this article helpful?

Related Articles