Code Duplication    Length = 33-35 lines in 2 locations

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

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

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

@@ 100-134 (lines=35) @@
97
		delete_transient( self::CALLABLES_AWAIT_TRANSIENT_NAME );
98
	}
99
	
100
	public function maybe_sync_callables() {
101
		if ( get_transient( self::CALLABLES_AWAIT_TRANSIENT_NAME ) ) {
102
			return;
103
		}
104
105
		set_transient( self::CALLABLES_AWAIT_TRANSIENT_NAME, microtime( true ), Jetpack_Sync_Defaults::$default_sync_callables_wait_time );
106
107
		$callables = $this->get_all_callables();
108
109
		if ( empty( $callables ) ) {
110
			return;
111
		}
112
113
		$callable_checksums = (array) get_option( self::CALLABLES_CHECKSUM_OPTION_NAME, array() );
114
115
		// only send the callables that have changed
116
		foreach ( $callables as $name => $value ) {
117
			$checksum = $this->get_check_sum( $value );
118
			// explicitly not using Identical comparison as get_option returns a string
119
			if ( ! $this->still_valid_checksum( $callable_checksums, $name, $checksum ) && ! is_null( $value ) ) {
120
				/**
121
				 * Tells the client to sync a callable (aka function) to the server
122
				 *
123
				 * @since 4.2.0
124
				 *
125
				 * @param string The name of the callable
126
				 * @param mixed The value of the callable
127
				 */
128
				do_action( 'jetpack_sync_callable', $name, $value );
129
				$callable_checksums[ $name ] = $checksum;
130
			} else {
131
				$callable_checksums[ $name ] = $checksum;
132
			}
133
		}
134
		update_option( self::CALLABLES_CHECKSUM_OPTION_NAME, $callable_checksums );
135
	}
136
137
	public function expand_callables( $args ) {