LP_MARKLESSONDONE::lp_mark_lesson_done( string $user_id, array $action_data, string $recipe_id,  $args )

Validation function when the action is hit.


Parameters Parameters

$user_id

(string) (Required) user id.

$action_data

(array) (Required) action data.

$recipe_id

(string) (Required) recipe id.


Source Source

File: src/integrations/learnpress/actions/lp-marklessondone.php

	public function lp_mark_lesson_done( $user_id, $action_data, $recipe_id ) {



		if ( ! function_exists( 'learn_press_get_current_user' ) ) {
			$error_message = 'The function learn_press_get_current_user does not exist';
			Automator()->complete_action( $user_id, $action_data, $recipe_id, $error_message );

			return;
		}
		$user      = learn_press_get_user( $user_id );
		$lesson_id = $action_data['meta'][ $this->action_meta ];
		$course_id = $action_data['meta']['LPCOURSE'];

		// Mark lesson completed.
		$result = $user->complete_lesson( $lesson_id, $course_id );

		if ( ! is_wp_error( $result ) ) {
			Automator()->complete_action( $user_id, $action_data, $recipe_id );
		} else {
			$error_message = $result->get_error_message();
			Automator()->complete_action( $user_id, $action_data, $recipe_id, $error_message );

			return;
		}

	}