Code Duplication    Length = 33-35 lines in 2 locations

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

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

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

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