Skip to content
This repository was archived by the owner on Oct 4, 2019. It is now read-only.

Commit 97f3d11

Browse files
authored
Merge pull request #28 from woocommerce/fix/27-suspend-jp-sync-during-rest-response
Disable jetpack sync during REST requests
2 parents 1dc3571 + 9c11c40 commit 97f3d11

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/**
3+
* Jetpack compatibility hotfixes
4+
*
5+
* @since 0.7.0
6+
*/
7+
8+
if ( ! defined( 'ABSPATH' ) ) {
9+
exit;
10+
}
11+
12+
/**
13+
* Disables jetpack sync during rest requests to avoid lengthly (> 5 second) response
14+
* times during the shutdown action for things like product creation
15+
*
16+
* See also https://core.trac.wordpress.org/ticket/41358#ticket
17+
* See also https://github.com/Automattic/jetpack/pull/7482
18+
*
19+
* This can be removed once we have either of the two fixes above released
20+
*
21+
* See also https://github.com/woocommerce/woocommerce/pull/16158
22+
*/
23+
24+
function wc_api_dev_jetpack_sync_sender_should_load( $sender_should_load ) {
25+
$starts_with = '/wp-json/wc/v';
26+
if ( $starts_with === substr( $_SERVER[ 'REQUEST_URI' ], 0, strlen( $starts_with ) ) ) {
27+
$sender_should_load = false;
28+
}
29+
30+
return $sender_should_load;
31+
}
32+
33+
add_filter( 'jetpack_sync_sender_should_load', 'wc_api_dev_jetpack_sync_sender_should_load', 999 );

readme.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Contributors: automattic, woothemes
33
Tags: woocommerce, rest-api, api
44
Requires at least: 4.6
55
Tested up to: 4.8
6-
Stable tag: 0.6.0
6+
Stable tag: 0.7.0
77
License: GPLv2 or later
88
License URI: http://www.gnu.org/licenses/gpl-2.0.html
99

@@ -25,6 +25,9 @@ This section describes how to install the plugin and get it working.
2525

2626
== Changelog ==
2727

28+
= 0.7.0 =
29+
* Fix - disable jetpack sync during rest api requests to avoid slow responses
30+
2831
= 0.6.0 =
2932
* Fix value default return on settings endpoints
3033
* Fix broken variation image set

wc-api-dev.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Plugin Name: WooCommerce API Dev
44
* Plugin URI: https://woocommerce.com/
55
* Description: A feature plugin providing a bleeding edge version of the WooCommerce REST API.
6-
* Version: 0.6.0
6+
* Version: 0.7.0
77
* Author: Automattic
88
* Author URI: https://woocommerce.com
99
* Requires at least: 4.4
@@ -117,6 +117,9 @@ public function includes() {
117117
include_once( dirname( __FILE__ ) . '/api/class-wc-rest-dev-system-status-tools-controller.php' );
118118
include_once( dirname( __FILE__ ) . '/api/class-wc-rest-dev-shipping-methods-controller.php' );
119119
include_once( dirname( __FILE__ ) . '/api/class-wc-rest-dev-payment-gateways-controller.php' );
120+
121+
// Things that aren't related to a specific endpoint but to things like cross-plugin compatibility
122+
include_once( dirname( __FILE__ ) . '/hotfixes/wc-api-dev-jetpack-hotfixes.php' );
120123
}
121124

122125
/**

0 commit comments

Comments
 (0)