/**
  * Create a new instance of PluginUpdateUtility from its JSON-encoded representation.
  *
  * @param string $json
  * @return PluginUpdateUtility
  */
 public static function fromJson($json)
 {
     //Since update-related information is simply a subset of the full plugin info,
     //we can parse the update JSON as if it was a plugin info string, then copy over
     //the parts that we care about.
     $pluginInfo = PU_PluginInfo::fromJson($json);
     if ($pluginInfo != null) {
         return PluginUpdateUtility::fromPluginInfo($pluginInfo);
     } else {
         return null;
     }
 }
 /**
  * Retrieve plugin info from the configured API endpoint.
  *
  * @uses wp_remote_get()
  *
  * @param array $queryArgs Additional query arguments to append to the request. Optional.
  * @return $pluginInfo
  */
 function requestInfo($queryArgs = array())
 {
     //Query args to append to the URL. Plugins can add their own by using a filter callback (see addQueryArgFilter()).
     $queryArgs['installed_version'] = $this->getInstalledVersion();
     $queryArgs['pu_request_plugin'] = $this->slug;
     if (empty($queryArgs['pu_plugin_api']) && !empty($this->api_secret_key)) {
         $queryArgs['pu_plugin_api'] = $this->api_secret_key;
     }
     if (empty($queryArgs['pu_install_key']) && !empty($this->install_key)) {
         $queryArgs['pu_install_key'] = $this->install_key;
     }
     //include version info
     $queryArgs['pue_active_version'] = $this->getInstalledVersion();
     global $wp_version;
     $queryArgs['wp_version'] = $wp_version;
     //include domain and multisite stats
     $queryArgs['domain'] = $_SERVER['SERVER_NAME'];
     if (is_multisite()) {
         $queryArgs['multisite'] = 1;
         $queryArgs['network_activated'] = is_plugin_active_for_network($this->pluginFile);
         global $wpdb;
         $queryArgs['active_sites'] = $wpdb->get_var("SELECT count(blog_id) FROM {$wpdb->blogs} WHERE public = '1' AND archived = '0' AND spam = '0' AND deleted = '0'");
     } else {
         $queryArgs['multisite'] = 0;
         $queryArgs['network_activated'] = 0;
         $queryArgs['active_sites'] = 1;
     }
     $queryArgs = apply_filters('puc_request_info_query_args-' . $this->slug, $queryArgs);
     //Various options for the wp_remote_get() call. Plugins can filter these, too.
     $options = array('timeout' => 10, 'headers' => array('Accept' => 'application/json'));
     $options = apply_filters('puc_request_info_options-' . $this->slug, array());
     $url = $this->metadataUrl;
     if (!empty($queryArgs)) {
         $url = add_query_arg($queryArgs, $url);
     }
     //echo $url; //DEBUG
     // Cache the API call so it only needs to be made once per plugin per page load.
     static $plugin_info_cache;
     $key = crc32(implode('', $queryArgs));
     if (isset($plugin_info_cache[$key])) {
         return $plugin_info_cache[$key];
     }
     $result = wp_remote_get($url, $options);
     //echo $result['body']; //DEBUG
     //Try to parse the response
     $pluginInfo = null;
     if (!is_wp_error($result) && isset($result['response']['code']) && $result['response']['code'] == 200 && !empty($result['body'])) {
         $pluginInfo = PU_PluginInfo::fromJson($result['body']);
     }
     $pluginInfo = apply_filters('puc_request_info_result-' . $this->slug, $pluginInfo, $result);
     $plugin_info_cache[$key] = $pluginInfo;
     return $pluginInfo;
 }