Code Duplication    Length = 41-42 lines in 2 locations

projects/packages/identity-crisis/src/class-identity-crisis.php 1 location

@@ 269-309 (lines=41) @@
266
	 *
267
	 * @since 4.4.0
268
	 */
269
	public static function validate_sync_error_idc_option() {
270
		$is_valid = false;
271
272
		// Is the site opted in and does the stored sync_error_idc option match what we now generate?
273
		$sync_error = Jetpack_Options::get_option( 'sync_error_idc' );
274
		if ( $sync_error && self::sync_idc_optin() ) {
275
			$local_options = self::get_sync_error_idc_option();
276
			// Ensure all values are set.
277
			if ( isset( $sync_error['home'] ) && isset( $local_options['home'] ) && isset( $sync_error['siteurl'] ) && isset( $local_options['siteurl'] ) ) {
278
				// If the WP.com expected home and siteurl match local home and siteurl it is not valid IDC.
279
				if (
280
					isset( $sync_error['wpcom_home'] ) &&
281
					isset( $sync_error['wpcom_siteurl'] ) &&
282
					$sync_error['wpcom_home'] === $local_options['home'] &&
283
					$sync_error['wpcom_siteurl'] === $local_options['siteurl']
284
				) {
285
					$is_valid = false;
286
					// Enable migrate_for_idc so that sync actions are accepted.
287
					Jetpack_Options::update_option( 'migrate_for_idc', true );
288
				} elseif ( $sync_error['home'] === $local_options['home'] && $sync_error['siteurl'] === $local_options['siteurl'] ) {
289
					$is_valid = true;
290
				}
291
			}
292
		}
293
294
		/**
295
		 * Filters whether the sync_error_idc option is valid.
296
		 *
297
		 * @param bool $is_valid If the sync_error_idc is valid or not.
298
		 *
299
		 * @since 4.4.0
300
		 */
301
		$is_valid = (bool) apply_filters( 'jetpack_sync_error_idc_validation', $is_valid );
302
303
		if ( ! $is_valid && $sync_error ) {
304
			// Since the option exists, and did not validate, delete it.
305
			Jetpack_Options::delete_option( 'sync_error_idc' );
306
		}
307
308
		return $is_valid;
309
	}
310
311
	/**
312
	 * Normalizes a url by doing three things:

projects/plugins/jetpack/class.jetpack.php 1 location

@@ 6185-6226 (lines=42) @@
6182
	 *
6183
	 * @return bool
6184
	 */
6185
	public static function validate_sync_error_idc_option() {
6186
		$is_valid = false;
6187
6188
		// Is the site opted in and does the stored sync_error_idc option match what we now generate?
6189
		$sync_error = Jetpack_Options::get_option( 'sync_error_idc' );
6190
		if ( $sync_error && self::sync_idc_optin() ) {
6191
			$local_options = self::get_sync_error_idc_option();
6192
			// Ensure all values are set.
6193
			if ( isset( $sync_error['home'] ) && isset( $local_options['home'] ) && isset( $sync_error['siteurl'] ) && isset( $local_options['siteurl'] ) ) {
6194
6195
				// If the WP.com expected home and siteurl match local home and siteurl it is not valid IDC.
6196
				if (
6197
						isset( $sync_error['wpcom_home'] ) &&
6198
						isset( $sync_error['wpcom_siteurl'] ) &&
6199
						$sync_error['wpcom_home'] === $local_options['home'] &&
6200
						$sync_error['wpcom_siteurl'] === $local_options['siteurl']
6201
				) {
6202
					$is_valid = false;
6203
					// Enable migrate_for_idc so that sync actions are accepted.
6204
					Jetpack_Options::update_option( 'migrate_for_idc', true );
6205
				} elseif ( $sync_error['home'] === $local_options['home'] && $sync_error['siteurl'] === $local_options['siteurl'] ) {
6206
					$is_valid = true;
6207
				}
6208
			}
6209
		}
6210
6211
		/**
6212
		 * Filters whether the sync_error_idc option is valid.
6213
		 *
6214
		 * @since 4.4.0
6215
		 *
6216
		 * @param bool $is_valid If the sync_error_idc is valid or not.
6217
		 */
6218
		$is_valid = (bool) apply_filters( 'jetpack_sync_error_idc_validation', $is_valid );
6219
6220
		if ( ! $is_valid && $sync_error ) {
6221
			// Since the option exists, and did not validate, delete it
6222
			Jetpack_Options::delete_option( 'sync_error_idc' );
6223
		}
6224
6225
		return $is_valid;
6226
	}
6227
6228
	/**
6229
	 * Normalizes a url by doing three things: