updated plugin Jetpack Protect
version 2.1.0
This commit is contained in:
@ -5,6 +5,48 @@ All notable changes to this project will be documented in this file.
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [2.10.1] - 2024-03-14
|
||||
### Changed
|
||||
- Internal updates.
|
||||
|
||||
## [2.10.0] - 2024-03-12
|
||||
### Added
|
||||
- Sync:Now Sync uses rest api endpoint for enabled sites [#36210]
|
||||
|
||||
## [2.9.0] - 2024-03-04
|
||||
### Added
|
||||
- Sync: Add feature flag for enabling the use of rest api for sending the sync data [#36118]
|
||||
- Whitelist the new wpcom_classic_early_release site option [#36111]
|
||||
|
||||
## [2.8.1] - 2024-03-01
|
||||
### Fixed
|
||||
- Jetpack Sync: Ensure Woo HPOS order date fields are properly encoded [#36023]
|
||||
|
||||
## [2.8.0] - 2024-02-22
|
||||
### Added
|
||||
- Ads Settings: Include option to toggle GDPR Consent Banner [#35205]
|
||||
|
||||
## [2.7.0] - 2024-02-19
|
||||
### Changed
|
||||
- Add jetpack_newsletters_publishing_default_frequency to Sync [#35672]
|
||||
|
||||
## [2.6.1] - 2024-02-13
|
||||
### Changed
|
||||
- Internal updates.
|
||||
|
||||
## [2.6.0] - 2024-02-12
|
||||
### Added
|
||||
- Added a new site setting option for opting out of research partners using your site's content. [#35509]
|
||||
|
||||
## [2.5.1] - 2024-02-07
|
||||
### Changed
|
||||
- Update dependencies.
|
||||
|
||||
## [2.5.0] - 2024-02-05
|
||||
### Changed
|
||||
- Jetpack Connection: Add jetpack_package_versions to Sync [#35409]
|
||||
- Jetpack Sync: Disable Sync sending while a Pull is in progress [#35339]
|
||||
|
||||
## [2.4.2] - 2024-01-18
|
||||
### Changed
|
||||
- Update dependencies.
|
||||
@ -1030,6 +1072,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
- Packages: Move sync to a classmapped package
|
||||
|
||||
[2.10.1]: https://github.com/Automattic/jetpack-sync/compare/v2.10.0...v2.10.1
|
||||
[2.10.0]: https://github.com/Automattic/jetpack-sync/compare/v2.9.0...v2.10.0
|
||||
[2.9.0]: https://github.com/Automattic/jetpack-sync/compare/v2.8.1...v2.9.0
|
||||
[2.8.1]: https://github.com/Automattic/jetpack-sync/compare/v2.8.0...v2.8.1
|
||||
[2.8.0]: https://github.com/Automattic/jetpack-sync/compare/v2.7.0...v2.8.0
|
||||
[2.7.0]: https://github.com/Automattic/jetpack-sync/compare/v2.6.1...v2.7.0
|
||||
[2.6.1]: https://github.com/Automattic/jetpack-sync/compare/v2.6.0...v2.6.1
|
||||
[2.6.0]: https://github.com/Automattic/jetpack-sync/compare/v2.5.1...v2.6.0
|
||||
[2.5.1]: https://github.com/Automattic/jetpack-sync/compare/v2.5.0...v2.5.1
|
||||
[2.5.0]: https://github.com/Automattic/jetpack-sync/compare/v2.4.2...v2.5.0
|
||||
[2.4.2]: https://github.com/Automattic/jetpack-sync/compare/v2.4.1...v2.4.2
|
||||
[2.4.1]: https://github.com/Automattic/jetpack-sync/compare/v2.4.0...v2.4.1
|
||||
[2.4.0]: https://github.com/Automattic/jetpack-sync/compare/v2.3.0...v2.4.0
|
||||
|
@ -5,16 +5,16 @@
|
||||
"license": "GPL-2.0-or-later",
|
||||
"require": {
|
||||
"php": ">=7.0",
|
||||
"automattic/jetpack-connection": "^2.2.0",
|
||||
"automattic/jetpack-constants": "^2.0.0",
|
||||
"automattic/jetpack-identity-crisis": "^0.15.0",
|
||||
"automattic/jetpack-password-checker": "^0.3.0",
|
||||
"automattic/jetpack-ip": "^0.2.1",
|
||||
"automattic/jetpack-roles": "^2.0.0",
|
||||
"automattic/jetpack-status": "^2.0.2"
|
||||
"automattic/jetpack-connection": "^2.4.1",
|
||||
"automattic/jetpack-constants": "^2.0.1",
|
||||
"automattic/jetpack-identity-crisis": "^0.17.3",
|
||||
"automattic/jetpack-password-checker": "^0.3.1",
|
||||
"automattic/jetpack-ip": "^0.2.2",
|
||||
"automattic/jetpack-roles": "^2.0.1",
|
||||
"automattic/jetpack-status": "^2.1.2"
|
||||
},
|
||||
"require-dev": {
|
||||
"automattic/jetpack-changelogger": "^4.0.5",
|
||||
"automattic/jetpack-changelogger": "^4.1.1",
|
||||
"yoast/phpunit-polyfills": "1.1.0",
|
||||
"automattic/wordbless": "@dev"
|
||||
},
|
||||
@ -49,7 +49,7 @@
|
||||
"link-template": "https://github.com/Automattic/jetpack-sync/compare/v${old}...v${new}"
|
||||
},
|
||||
"branch-alias": {
|
||||
"dev-trunk": "2.4.x-dev"
|
||||
"dev-trunk": "2.10.x-dev"
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
namespace Automattic\Jetpack\Sync;
|
||||
|
||||
use Automattic\Jetpack\Connection\Client;
|
||||
use Automattic\Jetpack\Connection\Manager as Jetpack_Connection;
|
||||
use Automattic\Jetpack\Constants;
|
||||
use Automattic\Jetpack\Identity_Crisis;
|
||||
@ -415,7 +416,7 @@ class Actions {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends data to WordPress.com via an XMLRPC request.
|
||||
* Sends data to WordPress.com via an XMLRPC or a REST API request based on the settings.
|
||||
*
|
||||
* @access public
|
||||
* @static
|
||||
@ -433,6 +434,7 @@ class Actions {
|
||||
public static function send_data( $data, $codec_name, $sent_timestamp, $queue_id, $checkout_duration, $preprocess_duration, $queue_size = null, $buffer_id = null ) {
|
||||
|
||||
$query_args = array(
|
||||
|
||||
'sync' => '1', // Add an extra parameter to the URL so we can tell it's a sync action.
|
||||
'codec' => $codec_name,
|
||||
'timestamp' => $sent_timestamp,
|
||||
@ -462,32 +464,57 @@ class Actions {
|
||||
*/
|
||||
$query_args = apply_filters( 'jetpack_sync_send_data_query_args', $query_args );
|
||||
|
||||
$connection = new Jetpack_Connection();
|
||||
$url = add_query_arg( $query_args, $connection->xmlrpc_api_url() );
|
||||
$retry_after_header = false;
|
||||
$dedicated_sync_header = false;
|
||||
|
||||
// If we're currently updating to Jetpack 7.7, the IXR client may be missing briefly
|
||||
// because since 7.7 it's being autoloaded with Composer.
|
||||
if ( ! class_exists( '\\Jetpack_IXR_Client' ) ) {
|
||||
return new WP_Error(
|
||||
'ixr_client_missing',
|
||||
esc_html__( 'Sync has been aborted because the IXR client is missing.', 'jetpack-sync' )
|
||||
// If REST API is enabled, use it.
|
||||
if ( Settings::is_wpcom_rest_api_enabled() ) {
|
||||
$jsonl_data = self::prepare_jsonl_data( $data );
|
||||
$url = '/sites/' . \Jetpack_Options::get_option( 'id' ) . '/jetpack-sync-actions';
|
||||
$url = add_query_arg( $query_args, $url );
|
||||
$args = array(
|
||||
'method' => 'POST',
|
||||
'format' => 'jsonl',
|
||||
'timeout' => $query_args['timeout'],
|
||||
);
|
||||
|
||||
$response = Client::wpcom_json_api_request_as_blog( $url, '2', $args, $jsonl_data, 'wpcom' );
|
||||
$retry_after_header = wp_remote_retrieve_header( $response, 'Retry-After' ) ? wp_remote_retrieve_header( $response, 'Retry-After' ) : false;
|
||||
$dedicated_sync_header = wp_remote_retrieve_header( $response, 'Jetpack-Dedicated-Sync' ) ? wp_remote_retrieve_header( $response, 'Jetpack-Dedicated-Sync' ) : false;
|
||||
$response = self::process_rest_api_response( $response );
|
||||
} else { // Use XML-RPC.
|
||||
$connection = new Jetpack_Connection();
|
||||
$url = add_query_arg( $query_args, $connection->xmlrpc_api_url() );
|
||||
|
||||
// If we're currently updating to Jetpack 7.7, the IXR client may be missing briefly
|
||||
// because since 7.7 it's being autoloaded with Composer.
|
||||
if ( ! class_exists( '\\Jetpack_IXR_Client' ) ) {
|
||||
return new WP_Error(
|
||||
'ixr_client_missing',
|
||||
esc_html__( 'Sync has been aborted because the IXR client is missing.', 'jetpack-sync' )
|
||||
);
|
||||
}
|
||||
|
||||
$rpc = new \Jetpack_IXR_Client(
|
||||
array(
|
||||
'url' => $url,
|
||||
'timeout' => $query_args['timeout'],
|
||||
)
|
||||
);
|
||||
$result = $rpc->query( 'jetpack.syncActions', $data );
|
||||
$retry_after_header = $rpc->get_response_header( 'Retry-After' );
|
||||
$dedicated_sync_header = $rpc->get_response_header( 'Jetpack-Dedicated-Sync' );
|
||||
if ( $result ) {
|
||||
$response = $rpc->getResponse();
|
||||
} else {
|
||||
$response = $rpc->get_jetpack_error();
|
||||
}
|
||||
}
|
||||
|
||||
$rpc = new \Jetpack_IXR_Client(
|
||||
array(
|
||||
'url' => $url,
|
||||
'timeout' => $query_args['timeout'],
|
||||
)
|
||||
);
|
||||
|
||||
$result = $rpc->query( 'jetpack.syncActions', $data );
|
||||
|
||||
// Adhere to Retry-After headers.
|
||||
$retry_after = $rpc->get_response_header( 'Retry-After' );
|
||||
if ( false !== $retry_after ) {
|
||||
if ( (int) $retry_after > 0 ) {
|
||||
update_option( self::RETRY_AFTER_PREFIX . $queue_id, microtime( true ) + (int) $retry_after, false );
|
||||
// Adhere to Retry-After headers.
|
||||
if ( false !== $retry_after_header ) {
|
||||
if ( (int) $retry_after_header > 0 ) {
|
||||
update_option( self::RETRY_AFTER_PREFIX . $queue_id, microtime( true ) + (int) $retry_after_header, false );
|
||||
} else {
|
||||
// if unexpected value default to 3 minutes.
|
||||
update_option( self::RETRY_AFTER_PREFIX . $queue_id, microtime( true ) + 180, false );
|
||||
@ -495,13 +522,13 @@ class Actions {
|
||||
}
|
||||
|
||||
// Enable/Disable Dedicated Sync flow via response headers.
|
||||
$dedicated_sync_header = $rpc->get_response_header( 'Jetpack-Dedicated-Sync' );
|
||||
if ( false !== $dedicated_sync_header ) {
|
||||
Dedicated_Sender::maybe_change_dedicated_sync_status_from_wpcom_header( $dedicated_sync_header );
|
||||
}
|
||||
|
||||
if ( ! $result ) {
|
||||
if ( false === $retry_after ) {
|
||||
if ( is_wp_error( $response ) ) {
|
||||
$error = $response;
|
||||
if ( false === $retry_after_header ) {
|
||||
// We received a non standard response from WP.com, lets backoff from sending requests for 1 minute.
|
||||
update_option( self::RETRY_AFTER_PREFIX . $queue_id, microtime( true ) + 60, false );
|
||||
}
|
||||
@ -515,18 +542,18 @@ class Actions {
|
||||
$error_log = array_slice( $error_log, -4, null, true );
|
||||
}
|
||||
// Add new error indexed to time.
|
||||
$error = $rpc->get_jetpack_error();
|
||||
$error->add_data( $rpc->get_last_response() );
|
||||
$error_log[ (string) microtime( true ) ] = $error;
|
||||
if ( Settings::is_wpcom_rest_api_enabled() ) {
|
||||
$error_log[ (string) microtime( true ) ] = $error;
|
||||
} else {
|
||||
$error_with_last_response = clone $error;
|
||||
$error_with_last_response->add_data( $rpc->get_last_response() );
|
||||
$error_log[ (string) microtime( true ) ] = $error_with_last_response;
|
||||
}
|
||||
// Update the error log.
|
||||
update_option( self::ERROR_LOG_PREFIX . $queue_id, $error_log );
|
||||
|
||||
// return request error.
|
||||
return $rpc->get_jetpack_error();
|
||||
return $error;
|
||||
}
|
||||
|
||||
$response = $rpc->getResponse();
|
||||
|
||||
// Check if WordPress.com IDC mitigation blocked the sync request.
|
||||
if ( Identity_Crisis::init()->check_response_for_idc( $response ) ) {
|
||||
return new WP_Error(
|
||||
@ -535,6 +562,10 @@ class Actions {
|
||||
);
|
||||
}
|
||||
|
||||
if ( Settings::is_wpcom_rest_api_enabled() ) { // Return only processed items.
|
||||
$response = $response['processed_items'];
|
||||
}
|
||||
|
||||
// Record last successful sync.
|
||||
update_option( self::LAST_SUCCESS_PREFIX . $queue_id, microtime( true ), false );
|
||||
|
||||
@ -1086,6 +1117,8 @@ class Actions {
|
||||
// Dedicated sync locks.
|
||||
\Jetpack_Options::delete_raw_option( Dedicated_Sender::DEDICATED_SYNC_REQUEST_LOCK_OPTION_NAME );
|
||||
delete_transient( Dedicated_Sender::DEDICATED_SYNC_TEMPORARY_DISABLE_FLAG );
|
||||
// Lock for disabling Sync sending temporarily.
|
||||
delete_transient( Sender::TEMP_SYNC_DISABLE_TRANSIENT_NAME );
|
||||
|
||||
// Queue locks.
|
||||
// Note that we are just unlocking the queues here, not reseting them.
|
||||
@ -1097,4 +1130,59 @@ class Actions {
|
||||
$full_sync_queue->unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare JSONL data.
|
||||
*
|
||||
* @param mixed $data The data to be prepared.
|
||||
*
|
||||
* @return string The prepared JSONL data.
|
||||
*/
|
||||
private static function prepare_jsonl_data( $data ) {
|
||||
$jsonl_data = implode(
|
||||
"\n",
|
||||
array_map(
|
||||
function ( $key, $value ) {
|
||||
return wp_json_encode( array( $key => $value ) );
|
||||
},
|
||||
array_keys( (array) $data ),
|
||||
array_values( (array) $data )
|
||||
)
|
||||
);
|
||||
return $jsonl_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to process the API response.
|
||||
*
|
||||
* @param mixed $response The response from the API.
|
||||
* @return array|Wp_Error Array for successful response or a WP_Error object.
|
||||
*/
|
||||
private static function process_rest_api_response( $response ) {
|
||||
|
||||
$response_code = wp_remote_retrieve_response_code( $response );
|
||||
$response_body = wp_remote_retrieve_body( $response );
|
||||
if ( is_wp_error( $response ) ) {
|
||||
return $response;
|
||||
}
|
||||
$decoded_response = json_decode( $response_body, true );
|
||||
|
||||
if ( false === is_array( $decoded_response ) ) {
|
||||
return new WP_Error( 'sync_rest_api_response_decoding_failed', 'Sync REST API response decoding failed', $response_body );
|
||||
}
|
||||
|
||||
if ( $response_code !== 200 || false === isset( $decoded_response['processed_items'] ) ) {
|
||||
if ( is_array( $decoded_response ) && isset( $decoded_response['code'] ) && isset( $decoded_response['message'] ) ) {
|
||||
return new WP_Error(
|
||||
'jetpack_sync_send_error_' . $decoded_response['code'],
|
||||
$decoded_response['message'],
|
||||
$decoded_response['data'] ?? null
|
||||
);
|
||||
} else {
|
||||
return new WP_Error( $response_code, 'Sync REST API request failed', $response_body );
|
||||
}
|
||||
} else {
|
||||
return $decoded_response;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -69,10 +69,12 @@ class Data_Settings {
|
||||
'jetpack_sync_settings_taxonomies_blacklist',
|
||||
'jetpack_sync_settings_dedicated_sync_enabled',
|
||||
'jetpack_sync_settings_custom_queue_table_enabled',
|
||||
'jetpack_sync_settings_wpcom_rest_api_enabled',
|
||||
/**
|
||||
* Connection related options
|
||||
*/
|
||||
'jetpack_connection_active_plugins',
|
||||
'jetpack_package_versions',
|
||||
/**
|
||||
* Generic site options
|
||||
*/
|
||||
|
@ -28,6 +28,7 @@ class Defaults {
|
||||
'avatar_rating',
|
||||
'blog_charset',
|
||||
'blog_public',
|
||||
'wpcom_data_sharing_opt_out',
|
||||
'blogdescription',
|
||||
'blogname',
|
||||
'carousel_background_color',
|
||||
@ -99,6 +100,7 @@ class Defaults {
|
||||
'jetpack_sync_settings_taxonomies_blacklist',
|
||||
'jetpack_sync_settings_dedicated_sync_enabled', // is Dedicated Sync flow enabled.
|
||||
'jetpack_sync_settings_custom_queue_table_enabled', // is custom queue table enabled.
|
||||
'jetpack_sync_settings_wpcom_rest_api_enabled', // is wpcom rest api enabled.
|
||||
'jetpack_testimonial',
|
||||
'jetpack_testimonial_posts_per_page',
|
||||
'jetpack_wga',
|
||||
@ -166,6 +168,7 @@ class Defaults {
|
||||
'videopress_private_enabled_for_site',
|
||||
'wordads_ccpa_enabled',
|
||||
'wordads_ccpa_privacy_policy_url',
|
||||
'wordads_cmp_enabled',
|
||||
'wordads_custom_adstxt',
|
||||
'wordads_custom_adstxt_enabled',
|
||||
'wordads_display_archive',
|
||||
@ -179,6 +182,7 @@ class Defaults {
|
||||
'wp_mobile_featured_images',
|
||||
'wp_page_for_privacy_policy',
|
||||
'wpcom_ai_site_prompt',
|
||||
'wpcom_classic_early_release',
|
||||
'wpcom_featured_image_in_email',
|
||||
'wpcom_gifting_subscription',
|
||||
'wpcom_is_fse_activated',
|
||||
@ -193,6 +197,8 @@ class Defaults {
|
||||
'wpcom_subscription_emails_use_excerpt',
|
||||
'jetpack_verbum_subscription_modal',
|
||||
'jetpack_blocks_disabled',
|
||||
'jetpack_package_versions',
|
||||
'jetpack_newsletters_publishing_default_frequency',
|
||||
);
|
||||
|
||||
/**
|
||||
@ -437,6 +443,8 @@ class Defaults {
|
||||
'wp_log', // WP Logging Plugin.
|
||||
'wpephpcompat_jobs',
|
||||
'wprss_feed_item',
|
||||
'memberships_coupon',
|
||||
'memberships_gift',
|
||||
);
|
||||
|
||||
/**
|
||||
@ -1317,4 +1325,11 @@ class Defaults {
|
||||
* @var int Bool-ish. Default 0.
|
||||
*/
|
||||
public static $default_custom_queue_table_enabled = 0;
|
||||
|
||||
/**
|
||||
* Default for enabling wpcom rest api for Sync.
|
||||
*
|
||||
* @var int Bool-ish. Default 0.
|
||||
*/
|
||||
public static $default_wpcom_rest_api_enabled = 0;
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ namespace Automattic\Jetpack\Sync;
|
||||
*/
|
||||
class Package_Version {
|
||||
|
||||
const PACKAGE_VERSION = '2.4.2';
|
||||
const PACKAGE_VERSION = '2.10.1';
|
||||
|
||||
const PACKAGE_SLUG = 'sync';
|
||||
|
||||
|
@ -622,7 +622,16 @@ class REST_Endpoints {
|
||||
return rest_ensure_response( $sender->immediate_full_sync_pull( $number_of_items ) );
|
||||
}
|
||||
|
||||
return rest_ensure_response( $sender->queue_pull( $queue_name, $number_of_items, $args ) );
|
||||
$response = $sender->queue_pull( $queue_name, $number_of_items, $args );
|
||||
// Disable sending while pulling.
|
||||
if ( ! is_wp_error( $response ) ) {
|
||||
set_transient( Sender::TEMP_SYNC_DISABLE_TRANSIENT_NAME, time(), Sender::TEMP_SYNC_DISABLE_TRANSIENT_EXPIRY );
|
||||
} elseif ( 'queue_size' === $response->get_error_code() ) {
|
||||
// Re-enable sending if the queue is empty.
|
||||
delete_transient( Sender::TEMP_SYNC_DISABLE_TRANSIENT_NAME );
|
||||
}
|
||||
|
||||
return rest_ensure_response( $response );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -24,6 +24,24 @@ class Sender {
|
||||
*/
|
||||
const NEXT_SYNC_TIME_OPTION_NAME = 'jetpack_next_sync_time';
|
||||
|
||||
/**
|
||||
* Name of the transient responsible for temprorarily disabling Sync sending during Pulls.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const TEMP_SYNC_DISABLE_TRANSIENT_NAME = 'jetpack_disable_sync_sending';
|
||||
|
||||
/**
|
||||
* Expiry of the transient responsible for temprorarily disabling Sync sending during Pulls.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const TEMP_SYNC_DISABLE_TRANSIENT_EXPIRY = MINUTE_IN_SECONDS;
|
||||
|
||||
/**
|
||||
* Sync timeout after a WPCOM error.
|
||||
*
|
||||
@ -440,6 +458,10 @@ class Sender {
|
||||
return new WP_Error( 'sender_disabled_for_queue_' . $queue->id );
|
||||
}
|
||||
|
||||
if ( get_transient( self::TEMP_SYNC_DISABLE_TRANSIENT_NAME ) ) {
|
||||
return new WP_Error( 'sender_temporarily_disabled_while_pulling' );
|
||||
}
|
||||
|
||||
// Return early if we've gotten a retry-after header response.
|
||||
$retry_time = get_option( Actions::RETRY_AFTER_PREFIX . $queue->id );
|
||||
if ( $retry_time ) {
|
||||
|
@ -61,6 +61,7 @@ class Settings {
|
||||
'checksum_disable' => true,
|
||||
'dedicated_sync_enabled' => true,
|
||||
'custom_queue_table_enabled' => true,
|
||||
'wpcom_rest_api_enabled' => true,
|
||||
);
|
||||
|
||||
/**
|
||||
@ -300,6 +301,26 @@ class Settings {
|
||||
update_option( self::SETTINGS_OPTION_PREFIX . $setting, 0, true );
|
||||
}
|
||||
}
|
||||
|
||||
// Do not enable wpcom rest api if we cannot send a test request.
|
||||
|
||||
if ( 'wpcom_rest_api_enabled' === $setting && $updated && (bool) $value ) {
|
||||
$sender = Sender::get_instance();
|
||||
$data = array(
|
||||
'timestamp' => microtime( true ),
|
||||
);
|
||||
$items = $sender->send_action( 'jetpack_sync_wpcom_rest_api_enable_test', $data );
|
||||
// If we can't send a test request, disable the setting and send action tolog the error.
|
||||
if ( is_wp_error( $items ) ) {
|
||||
update_option( self::SETTINGS_OPTION_PREFIX . $setting, 0, true );
|
||||
$data = array(
|
||||
'timestamp' => microtime( true ),
|
||||
'response_code' => $items->get_error_code(),
|
||||
'response_body' => $items->get_error_data() ? trim( $items->get_error_data() ) : '',
|
||||
);
|
||||
$sender->send_action( 'jetpack_sync_wpcom_rest_api_enable_error', $data );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -678,4 +699,16 @@ class Settings {
|
||||
public static function is_custom_queue_table_enabled() {
|
||||
return (bool) self::get_setting( 'custom_queue_table_enabled' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether wpcom rest api is enabled.
|
||||
*
|
||||
* @access public
|
||||
* @static
|
||||
*
|
||||
* @return boolean Whether wpcom rest api is enabled.
|
||||
*/
|
||||
public static function is_wpcom_rest_api_enabled() {
|
||||
return (bool) self::get_setting( 'wpcom_rest_api_enabled' );
|
||||
}
|
||||
}
|
||||
|
@ -127,9 +127,9 @@ class Users extends Module {
|
||||
add_action( 'jetpack_removed_user_from_blog', $callable, 10, 2 );
|
||||
|
||||
// User roles.
|
||||
add_action( 'add_user_role', array( $this, 'save_user_role_handler' ), 10, 2 );
|
||||
add_action( 'add_user_role', array( $this, 'add_user_role_handler' ), 10, 2 );
|
||||
add_action( 'set_user_role', array( $this, 'save_user_role_handler' ), 10, 3 );
|
||||
add_action( 'remove_user_role', array( $this, 'save_user_role_handler' ), 10, 2 );
|
||||
add_action( 'remove_user_role', array( $this, 'remove_user_role_handler' ), 10, 2 );
|
||||
|
||||
// User capabilities.
|
||||
add_action( 'added_user_meta', array( $this, 'maybe_save_user_meta' ), 10, 4 );
|
||||
@ -512,6 +512,9 @@ class Users extends Module {
|
||||
if ( false === $user->has_prop( $user_field ) ) {
|
||||
continue;
|
||||
}
|
||||
if ( 'ID' === $user_field ) {
|
||||
continue;
|
||||
}
|
||||
if ( $user->$user_field !== $field_value ) {
|
||||
if ( 'user_email' === $user_field ) {
|
||||
/**
|
||||
@ -547,6 +550,44 @@ class Users extends Module {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler for add user role change.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param int $user_id ID of the user.
|
||||
* @param string $role New user role.
|
||||
*/
|
||||
public function add_user_role_handler( $user_id, $role ) {
|
||||
$this->add_flags(
|
||||
$user_id,
|
||||
array(
|
||||
'role_added' => $role,
|
||||
)
|
||||
);
|
||||
|
||||
$this->save_user_role_handler( $user_id, $role );
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler for remove user role change.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param int $user_id ID of the user.
|
||||
* @param string $role Removed user role.
|
||||
*/
|
||||
public function remove_user_role_handler( $user_id, $role ) {
|
||||
$this->add_flags(
|
||||
$user_id,
|
||||
array(
|
||||
'role_removed' => $role,
|
||||
)
|
||||
);
|
||||
|
||||
$this->save_user_role_handler( $user_id, $role );
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler for user role change.
|
||||
*
|
||||
|
@ -254,6 +254,18 @@ class WooCommerce_HPOS_Orders extends Module {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* We need to convert the WC_DateTime objects to stdClass objects to ensure they are properly encoded.
|
||||
*
|
||||
* @see Automattic\Jetpack\Sync\Functions::json_wrap as the return value of get_object_vars can vary depending on PHP version.
|
||||
*/
|
||||
if ( in_array( $key, array( 'date_created', 'date_modified', 'date_paid', 'date_completed' ), true ) ) {
|
||||
if ( is_a( $order_data[ $key ], 'WC_DateTime' ) ) {
|
||||
$filtered_order_data[ $key ] = (object) (array) $order_data[ $key ];
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $order_data[ $key ] ) ) {
|
||||
$filtered_order_data[ $key ] = $order_data[ $key ];
|
||||
continue;
|
||||
|
Reference in New Issue
Block a user