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