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
Return Return
(array)
Source Source
File: includes/class.llms.ajax.handler.php
* @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'] ) );
}
// Record the attempt's completion.
$attempt->end();
// Setup a redirect.
$url = add_query_arg(
array(
'attempt_key' => $attempt->get_key(),
),
get_permalink( $attempt->get( 'quiz_id' ) )
);
return array(
/**
* Filter the quiz redirect URL on completion.
*
* @since Unknown
*
* @param string $url The quiz redirect URL on completion.
* @param LLMS_Quiz_Attempt $attempt The quiz attempt.
*/
'redirect' => apply_filters( 'llms_quiz_complete_redirect', $url, $attempt ),
);
}
/**
* Remove a coupon from an order during checkout
*
* @since 3.0.0
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| 3.9.0 | |
| 3.16.0 | Introduced. |