| @@ 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: |
|
| @@ 6221-6262 (lines=42) @@ | ||
| 6218 | * |
|
| 6219 | * @return bool |
|
| 6220 | */ |
|
| 6221 | public static function validate_sync_error_idc_option() { |
|
| 6222 | $is_valid = false; |
|
| 6223 | ||
| 6224 | // Is the site opted in and does the stored sync_error_idc option match what we now generate? |
|
| 6225 | $sync_error = Jetpack_Options::get_option( 'sync_error_idc' ); |
|
| 6226 | if ( $sync_error && self::sync_idc_optin() ) { |
|
| 6227 | $local_options = self::get_sync_error_idc_option(); |
|
| 6228 | // Ensure all values are set. |
|
| 6229 | if ( isset( $sync_error['home'] ) && isset( $local_options['home'] ) && isset( $sync_error['siteurl'] ) && isset( $local_options['siteurl'] ) ) { |
|
| 6230 | ||
| 6231 | // If the WP.com expected home and siteurl match local home and siteurl it is not valid IDC. |
|
| 6232 | if ( |
|
| 6233 | isset( $sync_error['wpcom_home'] ) && |
|
| 6234 | isset( $sync_error['wpcom_siteurl'] ) && |
|
| 6235 | $sync_error['wpcom_home'] === $local_options['home'] && |
|
| 6236 | $sync_error['wpcom_siteurl'] === $local_options['siteurl'] |
|
| 6237 | ) { |
|
| 6238 | $is_valid = false; |
|
| 6239 | // Enable migrate_for_idc so that sync actions are accepted. |
|
| 6240 | Jetpack_Options::update_option( 'migrate_for_idc', true ); |
|
| 6241 | } elseif ( $sync_error['home'] === $local_options['home'] && $sync_error['siteurl'] === $local_options['siteurl'] ) { |
|
| 6242 | $is_valid = true; |
|
| 6243 | } |
|
| 6244 | } |
|
| 6245 | } |
|
| 6246 | ||
| 6247 | /** |
|
| 6248 | * Filters whether the sync_error_idc option is valid. |
|
| 6249 | * |
|
| 6250 | * @since 4.4.0 |
|
| 6251 | * |
|
| 6252 | * @param bool $is_valid If the sync_error_idc is valid or not. |
|
| 6253 | */ |
|
| 6254 | $is_valid = (bool) apply_filters( 'jetpack_sync_error_idc_validation', $is_valid ); |
|
| 6255 | ||
| 6256 | if ( ! $is_valid && $sync_error ) { |
|
| 6257 | // Since the option exists, and did not validate, delete it |
|
| 6258 | Jetpack_Options::delete_option( 'sync_error_idc' ); |
|
| 6259 | } |
|
| 6260 | ||
| 6261 | return $is_valid; |
|
| 6262 | } |
|
| 6263 | ||
| 6264 | /** |
|
| 6265 | * Normalizes a url by doing three things: |
|