Jetpack::validate_sync_error_idc_option PHP Method

validate_sync_error_idc_option() public static method

Checks whether the sync_error_idc option is valid or not, and if not, will do cleanup.
public static validate_sync_error_idc_option ( ) : boolean
return boolean
    public static function validate_sync_error_idc_option()
    {
        $is_valid = false;
        $idc_allowed = get_transient('jetpack_idc_allowed');
        if (false === $idc_allowed) {
            $response = wp_remote_get('https://jetpack.com/is-idc-allowed/');
            if (200 === (int) wp_remote_retrieve_response_code($response)) {
                $json = json_decode(wp_remote_retrieve_body($response));
                $idc_allowed = isset($json, $json->result) && $json->result ? '1' : '0';
                $transient_duration = HOUR_IN_SECONDS;
            } else {
                // If the request failed for some reason, then assume IDC is allowed and set shorter transient.
                $idc_allowed = '1';
                $transient_duration = 5 * MINUTE_IN_SECONDS;
            }
            set_transient('jetpack_idc_allowed', $idc_allowed, $transient_duration);
        }
        // Is the site opted in and does the stored sync_error_idc option match what we now generate?
        $sync_error = Jetpack_Options::get_option('sync_error_idc');
        $local_options = self::get_sync_error_idc_option();
        if ($idc_allowed && $sync_error && self::sync_idc_optin()) {
            if ($sync_error['home'] === $local_options['home'] && $sync_error['siteurl'] === $local_options['siteurl']) {
                $is_valid = true;
            }
        }
        /**
         * Filters whether the sync_error_idc option is valid.
         *
         * @since 4.4.0
         *
         * @param bool $is_valid If the sync_error_idc is valid or not.
         */
        $is_valid = (bool) apply_filters('jetpack_sync_error_idc_validation', $is_valid);
        if (!$idc_allowed || !$is_valid && $sync_error) {
            // Since the option exists, and did not validate, delete it
            Jetpack_Options::delete_option('sync_error_idc');
        }
        return $is_valid;
    }

Usage Example

コード例 #1
0
 function __construct()
 {
     $this->jetpack = Jetpack::init();
     self::$block_page_rendering_for_idc = Jetpack::validate_sync_error_idc_option() && !Jetpack_Options::get_option('safe_mode_confirmed');
     if (!self::$block_page_rendering_for_idc) {
         add_action('admin_enqueue_scripts', array($this, 'additional_styles'));
     }
 }
All Usage Examples Of Jetpack::validate_sync_error_idc_option
Jetpack