Contact Form Submissions - Version 1.5.6

Version Description

  • Export bug fixes and added code filters
Download this release

Release Info

Developer jasongreen
Plugin Icon 128x128 Contact Form Submissions
Version 1.5.6
Comparing to
See all releases

Code changes from version 1.5.5 to 1.5.6

Files changed (4) hide show
  1. Admin.php +36 -20
  2. Submissions.php +41 -38
  3. contact-form-submissions.php +3 -2
  4. readme.txt +5 -2
Admin.php CHANGED
@@ -365,6 +365,8 @@ class WPCF7SAdmin
365
  }))
366
  );
367
 
 
 
368
  return $posted;
369
  }
370
 
@@ -388,6 +390,8 @@ class WPCF7SAdmin
388
  );
389
  }
390
 
 
 
391
  return $posted;
392
  }
393
 
@@ -447,24 +451,12 @@ class WPCF7SAdmin
447
  global $wp_query;
448
  $args = array_merge( $wp_query->query_vars, array('posts_per_page' => '-1', 'fields' => 'ids'));
449
  $submissions = get_posts($args);
450
-
451
- // get input columns
452
- $columns_field = array_map(function ($column_name){
453
- return str_replace('wpcf7s_posted-','',$column_name);
454
- }, array_keys($this->get_mail_posted_fields($submissions[0] )) );
455
-
456
- // get file columns
457
- $files_field = array_map(function ($column_name){
458
- return str_replace('wpcf7s_file-','',$column_name);
459
- }, array_keys($this->get_mail_files($submissions[0] )) );
460
-
461
- // merge input and file columns
462
- $columns = array_merge( array("id", "submission_date", "form_name"), $columns_field, $files_field );
463
-
464
- // put on first line columns name
465
- fputcsv($output,$columns);
466
  foreach($submissions as $post_id) {
 
467
  $values = $this->get_mail_posted_fields($post_id);
 
468
  foreach($values as $key => $value) {
469
  // Fix serialize field (select/radio inputs)
470
  $value = is_serialized($value) ? implode(', ', unserialize($value)) : $value;
@@ -475,7 +467,12 @@ class WPCF7SAdmin
475
  }
476
  }
477
  }
478
- $values[$key] = implode(',', $value);
 
 
 
 
 
479
  }
480
 
481
  // add file attachments
@@ -491,12 +488,31 @@ class WPCF7SAdmin
491
  $files[] = "$upload_dir/wpcf7-submissions/$post_id/$singleFile";
492
  }
493
  }
494
- $values[$keyFile] = implode(',', $files);
 
 
 
 
 
495
  }
496
  }
 
497
  $contact_form_id = get_post_meta($post_id, 'form_id', true);
498
- $submission_row = array_merge(array($post_id, get_the_date('Y-m-d H:i:s', $post_id), get_the_title($contact_form_id)), $values);
499
- fputcsv($output, $submission_row);
 
 
 
 
 
 
 
 
 
 
 
 
 
500
  }
501
 
502
  die;
365
  }))
366
  );
367
 
368
+ $posted = apply_filters('wpcf7s_posted_values', $posted);
369
+
370
  return $posted;
371
  }
372
 
390
  );
391
  }
392
 
393
+ $posted = apply_filters('wpcf7s_posted_files', $posted);
394
+
395
  return $posted;
396
  }
397
 
451
  global $wp_query;
452
  $args = array_merge( $wp_query->query_vars, array('posts_per_page' => '-1', 'fields' => 'ids'));
453
  $submissions = get_posts($args);
454
+ $csv_rows = array();
455
+ $columns = array();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
456
  foreach($submissions as $post_id) {
457
+
458
  $values = $this->get_mail_posted_fields($post_id);
459
+
460
  foreach($values as $key => $value) {
461
  // Fix serialize field (select/radio inputs)
462
  $value = is_serialized($value) ? implode(', ', unserialize($value)) : $value;
467
  }
468
  }
469
  }
470
+ $values[$key] = mb_convert_encoding(implode(',', $value), 'UTF-16LE');
471
+
472
+ // if we havent already stored this column, save it now
473
+ if(!in_array($key, $columns)){
474
+ $columns[] = $key;
475
+ }
476
  }
477
 
478
  // add file attachments
488
  $files[] = "$upload_dir/wpcf7-submissions/$post_id/$singleFile";
