| @@ -172,8 +172,9 @@ | ||
| 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 | // update hidden questions in quiz meta |
| 179 | 180 | $quiz = LP_Quiz::get_quiz( $quiz_id ); |
| @@ -259,9 +260,9 @@ | ||
| 259 | 260 | } |
| 260 | 261 | |
| 261 | 262 | $question = LP_Question::get_question( $question_id ); |
| 262 | 263 | |
| 263 | - $question = $this->question_curd->change_question_type( $question, $type ); | |
| 264 | + $this->question_curd->change_question_type( $question, $type ); | |
| 264 | 265 | |
| 265 | 266 | $this->result = $this->get_question_data_to_quiz_editor( $question, true ); |
| 266 | 267 | |
| 267 | 268 | return true; |
| @@ -281,8 +282,9 @@ | ||
| 281 | 282 | } |
| 282 | 283 | |
| 283 | 284 | // duplicate question |
| 284 | 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() ); | |
| 285 | 287 | |
| 286 | 288 | if ( ! is_wp_error( $new_question_id ) ) { |
| 287 | 289 | |
| 288 | 290 | // add question to hidden questions in quiz meta |
| @@ -316,8 +318,9 @@ | ||
| 316 | 318 | return false; |
| 317 | 319 | } |
| 318 | 320 | |
| 319 | 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() ); | |
| 320 | 323 | |
| 321 | 324 | return true; |
| 322 | 325 | } |
| 323 | 326 | |
| @@ -333,8 +336,9 @@ | ||
| 333 | 336 | return false; |
| 334 | 337 | } |
| 335 | 338 | |
| 336 | 339 | $this->result = wp_trash_post( $question_id ); |
| 340 | + $this->clear_cache_of_quiz_questions( $this->quiz->get_id() ); | |
| 337 | 341 | |
| 338 | 342 | return true; |
| 339 | 343 | } |
| 340 | 344 | |
| @@ -583,15 +587,15 @@ | ||
| 583 | 587 | if ( ! $questions ) { |
| 584 | 588 | return false; |
| 585 | 589 | } |
| 586 | 590 | |
| 587 | - $questions = json_decode( wp_unslash( $questions ), true ); | |
| 591 | + $questions = json_decode( $questions, true ); | |
| 588 | 592 | |
| 589 | 593 | $quiz_id = $this->quiz->get_id(); |
| 590 | 594 | |
| 591 | 595 | if ( get_post_status( $quiz_id ) == 'auto-draft' ) { |
| 592 | 596 | $draft_quiz = ! empty( $args['draft_quiz'] ) ? $args['draft_quiz'] : ''; |
| 593 | - $draft_quiz = (array) ( json_decode( wp_unslash( $draft_quiz ), '' ) ); | |
| 597 | + $draft_quiz = (array) json_decode( $draft_quiz, '' ); | |
| 594 | 598 | |
| 595 | 599 | $quiz_args = array( |
| 596 | 600 | 'id' => $quiz_id, |
| 597 | 601 | 'title' => $draft_quiz['title'], |
| @@ -623,9 +627,9 @@ | ||
| 623 | 627 | $hidden_questions = array_unique( $hidden_questions ); |
| 624 | 628 | |
| 625 | 629 | update_post_meta( $quiz_id, '_lp_hidden_questions', $hidden_questions ); |
| 626 | 630 | |
| 627 | - LP_Object_Cache::flush(); | |
| 631 | + $this->clear_cache_of_quiz_questions( $quiz_id ); | |
| 628 | 632 | $this->result = $this->quiz->quiz_editor_get_questions(); |
| 629 | 633 | |
| 630 | 634 | return true; |
| 631 | 635 | } |
| @@ -630,6 +634,21 @@ | ||
| 630 | 634 | return true; |
| 631 | 635 | } |
| 632 | 636 | |
| 633 | 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 ); | |
| 634 | 653 | } |
| 635 | 654 | } |