Contact Form Submissions - Version 1.5.4

Version Description

  • Minor bug fixes.
  • Credit to @fabriziopera for his contribution.
Download this release

Release Info

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

Code changes from version 1.5.2 to 1.5.4

Files changed (3) hide show
  1. Admin.php +53 -8
  2. contact-form-submissions.php +1 -1
  3. readme.txt +9 -2
Admin.php CHANGED
@@ -355,6 +355,7 @@ class WPCF7SAdmin
355
  */
356
  public function get_mail_posted_fields($post_id = 0)
357
  {
 
358
  $post_meta = get_post_meta($post_id);
359
  $posted = array_intersect_key(
360
  $post_meta,
@@ -414,13 +415,16 @@ class WPCF7SAdmin
414
  */
415
  public function extra_tablenav($which = '')
416
  {
417
- $capability = apply_filters('wpcf7s_export_capatability','export');
418
- if($capability){
419
- ?>
420
- <div class="alignleft actions wpcf7s-export">
421
- <button type="submit" name="wpcf7s-export" value="1" class="button-primary" title="<?php _e('Export the current set of results as CSV', 'contact-form-submissions'); ?>"><?php _e('Export to CSV', 'contact-form-submissions'); ?></button>
422
- </div>
423
- <?php
 
 
 
424
  }
425
  }
426
 
@@ -433,7 +437,7 @@ class WPCF7SAdmin
433
 
434
  // output headers so that the file is downloaded rather than displayed
435
  header('Content-Type: text/csv; charset=utf-8');
436
- header('Content-Disposition: attachment; filename=data.csv');
437
 
438
  // create a file pointer connected to the output stream
439
  $output = fopen('php://output', 'w');
@@ -443,11 +447,52 @@ class WPCF7SAdmin
443
  $args = array_merge( $wp_query->query_vars, array('posts_per_page' => '-1', 'fields' => 'ids'));
444
  $submissions = get_posts($args);
445
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
446
  foreach($submissions as $post_id) {
447
  $values = $this->get_mail_posted_fields($post_id);
448
  foreach($values as $key => $value) {
 
 
 
 
 
 
 
 
 
449
  $values[$key] = implode(',', $value);
450
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
451
  $contact_form_id = get_post_meta($post_id, 'form_id', true);
452
  $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);
453
  fputcsv($output, $submission_row);
355
  */
356
  public function get_mail_posted_fields($post_id = 0)
357
  {
358
+ $posted = array();
359
  $post_meta = get_post_meta($post_id);
360
  $posted = array_intersect_key(
361
  $post_meta,
415
  */
416
  public function extra_tablenav($which = '')
417
  {
418
+ $screen = get_current_screen();
419
+ if ('wpcf7s' === $screen->post_type){
420
+ $capability = apply_filters('wpcf7s_export_capatability','export');
421
+ if($capability){
422
+ ?>
423
+ <div class="alignleft actions wpcf7s-export">
424
+ <button type="submit" name="wpcf7s-export" value="1" class="button-primary" title="<?php _e('Export the current set of results as CSV', 'contact-form-submissions'); ?>"><?php _e('Export to CSV', 'contact-form-submissions'); ?></button>
425
+ </div>
426
+ <?php
427
+ }
428
  }
429
  }
430
 
437
 
438
  // output headers so that the file is downloaded rather than displayed
439
  header('Content-Type: text/csv; charset=utf-8');
440
+ header('Content-Disposition: attachment; filename=contact-form-submissions.csv');
441
 
442
  // create a file pointer connected to the output stream
443
  $output = fopen('php://output', 'w');
447
  $args = array_merge( $wp_query->query_vars, array('posts_per_page' => '-1', 'fields' => 'ids'));
448
  $submissions = get_posts($args);
449
 
450
+ // get input columns
451
+ $columns_field = array_map(function ($column_name){
452
+ return str_replace('wpcf7s_posted-','',$column_name);
453
+ }, array_keys($this->get_mail_posted_fields($submissions[0] )) );
454
+
455
+ // get file columns
456
+ $files_field = array_map(function ($column_name){
457
+ return str_replace('wpcf7s_file-','',$column_name);
458
+ }, array_keys($this->get_mail_files($submissions[0] )) );
459
+
460
+ // merge input and file columns
461
+ $columns = array_merge( array("id", "submission_date", "form_name"), $columns_field, $files_field );
462
+
463
+ // put on first line columns name
464
+ fputcsv($output,$columns);
465
  foreach($submissions as $post_id) {
466
  $values = $this->get_mail_posted_fields($post_id);
467
  foreach($values as $key => $value) {
468
+ // Fix serialize field (select/radio inputs)
469
+ $value = is_serialized($value) ? implode(', ', unserialize($value)) : $value;
470
+ if(!empty($value)){
471
+ foreach ($value as &$single){
472
+ if(is_serialized($single)){
473
+ $single=implode(', ', unserialize($single));
474
+ }
475
+ }
476
+ }
477
  $values[$key] = implode(',', $value);
478
  }
479
+
480
+ // add file attachments
481
+ $files=array();
482
+ $files_key =$this->get_mail_files($post_id);
483
+ $upload_dir = wp_upload_dir();
484
+ $upload_dir = $upload_dir['baseurl'];
485
+ if(!empty($files_key)){
486
+ foreach($files_key as $keyFile => $valueFile) {
487
+ $files=array();
488
+ if(!empty($valueFile)){
489
+ foreach ($valueFile as $singleFile){
490
+ $files[] = "$upload_dir/wpcf7-submissions/$post_id/$singleFile";
491
+ }
492
+ }
493
+ $values[$keyFile] = implode(',', $files);
494
+ }
495
+ }
496
  $contact_form_id = get_post_meta($post_id, 'form_id', true);
497
  $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);
498
  fputcsv($output, $submission_row);
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.2
6
  Author: Jason Green
7
  License: GPLv3
8
  Domain Path: /languages
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.4
6
  Author: Jason Green
7
  License: GPLv3
8
  Domain Path: /languages
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.3
7
- Stable tag: 1.5.2
8
  License: GPLv3
9
 
10
  Never miss an enquiry again! Save & Export your Contact Form 7 submissions.
@@ -40,6 +40,13 @@ None yet
40
 
41
  == Changelog ==
42
 
 
 
 
 
 
 
 
43
  = 1.5.2 =
44
  * Minor bug fixes
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.7.4
7
+ Stable tag: 1.5.4
8
  License: GPLv3
9
 
10
  Never miss an enquiry again! Save & Export your Contact Form 7 submissions.
40
 
41
  == Changelog ==
42
 
43
+ = 1.5.4 =
44
+ * Minor bug fixes.
45
+ * Credit to @fabriziopera for his contribution.
46
+
47
+ = 1.5.3 =
48
+ * Minor bug fixes
49
+
50
  = 1.5.2 =
51
  * Minor bug fixes
52