Trigger_Conditions::validate_conditions( $args )

Match trigger conditions. For example, if Any option is suppose to run, or specific meta has to match. This function either has to return true to continue processing trigger or false to bailout.


Parameters Parameters

$args

(Required)


Top ↑

Return Return

(array)


Source Source

File: src/core/lib/recipe-parts/triggers/trait-trigger-conditions.php

	protected function validate_conditions( $args ) {
		$matched_recipe_ids = array();
		/*
		 * Get recipes that matches the current trigger.
		 */
		$recipes = $this->trigger_recipes();
		if ( empty( $recipes ) ) {
			return $matched_recipe_ids;
		}
		/**
		 * Get all the conditions set for a trigger.
		 */
		$trigger_conditions = $this->get_conditions();
		/*
		 * No trigger conditions found. Return unfiltered trigger recipe ids.
		 */
		if ( empty( $trigger_conditions ) || ! is_object( $trigger_conditions ) ) {
			return $matched_recipe_ids;
		}
		foreach ( $trigger_conditions as $key => $condition ) {
			$match    = $condition->match;
			$match_in = $condition->match_in;
			$matched_condition          = $this->required_condition_in_trigger_meta( $recipes, $match_in );
			$matched_recipe_ids[ $key ] = $this->find_value_in_trigger_meta( $match, $matched_condition, $recipes );
		}
		return $this->unique_recipes( $matched_recipe_ids, count( (array) $trigger_conditions ) );
	}