PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.9
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.9
4.4.9 4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 All 140 releases
← All changes | inc/rest-api/v1/frontend/class-lp-rest-users-controller.php +22 -14 4.4.3 → 4.4.9 View file →
@@ -128,9 +128,9 @@
128 128 *
129 129 * @param WP_REST_Request $request
130 130 *
131 131 * @editor tungnx
132 - * @version 1.0.3
132 + * @version 1.0.4
133 133 * @sicne 4.0.0
134 134 * @return WP_REST_Response
135 135 */
136 136 public function start_quiz( WP_REST_Request $request ): WP_REST_Response {
@@ -153,14 +153,14 @@
153 153 $quiz = learn_press_get_quiz( $item_id );
154 154
155 155 $courseModel = CourseModel::find( $course_id, true );
156 156 if ( ! $courseModel ) {
157 - throw new Exception( 'The course is invalid', 'learnrpess' );
157 + throw new Exception( esc_html__( 'The course is invalid', 'learnpress' ) );
158 158 }
159 159
160 160 $quizPostModel = $courseModel->get_item_model( $item_id, LP_QUIZ_CPT );
161 161 if ( ! $quizPostModel ) {
162 - throw new Exception( 'The quiz is invalid', 'learnrpess' );
162 + throw new Exception( esc_html__( 'The quiz is invalid', 'learnpress' ) );
163 163 }
164 164
165 165 $quiz->set_course( $course );
166 166
@@ -280,20 +280,20 @@
280 280 $course = learn_press_get_course( $course_id );
281 281
282 282 $courseModel = CourseModel::find( $course_id, true );
283 283 if ( ! $courseModel ) {
284 - throw new Exception( 'The course is invalid', 'learnrpess' );
284 + throw new Exception( esc_html__( 'The course is invalid', 'learnpress' ) );
285 285 }
286 286
287 287 $quizPostModel = $courseModel->get_item_model( $item_id, LP_QUIZ_CPT );
288 288 if ( ! $quizPostModel ) {
289 - throw new Exception( 'The quiz is invalid', 'learnrpess' );
289 + throw new Exception( esc_html__( 'The quiz is invalid', 'learnpress' ) );
290 290 }
291 291
292 292 // Use for Review Quiz.
293 293 $quiz = learn_press_get_quiz( $item_id );
294 294 if ( ! $quiz ) {
295 - throw new Exception( __( 'The quiz is invalid!', 'learnpress' ) );
295 + throw new Exception( esc_html__( 'The quiz is invalid!', 'learnpress' ) );
296 296 }
297 297 $quiz->set_course( $course );
298 298
299 299 // Course is no required enroll (no need login)
@@ -359,8 +359,16 @@
359 359 }
360 360
361 361 $user_quiz->complete();
362 362
363 + /**
364 + * Clear cache result quiz
365 + * Cache set on @see LP_User_Item_Quiz::get_results, and start_quiz() clears the same
366 + * key. Without this the next read still serves the in-progress result and the
367 + * submitted answers all come back as skipped.
368 + */
369 + $user_quiz->clear_results_cache();
370 +
363 371 do_action( 'learn-press/user/quiz-finished', $item_id, $course_id, $user_id, $user_quiz );
364 372
365 373 $result['status'] = $user_quiz->get_status(); // Must be completed
366 374 $result['attempts'] = $user_quiz->get_attempts();
@@ -398,25 +406,25 @@
398 406 $checked = [];
399 407
400 408 $courseModel = CourseModel::find( $course_id, true );
401 409 if ( ! $courseModel ) {
402 - throw new Exception( 'The course is invalid', 'learnrpess' );
410 + throw new Exception( esc_html__( 'The course is invalid', 'learnpress' ) );
403 411 }
404 412
405 413 $quizPostModel = $courseModel->get_item_model( $quiz_id, LP_QUIZ_CPT );
406 414 if ( ! $quizPostModel ) {
407 - throw new Exception( 'The quiz is invalid', 'learnrpess' );
415 + throw new Exception( esc_html__( 'The quiz is invalid', 'learnpress' ) );
408 416 }
409 417
410 418 // Check question has in quiz
411 419 $quizQuestionModel = QuizQuestionModel::find( $quiz_id, $question_id );
412 420 if ( ! $quizQuestionModel ) {
413 - throw new Exception( 'The quiz question is invalid', 'learnrpess' );
421 + throw new Exception( esc_html__( 'The quiz question is invalid', 'learnpress' ) );
414 422 }
415 423
416 424 $questionModel = QuestionPostModel::find( $question_id, true );
417 425 if ( ! $questionModel ) {
418 - throw new Exception( 'The question is invalid', 'learnrpess' );
426 + throw new Exception( esc_html__( 'The question is invalid', 'learnpress' ) );
419 427 }
420 428
421 429 // For case user not login
422 430 if ( $course->is_no_required_enroll() ) {
@@ -424,19 +432,19 @@
424 432 $checked = $no_required_enroll->guest_check_question( $question_id, $answered );
425 433 } else { // For case user logged in
426 434 $user = learn_press_get_current_user();
427 435 if ( $user->is_guest() ) {
428 - throw new Exception( 'The user is invalid', 'learnrpess' );
436 + throw new Exception( esc_html__( 'You must be logged in to check answer.', 'learnpress' ) );
429 437 }
430 438
431 439 $user_course = $user->get_course_data( $course_id );
432 440 if ( ! $user_course ) {
433 - throw new Exception( 'User\'s course no data!', 'learnrpess' );
441 + throw new Exception( esc_html__( 'User\'s course no data!', 'learnpress' ) );
434 442 }
435 443
436 444 $user_quiz = $user_course->get_item( $quiz_id );
437 445 if ( ! $user_quiz ) {
438 - throw new Exception( 'User\'s quiz no data!', 'learnrpess' );
446 + throw new Exception( esc_html__( 'User\'s quiz no data!', 'learnpress' ) );
439 447 }
440 448
441 449 $checked = $user_quiz->instant_check_question( $question_id, $answered );
442 450 }
@@ -445,9 +453,9 @@
445 453 $response['explanation'] = $question->get_explanation();
446 454 $response['options'] = learn_press_get_question_options_for_js(
447 455 $question,
448 456 array(
449 - 'include_is_true' => true,
457 + 'include_is_true' => $quizPostModel->has_instant_check(),
450 458 'answer' => $answered,
451 459 )
452 460 );
453 461 $response['result'] = $checked;