Пример #1
0
 public function __construct($settings = array())
 {
     parent::__construct();
     // Make sure core is the correct version for this module.
     if (version_compare(icit_core::VERSION, self::VERSION, '<')) {
         error_log(sprintf(__('Wrong ICIT Core version. Class "%3$s" expecting core version version %2$s but got version %1$s in file %4$s', self::DOM), icit_core::VERSION, self::VERSION, __CLASS__, __FILE__), E_USER_WARNING);
         return false;
     }
     // Merge the settings passed in with the defaults
     $this->option_page_settings = wp_parse_args($settings, $this->option_page_settings);
     // Options page
     add_action('admin_menu', array($this, '_add_options_page'));
     // Set customiser
     if ($this->option_page_settings['use_customiser']) {
         add_action('customize_register', array($this, '_set_customiser'), 1);
     }
     // Add settings fields
     $register_settings_cb = is_callable($this->option_page_settings['register_settings']) ? $this->option_page_settings['register_settings'] : array($this, 'register_settings');
     add_action('admin_init', $register_settings_cb);
     if ($this->option_page_settings['use_customiser']) {
         add_action('customize_register', $register_settings_cb);
     }
     // Setup / get options page hidden post
     add_action('admin_init', array($this, '_set_options_post'));
     add_action('customize_register', array($this, '_set_options_post'));
     // Admin page scripts
     add_action('admin_enqueue_scripts', array($this, '_option_page_scripts'));
     // Option page posts, well and truly hidden away. Used to attach
     // images uploaded to option page for easy later reference (<=3.4.x)
     if (!get_post_type_object('icit_option_page')) {
         register_post_type('icit_option_page', array('public' => false, 'exclude_from_search' => true, 'publicly_queryable' => false, 'show_ui' => false, 'show_in_menu' => false, 'has_archive' => false, 'can_export' => false, 'rewrite' => false, 'query_var' => false, 'capability_type' => 'page'));
     }
     // Handle settings errors and notices
     add_action('admin_notices', array($this, '_admin_notices'));
 }
 public function render_content()
 {
     echo '<label><span class="customize-control-title">' . esc_html($this->label) . '</span></label>';
     ob_start();
     icit_fields::field_date_time(array('name' => $this->setting->id, 'description' => '', 'default' => $this->setting->default));
     $date_field = ob_get_clean();
     echo str_replace('<input', '<input ' . $this->get_link(), $date_field);
 }
Пример #3
0
 public function save_post($post_id, WP_Post $post, $update)
 {
     if (defined('DOING_AJAX') && DOING_AJAX) {
         return $post_id;
     }
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return $post_id;
     }
     if (!current_user_can('edit_post', $post_id)) {
         return $post_id;
     }
     // settings
     if (isset($_POST['type'])) {
         update_post_meta($post_id, 'type', icit_fields::validate_text($_POST['type']));
     }
     //if ( isset( $_POST[ 'timelimit' ] ) )
     //	update_post_meta( $post_id, 'timelimit', icit_fields::validate_numeric( $_POST[ 'timelimit' ] ) );
     if (isset($_POST['nextdelay'])) {
         update_post_meta($post_id, 'nextdelay', icit_fields::validate_numeric($_POST['nextdelay']));
     }
     if (isset($_POST['correct'])) {
         update_post_meta($post_id, 'correct', icit_fields::validate_text($_POST['correct']));
     }
     if (isset($_POST['incorrect'])) {
         update_post_meta($post_id, 'incorrect', icit_fields::validate_text($_POST['incorrect']));
     }
     // questions
     if (isset($_POST['questions'])) {
         $questions = is_array($_POST['questions']) ? $_POST['questions'] : array();
         // remove js placeholder from data
         if (isset($questions['__i__'])) {
             unset($questions['__i__']);
         }
         // add a new empty question to array
         if (isset($_POST['addquestion'])) {
             $questions[] = array();
         }
         // remove by index
         if (isset($_POST['deletequestion'])) {
             unset($questions[array_pop(array_keys($_POST['deletequestion']))]);
         }
         // process & validate questions
         if ($questions) {
             array_walk($questions, function (&$q, $i) {
                 // add a new empty answer to question
                 if (isset($_POST['addanswer']) && isset($_POST['addanswer'][$i])) {
                     $q['answers'][] = array();
                 }
                 // remove by index
                 if (isset($_POST['deleteanswer']) && isset($_POST['deleteanswer'][$i])) {
                     unset($q['answers'][array_pop(array_keys($_POST['deleteanswer'][$i]))]);
                 }
                 // fix the ridiculous lack of square brackets in names for editors
                 $q['result'] = isset($_POST["questions_{$i}_result"]) ? $_POST["questions_{$i}_result"] : '';
                 $q['resultcorrect'] = isset($_POST["questions_{$i}_resultcorrect"]) ? $_POST["questions_{$i}_resultcorrect"] : '';
                 $q['resultincorrect'] = isset($_POST["questions_{$i}_resultincorrect"]) ? $_POST["questions_{$i}_resultincorrect"] : '';
                 foreach ($q['answers'] as $a => $answer) {
                     $q['answers'][$a]['description'] = isset($_POST["answer_{$a}_answer_description"]) ? $_POST["answer_{$a}_answer_description"] : '';
                 }
                 $q = apply_filters('quizzlestick_save_questions', $q, $i);
                 return $q;
             });
         }
         update_post_meta($post_id, 'questions', $questions);
     }
     // results
     if (isset($_POST['result_introduction'])) {
         update_post_meta($post_id, 'result_introduction', icit_fields::validate_textarea($_POST['result_introduction']));
     }
     if (isset($_POST['result_heading'])) {
         update_post_meta($post_id, 'result_heading', icit_fields::validate_text($_POST['result_heading']));
     }
     if (isset($_POST['result'])) {
         update_post_meta($post_id, 'result', icit_fields::validate_textarea($_POST['result']));
     }
     if (isset($_POST['result_title'])) {
         update_post_meta($post_id, 'result_title', icit_fields::validate_text($_POST['result_title']));
     }
     if (isset($_POST['results']) || isset($_POST['addresult'])) {
         $results = is_array($_POST['results']) ? $_POST['results'] : array();
         // remove js placeholder from data
         if (isset($results['__i__'])) {
             unset($results['__i__']);
         }
         // order by points
         usort($results, function ($a, $b) {
             return $a['points'] > $b['points'];
         });
         // add a new empty answer to question
         if (isset($_POST['addresult'])) {
             $results[] = array();
         }
         // remove by index
         if (isset($_POST['deleteresult'])) {
             unset($results[array_pop(array_keys($_POST['deleteresult']))]);
         }
         // process & validate questions
         if ($results) {
             array_walk($results, function (&$r, $i) {
                 // fix the ridiculous lack of square brackets in names for editors
                 $r['result'] = isset($_POST["results_{$i}_result"]) ? $_POST["results_{$i}_result"] : '';
                 return $r;
             });
         }
         update_post_meta($post_id, 'results', $results);
     }
 }