Code Duplication    Length = 33-34 lines in 3 locations

sync/class.jetpack-sync-module-constants.php 1 location

@@ 63-96 (lines=34) @@
60
		return array( 'jetpack_full_sync_constants' );
61
	}
62
63
	function maybe_sync_constants() {
64
		if ( get_transient( self::CONSTANTS_AWAIT_TRANSIENT_NAME ) ) {
65
			return;
66
		}
67
68
		set_transient( self::CONSTANTS_AWAIT_TRANSIENT_NAME, microtime( true ), Jetpack_Sync_Defaults::$default_sync_constants_wait_time );
69
70
		$constants = $this->get_all_constants();
71
		if ( empty( $constants ) ) {
72
			return;
73
		}
74
75
		$constants_checksums = (array) get_option( self::CONSTANTS_CHECKSUM_OPTION_NAME, array() );
76
77
		foreach ( $constants as $name => $value ) {
78
			$checksum = $this->get_check_sum( $value );
79
			// explicitly not using Identical comparison as get_option returns a string
80
			if ( ! $this->still_valid_checksum( $constants_checksums, $name, $checksum ) && ! is_null( $value ) ) {
81
				/**
82
				 * Tells the client to sync a constant to the server
83
				 *
84
				 * @since 4.2.0
85
				 *
86
				 * @param string The name of the constant
87
				 * @param mixed The value of the constant
88
				 */
89
				do_action( 'jetpack_sync_constant', $name, $value );
90
				$constants_checksums[ $name ] = $checksum;
91
			} else {
92
				$constants_checksums[ $name ] = $checksum;
93
			}
94
		}
95
		update_option( self::CONSTANTS_CHECKSUM_OPTION_NAME, $constants_checksums );
96
	}
97
98
	// public so that we don't have to store an option for each constant
99
	function get_all_constants() {

sync/class.jetpack-sync-module-network-options.php 1 location

@@ 48-80 (lines=33) @@
45
		add_action( 'jetpack_sync_before_send_queue_sync', array( $this, 'maybe_sync_network_options' ) );
46
	}
47
48
	function maybe_sync_network_options() {
49
		if ( get_site_transient( self::OPTIONS_AWAIT_TRANSIENT_NAME ) ) {
50
			return;
51
		}
52
		set_site_transient( self::OPTIONS_AWAIT_TRANSIENT_NAME, microtime( true ), Jetpack_Sync_Defaults::$default_sync_options_wait_time );
53
54
		$options = $this->get_all_network_options();
55
		if ( empty( $options ) ) {
56
			return;
57
		}
58
59
		$options_checksums = (array) get_site_option( self::OPTIONS_CHECKSUM_OPTION_NAME, array() );
60
61
		foreach ( $options as $name => $value ) {
62
			$checksum = $this->get_check_sum( $value );
63
			// explicitly not using Identical comparison as get_option returns a string
64
			if ( ! $this->still_valid_checksum( $options_checksums, $name, $checksum ) && ! is_null( $value ) ) {
65
				/**
66
				 * Tells the client to sync an option to the server
67
				 *
68
				 * @since 5.3.0
69
				 *
70
				 * @param string The name of the constant
71
				 * @param mixed The value of the constant
72
				 */
73
				do_action( 'jetpack_sync_network_option', $name, $value );
74
				$options_checksums[ $name ] = $checksum;
75
			} else {
76
				$options_checksums[ $name ] = $checksum;
77
			}
78
		}
79
		update_site_option( self::OPTIONS_CHECKSUM_OPTION_NAME, $options_checksums );
80
	}
81
82
	public function set_defaults() {
83
		$this->network_options_whitelist = Jetpack_Sync_Defaults::get_network_options_whitelist();

sync/class.jetpack-sync-module-options.php 1 location

@@ 31-64 (lines=34) @@
28
29
	}
30
31
	function maybe_sync_options() {
32
		if ( get_transient( self::OPTIONS_AWAIT_TRANSIENT_NAME ) ) {
33
			return;
34
		}
35
36
		set_transient( self::OPTIONS_AWAIT_TRANSIENT_NAME, microtime( true ), Jetpack_Sync_Defaults::$default_sync_options_wait_time );
37
38
		$options = $this->get_all_options();
39
		if ( empty( $options ) ) {
40
			return;
41
		}
42
43
		$options_checksums = (array) get_option( self::OPTIONS_CHECKSUM_OPTION_NAME, array() );
44
45
		foreach ( $options as $name => $value ) {
46
			$checksum = $this->get_check_sum( $value );
47
			// explicitly not using Identical comparison as get_option returns a string
48
			if ( ! $this->still_valid_checksum( $options_checksums, $name, $checksum ) && ! is_null( $value ) ) {
49
				/**
50
				 * Tells the client to sync an option to the server
51
				 *
52
				 * @since 5.3.0
53
				 *
54
				 * @param string The name of the constant
55
				 * @param mixed The value of the constant
56
				 */
57
				do_action( 'jetpack_sync_option', $name, $value );
58
				$options_checksums[ $name ] = $checksum;
59
			} else {
60
				$options_checksums[ $name ] = $checksum;
61
			}
62
		}
63
		update_option( self::OPTIONS_CHECKSUM_OPTION_NAME, $options_checksums );
64
	}
65
66
	public function init_full_sync_listeners( $callable ) {
67
		add_action( 'jetpack_full_sync_options', $callable );