Jetpack::fix_url_for_bad_hosts PHP Method

fix_url_for_bad_hosts() public static method

Some hosts disable the OpenSSL extension and so cannot make outgoing HTTPS requsets
public static fix_url_for_bad_hosts ( $url )
    public static function fix_url_for_bad_hosts($url)
    {
        if (0 !== strpos($url, 'https://')) {
            return $url;
        }
        switch (JETPACK_CLIENT__HTTPS) {
            case 'ALWAYS':
                return $url;
            case 'NEVER':
                return set_url_scheme($url, 'http');
                // default : case 'AUTO' :
        }
        // we now return the unmodified SSL URL by default, as a security precaution
        return $url;
    }

Usage Example

 /**
  * @return bool|WP_Error
  */
 public static function register()
 {
     add_action('pre_update_jetpack_option_register', array('Jetpack_Options', 'delete_option'));
     $secrets = Jetpack::init()->generate_secrets();
     Jetpack_Options::update_option('register', $secrets[0] . ':' . $secrets[1] . ':' . $secrets[2]);
     @(list($secret_1, $secret_2, $secret_eol) = explode(':', Jetpack_Options::get_option('register')));
     if (empty($secret_1) || empty($secret_2) || empty($secret_eol) || $secret_eol < time()) {
         return new Jetpack_Error('missing_secrets');
     }
     $timeout = Jetpack::init()->get_remote_query_timeout_limit();
     $gmt_offset = get_option('gmt_offset');
     if (!$gmt_offset) {
         $gmt_offset = 0;
     }
     $stats_options = get_option('stats_options');
     $stats_id = isset($stats_options['blog_id']) ? $stats_options['blog_id'] : null;
     $args = array('method' => 'POST', 'body' => array('siteurl' => site_url(), 'home' => home_url(), 'gmt_offset' => $gmt_offset, 'timezone_string' => (string) get_option('timezone_string'), 'site_name' => (string) get_option('blogname'), 'secret_1' => $secret_1, 'secret_2' => $secret_2, 'site_lang' => get_locale(), 'timeout' => $timeout, 'stats_id' => $stats_id), 'headers' => array('Accept' => 'application/json'), 'timeout' => $timeout);
     $response = Jetpack_Client::_wp_remote_request(Jetpack::fix_url_for_bad_hosts(Jetpack::api_url('register')), $args, true);
     // Make sure the response is valid and does not contain any Jetpack errors
     $valid_response = Jetpack::init()->validate_remote_register_response($response);
     if (is_wp_error($valid_response) || !$valid_response) {
         return $valid_response;
     }
     // Grab the response values to work with
     $code = wp_remote_retrieve_response_code($response);
     $entity = wp_remote_retrieve_body($response);
     if ($entity) {
         $json = json_decode($entity);
     } else {
         $json = false;
     }
     if (empty($json->jetpack_secret) || !is_string($json->jetpack_secret)) {
         return new Jetpack_Error('jetpack_secret', '', $code);
     }
     if (isset($json->jetpack_public)) {
         $jetpack_public = (int) $json->jetpack_public;
     } else {
         $jetpack_public = false;
     }
     Jetpack_Options::update_options(array('id' => (int) $json->jetpack_id, 'blog_token' => (string) $json->jetpack_secret, 'public' => $jetpack_public));
     return true;
 }
All Usage Examples Of Jetpack::fix_url_for_bad_hosts
Jetpack