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

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
		$callables = $this->get_all_callables();
106
107
		if ( empty( $callables ) ) {
108
			return;
109
		}
110
111
		set_transient( self::CALLABLES_AWAIT_TRANSIENT_NAME, microtime( true ), Jetpack_Sync_Defaults::$default_sync_callables_wait_time );
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 ) {