PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.7
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.7
16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 All 506 releases
← All changes | jetpack_vendor/automattic/jetpack-sync/src/modules/class-options.php +70 -5 13.7.2 → 16.3-a.7 View file →
@@ -9,8 +9,12 @@
9 9
10 10 use Automattic\Jetpack\Sync\Defaults;
11 11 use Automattic\Jetpack\Sync\Settings;
12 12
13 +if ( ! defined( 'ABSPATH' ) ) {
14 + exit( 0 );
15 +}
16 +
13 17 /**
14 18 * Class to handle sync for options.
15 19 */
16 20 class Options extends Module {
@@ -109,8 +113,9 @@
109 113 */
110 114 public function set_late_default() {
111 115 /** This filter is already documented in json-endpoints/jetpack/class.wpcom-json-api-get-option-endpoint.php */
112 116 $late_options = apply_filters( 'jetpack_options_whitelist', array() );
117 + $late_options = apply_filters( 'jetpack_sync_options_whitelist', $late_options );
113 118 if ( ! empty( $late_options ) && is_array( $late_options ) ) {
114 119 $this->options_whitelist = array_merge( $this->options_whitelist, $late_options );
115 120 }
116 121 }
@@ -171,19 +176,25 @@
171 176 *
172 177 * @access public
173 178 *
174 179 * @param array $config Full sync configuration for this sync module.
180 + * @param array $status This module Full Sync status.
175 181 * @param int $send_until The timestamp until the current request can send.
176 - * @param array $state This module Full Sync status.
182 + * @param int $started The timestamp when the full sync started.
177 183 *
178 184 * @return array This module Full Sync status.
179 185 */
180 - public function send_full_sync_actions( $config, $send_until, $state ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
186 + public function send_full_sync_actions( $config, $status, $send_until, $started ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
181 187 // we call this instead of do_action when sending immediately.
182 - $this->send_action( 'jetpack_full_sync_options', array( true ) );
188 + $result = $this->send_action( 'jetpack_full_sync_options', array( true ) );
183 189
184 - // The number of actions enqueued, and next module state (true == done).
185 - return array( 'finished' => true );
190 + if ( is_wp_error( $result ) ) {
191 + $status['error'] = true;
192 + return $status;
193 + }
194 + $status['finished'] = true;
195 + $status['sent'] = $status['total'];
196 + return $status;
186 197 }
187 198
188 199 /**
189 200 * Retrieve an estimated number of actions that will be enqueued.
@@ -306,8 +317,17 @@
306 317 if ( ! $this->is_whitelisted_option( $args[0] ) ) {
307 318 return false;
308 319 }
309 320
321 + // Check if 'jetpack_options' were updated and reject if the change affected only blacklisted keys.
322 + if ( 'jetpack_options' === $args[0] && 3 === count( $args ) ) {
323 + if ( ! $this->should_enqueue_jetpack_options_update( $args[1], $args[2] ) ) {
324 + return false;
325 + }
326 +
327 + return $args;
328 + }
329 +
310 330 // Filter our weird array( false ) value for theme_mods_*.
311 331 if ( str_starts_with( $args[0], 'theme_mods_' ) ) {
312 332 $this->filter_theme_mods( $args[1] );
313 333 if ( isset( $args[2] ) ) {
@@ -475,6 +495,51 @@
475 495 }
476 496 }
477 497
478 498 return 'OPTION-DOES-NOT-EXIST';
499 + }
500 +
501 + /**
502 + * Check if 'jetpack_options' option update should be processed based on excluded keys.
503 + *
504 + * @param mixed $old_value The old option value.
505 + * @param mixed $value The new option value.
506 + * @return bool False if only excluded keys changed (or no change), true otherwise.
507 + */
508 + private function should_enqueue_jetpack_options_update( $old_value, $value ) {
509 + // No changes at all.
510 + if ( $old_value === $value ) {
511 + return false;
512 + }
513 + // Values are different but not both arrays - meaningful change.
514 + if ( ! is_array( $old_value ) || ! is_array( $value ) ) {
515 + return true;
516 + }
517 + // Determine all top-level keys present in either the old or new value.
518 + $all_keys = array_unique(
519 + array_merge(
520 + array_keys( $old_value ),
521 + array_keys( $value )
522 + )
523 + );
524 + // Short-circuit as soon as we find a changed key that is not blacklisted.
525 + foreach ( $all_keys as $key ) {
526 + $old_has_key = array_key_exists( $key, $old_value );
527 + $new_has_key = array_key_exists( $key, $value );
528 + // Key was added or removed.
529 + if ( ! $old_has_key || ! $new_has_key ) {
530 + if ( ! in_array( $key, Defaults::$jetpack_options_blacklist, true ) ) {
531 + return true;
532 + }
533 + continue;
534 + }
535 + // Key exists in both arrays but the value changed.
536 + if ( $old_value[ $key ] !== $value[ $key ] ) {
537 + if ( ! in_array( $key, Defaults::$jetpack_options_blacklist, true ) ) {
538 + return true;
539 + }
540 + }
541 + }
542 + // Either there were no effective changes, or all changed keys are excluded.
543 + return false;
479 544 }
480 545 }