LLMS_AJAX_Handler::quiz_end( array $request, LLMS_Quiz_Attempt|null $attempt = null )

End a quiz attempt


Parameters Parameters

$request

(array) (Required) $_POST data.

$attempt

(LLMS_Quiz_Attempt|null) (Optional) The quiz attempt. Default null.

Default value: null


Top ↑

Return Return

(array)


Top ↑

Source Source

File: includes/class.llms.ajax.handler.php

		if ( $question_id ) {
			$attempt->set( 'current_question_id', absint( $question_id ) );
			$attempt->save();

			$html = llms_get_template_ajax(
				'content-single-question.php',
				array(
					'attempt'  => $attempt,
					'question' => llms_get_post( $question_id ),
				)
			);

			return array(
				'html'        => $html,
				'question_id' => $question_id,
			);

		} else {

			return self::quiz_end( $request, $attempt );

		}
	}

	/**
	 * End a quiz attempt.
	 *
	 * @since 3.9.0
	 * @since 3.16.0 Unknown.
	 *
	 * @param array                  $request $_POST data.
	 * @param LLMS_Quiz_Attempt|null $attempt The quiz attempt.
	 * @return array
	 */
	public static function quiz_end( $request, $attempt = null ) {

		$err = new WP_Error();

		if ( ! $attempt ) {

			$student = llms_get_student();
			if ( ! $student ) {
				$err->add( 400, __( 'You must be logged in to take quizzes.', 'lifterlms' ) );
				return $err;
			}

			if ( ! isset( $request['attempt_key'] ) ) {
				$err->add( 400, __( 'Missing required parameters. Could not proceed.', 'lifterlms' ) );
				return $err;
			}

			$attempt = $student->quizzes()->get_attempt_by_key( sanitize_text_field( $request['attempt_key'] ) );


Top ↑

Changelog Changelog

Changelog
Version Description
3.9.0
3.16.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.