From 647a3e07d31b304ba9a64d5c6a274e3b869a0220 Mon Sep 17 00:00:00 2001 From: Allen Snook Date: Tue, 18 Jul 2017 11:46:00 -0700 Subject: [PATCH 1/2] Disable jetpack sync during REST requests --- hotfixes/wc-api-dev-jetpack-hotfixes.php | 32 ++++++++++++++++++++++++ readme.txt | 5 +++- wc-api-dev.php | 5 +++- 3 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 hotfixes/wc-api-dev-jetpack-hotfixes.php diff --git a/hotfixes/wc-api-dev-jetpack-hotfixes.php b/hotfixes/wc-api-dev-jetpack-hotfixes.php new file mode 100644 index 0000000..176e347 --- /dev/null +++ b/hotfixes/wc-api-dev-jetpack-hotfixes.php @@ -0,0 +1,32 @@ + 5 second) response + * times during the shutdown action for things like product creation + * + * See also https://core.trac.wordpress.org/ticket/41358#ticket + * See also https://github.com/Automattic/jetpack/pull/7482 + * + * This can be removed once we have either of the two fixes above released + * + * See also https://github.com/woocommerce/woocommerce/pull/16158 + */ + +function wc_api_dev_jetpack_sync_sender_should_load( $sender_should_load ) { + if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) { + $sender_should_load = false; + } + + return $sender_should_load; +} + +add_filter( 'jetpack_sync_sender_should_load', 'wc_api_dev_jetpack_sync_sender_should_load', 999 ); diff --git a/readme.txt b/readme.txt index 11dfe5f..47849f3 100644 --- a/readme.txt +++ b/readme.txt @@ -3,7 +3,7 @@ Contributors: automattic, woothemes Tags: woocommerce, rest-api, api Requires at least: 4.6 Tested up to: 4.8 -Stable tag: 0.6.0 +Stable tag: 0.7.0 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -25,6 +25,9 @@ This section describes how to install the plugin and get it working. == Changelog == += 0.7.0 = +* Fix - disable jetpack sync during rest api requests to avoid slow responses + = 0.6.0 = * Fix value default return on settings endpoints * Fix broken variation image set diff --git a/wc-api-dev.php b/wc-api-dev.php index b1de37a..9b07e32 100644 --- a/wc-api-dev.php +++ b/wc-api-dev.php @@ -3,7 +3,7 @@ * Plugin Name: WooCommerce API Dev * Plugin URI: https://woocommerce.com/ * Description: A feature plugin providing a bleeding edge version of the WooCommerce REST API. - * Version: 0.6.0 + * Version: 0.7.0 * Author: Automattic * Author URI: https://woocommerce.com * Requires at least: 4.4 @@ -117,6 +117,9 @@ public function includes() { include_once( dirname( __FILE__ ) . '/api/class-wc-rest-dev-system-status-tools-controller.php' ); include_once( dirname( __FILE__ ) . '/api/class-wc-rest-dev-shipping-methods-controller.php' ); include_once( dirname( __FILE__ ) . '/api/class-wc-rest-dev-payment-gateways-controller.php' ); + + // Things that aren't related to a specific endpoint but to things like cross-plugin compatibility + include_once( dirname( __FILE__ ) . '/hotfixes/wc-api-dev-jetpack-hotfixes.php' ); } /** From 9c11c4002bfeac24d3b00af2525a2c39339c79b1 Mon Sep 17 00:00:00 2001 From: Allen Snook Date: Tue, 18 Jul 2017 14:57:25 -0700 Subject: [PATCH 2/2] Change to testing the request uri since REST_REQUEST isn't yet available when this filter gets run --- hotfixes/wc-api-dev-jetpack-hotfixes.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hotfixes/wc-api-dev-jetpack-hotfixes.php b/hotfixes/wc-api-dev-jetpack-hotfixes.php index 176e347..d76e8a9 100644 --- a/hotfixes/wc-api-dev-jetpack-hotfixes.php +++ b/hotfixes/wc-api-dev-jetpack-hotfixes.php @@ -22,7 +22,8 @@ */ function wc_api_dev_jetpack_sync_sender_should_load( $sender_should_load ) { - if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) { + $starts_with = '/wp-json/wc/v'; + if ( $starts_with === substr( $_SERVER[ 'REQUEST_URI' ], 0, strlen( $starts_with ) ) ) { $sender_should_load = false; }