예제 #1
0
 /**
  * Create a new item
  *
  * @uses "wp_ajax_frmwks_create_formworks"  action
  *
  * @since 0.0.1
  */
 public function create_new_formworks()
 {
     $can = options::can();
     if (!$can) {
         status_header(500);
         wp_die(__('Access denied', 'formworks'));
     }
     if (!empty($_POST['import'])) {
         $config = json_decode(stripslashes_deep($_POST['import']), true);
         if (empty($config['name']) || empty($config['slug'])) {
             wp_send_json_error($_POST);
         }
         $id = null;
         if (!empty($config['id'])) {
             $id = $config['id'];
         }
         options::create($config['name'], $config['slug'], $id);
         options::update($config);
         wp_send_json_success($config);
     }
     $new = options::create($_POST['name'], $_POST['slug'], $_POST['form'], $_POST['view_type']);
     if (is_array($new)) {
         wp_send_json_success($new);
     } else {
         wp_send_json_error($_POST);
     }
 }