-
Notifications
You must be signed in to change notification settings - Fork 135
/
start-button.php
134 lines (107 loc) · 4.4 KB
/
start-button.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
/**
* Quiz Start & Next lesson buttons
*
* @since 1.0.0
* @since 3.25.0 Unknown.
* @since 4.17.0 Early bail on orphan quiz.
* @since 7.8.0 Added support for quiz resume.
* @version 7.8.0
*/
defined( 'ABSPATH' ) || exit;
global $post;
$quiz = llms_get_post( $post );
$lesson = $quiz->get_lesson();
if ( ! $lesson || ! is_a( $lesson, 'LLMS_Lesson' ) ) {
return;
}
?>
<div class="llms-quiz-buttons llms-button-wrapper" id="quiz-start-button">
<?php
/**
* Fired before the start quiz button
*
* @since Unknown
*/
do_action( 'lifterlms_before_start_quiz' );
?>
<?php if ( $quiz ) : ?>
<?php if ( $quiz->is_open() ) : ?>
<form method="POST" action="" name="llms_start_quiz" enctype="multipart/form-data">
<input id="llms-lesson-id" name="llms_lesson_id" type="hidden" value="<?php echo esc_attr( $lesson->get( 'id' ) ); ?>"/>
<input id="llms-quiz-id" name="llms_quiz_id" type="hidden" value="<?php echo esc_attr( $quiz->get( 'id' ) ); ?>"/>
<input type="hidden" name="action" value="llms_start_quiz" />
<?php wp_nonce_field( 'llms_start_quiz' ); ?>
<?php if ( $quiz->can_be_resumed_by_student() ) : ?>
<?php
$message = esc_html__( 'You have a partially completed attempt for this quiz. You can continue where you left off by clicking the Resume Quiz button below.', 'lifterlms' );
$message .= '<div><button class="llms-start-quiz-button llms-button-secondary button" id="llms_start_quiz" name="llms_start_quiz" type="submit">';
/**
* Filters the restart quiz button text
*
* @since Unknown
*
* @param string $button_text The start quiz button text.
* @param LLMS_Quiz $quiz The current quiz instance.
* @param LLMS_Lesson $lesson The parent lesson instance.
*/
$message .= wp_kses_post( apply_filters( 'lifterlms_restart_quiz_button_text', __( 'Restart Quiz Instead', 'lifterlms' ), $quiz, $lesson ) );
$message .= '</button></div>';
?>
<?php llms_print_notice( $message, 'notice' ); ?>
<?php else : ?>
<button class="llms-start-quiz-button llms-button-action button" id="llms_start_quiz" name="llms_start_quiz" type="submit">
<?php
/**
* Filters the quiz button text
*
* @since Unknown
*
* @param string $button_text The start quiz button text.
* @param LLMS_Quiz $quiz The current quiz instance.
* @param LLMS_Lesson $lesson The parent lesson instance.
*/
echo wp_kses_post( apply_filters( 'lifterlms_begin_quiz_button_text', __( 'Start Quiz', 'lifterlms' ), $quiz, $lesson ) );
?>
</button>
<?php endif; ?>
</form>
<?php else : ?>
<p><?php esc_html_e( 'You are not able to take this quiz', 'lifterlms' ); ?></p>
<?php endif; ?>
<?php if ( $quiz->can_be_resumed_by_student() ) : ?>
<form method="POST" action="" name="llms_resume_quiz" enctype="multipart/form-data">
<input id="llms-attempt-key" name="llms_attempt_key" type="hidden" value="<?php echo esc_attr( $quiz->get_student_last_attempt_key() ); ?>"/>
<input type="hidden" name="action" value="llms_resume_quiz" />
<?php wp_nonce_field( 'llms_resume_quiz' ); ?>
<button class="llms-resume-quiz-button llms-button-action button" id="llms_resume_quiz" name="llms_resume_quiz" type="submit">
<?php
/**
* Filters the quiz resume button text.
*
* @since 7.8.0
*
* @param string $button_text The resume quiz button text.
* @param LLMS_Quiz $quiz The current quiz instance.
* @param LLMS_Lesson $lesson The parent lesson instance.
*/
echo esc_html( apply_filters( 'lifterlms_resume_quiz_button_text', esc_html__( 'Resume Quiz', 'lifterlms' ), $quiz, $lesson ) );
?>
</button>
</form>
<?php endif; ?>
<?php if ( $lesson->get_next_lesson() && llms_is_complete( get_current_user_id(), $lesson->get( 'id' ), 'lesson' ) ) : ?>
<a href="<?php echo esc_url( get_permalink( $lesson->get_next_lesson() ) ); ?>" class="button llms-button-secondary llms-next-lesson"><?php esc_html_e( 'Next Lesson', 'lifterlms' ); ?></a>
<?php endif; ?>
<?php else : ?>
<p><?php esc_html_e( 'You are not able to take this quiz', 'lifterlms' ); ?></p>
<?php endif; ?>
<?php
/**
* Fired after the start quiz button
*
* @since Unknown
*/
do_action( 'lifterlms_after_start_quiz' );
?>
</div>