Code Duplication    Length = 33-35 lines in 2 locations

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

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

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

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