Wp_Fluent_Forms_Helpers::match_condition( array $entry, array|null $recipes = null, string|null $trigger_meta = null, string|null $trigger_code = null, string|null $trigger_second_code = null )

Matching form fields values.


Parameters Parameters

$entry

(array) (Required) form data.

$recipes

(array|null) (Optional) recipe data.

Default value: null

$trigger_meta

(string|null) (Optional) trigger meta key.

Default value: null

$trigger_code

(string|null) (Optional) trigger code key.

Default value: null

$trigger_second_code

(string|null) (Optional) trigger second code key.

Default value: null


Top ↑

Return Return

(array|bool)


Source Source

File: src/integrations/wp-fluent-forms/helpers/wp-fluent-forms-helpers.php

	public function match_condition( $entry, $recipes = null, $trigger_meta = null, $trigger_code = null, $trigger_second_code = null ) {
		if ( null === $recipes ) {
			return false;
		}

		$matches        = array();
		$recipe_ids     = array();
		$entry_to_match = $entry['form_id'];
		//Matching recipe ids that has trigger meta
		foreach ( $recipes as $recipe ) {
			foreach ( $recipe['triggers'] as $trigger ) {
				if ( key_exists( $trigger_meta, $trigger['meta'] ) && (int) $trigger['meta'][ $trigger_meta ] === (int) $entry_to_match ) {
					$matches[ $recipe['ID'] ]    = [
						'field' => $trigger['meta'][ $trigger_code ],
						'value' => $trigger['meta'][ $trigger_second_code ],
					];
					$recipe_ids[ $recipe['ID'] ] = $recipe['ID'];
					break;
				}
			}
		}

		//Figure if field is available and data matches!!
		if ( ! empty( $matches ) ) {
			$matched = false;
			$fields  = $entry['fields'];
			foreach ( $matches as $recipe_id => $match ) {
				foreach ( $fields as $field ) {
					$field_id = $field['id'];
					if ( absint( $match['field'] ) !== absint( $field_id ) ) {
						continue;
					}

					$value = $field['value'];
					if ( ( (int) $field_id === (int) $match['field'] ) && ( $value == $match['value'] ) ) {
						$matched = true;
						break;
					}
				}

				if ( ! $matched ) {
					unset( $recipe_ids[ $recipe_id ] );
				}
			}
		}

		if ( ! empty( $recipe_ids ) ) {
			return [
				'recipe_ids' => $recipe_ids,
				'result'     => true,
			];
		}

		return false;
	}