static function load_question_settings() { $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : null; $question_id = isset($_REQUEST['question_id']) ? $_REQUEST['question_id'] : null; $options = array('ID' => $question_id); $question = LP_Question::instance($type, $options); $options = $question->get('options'); if (isset($options['type']) && $options['type'] == $type) { } else { unset($options['answer']); $question->set('options', $options); } $post_options = !empty($_REQUEST['options']) ? $_REQUEST['options'] : null; if ($type == 'single_choice') { $selected = -1; if ($post_options && $post_options['answer']) { foreach ($post_options['answer'] as $k => $option) { if (!empty($option['is_true'])) { $selected = $k; } $post_options['answer'][$k]['is_true'] = 0; } } if ($selected > -1) { $post_options['answer'][$selected]['is_true'] = 1; } } if ($post_options) { $question->set('options', $post_options); } $question->admin_interface(); die; }
static function save_quiz_questions($post_id) { learn_press_debug($_POST); die; static $has_updated; $questions = isset($_POST[LP()->question_post_type]) ? $_POST[LP()->question_post_type] : null; if (!$questions) { return; } $postmeta = array(); // prevent infinite loop with save_post action if ($has_updated) { return; } $has_updated = true; foreach ($questions as $question_id => $options) { $question = LP_Question::instance($question_id); if ($question) { $question_id = $question->save_post_action(); if ($question_id) { $postmeta[$question_id] = array('toggle' => $options['toggle']); if (!empty($options['type'])) { $post_data = get_post_meta($question_id, '_lpr_question', true); $post_data['type'] = $options['type']; update_post_meta($question_id, '_lpr_question', $post_data); } } } } update_post_meta($post_id, '_lpr_quiz_questions', $postmeta); }