Version Description
- Added support for files
Download this release
Release Info
Developer | jasongreen |
Plugin | Contact Form Submissions |
Version | 1.5 |
Comparing to | |
See all releases |
Code changes from version 1.4.1 to 1.5
- Admin.php +212 -71
- Submissions.php +121 -44
- contact-form-submissions.php +24 -12
- readme.txt +7 -2
Admin.php
CHANGED
@@ -1,47 +1,60 @@
|
|
1 |
<?php
|
2 |
-
class WPCF7SAdmin
|
3 |
-
|
4 |
-
function __construct()
|
5 |
-
|
6 |
-
|
7 |
-
add_action('
|
|
|
8 |
|
9 |
-
add_action('add_meta_boxes', array($this, 'meta_boxes'), 25
|
10 |
|
11 |
-
add_action('pre_get_posts', array($this, 'admin_posts')
|
12 |
-
add_action('pre_get_posts', array($this, 'set_post_order')
|
13 |
|
14 |
-
add_filter('page_row_actions',array($this, 'action_row'), 25, 2);
|
15 |
-
add_action('admin_enqueue_scripts', array($this, 'scripts')
|
16 |
|
17 |
add_filter('views_edit-wpcf7s', array($this, 'views'), 999);
|
18 |
|
19 |
add_filter('gettext', array($this, 'custom_status'), 20, 3);
|
20 |
}
|
21 |
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
24 |
$translations = __('Submitted', 'contact-form-submissions');
|
25 |
}
|
26 |
return $translations;
|
27 |
}
|
28 |
|
29 |
-
|
|
|
|
|
|
|
|
|
30 |
global $pagenow, $post_type;
|
31 |
if ('wpcf7s' === $post_type && is_admin() && 'edit.php' == $pagenow && !isset($_GET['orderby'])) {
|
32 |
-
$query->set(
|
33 |
-
$query->set(
|
34 |
}
|
35 |
}
|
36 |
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
|
|
40 |
}
|
41 |
$keep_views = array('all', 'publish', 'trash');
|
42 |
// remove others
|
43 |
-
foreach($views as $key => $view){
|
44 |
-
if(!in_array($key, $keep_views)){
|
45 |
unset($views[$key]);
|
46 |
}
|
47 |
}
|
@@ -49,51 +62,70 @@ class WPCF7SAdmin {
|
|
49 |
return $views;
|
50 |
}
|
51 |
|
52 |
-
|
|
|
|
|
|
|
|
|
53 |
//execute only on the 'post' content type
|
54 |
global $post_type;
|
55 |
-
if($post_type == 'wpcf7s'){
|
56 |
$args = array(
|
57 |
'post_type' =>'wpcf7_contact_form',
|
58 |
'posts_per_page' => '-1'
|
59 |
);
|
60 |
-
$forms = get_posts($args);
|
61 |
-
?>
|
62 |
<select name="wpcf7_contact_form">
|
63 |
<option value="0"><?php _e('Contact Form', 'contact-form-submissions'); ?></option>
|
64 |
-
<?php foreach($forms as $post){
|
|
|
65 |
<?php $selected = ($post->ID == $_GET['wpcf7_contact_form']) ? 'selected' : ''; ?>
|
66 |
<option value="<?php echo $post->ID; ?>" <?php echo $selected; ?>><?php echo $post->post_title; ?></option>
|
67 |
-
<?php
|
|
|
68 |
</select>
|
69 |
<?php
|
|
|
70 |
}
|
71 |
}
|
72 |
|
73 |
-
|
74 |
-
|
75 |
-
|
|
|
|
|
|
|
|
|
|
|
76 |
}
|
77 |
}
|
78 |
|
79 |
-
|
|
|
|
|
|
|
|
|
80 |
global $post_type;
|
81 |
-
if ('wpcf7s' === $post_type){
|
82 |
// remove defaults
|
83 |
unset($actions['edit']);
|
84 |
unset($actions['inline hide-if-no-js']);
|
85 |
|
86 |
-
$actions = array_merge(array('aview' => '<a href="' . get_edit_post_link(
|
87 |
}
|
88 |
return $actions;
|
89 |
}
|
90 |
|
91 |
-
|
|
|
|
|
|
|
|
|
92 |
global $post_type;
|
93 |
-
if($query->is_admin && 'wpcf7s' === $post_type && $query->is_main_query()){
|
94 |
$form_id = esc_attr($_GET['wpcf7_contact_form']);
|
95 |
-
if(!empty($form_id)){
|
96 |
-
$query->set(
|
97 |
array(
|
98 |
'key' => 'form_id',
|
99 |
'value' => $form_id,
|
@@ -104,19 +136,24 @@ class WPCF7SAdmin {
|
|
104 |
}
|
105 |
}
|
106 |
|
107 |
-
|
|
|
|
|
|
|
|
|
108 |
$columns = array(
|
109 |
'cb' => '<input type="checkbox">',
|
110 |
'submission' => __('Submission', 'contact-form-submissions'),
|
111 |
'form' => __('Contact Form', 'contact-form-submissions')
|
112 |
);
|
113 |
|
114 |
-
if
|
|
|
115 |
$form_id = $_GET['wpcf7_contact_form'];
|
116 |
|
117 |
$wpcf7s_columns = $this->get_available_columns($form_id);
|
118 |
|
119 |
-
foreach($wpcf7s_columns as $meta_key){
|
120 |
$columns[$meta_key] = str_replace('wpcf7s_posted-', '', $meta_key);
|
121 |
}
|
122 |
}
|
@@ -126,20 +163,24 @@ class WPCF7SAdmin {
|
|
126 |
return $columns;
|
127 |
}
|
128 |
|
129 |
-
|
|
|
|
|
|
|
|
|
130 |
$form_id = get_post_meta($post_id, 'form_id', true);
|
131 |
$post_parent = wp_get_post_parent_id($post_id);
|
132 |
$nested = ($post_parent > 0) ? '— ' : '';
|
133 |
|
134 |
-
switch (
|
135 |
|
136 |
-
case 'form'
|
137 |
?><a href="<?php echo add_query_arg(array('page'=>'wpcf7', 'post'=>$form_id, 'action'=>'edit'), admin_url('admin.php')); ?>"><?php echo get_the_title($form_id); ?></a><?php
|
138 |
break;
|
139 |
-
case 'sent'
|
140 |
?><a href="<?php echo add_query_arg(array('page'=>'wpcf7', 'post'=>$form_id, 'action'=>'edit'), admin_url('admin.php')); ?>"><?php echo get_the_title($form_id); ?></a><?php
|
141 |
break;
|
142 |
-
case 'submission'
|
143 |
?>
|
144 |
<strong>
|
145 |
<a class="row-title" href="<?php echo get_edit_post_link($post_id); ?>">
|
@@ -148,28 +189,44 @@ class WPCF7SAdmin {
|
|
148 |
</strong>
|
149 |
<?php
|
150 |
break;
|
151 |
-
default
|
152 |
echo get_post_meta($post_id, $column, true);
|
153 |
break;
|
154 |
}
|
155 |
}
|
156 |
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
162 |
}
|
163 |
|
164 |
-
|
|
|
|
|
|
|
|
|
165 |
$form_id = get_post_meta($post->ID, 'form_id', true);
|
166 |
$sender = get_post_meta($post->ID, 'sender', true);
|
167 |
$sender_mailto = preg_replace('/([a-zA-Z0-9_\-\.]*@\\S+\\.\\w+)/', '<a href="mailto:$1">$1</a>', $sender);
|
168 |
$recipient = get_post_meta($post->ID, 'recipient', true);
|
169 |
$recipient_mailto = preg_replace('/([a-zA-Z0-9_\-\.]*@\\S+\\.\\w+)/', '<a href="mailto:$1">$1</a>', $recipient);
|
170 |
|
171 |
-
$additional_headers = get_post_meta($post->ID, 'additional_headers', true);
|
172 |
-
?>
|
173 |
<table class="form-table contact-form-submission">
|
174 |
<tbody>
|
175 |
<tr>
|
@@ -192,40 +249,85 @@ class WPCF7SAdmin {
|
|
192 |
<th scope="row"><?php _e('Body', 'contact-form-submissions'); ?></th>
|
193 |
<td><?php echo apply_filters('the_content', $post->post_content); ?></td>
|
194 |
</tr>
|
195 |
-
<?php if(!empty($additional_headers)){
|
|
|
196 |
<tr>
|
197 |
<th scope="row"><?php _e('Additional Headers', 'contact-form-submissions'); ?></th>
|
198 |
<td><?php echo get_post_meta($post->ID, 'additional_headers', true); ?></td>
|
199 |
</tr>
|
200 |
-
<?php
|
|
|
201 |
</tbody>
|
202 |
</table>
|
203 |
|
204 |
<?php
|
205 |
-
}
|
206 |
-
|
207 |
-
function posted_meta_box($post){
|
208 |
-
$values = $this->get_mail_posted_fields($post->ID);
|
209 |
|
210 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
211 |
<table class="form-table contact-form-submission">
|
212 |
<tbody>
|
213 |
-
<?php foreach($values as $key => $value){
|
|
|
214 |
<tr>
|
215 |
<th scope="row"><?php _e(str_replace('wpcf7s_posted-', '', $key), 'contact-form-submissions'); ?></th>
|
216 |
<td><?php echo is_serialized($value[0]) ? implode(', ', unserialize($value[0])) : $value[0]; ?></td>
|
217 |
</tr>
|
218 |
-
<?php
|
|
|
219 |
</tbody>
|
220 |
</table>
|
221 |
|
222 |
<?php
|
|
|
223 |
}
|
224 |
|
225 |
-
function
|
226 |
-
|
227 |
-
|
228 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
229 |
<div id="minor-publishing">
|
230 |
|
231 |
<div id="misc-publishing-actions">
|
@@ -236,13 +338,22 @@ class WPCF7SAdmin {
|
|
236 |
<div class="clear"></div>
|
237 |
</div>
|
238 |
<?php
|
|
|
239 |
}
|
240 |
|
241 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
242 |
$post_meta = get_post_meta($post_id);
|
243 |
$posted = array_intersect_key(
|
244 |
$post_meta,
|
245 |
-
array_flip(array_filter(array_keys($post_meta), function($key) {
|
246 |
return preg_match('/^wpcf7s_posted-/', $key);
|
247 |
}))
|
248 |
);
|
@@ -250,7 +361,37 @@ class WPCF7SAdmin {
|
|
250 |
return $posted;
|
251 |
}
|
252 |
|
253 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
254 |
global $wpdb;
|
255 |
|
256 |
$post_id = $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = 'form_id' AND meta_value = $form_id LIMIT 1;");
|
@@ -259,4 +400,4 @@ class WPCF7SAdmin {
|
|
259 |
|
260 |
return $columns;
|
261 |
}
|
262 |
-
}
|
1 |
<?php
|
2 |
+
class WPCF7SAdmin
|
3 |
+
{
|
4 |
+
public function __construct()
|
5 |
+
{
|
6 |
+
add_filter('manage_wpcf7s_posts_columns', array($this, 'set_columns'), 999);
|
7 |
+
add_action('manage_wpcf7s_posts_custom_column', array($this, 'column'), 10, 2);
|
8 |
+
add_action('restrict_manage_posts', array($this, 'filters'));
|
9 |
|
10 |
+
add_action('add_meta_boxes', array($this, 'meta_boxes'), 25);
|
11 |
|
12 |
+
add_action('pre_get_posts', array($this, 'admin_posts'));
|
13 |
+
add_action('pre_get_posts', array($this, 'set_post_order'));
|
14 |
|
15 |
+
add_filter('page_row_actions', array($this, 'action_row'), 25, 2);
|
16 |
+
add_action('admin_enqueue_scripts', array($this, 'scripts'));
|
17 |
|
18 |
add_filter('views_edit-wpcf7s', array($this, 'views'), 999);
|
19 |
|
20 |
add_filter('gettext', array($this, 'custom_status'), 20, 3);
|
21 |
}
|
22 |
|
23 |
+
/**
|
24 |
+
* Replace the default post status
|
25 |
+
*/
|
26 |
+
public function custom_status($translations = '', $text = '', $domain = '')
|
27 |
+
{
|
28 |
+
if ('Published' === $text) {
|
29 |
$translations = __('Submitted', 'contact-form-submissions');
|
30 |
}
|
31 |
return $translations;
|
32 |
}
|
33 |
|
34 |
+
/**
|
35 |
+
* Change the default post sort
|
36 |
+
*/
|
37 |
+
public function set_post_order($query = false)
|
38 |
+
{
|
39 |
global $pagenow, $post_type;
|
40 |
if ('wpcf7s' === $post_type && is_admin() && 'edit.php' == $pagenow && !isset($_GET['orderby'])) {
|
41 |
+
$query->set('orderby', 'date');
|
42 |
+
$query->set('order', 'DESC');
|
43 |
}
|
44 |
}
|
45 |
|
46 |
+
/**
|
47 |
+
* Change the default quick post links
|
48 |
+
*/
|
49 |
+
public function views($views)
|
50 |
+
{
|
51 |
+
if (isset($views['publish'])) {
|
52 |
+
$views['publish'] = str_replace(__('Published', 'contact-form-submissions'), __('Submitted', 'contact-form-submissions'), $views['publish']);
|
53 |
}
|
54 |
$keep_views = array('all', 'publish', 'trash');
|
55 |
// remove others
|
56 |
+
foreach ($views as $key => $view) {
|
57 |
+
if (!in_array($key, $keep_views)) {
|
58 |
unset($views[$key]);
|
59 |
}
|
60 |
}
|
62 |
return $views;
|
63 |
}
|
64 |
|
65 |
+
/**
|
66 |
+
* Add dropdowns to filter the posts
|
67 |
+
*/
|
68 |
+
public function filters()
|
69 |
+
{
|
70 |
//execute only on the 'post' content type
|
71 |
global $post_type;
|
72 |
+
if ($post_type == 'wpcf7s') {
|
73 |
$args = array(
|
74 |
'post_type' =>'wpcf7_contact_form',
|
75 |
'posts_per_page' => '-1'
|
76 |
);
|
77 |
+
$forms = get_posts($args); ?>
|
|
|
78 |
<select name="wpcf7_contact_form">
|
79 |
<option value="0"><?php _e('Contact Form', 'contact-form-submissions'); ?></option>
|
80 |
+
<?php foreach ($forms as $post) {
|
81 |
+
?>
|
82 |
<?php $selected = ($post->ID == $_GET['wpcf7_contact_form']) ? 'selected' : ''; ?>
|
83 |
<option value="<?php echo $post->ID; ?>" <?php echo $selected; ?>><?php echo $post->post_title; ?></option>
|
84 |
+
<?php
|
85 |
+
} ?>
|
86 |
</select>
|
87 |
<?php
|
88 |
+
|
89 |
}
|
90 |
}
|
91 |
|
92 |
+
/**
|
93 |
+
* Enqueue stylesheet
|
94 |
+
*/
|
95 |
+
public function scripts()
|
96 |
+
{
|
97 |
+
// only enqueue if your on the submissions page
|
98 |
+
if ('wpcf7s' === get_post_type()) {
|
99 |
+
wp_enqueue_style('wpcf7s-style', plugins_url('/css/admin.css', WPCF7S_FILE));
|
100 |
}
|
101 |
}
|
102 |
|
103 |
+
/**
|
104 |
+
* Change the post actions
|
105 |
+
*/
|
106 |
+
public function action_row($actions, $post)
|
107 |
+
{
|
108 |
global $post_type;
|
109 |
+
if ('wpcf7s' === $post_type) {
|
110 |
// remove defaults
|
111 |
unset($actions['edit']);
|
112 |
unset($actions['inline hide-if-no-js']);
|
113 |
|
114 |
+
$actions = array_merge(array('aview' => '<a href="' . get_edit_post_link($post->ID) . '">'.__('View', 'contact-form-submissions').'</a>'), $actions);
|
115 |
}
|
116 |
return $actions;
|
117 |
}
|
118 |
|
119 |
+
/**
|
120 |
+
* Query posts by a specific form
|
121 |
+
*/
|
122 |
+
public function admin_posts($query)
|
123 |
+
{
|
124 |
global $post_type;
|
125 |
+
if ($query->is_admin && 'wpcf7s' === $post_type && $query->is_main_query()) {
|
126 |
$form_id = esc_attr($_GET['wpcf7_contact_form']);
|
127 |
+
if (!empty($form_id)) {
|
128 |
+
$query->set('meta_query', array(
|
129 |
array(
|
130 |
'key' => 'form_id',
|
131 |
'value' => $form_id,
|
136 |
}
|
137 |
}
|
138 |
|
139 |
+
/**
|
140 |
+
* Change the default table columns
|
141 |
+
*/
|
142 |
+
public function set_columns($columns)
|
143 |
+
{
|
144 |
$columns = array(
|
145 |
'cb' => '<input type="checkbox">',
|
146 |
'submission' => __('Submission', 'contact-form-submissions'),
|
147 |
'form' => __('Contact Form', 'contact-form-submissions')
|
148 |
);
|
149 |
|
150 |
+
// dynamically add cols if the user selects a form
|
151 |
+
if (isset($_GET['wpcf7_contact_form']) && !empty($_GET['wpcf7_contact_form'])) {
|
152 |
$form_id = $_GET['wpcf7_contact_form'];
|
153 |
|
154 |
$wpcf7s_columns = $this->get_available_columns($form_id);
|
155 |
|
156 |
+
foreach ($wpcf7s_columns as $meta_key) {
|
157 |
$columns[$meta_key] = str_replace('wpcf7s_posted-', '', $meta_key);
|
158 |
}
|
159 |
}
|
163 |
return $columns;
|
164 |
}
|
165 |
|
166 |
+
/**
|
167 |
+
* Output values in custom columns
|
168 |
+
*/
|
169 |
+
public function column($column, $post_id)
|
170 |
+
{
|
171 |
$form_id = get_post_meta($post_id, 'form_id', true);
|
172 |
$post_parent = wp_get_post_parent_id($post_id);
|
173 |
$nested = ($post_parent > 0) ? '— ' : '';
|
174 |
|
175 |
+
switch ($column) {
|
176 |
|
177 |
+
case 'form':
|
178 |
?><a href="<?php echo add_query_arg(array('page'=>'wpcf7', 'post'=>$form_id, 'action'=>'edit'), admin_url('admin.php')); ?>"><?php echo get_the_title($form_id); ?></a><?php
|
179 |
break;
|
180 |
+
case 'sent':
|
181 |
?><a href="<?php echo add_query_arg(array('page'=>'wpcf7', 'post'=>$form_id, 'action'=>'edit'), admin_url('admin.php')); ?>"><?php echo get_the_title($form_id); ?></a><?php
|
182 |
break;
|
183 |
+
case 'submission':
|
184 |
?>
|
185 |
<strong>
|
186 |
<a class="row-title" href="<?php echo get_edit_post_link($post_id); ?>">
|
189 |
</strong>
|
190 |
<?php
|
191 |
break;
|
192 |
+
default:
|
193 |
echo get_post_meta($post_id, $column, true);
|
194 |
break;
|
195 |
}
|
196 |
}
|
197 |
|
198 |
+
/**
|
199 |
+
* Register custom metaboxes
|
200 |
+
*/
|
201 |
+
public function meta_boxes()
|
202 |
+
{
|
203 |
+
global $post_id;
|
204 |
+
|
205 |
+
add_meta_box('wpcf7s_mail', __('Mail', 'contact-form-submissions'), array($this, 'mail_meta_box'), 'wpcf7s', 'normal');
|
206 |
+
add_meta_box('wpcf7s_posted', __('Posted', 'contact-form-submissions'), array($this, 'posted_meta_box'), 'wpcf7s', 'normal');
|
207 |
+
|
208 |
+
add_meta_box('wpcf7s_actions', __('Overview', 'contact-form-submissions'), array($this, 'actions_meta_box'), 'wpcf7s', 'side');
|
209 |
+
remove_meta_box('submitdiv', 'wpcf7s', 'side');
|
210 |
+
|
211 |
+
// only show the meta box if the post has files
|
212 |
+
$files = $this->get_mail_files($post_id);
|
213 |
+
if(!empty($files)){
|
214 |
+
add_meta_box('wpcf7s_files', __('Files', 'contact-form-submissions'), array($this, 'files_meta_box'), 'wpcf7s', 'normal');
|
215 |
+
}
|
216 |
}
|
217 |
|
218 |
+
/**
|
219 |
+
* Output for the mail metabox
|
220 |
+
*/
|
221 |
+
public function mail_meta_box($post)
|
222 |
+
{
|
223 |
$form_id = get_post_meta($post->ID, 'form_id', true);
|
224 |
$sender = get_post_meta($post->ID, 'sender', true);
|
225 |
$sender_mailto = preg_replace('/([a-zA-Z0-9_\-\.]*@\\S+\\.\\w+)/', '<a href="mailto:$1">$1</a>', $sender);
|
226 |
$recipient = get_post_meta($post->ID, 'recipient', true);
|
227 |
$recipient_mailto = preg_replace('/([a-zA-Z0-9_\-\.]*@\\S+\\.\\w+)/', '<a href="mailto:$1">$1</a>', $recipient);
|
228 |
|
229 |
+
$additional_headers = get_post_meta($post->ID, 'additional_headers', true); ?>
|
|
|
230 |
<table class="form-table contact-form-submission">
|
231 |
<tbody>
|
232 |
<tr>
|
249 |
<th scope="row"><?php _e('Body', 'contact-form-submissions'); ?></th>
|
250 |
<td><?php echo apply_filters('the_content', $post->post_content); ?></td>
|
251 |
</tr>
|
252 |
+
<?php if (!empty($additional_headers)) {
|
253 |
+
?>
|
254 |
<tr>
|
255 |
<th scope="row"><?php _e('Additional Headers', 'contact-form-submissions'); ?></th>
|
256 |
<td><?php echo get_post_meta($post->ID, 'additional_headers', true); ?></td>
|
257 |
</tr>
|
258 |
+
<?php
|
259 |
+
} ?>
|
260 |
</tbody>
|
261 |
</table>
|
262 |
|
263 |
<?php
|
|
|
|
|
|
|
|
|
264 |
|
265 |
+
}
|
266 |
+
/**
|
267 |
+
* Output for the posted values metabox
|
268 |
+
*/
|
269 |
+
public function posted_meta_box($post)
|
270 |
+
{
|
271 |
+
$values = $this->get_mail_posted_fields($post->ID); ?>
|
272 |
<table class="form-table contact-form-submission">
|
273 |
<tbody>
|
274 |
+
<?php foreach ($values as $key => $value) {
|
275 |
+
?>
|
276 |
<tr>
|
277 |
<th scope="row"><?php _e(str_replace('wpcf7s_posted-', '', $key), 'contact-form-submissions'); ?></th>
|
278 |
<td><?php echo is_serialized($value[0]) ? implode(', ', unserialize($value[0])) : $value[0]; ?></td>
|
279 |
</tr>
|
280 |
+
<?php
|
281 |
+
} ?>
|
282 |
</tbody>
|
283 |
</table>
|
284 |
|
285 |
<?php
|
286 |
+
|
287 |
}
|
288 |
|
289 |
+
public function files_meta_box($post)
|
290 |
+
{
|
291 |
+
global $contact_form_submissions;
|
292 |
+
|
293 |
+
$values = $this->get_mail_files($post->ID);
|
294 |
+
|
295 |
+
$image_exts = array( 'jpg', 'jpeg', 'jpe', 'gif', 'png' ); ?>
|
296 |
+
<table class="form-table contact-form-submission">
|
297 |
+
<tbody>
|
298 |
+
<?php foreach ($values as $key => $files) {
|
299 |
+
?>
|
300 |
+
<tr>
|
301 |
+
<th scope="row"><?php _e(str_replace('wpcf7s_file-', '', $key), 'contact-form-submissions'); ?></th>
|
302 |
+
<td><?php foreach ($files as $file_path) {
|
303 |
+
$file_type = wp_check_filetype($file_path);
|
304 |
+
|
305 |
+
$wpcf7s_dir = $contact_form_submissions->get_wpcf7s_url();
|
306 |
+
$file_url = $wpcf7s_dir . '/' . $post->ID . '/' . $file_path;
|
307 |
+
|
308 |
+
if(in_array($file_type['ext'], $image_exts)){
|
309 |
+
printf('<a href="%1$s" target="_blank"><img width="100" class="contact-form-submission-image" src="%1$s" /></a>', $file_url);
|
310 |
+
} else {
|
311 |
+
printf('<a href="%1$s" target="_blank">Open File</a>', $file_url);
|
312 |
+
}
|
313 |
+
} ?></td>
|
314 |
+
</tr>
|
315 |
+
<?php
|
316 |
+
} ?>
|
317 |
+
</tbody>
|
318 |
+
</table>
|
319 |
+
|
320 |
+
<?php
|
321 |
+
|
322 |
+
}
|
323 |
+
|
324 |
+
/**
|
325 |
+
* Output for the actions metabox
|
326 |
+
*/
|
327 |
+
public function actions_meta_box($post)
|
328 |
+
{
|
329 |
+
$datef = __('M j, Y @ H:i');
|
330 |
+
$date = date_i18n($datef, strtotime($post->post_date)); ?>
|
331 |
<div id="minor-publishing">
|
332 |
|
333 |
<div id="misc-publishing-actions">
|
338 |
<div class="clear"></div>
|
339 |
</div>
|
340 |
<?php
|
341 |
+
|
342 |
}
|
343 |
|
344 |
+
/**
|
345 |
+
* Get the posted data for a form
|
346 |
+
*
|
347 |
+
* @param integer $post_id the form post ID
|
348 |
+
*
|
349 |
+
* @return array the form values
|
350 |
+
*/
|
351 |
+
public function get_mail_posted_fields($post_id = 0)
|
352 |
+
{
|
353 |
$post_meta = get_post_meta($post_id);
|
354 |
$posted = array_intersect_key(
|
355 |
$post_meta,
|
356 |
+
array_flip(array_filter(array_keys($post_meta), function ($key) {
|
357 |
return preg_match('/^wpcf7s_posted-/', $key);
|
358 |
}))
|
359 |
);
|
361 |
return $posted;
|
362 |
}
|
363 |
|
364 |
+
/**
|
365 |
+
* Get the posted files for a form
|
366 |
+
*
|
367 |
+
* @param integer $post_id the form post ID
|
368 |
+
*
|
369 |
+
* @return array the form values
|
370 |
+
*/
|
371 |
+
public function get_mail_files($post_id = 0)
|
372 |
+
{
|
373 |
+
$post_meta = get_post_meta($post_id);
|
374 |
+
if($post_meta){
|
375 |
+
$posted = array_intersect_key(
|
376 |
+
$post_meta,
|
377 |
+
array_flip(array_filter(array_keys($post_meta), function ($key) {
|
378 |
+
return preg_match('/^wpcf7s_file-/', $key);
|
379 |
+
}))
|
380 |
+
);
|
381 |
+
}
|
382 |
+
|
383 |
+
return $posted;
|
384 |
+
}
|
385 |
+
|
386 |
+
/**
|
387 |
+
* Get the fields from a form
|
388 |
+
*
|
389 |
+
* @param integer $form_id the form post ID
|
390 |
+
*
|
391 |
+
* @return array|boolean the form keys
|
392 |
+
*/
|
393 |
+
public function get_available_columns($form_id = 0)
|
394 |
+
{
|
395 |
global $wpdb;
|
396 |
|
397 |
$post_id = $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = 'form_id' AND meta_value = $form_id LIMIT 1;");
|
400 |
|
401 |
return $columns;
|
402 |
}
|
403 |
+
}
|
Submissions.php
CHANGED
@@ -1,28 +1,33 @@
|
|
1 |
<?php
|
2 |
-
class WPCF7Submissions
|
3 |
-
|
4 |
-
function __construct()
|
5 |
-
|
|
|
6 |
|
7 |
add_filter('wpcf7_mail_components', array($this, 'submission'), 999, 3);
|
8 |
add_filter('wpcf7_posted_data', array($this, 'posted'), 999, 3);
|
9 |
}
|
10 |
|
11 |
-
|
|
|
|
|
|
|
|
|
12 |
$labels = array(
|
13 |
-
'name' => __(
|
14 |
-
'singular_name' => __(
|
15 |
-
'menu_name' => __(
|
16 |
-
'all_items' => __(
|
17 |
-
'view_item' => __(
|
18 |
-
'edit_item' => __(
|
19 |
-
'search_items' => __(
|
20 |
-
'not_found' => __(
|
21 |
-
'not_found_in_trash' => __(
|
22 |
);
|
23 |
$args = array(
|
24 |
-
'label' => __(
|
25 |
-
'description' => __(
|
26 |
'labels' => $labels,
|
27 |
'supports' => false,
|
28 |
'hierarchical' => true,
|
@@ -43,10 +48,14 @@ class WPCF7Submissions {
|
|
43 |
),
|
44 |
'map_meta_cap' => true
|
45 |
);
|
46 |
-
register_post_type(
|
47 |
}
|
48 |
|
49 |
-
|
|
|
|
|
|
|
|
|
50 |
global $wpcf7s_posted_data;
|
51 |
|
52 |
$wpcf7s_posted_data = $posted_data;
|
@@ -54,30 +63,44 @@ class WPCF7Submissions {
|
|
54 |
return $posted_data;
|
55 |
}
|
56 |
|
57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
global $wpcf7s_post_id, $wpcf7s_posted_data;
|
59 |
|
60 |
-
if(!empty($wpcf7s_posted_data)) {
|
61 |
-
foreach($wpcf7s_posted_data as $name => $value){
|
62 |
-
if('_wpcf7' !== substr($name, 0, 6)){
|
63 |
$fields[$name] = $value;
|
64 |
}
|
65 |
}
|
66 |
}
|
67 |
|
68 |
$contact_form_id = 0;
|
69 |
-
if(method_exists($contact_form,'id')){
|
70 |
$contact_form_id = $contact_form->id();
|
71 |
-
} elseif(property_exists($contact_form
|
72 |
$contact_form_id = $contact_form->id;
|
73 |
}
|
74 |
|
75 |
$body = $components['body'];
|
76 |
-
$sender = wpcf7_strip_newline(
|
77 |
-
$recipient = wpcf7_strip_newline(
|
78 |
-
$subject = wpcf7_strip_newline(
|
79 |
$headers = trim($components['additional_headers']);
|
80 |
-
|
|
|
|
|
|
|
|
|
81 |
|
82 |
$submission = array(
|
83 |
'form_id' => $contact_form_id,
|
@@ -90,20 +113,25 @@ class WPCF7Submissions {
|
|
90 |
'fields' => $fields
|
91 |
);
|
92 |
|
93 |
-
if(!empty($wpcf7s_post_id)){
|
94 |
$submission['parent'] = $wpcf7s_post_id;
|
95 |
}
|
96 |
|
|
|
97 |
$post_id = $this->save($submission);
|
98 |
|
99 |
-
if(empty($wpcf7s_post_id)){
|
100 |
$wpcf7s_post_id = $post_id;
|
101 |
}
|
102 |
|
103 |
return $components;
|
104 |
}
|
105 |
|
106 |
-
|
|
|
|
|
|
|
|
|
107 |
$post = array(
|
108 |
'post_title' => ' ',
|
109 |
'post_content' => $submission['body'],
|
@@ -111,27 +139,76 @@ class WPCF7Submissions {
|
|
111 |
'post_type' => 'wpcf7s',
|
112 |
);
|
113 |
|
114 |
-
if(isset($submission['parent'])){
|
115 |
$post['post_parent'] = $submission['parent'];
|
116 |
}
|
117 |
|
118 |
$post_id = wp_insert_post($post);
|
119 |
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
}
|
132 |
-
}
|
133 |
}
|
134 |
|
135 |
return $post_id;
|
136 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
137 |
}
|
1 |
<?php
|
2 |
+
class WPCF7Submissions
|
3 |
+
{
|
4 |
+
public function __construct()
|
5 |
+
{
|
6 |
+
add_action('init', array($this, 'post_type'));
|
7 |
|
8 |
add_filter('wpcf7_mail_components', array($this, 'submission'), 999, 3);
|
9 |
add_filter('wpcf7_posted_data', array($this, 'posted'), 999, 3);
|
10 |
}
|
11 |
|
12 |
+
/**
|
13 |
+
* Register the post type
|
14 |
+
*/
|
15 |
+
public function post_type()
|
16 |
+
{
|
17 |
$labels = array(
|
18 |
+
'name' => __('Contact Form Submissions', 'contact-form-submissions'),
|
19 |
+
'singular_name' => __('Submission', 'contact-form-submissions'),
|
20 |
+
'menu_name' => __('Submission', 'contact-form-submissions'),
|
21 |
+
'all_items' => __('Submissions', 'contact-form-submissions'),
|
22 |
+
'view_item' => __('Submission', 'contact-form-submissions'),
|
23 |
+
'edit_item' => __('Submission', 'contact-form-submissions'),
|
24 |
+
'search_items' => __('Search', 'contact-form-submissions'),
|
25 |
+
'not_found' => __('Not found', 'contact-form-submissions'),
|
26 |
+
'not_found_in_trash' => __('Not found in Trash', 'contact-form-submissions'),
|
27 |
);
|
28 |
$args = array(
|
29 |
+
'label' => __('Submission', 'contact-form-submissions'),
|
30 |
+
'description' => __('Post Type Description', 'contact-form-submissions'),
|
31 |
'labels' => $labels,
|
32 |
'supports' => false,
|
33 |
'hierarchical' => true,
|
48 |
),
|
49 |
'map_meta_cap' => true
|
50 |
);
|
51 |
+
register_post_type('wpcf7s', $args);
|
52 |
}
|
53 |
|
54 |
+
/**
|
55 |
+
* Hook into when a cf7 form is submitted to save the post data
|
56 |
+
*/
|
57 |
+
public function posted($posted_data)
|
58 |
+
{
|
59 |
global $wpcf7s_posted_data;
|
60 |
|
61 |
$wpcf7s_posted_data = $posted_data;
|
63 |
return $posted_data;
|
64 |
}
|
65 |
|
66 |
+
/**
|
67 |
+
* Hook into when a cf7 form has been submitted and the values have been inserted
|
68 |
+
*
|
69 |
+
* @param [type] $components [description]
|
70 |
+
* @param [type] $contact_form [description]
|
71 |
+
* @param [type] $mail [description]
|
72 |
+
*
|
73 |
+
* @return [type] [description]
|
74 |
+
*/
|
75 |
+
public function submission($components, $contact_form, $mail)
|
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 ('_wpcf7' !== substr($name, 0, 6)) {
|
82 |
$fields[$name] = $value;
|
83 |
}
|
84 |
}
|
85 |
}
|
86 |
|
87 |
$contact_form_id = 0;
|
88 |
+
if (method_exists($contact_form, 'id')) {
|
89 |
$contact_form_id = $contact_form->id();
|
90 |
+
} elseif (property_exists($contact_form, 'id')) {
|
91 |
$contact_form_id = $contact_form->id;
|
92 |
}
|
93 |
|
94 |
$body = $components['body'];
|
95 |
+
$sender = wpcf7_strip_newline($components['sender']);
|
96 |
+
$recipient = wpcf7_strip_newline($components['recipient']);
|
97 |
+
$subject = wpcf7_strip_newline($components['subject']);
|
98 |
$headers = trim($components['additional_headers']);
|
99 |
+
|
100 |
+
// get the form file attachements
|
101 |
+
if ( $submission = WPCF7_Submission::get_instance() ) {
|
102 |
+
$attachments = $submission->uploaded_files();
|
103 |
+
}
|
104 |
|
105 |
$submission = array(
|
106 |
'form_id' => $contact_form_id,
|
113 |
'fields' => $fields
|
114 |
);
|
115 |
|
116 |
+
if (!empty($wpcf7s_post_id)) {
|
117 |
$submission['parent'] = $wpcf7s_post_id;
|
118 |
}
|
119 |
|
120 |
+
// store the form submission
|
121 |
$post_id = $this->save($submission);
|
122 |
|
123 |
+
if (empty($wpcf7s_post_id)) {
|
124 |
$wpcf7s_post_id = $post_id;
|
125 |
}
|
126 |
|
127 |
return $components;
|
128 |
}
|
129 |
|
130 |
+
/**
|
131 |
+
* Save the form submission into the db
|
132 |
+
*/
|
133 |
+
private function save($submission = array())
|
134 |
+
{
|
135 |
$post = array(
|
136 |
'post_title' => ' ',
|
137 |
'post_content' => $submission['body'],
|
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 |
+
/**
|
192 |
+
* Get the path of where uploads go
|
193 |
+
*
|
194 |
+
* @return string full path
|
195 |
+
*/
|
196 |
+
public function get_wpcf7s_dir(){
|
197 |
+
$upload_dir = wp_upload_dir();
|
198 |
+
$wpcf7s_dir = apply_filters('wpcf7s_dir', $upload_dir['basedir'] .'/wpcf7-submissions');
|
199 |
+
|
200 |
+
return $wpcf7s_dir;
|
201 |
+
}
|
202 |
+
|
203 |
+
/**
|
204 |
+
* Get the url of where uploads go
|
205 |
+
*
|
206 |
+
* @return string full url
|
207 |
+
*/
|
208 |
+
public function get_wpcf7s_url(){
|
209 |
+
$upload_dir = wp_upload_dir();
|
210 |
+
$wpcf7s_url = apply_filters('wpcf7s_url', $upload_dir['baseurl'] .'/wpcf7-submissions');
|
211 |
+
|
212 |
+
return $wpcf7s_url;
|
213 |
+
}
|
214 |
}
|
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.
|
6 |
Author: Jason Green
|
7 |
License: GPLv3
|
8 |
Domain Path: /languages
|
@@ -15,19 +15,31 @@ define('WPCF7S_FILE', 'contact-form-submissions/contact-form-submissions.php');
|
|
15 |
require_once WPCF7S_DIR . '/Submissions.php';
|
16 |
require_once WPCF7S_DIR . '/Admin.php';
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
21 |
}
|
22 |
-
add_action(
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
|
|
27 |
}
|
28 |
-
add_action(
|
29 |
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
32 |
}
|
33 |
-
add_action(
|
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 |
Author: Jason Green
|
7 |
License: GPLv3
|
8 |
Domain Path: /languages
|
15 |
require_once WPCF7S_DIR . '/Submissions.php';
|
16 |
require_once WPCF7S_DIR . '/Admin.php';
|
17 |
|
18 |
+
/**
|
19 |
+
* Save the WPCF7Submissions class for later
|
20 |
+
*/
|
21 |
+
function contact_form_submissions_init()
|
22 |
+
{
|
23 |
+
global $contact_form_submissions;
|
24 |
+
$contact_form_submissions = new WPCF7Submissions();
|
25 |
}
|
26 |
+
add_action('init', 'contact_form_submissions_init', 9);
|
27 |
|
28 |
+
/**
|
29 |
+
* Save the WPCF7SAdmin class for later
|
30 |
+
*/
|
31 |
+
function contact_form_submissions_admin_init()
|
32 |
+
{
|
33 |
+
global $contact_form_submissions_admin;
|
34 |
+
$contact_form_submissions_admin = new WPCF7SAdmin();
|
35 |
}
|
36 |
+
add_action('admin_init', 'contact_form_submissions_admin_init');
|
37 |
|
38 |
+
/**
|
39 |
+
* Load language file
|
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');
|
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
|
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 |
-
Stable tag: 1.
|
8 |
License: GPLv3
|
9 |
|
10 |
Never miss an enquiry again! Save all Contact Form 7 submissions safely in your database.
|
@@ -15,6 +15,8 @@ Easy install, no configuration necessary. Once activated all contact form 7 subm
|
|
15 |
|
16 |
Each submission is stored in the database so they can be easily managed using the default WordPress interface. You can filter subsmissions by searching for keywords, selecting individual contact forms or picking a date range. To show the posted values in the listing table just filter the submissions by a form.
|
17 |
|
|
|
|
|
18 |
All submissions can be exported using the any WordPress post exporter.
|
19 |
|
20 |
This plugin has been made with no ads or donation links so you can use this on all your sites.
|
@@ -38,6 +40,9 @@ None yet
|
|
38 |
|
39 |
== Changelog ==
|
40 |
|
|
|
|
|
|
|
41 |
= 1.4.1 =
|
42 |
* Minor bug fix
|
43 |
|
3 |
Tags: contact form 7, save contact form, submissions, contact form db, cf7, wpcf7, contact form storage, contact form seven, contact form 7 db
|
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.2
|
7 |
+
Stable tag: 1.5
|
8 |
License: GPLv3
|
9 |
|
10 |
Never miss an enquiry again! Save all Contact Form 7 submissions safely in your database.
|
15 |
|
16 |
Each submission is stored in the database so they can be easily managed using the default WordPress interface. You can filter subsmissions by searching for keywords, selecting individual contact forms or picking a date range. To show the posted values in the listing table just filter the submissions by a form.
|
17 |
|
18 |
+
Files are stored in the /wp-content/uploads directory and can be previewed or downloaded from the single submission page.
|
19 |
+
|
20 |
All submissions can be exported using the any WordPress post exporter.
|
21 |
|
22 |
This plugin has been made with no ads or donation links so you can use this on all your sites.
|
40 |
|
41 |
== Changelog ==
|
42 |
|
43 |
+
= 1.5 =
|
44 |
+
* Added support for files
|
45 |
+
|
46 |
= 1.4.1 =
|
47 |
* Minor bug fix
|
48 |
|