Contact Form Submissions - Version 1.5.8

Version Description

  • Disabled saving mail2 by default. Overridable with filter wpcf7s_save_submission_mail2.
  • Fixed issue where attachments were not being saved.
Download this release

Release Info

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

Code changes from version 1.5.7 to 1.5.8

Files changed (3) hide show
  1. Submissions.php +125 -123
  2. contact-form-submissions.php +1 -1
  3. readme.txt +7 -1
Submissions.php CHANGED
@@ -5,7 +5,7 @@ class WPCF7Submissions
5
  {
6
  add_action('init', array($this, 'post_type'));
7
 
8
- add_action('wpcf7_submit', array($this, 'submission'), 999, 2);
9
  add_filter('wpcf7_posted_data', array($this, 'posted'), 999, 3);
10
  }
11
 
@@ -72,132 +72,134 @@ class WPCF7Submissions
72
  *
73
  * @return [type] [description]
74
  */
75
- public function submission($contact_form, $result)
76
- {
77
- global $wpcf7s_post_id, $wpcf7s_posted_data;
78
-
79
- if (!empty($wpcf7s_posted_data)) {
80
- foreach ($wpcf7s_posted_data as $name => $value) {
81
- if (!empty($value) && '_wpcf7' !== substr($name, 0, 6)) {
82
- // skip empty arrays
83
- if(is_array($value) && !array_filter($value)){
84
- continue;
85
- }
86
-
87
- $fields[$name] = $value;
88
- }
89
- }
90
- }
91
-
92
- $contact_form_id = 0;
93
- if (method_exists($contact_form, 'id')) {
94
- $contact_form_id = $contact_form->id();
95
- } elseif (property_exists($contact_form, 'id')) {
96
- $contact_form_id = $contact_form->id;
97
- }
98
-
99
- // get the cf7 form template
100
- $mail = $contact_form->prop( 'mail' );
101
- // replace cf7 shortcodes with posted data
102
- $mail = wpcf7_mail_replace_tags( $mail, array( 'html' => true ) );
103
-
104
- $body = $mail['body'];
105
- $sender = wpcf7_strip_newline($mail['sender']);
106
- $recipient = wpcf7_strip_newline($mail['recipient']);
107
- $subject = wpcf7_strip_newline($mail['subject']);
108
- $headers = trim($mail['additional_headers']);
109
-
110
- // get the form file attachements
111
- if ( $submission = WPCF7_Submission::get_instance() ) {
112
- $attachments = $submission->uploaded_files();
113
- }
114
-
115
- $submission = array(
116
- 'form_id' => $contact_form_id,
117
- 'body' => $body,
118
- 'sender' => $sender,
119
- 'subject' => $subject,
120
- 'recipient' => $recipient,
121
- 'additional_headers' => $headers,
122
- 'attachments' => $attachments,
123
- 'fields' => $fields
124
- );
125
-
126
- if (!empty($wpcf7s_post_id)) {
127
- $submission['parent'] = $wpcf7s_post_id;
128
- }
129
-
130
- // store the form submission
131
- $post_id = $this->save($submission);
132
-
133
- if (empty($wpcf7s_post_id)) {
134
- $wpcf7s_post_id = $post_id;
135
- }
136
- }
 
 
137
 
138
  /**
139
  * Save the form submission into the db
140
  */
