Code Duplication    Length = 33-35 lines in 2 locations

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

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

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

@@ 64-96 (lines=33) @@
61
		return array( 'jetpack_full_sync_constants' );
62
	}
63
64
	function maybe_sync_constants() {
65
		if ( get_transient( self::CONSTANTS_AWAIT_TRANSIENT_NAME ) ) {
66
			return;
67
		}
68
69
		$constants = $this->get_all_constants();
70
		if ( empty( $constants ) ) {
71
			return;
72
		}
73
74
		set_transient( self::CONSTANTS_AWAIT_TRANSIENT_NAME, microtime( true ), Jetpack_Sync_Defaults::$default_sync_constants_wait_time );
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() {