| @@ 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: |
|
| @@ 6242-6283 (lines=42) @@ | ||
| 6239 | * |
|
| 6240 | * @return bool |
|
| 6241 | */ |
|
| 6242 | public static function validate_sync_error_idc_option() { |
|
| 6243 | $is_valid = false; |
|
| 6244 | ||
| 6245 | // Is the site opted in and does the stored sync_error_idc option match what we now generate? |
|
| 6246 | $sync_error = Jetpack_Options::get_option( 'sync_error_idc' ); |
|
| 6247 | if ( $sync_error && self::sync_idc_optin() ) { |
|
| 6248 | $local_options = self::get_sync_error_idc_option(); |
|
| 6249 | // Ensure all values are set. |
|
| 6250 | if ( isset( $sync_error['home'] ) && isset( $local_options['home'] ) && isset( $sync_error['siteurl'] ) && isset( $local_options['siteurl'] ) ) { |
|
| 6251 | ||
| 6252 | // If the WP.com expected home and siteurl match local home and siteurl it is not valid IDC. |
|
| 6253 | if ( |
|
| 6254 | isset( $sync_error['wpcom_home'] ) && |
|
| 6255 | isset( $sync_error['wpcom_siteurl'] ) && |
|
| 6256 | $sync_error['wpcom_home'] === $local_options['home'] && |
|
| 6257 | $sync_error['wpcom_siteurl'] === $local_options['siteurl'] |
|
| 6258 | ) { |
|
| 6259 | $is_valid = false; |
|
| 6260 | // Enable migrate_for_idc so that sync actions are accepted. |
|
| 6261 | Jetpack_Options::update_option( 'migrate_for_idc', true ); |
|
| 6262 | } elseif ( $sync_error['home'] === $local_options['home'] && $sync_error['siteurl'] === $local_options['siteurl'] ) { |
|
| 6263 | $is_valid = true; |
|
| 6264 | } |
|
| 6265 | } |
|
| 6266 | } |
|
| 6267 | ||
| 6268 | /** |
|
| 6269 | * Filters whether the sync_error_idc option is valid. |
|
| 6270 | * |
|
| 6271 | * @since 4.4.0 |
|
| 6272 | * |
|
| 6273 | * @param bool $is_valid If the sync_error_idc is valid or not. |
|
| 6274 | */ |
|
| 6275 | $is_valid = (bool) apply_filters( 'jetpack_sync_error_idc_validation', $is_valid ); |
|
| 6276 | ||
| 6277 | if ( ! $is_valid && $sync_error ) { |
|
| 6278 | // Since the option exists, and did not validate, delete it |
|
| 6279 | Jetpack_Options::delete_option( 'sync_error_idc' ); |
|
| 6280 | } |
|
| 6281 | ||
| 6282 | return $is_valid; |
|
| 6283 | } |
|
| 6284 | ||
| 6285 | /** |
|
| 6286 | * Normalizes a url by doing three things: |
|