/**
  * An ajax callback function that creates a new form with default fields and settings after checking the nonce.
  **/
 public function create_form_ajax()
 {
     $form_name = $_POST['form_name'];
     $post_type = $_POST['post_type'];
     $description = $_POST['form_description'];
     $parent_form_id = $_POST['parent_form'];
     $parent_form = false;
     $nonce = $_POST['_wpnonce'];
     if (!($form_name && $post_type)) {
         $response = array('success' => false, 'error' => __('You missed a required item.', 'wpfepp-plugin'));
         die(json_encode($response));
     }
     if (!wp_verify_nonce($nonce, 'wpfepp-create-form')) {
         $response = array('success' => false, 'error' => __('Security check failed!', 'wpfepp-plugin'));
         die(json_encode($response));
     }
     if ($parent_form_id != -1) {
         $parent_form = $this->db->get($parent_form_id);
         if ($parent_form && $parent_form['post_type'] != $post_type) {
             $response = array('success' => false, 'error' => __('You can only import items from a form which has the same post type as the one selected for this form.', 'wpfepp-plugin'));
             die(json_encode($response));
         }
     }
     $fields = $parent_form ? $parent_form['fields'] : $this->defaults['fields'][$post_type];
     $settings = $parent_form ? $parent_form['settings'] : $this->defaults['settings'];
     $emails = $parent_form ? $parent_form['emails'] : $this->defaults['emails'];
     $this->db->add($form_name, $post_type, $description, $fields, $settings, $emails);
     ob_start();
     $this->render_form_list_table();
     $table_html = ob_get_clean();
     $response = array('success' => true, 'table_html' => $table_html);
     die(json_encode($response));
 }
Пример #2
0
 /**
  * Fetches the form data from the database table and initializes all the class attributes.
  * 
  * @param int $form_id The row ID of this form from the database table.
  **/
 public function __construct($version, $form_id = -1)
 {
     $this->load_dependencies();
     $this->version = $version;
     if ($form_id < 0) {
         $this->valid = false;
         return;
     }
     require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-wpfepp-db-table.php';
     $this->id = $form_id;
     $this->db = WPFEPP_DB_Table::get_instance();
     $row = $this->db->get($form_id);
     $this->captcha = new WPFEPP_Captcha($this->version);
     if ($row) {
         $this->valid = true;
     } else {
         $this->valid = false;
     }
     if ($this->valid) {
         $this->name = $row['name'];
         $this->description = $row['description'];
         $this->post_type = $row['post_type'];
         $this->fields = $row['fields'];
         $this->settings = $row['settings'];
         $this->emails = $row['emails'];
         //Necessary because we need to check if the post type is public before showing any links to the end user.
         $this->post_type_obj = get_post_type_object($this->post_type);
     }
 }