LD_TOPICDONE::topic_completed( $data )

Validation function when the trigger action is hit


Parameters Parameters

$data

(Required)


Source Source

File: src/integrations/learndash/triggers/ld-topicdone.php

	public function topic_completed( $data ) {

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



		$user   = $data['user'];
		$topic  = $data['topic'];
		$lesson = $data['lesson'];
		$course = $data['course'];

		$args = [
			'code'    => $this->trigger_code,
			'meta'    => $this->trigger_meta,
			'post_id' => $topic->ID,
			'user_id' => $user->ID,
		];

		$args = Automator()->maybe_add_trigger_entry( $args, false );
		if ( $args ) {
			foreach ( $args as $result ) {
				if ( true === $result['result'] ) {
					Automator()->insert_trigger_meta(
						[
							'user_id'        => $user->ID,
							'trigger_id'     => $result['args']['trigger_id'],
							'meta_key'       => 'LDCOURSE',
							'meta_value'     => $course->ID,
							'trigger_log_id' => $result['args']['get_trigger_id'],
							'run_number'     => $result['args']['run_number'],
						]
					);
					Automator()->insert_trigger_meta(
						[
							'user_id'        => $user->ID,
							'trigger_id'     => $result['args']['trigger_id'],
							'meta_key'       => 'LDLESSON',
							'meta_value'     => $lesson->ID,
							'trigger_log_id' => $result['args']['get_trigger_id'],
							'run_number'     => $result['args']['run_number'],
						]
					);
					Automator()->maybe_trigger_complete( $result['args'] );
				}
			}
		}
	}