141
- private function save($submission = array())
142
- {
143
- if(true === apply_filters('wpcf7s_save_submission', true, $submission['form_id']))
144
- {
145
- $post = array(
146
- 'post_title' => ' ',
147
- 'post_content' => $submission['body'],
148
- 'post_status' => 'publish',
149
- 'post_type' => 'wpcf7s',
150
- );
151
-
152
- if (isset($submission['parent'])) {
153
- $post['post_parent'] = $submission['parent'];
154
- }
155
-
156
- $post_id = wp_insert_post($post);
157
-
158
- // check the post was created
159
- if(!empty($post_id) && !is_wp_error($post_id)){
160
-
161
- add_post_meta($post_id, 'form_id', $submission['form_id']);
162
- add_post_meta($post_id, 'subject', $submission['subject']);
163
- add_post_meta($post_id, 'sender', $submission['sender']);
164
- add_post_meta($post_id, 'recipient', $submission['recipient']);
165
- add_post_meta($post_id, 'additional_headers', $submission['additional_headers']);
166
-
167
- $additional_fields = apply_filters('wpcf7s_submission_fields', $submission['fields'], $submission['form_id']);
168
- if (!empty($additional_fields)) {
169
- foreach ($additional_fields as $name => $value) {
170
- if (!empty($value)) {
171
- add_post_meta($post_id, 'wpcf7s_posted-' . $name, $value);
172
- }
173
- }
174
- }
175
-
176
- $attachments = $submission['attachments'];
177
- if (!empty($attachments)) {
178
-
179
- $wpcf7s_dir = $this->get_wpcf7s_dir();
180
- // add a sub directory of the submission post id
181
- $wpcf7s_dir .= '/' . $post_id;
182
-
183
- mkdir($wpcf7s_dir, 0755, true);
184
-
185
- foreach ($attachments as $name => $file_path) {
186
- if (!empty($file_path)) {
187
- // get the file name
188
- $file_name = basename($file_path);
189
-
190
- copy($file_path, $wpcf7s_dir . '/' . $file_name);
191
-
192
- add_post_meta($post_id, 'wpcf7s_file-' . $name, $file_name, false);
193
- }
194
- }
195
- }
196
- }
197
-
198
- return $post_id;
199
- }
200
- }
201
 
202
  /**
203
  * Get the path of where uploads go
5
  {
6
  add_action('init', array($this, 'post_type'));
7
 
8
+ add_action('wpcf7_mail_components', array($this, 'submission'), 999, 2);
9
  add_filter('wpcf7_posted_data', array($this, 'posted'), 999, 3);
10
  }
11
 
72
  *
73
  * @return [type] [description]
74
  */
75
+ public function submission($components, $contact_form)
76
+ {
77
+ global $wpcf7s_post_id, $wpcf7s_posted_data;
78
+
79
+ $contact_form_id = 0;
80
+ if (method_exists($contact_form, 'id')) {
81
+ $contact_form_id = $contact_form->id();
82
+ } elseif (property_exists($contact_form, 'id')) {
83
+ $contact_form_id = $contact_form->id;
84
+ }
85
+
86
+ // don't save mail2 autoresponders by default
87
+ if (!empty($wpcf7s_post_id) && false === apply_filters('wpcf7s_save_submission_mail2', false, $contact_form_id)) {
88
+ return;
89
+ }
90
+
91
+ if (!empty($wpcf7s_posted_data)) {
92
+ foreach ($wpcf7s_posted_data as $name => $value) {
93
+ if ('_wpcf7' !== substr($name, 0, 6)) {
94
+ // skip empty arrays
95
+ if(is_array($value) && !array_filter($value)){
96
+ continue;
97
+ }
98
+
99
+ $fields[$name] = $value;
100
+ }
101
+ }
102
+ }
103
+
104
+ $body = $components['body'];
105
+ $sender = wpcf7_strip_newline($components['sender']);
106
+ $recipient = wpcf7_strip_newline($components['recipient']);
107
+ $subject = wpcf7_strip_newline($components['subject']);
108
+ $headers = trim($components['additional_headers']);
109
+
110
+ // get the form file attachements
111
+ if ( $submission = WPCF7_Submission::get_instance() ) {
112
+ $attachments = $submission->uploaded_files();
113
+ }
114
+
115
+ $submission = array(
116
+ 'form_id' => $contact_form_id,
117
+ 'body' => $body,
118
+ 'sender' => $sender,
119
+ 'subject' => $subject,
120
+ 'recipient' => $recipient,
121
+ 'additional_headers' => $headers,
122
+ 'attachments' => $attachments,
123
+ 'fields' => $fields
124
+ );
125
+
126
+ if (!empty($wpcf7s_post_id)) {
127
+ $submission['parent'] = $wpcf7s_post_id;
128
+ }
129
+
130
+ // store the form submission
131
+ $post_id = $this->save($submission);
132
+
133
+ if (empty($wpcf7s_post_id)) {
134
+ $wpcf7s_post_id = $post_id;
135
+ }
136
+
137
+ return $components;
138
+ }
139
 
140
  /**
141
  * Save the form submission into the db
142
  */
