Custom Contact Forms - Version 6.4.9

Version Description

  • Don't cache backend endpoints. A useful fix for W3 Total Cache users.
Download this release

Release Info

Developer tlovett1
Plugin Icon 128x128 Custom Contact Forms
Version 6.4.9
Comparing to
See all releases

Code changes from version 6.4.8 to 6.4.9

classes/class-ccf-api.php CHANGED
@@ -128,6 +128,164 @@ class CCF_API extends WP_JSON_Posts {
128
  ) );
129
  }
130
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131
  /**
132
  * Ensure value is boolean
133
  *
@@ -548,7 +706,7 @@ class CCF_API extends WP_JSON_Posts {
548
  return new WP_Error( 'json_cannot_view_ccf_forms', esc_html__( 'Sorry, you cannot view forms.', 'custom-contact-forms' ), array( 'status' => 403 ) );
549
  }
550
 
551
- return parent::get_posts( $filter, $context, 'ccf_form', $page );
552
  }
553
 
554
  /**
@@ -570,7 +728,7 @@ class CCF_API extends WP_JSON_Posts {
570
 
571
  $filter['post_parent'] = $id;
572
 
573
- return parent::get_posts( $filter, $context, 'ccf_submission', $page );
574
  }
575
 
576
  /**
@@ -598,7 +756,7 @@ class CCF_API extends WP_JSON_Posts {
598
  return new WP_Error( 'json_cannot_view_ccf_form', esc_html__( 'Sorry, you cannot view this form.', 'custom-contact-forms' ), array( 'status' => 403 ) );
599
  }
600
 
601
- return parent::get_post( $id, $context );
602
  }
603
 
604
  /**
128
  ) );
129
  }
130
 
131
+ /**
132
+ * Retrieve a post.
133
+ *
134
+ * @uses get_post()
135
+ * @since 6.4.9
136
+ * @param int $id Post ID
137
+ * @param string $context The context; 'view' (default) or 'edit'.
138
+ * @return array Post entity
139
+ */
140
+ public function get_post( $id, $context = 'view' ) {
141
+ $id = (int) $id;
142
+
143
+ $post = get_post( $id, ARRAY_A );
144
+
145
+ if ( empty( $id ) || empty( $post['ID'] ) ) {
146
+ return new WP_Error( 'json_post_invalid_id', __( 'Invalid post ID.' ), array( 'status' => 404 ) );
147
+ }
148
+
149
+ if ( ! json_check_post_permission( $post, 'read' ) ) {
150
+ return new WP_Error( 'json_user_cannot_read', __( 'Sorry, you cannot read this post.' ), array( 'status' => 401 ) );
151
+ }
152
+
153
+ // Link headers (see RFC 5988)
154
+
155
+ $response = new WP_JSON_Response();
156
+ // Modified now, no cache
157
+ $response->header( 'Cache-Control', 'no-cache, no-store, must-revalidate' );
158
+ $response->header( 'Expires', 'Wed, 11 Jan 1984 05:00:00 GMT' );
159
+ $response->header( 'Pragma', 'no-cache' );
160
+ $response->header( 'Last-Modified', gmdate( 'D, d M Y H:i:s' ) . ' GMT' );
161
+
162
+ $post = $this->prepare_post( $post, $context );
163
+
164
+ if ( is_wp_error( $post ) ) {
165
+ return $post;
166
+ }
167
+
168
+ foreach ( $post['meta']['links'] as $rel => $url ) {
169
+ $response->link_header( $rel, $url );
170
+ }
171
+
172
+ $response->link_header( 'alternate', get_permalink( $id ), array( 'type' => 'text/html' ) );
173
+ $response->set_data( $post );
174
+
175
+ return $response;
176
+ }
177
+
178
+ /**
179
+ * Retrieve posts. We need to override last modified date
180
+ *
181
+ * @since 6.4.9
182
+ *
183
+ * The optional $filter parameter modifies the query used to retrieve posts.
184
+ * Accepted keys are 'post_type', 'post_status', 'number', 'offset',
185
+ * 'orderby', and 'order'.
186
+ *
187
+ * @uses wp_get_recent_posts()
188
+ * @see get_posts() for more on $filter values
189
+ *
190
+ * @param array $filter Parameters to pass through to `WP_Query`
191
+ * @param string $context The context; 'view' (default) or 'edit'.
192
+ * @param string|array $type Post type slug, or array of slugs
193
+ * @param int $page Page number (1-indexed)
194
+ * @return stdClass[] Collection of Post entities
195
+ */
196
+ public function get_posts( $filter = array(), $context = 'edit', $type = 'post', $page = 1 ) {
197
+ $query = array();
198
+
199
+ // Validate post types and permissions
200
+ $query['post_type'] = array();
201
+
202
+ foreach ( (array) $type as $type_name ) {
203
+ $post_type = get_post_type_object( $type_name );
204
+
205
+ if ( ! ( (bool) $post_type ) || ! $post_type->show_in_json ) {
206
+ return new WP_Error( 'json_invalid_post_type', sprintf( __( 'The post type "%s" is not valid' ), $type_name ), array( 'status' => 403 ) );
207
+ }
208
+
209
+ $query['post_type'][] = $post_type->name;
210
+ }
211
+
212
+ global $wp;
213
+
214
+ // Allow the same as normal WP
215
+ $valid_vars = apply_filters('query_vars', $wp->public_query_vars);
216
+
217
+ // If the user has the correct permissions, also allow use of internal
218
+ // query parameters, which are only undesirable on the frontend
219
+ //
220
+ // To disable anyway, use `add_filter('json_private_query_vars', '__return_empty_array');`
221
+
222
+ if ( current_user_can( $post_type->cap->edit_posts ) ) {
223
+ $private = apply_filters( 'json_private_query_vars', $wp->private_query_vars );
224
+ $valid_vars = array_merge( $valid_vars, $private );
225
+ }
226
+
227
+ // Define our own in addition to WP's normal vars
228
+ $json_valid = array( 'posts_per_page' );
229
+ $valid_vars = array_merge( $valid_vars, $json_valid );
230
+
231
+ // Filter and flip for querying
232
+ $valid_vars = apply_filters( 'json_query_vars', $valid_vars );
233
+ $valid_vars = array_flip( $valid_vars );
234
+
235
+ // Exclude the post_type query var to avoid dodging the permission
236
+ // check above
237
+ unset( $valid_vars['post_type'] );
238
+
239
+ foreach ( $valid_vars as $var => $index ) {
240
+ if ( isset( $filter[ $var ] ) ) {
241
+ $query[ $var ] = apply_filters( 'json_query_var-' . $var, $filter[ $var ] );
242
+ }
243
+ }
244
+
245
+ // Special parameter handling
246
+ $query['paged'] = absint( $page );
247
+
248
+ $post_query = new WP_Query();
249
+ $posts_list = $post_query->query( $query );
250
+ $response = new WP_JSON_Response();
251
+ $response->query_navigation_headers( $post_query );
252
+
253
+ if ( ! $posts_list ) {
254
+ $response->set_data( array() );
255
+ return $response;
256
+ }
257
+
258
+ // holds all the posts data
259
+ $struct = array();
260
+
261
+ // Modified now, no cache
262
+ $response->header( 'Cache-Control', 'no-cache, no-store, must-revalidate' );
263
+ $response->header( 'Expires', 'Wed, 11 Jan 1984 05:00:00 GMT' );
264
+ $response->header( 'Pragma', 'no-cache' );
265
+ $response->header( 'Last-Modified', gmdate( 'D, d M Y H:i:s' ) . ' GMT' );
266
+
267
+ foreach ( $posts_list as $post ) {
268
+ $post = get_object_vars( $post );
269
+
270
+ // Do we have permission to read this post?
271
+ if ( ! json_check_post_permission( $post, 'read' ) ) {
272
+ continue;
273
+ }
274
+
275
+ $response->link_header( 'item', json_url( '/posts/' . $post['ID'] ), array( 'title' => $post['post_title'] ) );
276
+ $post_data = $this->prepare_post( $post, $context );
277
+ if ( is_wp_error( $post_data ) ) {
278
+ continue;
279
+ }
280
+
281
+ $struct[] = $post_data;
282
+ }
283
+ $response->set_data( $struct );
284
+
285
+ return $response;
286
+ }
287
+
288
+
289
  /**
290
  * Ensure value is boolean
291
  *
706
  return new WP_Error( 'json_cannot_view_ccf_forms', esc_html__( 'Sorry, you cannot view forms.', 'custom-contact-forms' ), array( 'status' => 403 ) );
707
  }
708
 
709
+ return $this->get_posts( $filter, $context, 'ccf_form', $page );
710
  }
711
 
712
  /**
728
 
729
  $filter['post_parent'] = $id;
730
 
731
+ return $this->get_posts( $filter, $context, 'ccf_submission', $page );
732
  }
733
 
734
  /**
756
  return new WP_Error( 'json_cannot_view_ccf_form', esc_html__( 'Sorry, you cannot view this form.', 'custom-contact-forms' ), array( 'status' => 403 ) );
757
  }
758
 
759
+ return $this->get_post( $id, $context );
760
  }
761
 
762
  /**
classes/class-ccf-submission-cpt.php CHANGED
@@ -39,9 +39,12 @@ class CCF_Submission_CPT {
39
  public function setup_cpt() {
40
  $args = array(
41
  'labels' => false,
42
- 'public' => false,
43
- 'query_var' => false,
 
 
44
  'publicly_queryable' => true,
 
45
  'rewrite' => false,
46
  'capability_type' => 'post',
47
  'hierarchical' => false,
39
  public function setup_cpt() {
40
  $args = array(
41
  'labels' => false,
42
+ 'public' => true,
43
+ 'exclude_from_search' => true,
44
+ 'show_in_nav_menus' => false,
45
+ 'show_ui' => false,
46
  'publicly_queryable' => true,
47
+ 'query_var' => false,
48
  'rewrite' => false,
49
  'capability_type' => 'post',
50
  'hierarchical' => false,
custom-contact-forms.php CHANGED
@@ -4,7 +4,7 @@
4
  * Plugin URI: http://www.taylorlovett.com
5
  * Description: Build beautiful custom forms the WordPress way. View live previews of your forms while you build them.
6
  * Author: Taylor Lovett
7
- * Version: 6.4.8
8
  * Author URI: http://www.taylorlovett.com
9
  */
10
 
4
  * Plugin URI: http://www.taylorlovett.com
5
  * Description: Build beautiful custom forms the WordPress way. View live previews of your forms while you build them.
6
  * Author: Taylor Lovett
7
+ * Version: 6.4.9
8
  * Author URI: http://www.taylorlovett.com
9
  */
10
 
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
4
  Tags: contact form, web form, custom contact form, custom forms, captcha form, contact fields, form mailers, forms
5
  Requires at least: 3.9
6
  Tested up to: 4.2
7
- Stable tag: 6.4.8
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -35,6 +35,9 @@ For questions, feature requests, and support concerning the Custom Contact Forms
35
 
36
  == Changelog ==
37
 
 
 
 
38
  = 6.4.8 =
39
  * Use WP timezone for forms and submissions
40
 
4
  Tags: contact form, web form, custom contact form, custom forms, captcha form, contact fields, form mailers, forms
5
  Requires at least: 3.9
6
  Tested up to: 4.2
7
+ Stable tag: 6.4.9
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
35
 
36
  == Changelog ==
37
 
38
+ = 6.4.9 =
39
+ * Don't cache backend endpoints. A useful fix for W3 Total Cache users.
40
+
41
  = 6.4.8 =
42
  * Use WP timezone for forms and submissions
43