489
  }
490
  }
491
+ $values[$keyFile] = mb_convert_encoding(implode(',', $files), 'UTF-16LE');
492
+
493
+ // if we havent already stored this column, save it now
494
+ if(!in_array($keyFile, $columns)){
495
+ $columns[] = $keyFile;
496
+ }
497
  }
498
  }
499
+
500
  $contact_form_id = get_post_meta($post_id, 'form_id', true);
501
+ $csv_rows[] = array_merge(array('id'=> $post_id, 'submission_date'=> get_the_date('Y-m-d H:i:s', $post_id), 'form_name' => get_the_title($contact_form_id)), $values);
502
+ }
503
+ // add default columns
504
+ $pretty_columns = $columns = array_merge( array("id", "submission_date", "form_name"), $columns);
505
+ foreach($pretty_columns as $key => $column) {
506
+ // remove the plugin's prepended keys
507
+ $pretty_columns[$key] = str_replace(array('wpcf7s_posted-', 'wpcf7s_file-'), '', $column);
508
+ }
509
+ fputcsv($output,$pretty_columns);
510
+
511
+ foreach($csv_rows as $key => $row){
512
+ foreach($columns as $column){
513
+ $row_values[$column] = $row[$column];
514
+ }
515
+ fputcsv($output,$row_values);
516
  }
517
 
518
  die;
Submissions.php CHANGED
@@ -132,60 +132,63 @@ class WPCF7Submissions
132
  */
133
  private function save($submission = array())
134
  {
135
- $post = array(
136
- 'post_title' => ' ',
137
- 'post_content' => $submission['body'],
138
- 'post_status' => 'publish',
139
- 'post_type' => 'wpcf7s',
140
- );
141
-
142
- if (isset($submission['parent'])) {
143
- $post['post_parent'] = $submission['parent'];
144
- }
 
 
145
 
146
- $post_id = wp_insert_post($post);
147
 
148
- // check the post was created
149
- if(!empty($post_id) && !is_wp_error($post_id)){
150
 
151
- add_post_meta($post_id, 'form_id', $submission['form_id']);
152
- add_post_meta($post_id, 'subject', $submission['subject']);
153
- add_post_meta($post_id, 'sender', $submission['sender']);
154
- add_post_meta($post_id, 'recipient', $submission['recipient']);
155
- add_post_meta($post_id, 'additional_headers', $submission['additional_headers']);
156
 
157
- $additional_fields = $submission['fields'];
158
- if (!empty($additional_fields)) {
159
- foreach ($additional_fields as $name => $value) {
160
- if (!empty($value)) {
161
- add_post_meta($post_id, 'wpcf7s_posted-' . $name, $value);
 
162
  }
163
  }
164
- }
165
 
166
- $attachments = $submission['attachments'];
167
- if (!empty($attachments)) {
168
 
169
- $wpcf7s_dir = $this->get_wpcf7s_dir();
170
- // add a sub directory of the submission post id
171
- $wpcf7s_dir .= '/' . $post_id;
172
 
173
- mkdir($wpcf7s_dir, 0755, true);
174
 
175
- foreach ($attachments as $name => $file_path) {
176
- if (!empty($file_path)) {
177
- // get the file name
178
- $file_name = basename($file_path);
179
 
180
- $copied = copy($file_path, $wpcf7s_dir . '/' . $file_name);
181
 
182
- add_post_meta($post_id, 'wpcf7s_file-' . $name, $file_name, false);
 
183
  }
184
  }
185
  }
186
- }
187
 
188
- return $post_id;
 
189
  }
190
 
191
  /**
132
  */
133
  private function save($submission = array())
