UT_GROUP_LEADER_IMPORTED::a_user_is_imported( $user_id,  $csv_data,  $csv_header,  $key_location )

Running an actual function on the trigger


Parameters Parameters

$user_id

(Required)

$csv_data

(Required)

$csv_header

(Required)

$key_location

(Required)


Source Source

File: src/integrations/uncanny-toolkit/triggers/ut-group-leader-imported.php

	public function a_user_is_imported( $user_id, $csv_data, $csv_header, $key_location ) {

		if ( ! is_numeric( $user_id ) ) {
			return;
		}

		$meta_value = Uncanny_Toolkit_Helpers::build_token_data( $csv_data, $csv_header, $key_location, $user_id );

		if ( ! isset( $meta_value['learndash_group_leader_ids'] ) ) {
			return;
		}

		if ( empty( $meta_value['learndash_group_leader_ids'] ) ) {
			return;
		}

		$recipes = Automator()->get->recipes_from_trigger_code( $this->trigger_code );

		if ( empty( $recipes ) ) {
			return;
		}

		$required_group = Automator()->get->meta_from_recipes( $recipes, $this->trigger_meta );

		if ( empty( $required_group ) ) {
			return;
		}

		foreach ( $meta_value['learndash_group_leader_ids'] as $group_id ) {
			foreach ( $recipes as $recipe_id => $recipe ) {
				foreach ( $recipe['triggers'] as $trigger ) {
					$trigger_id = $trigger['ID'];//return early for all products
					if ( ! isset( $required_group[ $recipe_id ] ) ) {
						continue;
					}
					if ( ! isset( $required_group[ $recipe_id ][ $trigger_id ] ) ) {
						continue;
					}
					if ( intval( '-1' ) === intval( $required_group[ $recipe_id ][ $trigger_id ] ) || (int) $required_group[ $recipe_id ][ $trigger_id ] === (int) $group_id ) {
						$args = array(
							'code'             => $this->trigger_code,
							'meta'             => $this->trigger_meta,
							'ignore_post_id'   => true,
							'user_id'          => $user_id,
							'is_signed_in'     => true,
							'recipe_to_match'  => $recipe_id,
							'trigger_to_match' => $trigger_id,
						);

						$this->complete_trigger( $meta_value, $args, $group_id );
					}
				}
			}
		}
	}