143
+ private function save($submission = array())
144
+ {
145
+ if(true === apply_filters('wpcf7s_save_submission', true, $submission['form_id']))
146
+ {
147
+ $post = array(
148
+ 'post_title' => ' ',
149
+ 'post_content' => $submission['body'],
150
+ 'post_status' => 'publish',
151
+ 'post_type' => 'wpcf7s',
152
+ );
153
+
154
+ if (isset($submission['parent'])) {
155
+ $post['post_parent'] = $submission['parent'];
156
+ }
157
+
158
+ $post_id = wp_insert_post($post);
159
+
160
+ // check the post was created
161
+ if(!empty($post_id) && !is_wp_error($post_id)){
162
+
163
+ add_post_meta($post_id, 'form_id', $submission['form_id']);
164
+ add_post_meta($post_id, 'subject', $submission['subject']);
165
+ add_post_meta($post_id, 'sender', $submission['sender']);
166
+ add_post_meta($post_id, 'recipient', $submission['recipient']);
167
+ add_post_meta($post_id, 'additional_headers', $submission['additional_headers']);
168
+
169
+ $additional_fields = apply_filters('wpcf7s_submission_fields', $submission['fields'], $submission['form_id']);
170
+ if (!empty($additional_fields)) {
171
+ foreach ($additional_fields as $name => $value) {
172
+ if (!empty($value)) {
173
+ add_post_meta($post_id, 'wpcf7s_posted-' . $name, $value);
174
+ }
175
+ }
176
+ }
177
+
178
+ $attachments = $submission['attachments'];
179
+ if (!empty($attachments)) {
180
+
181
+ $wpcf7s_dir = $this->get_wpcf7s_dir();
182
+ // add a sub directory of the submission post id
183
+ $wpcf7s_dir .= '/' . $post_id;
184
+
185
+ mkdir($wpcf7s_dir, 0755, true);
186
+
187
+ foreach ($attachments as $name => $file_path) {
188
+ if (!empty($file_path)) {
189
+ // get the file name
190
+ $file_name = basename($file_path);
191
+
192
+ $copied = copy($file_path, $wpcf7s_dir . '/' . $file_name);
193
+
194
+ add_post_meta($post_id, 'wpcf7s_file-' . $name, $file_name, false);
195
+ }
196
+ }
197
+ }
198
+ }
199
+
200
+ return $post_id;
201
+ }
202
+ }
203
 
204
  /**
205
  * Get the path of where uploads go
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.7
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.8
6
  Author: Jason Green
7
  License: GPLv3
8
  Domain Path: /languages
readme.txt CHANGED
@@ -4,7 +4,7 @@ Tags: contact form 7, save contact form, submissions, contact form db, cf7, wpcf
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.1
7
- Stable tag: 1.5.7
8
  License: GPLv3
9
 
10
  Never miss an enquiry again! Save & Export your Contact Form 7 submissions.
@@ -19,6 +19,8 @@ Files are stored in the /wp-content/uploads directory and can be previewed or do
19
 
20
  All submissions can be exported in CSV format using the export button.
21
 
 
 
22
  This plugin has been made with no ads or donation links so you can use this on all your sites.
23
 
24
  == Installation ==
@@ -40,6 +42,10 @@ None yet
40
 
41
  == Changelog ==
42
 
 
 
 
 
43
  = 1.5.7 =
44
  * Fixed an issue where some admins were not able to export submissions.
45
  * Now saves submissions when demo mode is enabled.
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.1
7
+ Stable tag: 1.5.8
8
  License: GPLv3
9
 
10
  Never miss an enquiry again! Save & Export your Contact Form 7 submissions.
19
 
20
  All submissions can be exported in CSV format using the export button.
21
 
22
+ Please note this plugin will not work with demo mode enabled.
23
+
24
  This plugin has been made with no ads or donation links so you can use this on all your sites.
25
 
26
  == Installation ==
42
 
43
  == Changelog ==
44
 
45
+ = 1.5.8 =
46
+ * Disabled saving mail2 by default. Overridable with filter wpcf7s_save_submission_mail2.
47
+ * Fixed issue where attachments were not being saved.
48
+
49
  = 1.5.7 =
50
  * Fixed an issue where some admins were not able to export submissions.
51
  * Now saves submissions when demo mode is enabled.