public function step()
 {
     if (!is_numeric($this->args['form_id'])) {
         wp_die(__('Invalid form id', 'ninja-forms'));
     }
     $this->args['filename'] = wp_kses_post($this->args['filename']);
     $exported_subs = get_user_option(get_current_user_id(), 'nf_download_all_subs_ids');
     if (!is_array($exported_subs)) {
         $exported_subs = array();
     }
     $previous_name = get_user_option(get_current_user_id(), 'nf_download_all_subs_filename');
     if ($previous_name) {
         $this->args['filename'] = $previous_name;
     }
     $args = array('posts_per_page' => 250, 'paged' => $this->step, 'post_type' => 'nf_sub', 'meta_query' => array(array('key' => '_form_id', 'value' => $this->args['form_id'])));
     $subs_results = get_posts($args);
     if (is_array($subs_results) && !empty($subs_results)) {
         $upload_dir = wp_upload_dir();
         $file_path = trailingslashit($upload_dir['path']) . $this->args['filename'] . '.csv';
         $myfile = fopen($file_path, 'a') or die('Unable to open file!');
         $x = 0;
         $export = '';
         foreach ($subs_results as $sub) {
             $sub_export = NF_Database_Models_Submission::export($this->args['form_id'], array($sub->ID), TRUE);
             if ($x > 0 || $this->step > 1) {
                 $sub_export = substr($sub_export, strpos($sub_export, "\n") + 1);
             }
             if (!in_array($sub->ID, $exported_subs)) {
                 $export .= $sub_export;
                 $exported_subs[] = $sub->ID;
             }
             $x++;
         }
         fwrite($myfile, $export);
         fclose($myfile);
     }
     update_user_option(get_current_user_id(), 'nf_download_all_subs_ids', $exported_subs);
 }
Ejemplo n.º 2
0
 /**
  * Export Submissions
  *
  * A wrapper for the Submission Model export method.
  *
  * @param array $sub_ids
  * @param bool|FALSE $return
  * @return string
  */
 public function export_subs(array $sub_ids = array(), $return = FALSE)
 {
     $form_id = $this->_object->get_id();
     return NF_Database_Models_Submission::export($form_id, $sub_ids, $return);
 }