134
  {
135
+ if(true === apply_filters('wpcf7s_save_submission', true, $submission['form_id']))
136
+ {
137
+ $post = array(
138
+ 'post_title' => ' ',
139
+ 'post_content' => $submission['body'],
140
+ 'post_status' => 'publish',
141
+ 'post_type' => 'wpcf7s',
142
+ );
143
+
144
+ if (isset($submission['parent'])) {
145
+ $post['post_parent'] = $submission['parent'];
146
+ }
147
 
148
+ $post_id = wp_insert_post($post);
149
 
150
+ // check the post was created
151
+ if(!empty($post_id) && !is_wp_error($post_id)){
152
 
153
+ add_post_meta($post_id, 'form_id', $submission['form_id']);
154
+ add_post_meta($post_id, 'subject', $submission['subject']);
155
+ add_post_meta($post_id, 'sender', $submission['sender']);
156
+ add_post_meta($post_id, 'recipient', $submission['recipient']);
157
+ add_post_meta($post_id, 'additional_headers', $submission['additional_headers']);
158
 
159
+ $additional_fields = apply_filters('wpcf7s_submission_fields', $submission['fields'], $submission['form_id']);
160
+ if (!empty($additional_fields)) {
161
+ foreach ($additional_fields as $name => $value) {
162
+ if (!empty($value)) {
163
+ add_post_meta($post_id, 'wpcf7s_posted-' . $name, $value);
164
+ }
165
  }
166
  }
 
167
 
168
+ $attachments = $submission['attachments'];
169
+ if (!empty($attachments)) {
170
 
171
+ $wpcf7s_dir = $this->get_wpcf7s_dir();
172
+ // add a sub directory of the submission post id
173
+ $wpcf7s_dir .= '/' . $post_id;
174
 
175
+ mkdir($wpcf7s_dir, 0755, true);
176
 
177
+ foreach ($attachments as $name => $file_path) {
178
+ if (!empty($file_path)) {
179
+ // get the file name
180
+ $file_name = basename($file_path);
181
 
182
+ $copied = copy($file_path, $wpcf7s_dir . '/' . $file_name);
183
 
184
+ add_post_meta($post_id, 'wpcf7s_file-' . $name, $file_name, false);
185
+ }
186
  }
187
  }
188
  }
 
189
 
190
+ return $post_id;
191
+ }
192
  }
193
 
194
  /**
contact-form-submissions.php CHANGED
@@ -2,7 +2,7 @@
2
  /*
3
  Plugin Name: Contact Form Submissions
4
  Description: Never miss an enquiry again! Save all Contact Form 7 submissions in your database.
5
- Version: 1.5.5
6
  Author: Jason Green
7
  License: GPLv3
8
  Domain Path: /languages
@@ -40,6 +40,7 @@ add_action('admin_init', 'contact_form_submissions_admin_init');
40
  */
41
  function contact_form_submissions_textdomain()
42
  {
43
- load_plugin_textdomain('contact-form-submissions', false, WPCF7S_DIR . '/languages/');
 
44
  }
45
  add_action('plugins_loaded', 'contact_form_submissions_textdomain');
2
  /*
3
  Plugin Name: Contact Form Submissions
4
  Description: Never miss an enquiry again! Save all Contact Form 7 submissions in your database.
5
+ Version: 1.5.6
6
  Author: Jason Green
7
  License: GPLv3
8
  Domain Path: /languages
40
  */
41
  function contact_form_submissions_textdomain()
42
  {
43
+ load_plugin_textdomain('contact-form-submissions', false, basename( dirname( __FILE__ ) ) . '/languages/');
44
+
45
  }
46
  add_action('plugins_loaded', 'contact_form_submissions_textdomain');
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: jasongreen
3
  Tags: contact form 7, save contact form, submissions, contact form db, cf7, wpcf7, contact form storage, contact form seven, contact form 7 db, export contact form
4
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=SNHXWSXSPYATE
5
  Requires at least: 3.0.1
6
- Tested up to: 4.7.4
7
- Stable tag: 1.5.5
8
  License: GPLv3
9
 
10
  Never miss an enquiry again! Save & Export your Contact Form 7 submissions.
@@ -40,6 +40,9 @@ None yet
40
 
41
  == Changelog ==
42
 
 
 
 
43
  = 1.5.5 =
44
  * Minor bug fix
45
 
3
  Tags: contact form 7, save contact form, submissions, contact form db, cf7, wpcf7, contact form storage, contact form seven, contact form 7 db, export contact form
4
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=SNHXWSXSPYATE
5
  Requires at least: 3.0.1
6
+ Tested up to: 4.8.0
7
+ Stable tag: 1.5.6
8
  License: GPLv3
9
 
10
  Never miss an enquiry again! Save & Export your Contact Form 7 submissions.
40
 
41
  == Changelog ==
42
 
43
+ = 1.5.6 =
44
+ * Export bug fixes and added code filters
45
+
46
  = 1.5.5 =
47
  * Minor bug fix
48