Example #1
0
 function form_handler()
 {
     if (empty($_POST['action'])) {
         return false;
     }
     check_admin_referer($this->nonce);
     if (!isset($this->options)) {
         trigger_error('options handler not set', E_USER_WARNING);
         return false;
     }
     $new_data = scbUtil::array_extract($_POST, array_keys($this->options->get_defaults()));
     $new_data = stripslashes_deep($new_data);
     $new_data = $this->validate($new_data, $this->options->get());
     $this->options->set($new_data);
     $this->admin_msg();
 }
Example #2
0
 static function ajax_response()
 {
     // Is user trusted?
     check_ajax_referer(self::$nonce, 'nonce');
     extract(scbUtil::array_extract($_POST, array('callback', 'data')));
     $filter = $data['filter'];
     self::make_instances();
     // Is the current field defined?
     if (!($instance = self::$instances[$filter])) {
         die(-1);
     }
     // Does the user have the right to do this?
     if (!$instance->check($data) || !$instance->allow($data)) {
         die(-1);
     }
     $args = self::get_args($filter);
     try {
         if ('save' == $callback) {
             $content = stripslashes_deep($_POST['content']);
             $result = $instance->save($data, $content);
             $result = @apply_filters($filter, $result);
         } elseif ('get' == $callback) {
             $result = (string) $instance->get($data);
             if ('rich' == $data['type']) {
                 $result = wpautop($result);
             }
         }
         $result = array('content' => $result);
     } catch (Exception $e) {
         $result = array('error' => $e->getMessage());
     }
     die(json_encode($result));
 }