Ejemplo n.º 1
0
 public function addNewPost($post_id)
 {
     include_once ABSPATH . 'wp-admin/includes/plugin.php';
     global $wpdb;
     $temppost_id = $post_id;
     $post_id = explode("-", $post_id);
     if ($post_id[0] != 'new') {
         return $post_id;
     }
     if (count($post_id) > 2) {
         array_shift($post_id);
         $post_id[1] = implode("-", $post_id);
     }
     foreach ($_POST['fields'] as $key => $value) {
         $currentacf = $key;
         // Get fields and make their shortcodes
         if (is_plugin_active('acf-front-end-form-premium/acf-frontend-form-premium.php')) {
             $t = get_field_object($key);
             add_shortcode('acffef', array($this, 'generate_scodes'));
             $this->val[$t['name']] = $value;
         }
     }
     $sql_query = "\n\t\t\tSELECT {$wpdb->postmeta}.post_id\n\t\t\tFROM {$wpdb->postmeta}\n\t\t\tWHERE {$wpdb->postmeta}.meta_key = '{$currentacf}'\n\t\t";
     $results = $wpdb->get_results($sql_query, ARRAY_A);
     $this->acfdisplay = $results[0]["post_id"];
     $subject = get_option("acffef/subject");
     // Get fields shortcode and use that in title
     if (is_plugin_active('acf-front-end-form-premium/acf-frontend-form-premium.php')) {
         $subject = stripslashes_deep($subject);
         if (strpos($subject, 'field_name') !== false) {
             $subject = do_shortcode($subject);
         }
     }
     $post = array('post_status' => 'publish', 'post_title' => $subject, 'post_type' => $post_id[1]);
     $post_type = $post_id[1];
     $post_id = wp_insert_post($post);
     $_POST['return'] = add_query_arg(array('post_id' => $post_id, '?' => '#message'), $_POST['return']);
     do_action('notifyACFFE');
     /*
      * Integration with Project Manager 
      */
     if (get_option("acffef/cpmintegrate") == 1) {
         $quickQuery = $wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_name = %s AND post_type = project', sanitize_title_with_dashes($post_type));
         $projectID = $wpdb->get_var($quickQuery);
         $cpmController = new CPM_Project();
         $_POST['project_name'] = ucwords($post_type);
         $_POST['project_description'] = "Automatically created by Front End Form Extension for ACF";
         if (empty($projectID)) {
             $projectID = $cpmController->create();
         }
         $cpmController = new CPM_Task();
         $_POST['tasklist_name'] = "Support Requests";
         $_POST['tasklist_detail'] = "Automatically created by Front End Form Extension for ACF";
         $cpmController->add_list($projectID);
     }
     return $post_id;
 }