Ut_Tokens::parse_uncanny_toolkit_token( $value,  $pieces,  $recipe_id,  $trigger_data,  $user_id,  $replace_args )

Parse tokens of the triggers


Parameters Parameters

$value

(Required)

$pieces

(Required)

$recipe_id

(Required)

$trigger_data

(Required)

$user_id

(Required)

$replace_args

(Required)


Top ↑

Return Return

(mixed|string)


Source Source

File: src/integrations/uncanny-toolkit/tokens/ut-tokens.php

	public function parse_uncanny_toolkit_token( $value, $pieces, $recipe_id, $trigger_data, $user_id, $replace_args ) {
		$trigger_meta_match = array(
			'UTUSERIMPORTED',
			'UTUSERIMPORTEDCOURSE',
			'UTUSERIMPORTEDGROUP',
			'UTGROUPLEADERIMPORTED',
			'UTUSERSTIMEINCOURSEEXCEEDS',
			'UOUSERSTIMEINCOURSEEXCEEDS',
		);

		if ( empty( $pieces ) ) {
			return $value;
		}
		if ( ! isset( $pieces[2] ) ) {
			return $value;
		}
		if ( empty( $trigger_data ) ) {
			return $value;
		}
		if ( ! array_intersect( $trigger_meta_match, $pieces ) ) {
			return $value;
		}

		$trigger_id = absint( $pieces[0] );
		$token      = $pieces[2];
		$token_args = array(
			'trigger_id'     => $trigger_id,
			'trigger_log_id' => $replace_args['trigger_log_id'],
			'user_id'        => $user_id,
		);
		$token_meta = maybe_unserialize( Automator()->db->trigger->get_token_meta( 'imported_row', $token_args ) );
		if ( isset( $token_meta[ $token ] ) ) {
			$val = maybe_unserialize( $token_meta[ $token ] );
			if ( is_array( $val ) ) {
				return join( ' | ', $val );
			}

			return wp_strip_all_tags( $val );
		}

		if ( 'UOUSERIMPORTEDCOURSE' === $token && isset( $token_meta['learndash_course_id'] ) ) {
			return get_the_title( $token_meta['learndash_course_id'] );
		}
		if ( 'UOUSERIMPORTEDGROUP' === $token && isset( $token_meta['learndash_group_id'] ) ) {
			return get_the_title( $token_meta['learndash_group_id'] );
		}

		if ( 'UOUSERSTIMEINCOURSEEXCEEDS' === $token ) {
			return maybe_unserialize( Automator()->db->trigger->get_token_meta( 'UOUSERSTIMEINCOURSEEXCEEDS', $token_args ) );
		}
		if ( 'UOUSERSTIMEINCOURSEEXCEEDS_ID' === $token ) {
			return maybe_unserialize( Automator()->db->trigger->get_token_meta( 'UOUSERSTIMEINCOURSEEXCEEDS_ID', $token_args ) );
		}
		if ( 'UOUSERSTIMEINCOURSEEXCEEDS_COURSEMINUTES' === $token ) {
			return maybe_unserialize( Automator()->db->trigger->get_token_meta( 'UOUSERSTIMEINCOURSEEXCEEDS_COURSEMINUTES', $token_args ) );
		}
		if ( 'UOUSERSTIMEINCOURSEEXCEEDS_URL' === $token ) {
			return maybe_unserialize( Automator()->db->trigger->get_token_meta( 'UOUSERSTIMEINCOURSEEXCEEDS_URL', $token_args ) );
		}
		if ( 'UOUSERSTIMEINCOURSEEXCEEDS_THUMB_ID' === $token ) {
			return maybe_unserialize( Automator()->db->trigger->get_token_meta( 'UOUSERSTIMEINCOURSEEXCEEDS_THUMB_ID', $token_args ) );
		}
		if ( 'UOUSERSTIMEINCOURSEEXCEEDS_THUMB_URL' === $token ) {
			return maybe_unserialize( Automator()->db->trigger->get_token_meta( 'UOUSERSTIMEINCOURSEEXCEEDS_THUMB_URL', $token_args ) );
		}

		return $value;
	}