WooCommerce Services - Version 1.12.2

Version Description

  • Fix some REST API calls being erroneously cached by certain hosting providers
Download this release

Release Info

Developer woothemes
Plugin Icon 128x128 WooCommerce Services
Version 1.12.2
Comparing to
See all releases

Code changes from version 1.12.1 to 1.12.2

classes/class-wc-rest-connect-base-controller.php CHANGED
@@ -59,17 +59,44 @@ abstract class WC_REST_Connect_Base_Controller extends WP_REST_Controller {
59
  }
60
  }
61
 
62
- public function get_internal( $request ) {
 
 
 
63
  if ( ! defined( 'DONOTCACHEPAGE' ) ) {
64
  define( 'DONOTCACHEPAGE', true ); // Play nice with WP-Super-Cache
65
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  return $this->get( $request );
67
  }
68
 
69
  public function post_internal( $request ) {
70
- if ( ! defined( 'DONOTCACHEPAGE' ) ) {
71
- define( 'DONOTCACHEPAGE', true ); // Play nice with WP-Super-Cache
72
- }
73
  return $this->post( $request );
74
  }
75
 
59
  }
60
  }
61
 
62
+ /**
63
+ * Consolidate cache prevention mechanisms.
64
+ */
65
+ public function prevent_route_caching() {
66
  if ( ! defined( 'DONOTCACHEPAGE' ) ) {
67
  define( 'DONOTCACHEPAGE', true ); // Play nice with WP-Super-Cache
68
  }
69
+
70
+ // Prevent our REST API endpoint responses from being added to browser cache
71
+ add_filter( 'rest_post_dispatch', array( $this, 'send_nocache_header' ), PHP_INT_MAX, 2 );
72
+ }
73
+
74
+ /**
75
+ * Send a no-cache header for WCS REST API responses. Prompted by cache issues
76
+ * on the Pantheon hosting platform.
77
+ *
78
+ * See: https://pantheon.io/docs/cache-control/
79
+ *
80
+ * @param WP_REST_Response $response
81
+ * @param WP_REST_Server $server
82
+ *
83
+ * @return WP_REST_Response passthrough $response parameter
84
+ */
85
+ public function send_nocache_header( $response, $server ) {
86
+ $server->send_header( 'Cache-Control', 'no-cache, must-revalidate, max-age=0' );
87
+
88
+ return $response;
89
+ }
90
+
91
+ public function get_internal( $request ) {
92
+ $this->prevent_route_caching();
93
+
94
  return $this->get( $request );
95
  }
96
 
97
  public function post_internal( $request ) {
98
+ $this->prevent_route_caching();
99
+
 
100
  return $this->post( $request );
101
  }
102
 
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: automattic, woothemes, allendav, kellychoffman, jkudish, jeffstiel
3
  Tags: canada-post, shipping, stamps, usps, woocommerce, taxes, payment, stripe
4
  Requires at least: 4.6
5
  Tested up to: 4.9.4
6
- Stable tag: 1.12.1
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -90,8 +90,8 @@ The source code is freely available [in GitHub](https://github.com/Automattic/wo
90
 
91
  == Changelog ==
92
 
93
- = 1.12.1 =
94
- * Fix missing file in plugin release
95
 
96
  = 1.12.0 =
97
  * Add email receipts for purchased shipping labels
3
  Tags: canada-post, shipping, stamps, usps, woocommerce, taxes, payment, stripe
4
  Requires at least: 4.6
5
  Tested up to: 4.9.4
6
+ Stable tag: 1.12.2
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
90
 
91
  == Changelog ==
92
 
93
+ = 1.12.2 =
94
+ * Fix some REST API calls being erroneously cached by certain hosting providers
95
 
96
  = 1.12.0 =
97
  * Add email receipts for purchased shipping labels
woocommerce-services.php CHANGED
@@ -7,7 +7,7 @@
7
  * Author URI: https://woocommerce.com/
8
  * Text Domain: woocommerce-services
9
  * Domain Path: /i18n/languages/
10
- * Version: 1.12.1
11
  * WC requires at least: 3.0.0
12
  * WC tested up to: 3.3.0
13
  *
7
  * Author URI: https://woocommerce.com/
8
  * Text Domain: woocommerce-services
9
  * Domain Path: /i18n/languages/
10
+ * Version: 1.12.2
11
  * WC requires at least: 3.0.0
12
  * WC tested up to: 3.3.0
13
  *