@@ 274-314 (lines=41) @@ | ||
271 | * |
|
272 | * @since 4.4.0 |
|
273 | */ |
|
274 | public static function validate_sync_error_idc_option() { |
|
275 | $is_valid = false; |
|
276 | ||
277 | // Is the site opted in and does the stored sync_error_idc option match what we now generate? |
|
278 | $sync_error = Jetpack_Options::get_option( 'sync_error_idc' ); |
|
279 | if ( $sync_error && self::sync_idc_optin() ) { |
|
280 | $local_options = self::get_sync_error_idc_option(); |
|
281 | // Ensure all values are set. |
|
282 | if ( isset( $sync_error['home'] ) && isset( $local_options['home'] ) && isset( $sync_error['siteurl'] ) && isset( $local_options['siteurl'] ) ) { |
|
283 | // If the WP.com expected home and siteurl match local home and siteurl it is not valid IDC. |
|
284 | if ( |
|
285 | isset( $sync_error['wpcom_home'] ) && |
|
286 | isset( $sync_error['wpcom_siteurl'] ) && |
|
287 | $sync_error['wpcom_home'] === $local_options['home'] && |
|
288 | $sync_error['wpcom_siteurl'] === $local_options['siteurl'] |
|
289 | ) { |
|
290 | $is_valid = false; |
|
291 | // Enable migrate_for_idc so that sync actions are accepted. |
|
292 | Jetpack_Options::update_option( 'migrate_for_idc', true ); |
|
293 | } elseif ( $sync_error['home'] === $local_options['home'] && $sync_error['siteurl'] === $local_options['siteurl'] ) { |
|
294 | $is_valid = true; |
|
295 | } |
|
296 | } |
|
297 | } |
|
298 | ||
299 | /** |
|
300 | * Filters whether the sync_error_idc option is valid. |
|
301 | * |
|
302 | * @param bool $is_valid If the sync_error_idc is valid or not. |
|
303 | * |
|
304 | * @since 4.4.0 |
|
305 | */ |
|
306 | $is_valid = (bool) apply_filters( 'jetpack_sync_error_idc_validation', $is_valid ); |
|
307 | ||
308 | if ( ! $is_valid && $sync_error ) { |
|
309 | // Since the option exists, and did not validate, delete it. |
|
310 | Jetpack_Options::delete_option( 'sync_error_idc' ); |
|
311 | } |
|
312 | ||
313 | return $is_valid; |
|
314 | } |
|
315 | ||
316 | /** |
|
317 | * Normalizes a url by doing three things: |
@@ 6275-6316 (lines=42) @@ | ||
6272 | * |
|
6273 | * @return bool |
|
6274 | */ |
|
6275 | public static function validate_sync_error_idc_option() { |
|
6276 | $is_valid = false; |
|
6277 | ||
6278 | // Is the site opted in and does the stored sync_error_idc option match what we now generate? |
|
6279 | $sync_error = Jetpack_Options::get_option( 'sync_error_idc' ); |
|
6280 | if ( $sync_error && self::sync_idc_optin() ) { |
|
6281 | $local_options = self::get_sync_error_idc_option(); |
|
6282 | // Ensure all values are set. |
|
6283 | if ( isset( $sync_error['home'] ) && isset( $local_options['home'] ) && isset( $sync_error['siteurl'] ) && isset( $local_options['siteurl'] ) ) { |
|
6284 | ||
6285 | // If the WP.com expected home and siteurl match local home and siteurl it is not valid IDC. |
|
6286 | if ( |
|
6287 | isset( $sync_error['wpcom_home'] ) && |
|
6288 | isset( $sync_error['wpcom_siteurl'] ) && |
|
6289 | $sync_error['wpcom_home'] === $local_options['home'] && |
|
6290 | $sync_error['wpcom_siteurl'] === $local_options['siteurl'] |
|
6291 | ) { |
|
6292 | $is_valid = false; |
|
6293 | // Enable migrate_for_idc so that sync actions are accepted. |
|
6294 | Jetpack_Options::update_option( 'migrate_for_idc', true ); |
|
6295 | } elseif ( $sync_error['home'] === $local_options['home'] && $sync_error['siteurl'] === $local_options['siteurl'] ) { |
|
6296 | $is_valid = true; |
|
6297 | } |
|
6298 | } |
|
6299 | } |
|
6300 | ||
6301 | /** |
|
6302 | * Filters whether the sync_error_idc option is valid. |
|
6303 | * |
|
6304 | * @since 4.4.0 |
|
6305 | * |
|
6306 | * @param bool $is_valid If the sync_error_idc is valid or not. |
|
6307 | */ |
|
6308 | $is_valid = (bool) apply_filters( 'jetpack_sync_error_idc_validation', $is_valid ); |
|
6309 | ||
6310 | if ( ! $is_valid && $sync_error ) { |
|
6311 | // Since the option exists, and did not validate, delete it |
|
6312 | Jetpack_Options::delete_option( 'sync_error_idc' ); |
|
6313 | } |
|
6314 | ||
6315 | return $is_valid; |
|
6316 | } |
|
6317 | ||
6318 | /** |
|
6319 | * Normalizes a url by doing three things: |