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
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 * * Return an associative array containing at least the `$id` to cease execution and have * the custom item returned via the `process_trash()` method. * * A successful deletion return should be: `array( 'id' => $id )`. * * A failure should contain an error message in a second array member: * `array( 'id' => $id, 'error' => esc_html__( 'My error message', 'my-domain' ) )`. * * @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 ), ); }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
3.9.0 | |
3.16.0 | Introduced. |