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/admin/editor/class-lp-admin-editor-quiz.php +34 -12 4.1.6.9.1 → 4.4.9 View file →
@@ -172,18 +172,21 @@
172 172 'type' => $question['type'],
173 173 );
174 174
175 175 $new_question = $this->question_curd->create( $args );
176 + $this->clear_cache_of_quiz_questions( $quiz_id );
176 177
177 178 if ( ! is_wp_error( $new_question ) ) {
178 -
179 179 // update hidden questions in quiz meta
180 180 $quiz = LP_Quiz::get_quiz( $quiz_id );
181 - $hidden_questions = $quiz->get_questions();
181 + $hidden_questions = $quiz->get_question_ids();
182 182
183 183 if ( $hidden_questions ) {
184 - unset( $hidden_questions[ $new_question->get_id() ] );
185 - $hidden_questions = array_keys( $hidden_questions );
184 + $index = array_search( $new_question->get_id(), $hidden_questions );
185 + if ( $index !== false ) {
186 + unset( $hidden_questions[ $index ] );
187 + }
188 + //$hidden_questions = array_keys( $hidden_questions );
186 189 }
187 190
188 191 update_post_meta( $quiz_id, '_lp_hidden_questions', $hidden_questions );
189 192
@@ -257,9 +260,9 @@
257 260 }
258 261
259 262 $question = LP_Question::get_question( $question_id );
260 263
261 - $question = $this->question_curd->change_question_type( $question, $type );
264 + $this->question_curd->change_question_type( $question, $type );
262 265
263 266 $this->result = $this->get_question_data_to_quiz_editor( $question, true );
264 267
265 268 return true;
@@ -279,8 +282,9 @@
279 282 }
280 283
281 284 // duplicate question
282 285 $new_question_id = $this->question_curd->duplicate( $question['id'], array( 'post_status' => 'publish' ) );
286 + $this->clear_cache_of_quiz_questions( $this->quiz->get_id() );
283 287
284 288 if ( ! is_wp_error( $new_question_id ) ) {
285 289
286 290 // add question to hidden questions in quiz meta
@@ -314,8 +318,9 @@
314 318 return false;
315 319 }
316 320
317 321 $this->result = $this->quiz_curd->remove_questions( $this->quiz->get_id(), $question_id );
322 + $this->clear_cache_of_quiz_questions( $this->quiz->get_id() );
318 323
319 324 return true;
320 325 }
321 326
@@ -331,8 +336,9 @@
331 336 return false;
332 337 }
333 338
334 339 $this->result = wp_trash_post( $question_id );
340 + $this->clear_cache_of_quiz_questions( $this->quiz->get_id() );
335 341
336 342 return true;
337 343 }
338 344
@@ -410,12 +416,12 @@
410 416 *
411 417 * @return bool
412 418 */
413 419 public function delete_question_answer( $args = array() ) {
414 - $question_id = isset( $_POST['question_id'] ) ? $_POST['question_id'] : false;
415 - $answer_id = isset( $_POST['answer_id'] ) ? intval( $_POST['answer_id'] ) : false;
420 + $question_id = LP_Helper::sanitize_params_submitted( $_POST['question_id'] ?? 0 );
421 + $answer_id = LP_Helper::sanitize_params_submitted( $_POST['answer_id'] ?? 0 );
416 422
417 - if ( ! ( $question_id && $answer_id ) ) {
423 + if ( ! $question_id || ! $answer_id ) {
418 424 return false;
419 425 }
420 426
421 427 $this->result = $this->question_curd->delete_answer( $question_id, $answer_id );
@@ -575,20 +581,21 @@
575 581 *
576 582 * @return bool
577 583 */
578 584 public function add_questions_to_quiz( $args = array() ) {
579 - $questions = isset( $_POST['items'] ) ? $_POST['items'] : false;
580 - $questions = json_decode( wp_unslash( $questions ), true );
585 + $questions = LP_Helper::sanitize_params_submitted( $_POST['items'] ?? '' );
581 586
582 587 if ( ! $questions ) {
583 588 return false;
584 589 }
585 590
591 + $questions = json_decode( $questions, true );
592 +
586 593 $quiz_id = $this->quiz->get_id();
587 594
588 595 if ( get_post_status( $quiz_id ) == 'auto-draft' ) {
589 596 $draft_quiz = ! empty( $args['draft_quiz'] ) ? $args['draft_quiz'] : '';
590 - $draft_quiz = (array) ( json_decode( wp_unslash( $draft_quiz ), '' ) );
597 + $draft_quiz = (array) json_decode( $draft_quiz, '' );
591 598
592 599 $quiz_args = array(
593 600 'id' => $quiz_id,
594 601 'title' => $draft_quiz['title'],
@@ -620,9 +627,9 @@
620 627 $hidden_questions = array_unique( $hidden_questions );
621 628
622 629 update_post_meta( $quiz_id, '_lp_hidden_questions', $hidden_questions );
623 630
624 - LP_Object_Cache::flush();
631 + $this->clear_cache_of_quiz_questions( $quiz_id );
625 632 $this->result = $this->quiz->quiz_editor_get_questions();
626 633
627 634 return true;
628 635 }
@@ -627,6 +634,21 @@
627 634 return true;
628 635 }
629 636
630 637 return false;
638 + }
639 +
640 + /**
641 + * Clear cache when add/remove question to quiz
642 + *
643 + * @param $quiz_id
644 + *
645 + * @return void
646 + * @since 4.2.5.8
647 + * @version 1.0.0
648 + */
649 + public function clear_cache_of_quiz_questions( $quiz_id ) {
650 + $lp_quiz_cache = LP_Quiz_Cache::instance();
651 + $key_cache = "$quiz_id/question_ids";
652 + $lp_quiz_cache->clear( $key_cache );
631 653 }
632 654 }