Wplms_Tokens::wplms_token( $value,  $pieces,  $recipe_id,  $trigger_data,  $user_id,  $replace_args )


Parameters Parameters

$value

(Required)

$pieces

(Required)

$recipe_id

(Required)

$trigger_data

(Required)

$user_id

(Required)

$replace_args

(Required)


Top ↑

Return Return

(string|null)


Source Source

File: src/integrations/wplms/tokens/wplms-tokens.php

	public function wplms_token( $value, $pieces, $recipe_id, $trigger_data, $user_id, $replace_args ) {
		$wplms_pieces = array(
			'WPLMSUNITCOMPLETED',
			'WPLMSQUIZCOMPLETED',
			'WPLMSCOURSESTARTED',
			'WPLMSCOURSECOMPLETED',
		);
		if ( empty( array_intersect( $pieces, $wplms_pieces ) ) ) {
			return $value;
		}
		if ( empty( $trigger_data ) ) {
			return $value;
		}
		$trigger_meta = $pieces[1];
		$token        = $pieces[2];
		foreach ( $trigger_data as $trigger ) {
			$trigger_id     = absint( $trigger['ID'] );
			$trigger_log_id = absint( $replace_args['trigger_log_id'] );
			$parse_tokens   = array(
				'trigger_id'     => $trigger_id,
				'trigger_log_id' => $trigger_log_id,
				'user_id'        => $user_id,
			);

			$meta_key = $trigger_meta . '_tokens';
			$entry    = Automator()->db->trigger->get_token_meta( $meta_key, $parse_tokens );
			if ( empty( $entry ) ) {
				continue;
			}
			$entry     = maybe_unserialize( $entry );
			$course_id = isset( $entry['course_id'] ) ? absint( $entry['course_id'] ) : 0;
			$unit_id   = isset( $entry['unit_id'] ) ? absint( $entry['unit_id'] ) : 0;
			$quiz_id   = isset( $entry['quiz_id'] ) ? absint( $entry['quiz_id'] ) : 0;
			switch ( $token ) {
				case 'WPLMS_UNIT':
					$value = get_the_title( $unit_id );
					break;
				case 'WPLMS_UNIT_ID':
					$value = $unit_id;
					break;
				case 'WPLMS_UNIT_URL':
					$value = get_permalink( $unit_id );
					break;
				case 'WPLMS_UNIT_THUMB_ID':
					$value = get_post_thumbnail_id( $entry['unit_id'] );
					$value = empty( $value ) || 0 == $value ? 'N/A' : $value; //phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
					break;
				case 'WPLMS_UNIT_THUMB_URL':
					$value = get_the_post_thumbnail_url( $unit_id );
					$value = empty( $value ) || 0 == $value ? 'N/A' : $value; //phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
					break;
				case 'WPLMS_COURSESTART':
				case 'WPLMS_COURSE':
					$value = get_the_title( $course_id );
					break;
				case 'WPLMS_COURSESTART_ID':
				case 'WPLMS_COURSE_ID':
					$value = $course_id;
					break;
				case 'WPLMS_COURSE_URL':
				case 'WPLMS_COURSESTART_URL':
					$value = get_permalink( $course_id );
					break;
				case 'WPLMS_COURSE_THUMB_ID':
				case 'WPLMS_COURSESTART_THUMB_ID':
					$value = get_post_thumbnail_id( $course_id );
					$value = empty( $value ) || 0 == $value ? 'N/A' : $value; //phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
					break;
				case 'WPLMS_COURSE_THUMB_URL':
				case 'WPLMS_COURSESTART_THUMB_URL':
					$value = get_the_post_thumbnail_url( $course_id );
					$value = empty( $value ) || 0 == $value ? 'N/A' : $value; //phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
					break;
				case 'WPLMS_QUIZ':
					$value = get_the_title( $quiz_id );
					break;
				case 'WPLMS_QUIZ_ID':
					$value = $quiz_id;
					break;
				case 'WPLMS_QUIZ_URL':
					$value = get_permalink( $quiz_id );
					break;
				case 'WPLMS_QUIZ_THUMB_ID':
					$value = get_post_thumbnail_id( $quiz_id );
					$value = empty( $value ) || 0 == $value ? 'N/A' : $value; //phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
					break;
				case 'WPLMS_QUIZ_THUMB_URL':
					$value = get_the_post_thumbnail_url( $quiz_id );
					$value = empty( $value ) || 0 == $value ? 'N/A' : $value; //phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
					break;
			}
		}

		return $value;
	}