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 +29 -8 4.1.7 → 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
@@ -581,15 +587,15 @@
581 587 if ( ! $questions ) {
582 588 return false;
583 589 }
584 590
585 - $questions = json_decode( wp_unslash( $questions ), true );
591 + $questions = json_decode( $questions, true );
586 592
587 593 $quiz_id = $this->quiz->get_id();
588 594
589 595 if ( get_post_status( $quiz_id ) == 'auto-draft' ) {
590 596 $draft_quiz = ! empty( $args['draft_quiz'] ) ? $args['draft_quiz'] : '';
591 - $draft_quiz = (array) ( json_decode( wp_unslash( $draft_quiz ), '' ) );
597 + $draft_quiz = (array) json_decode( $draft_quiz, '' );
592 598
593 599 $quiz_args = array(
594 600 'id' => $quiz_id,
595 601 'title' => $draft_quiz['title'],
@@ -621,9 +627,9 @@
621 627 $hidden_questions = array_unique( $hidden_questions );
622 628
623 629 update_post_meta( $quiz_id, '_lp_hidden_questions', $hidden_questions );
624 630
625 - LP_Object_Cache::flush();
631 + $this->clear_cache_of_quiz_questions( $quiz_id );
626 632 $this->result = $this->quiz->quiz_editor_get_questions();
627 633
628 634 return true;
629 635 }
@@ -628,6 +634,21 @@
628 634 return true;
629 635 }
630 636
631 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 );
632 653 }
633 654 }