Code Duplication    Length = 33-35 lines in 2 locations

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

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