/**
  * Create a new instance of PluginUpdate from its JSON-encoded representation.
  *
  * @param string $json
  * @param bool $triggerErrors
  *
  * @return RT_Plugin_Update|null
  */
 public static function from_json($json, $triggerErrors = false)
 {
     //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 = RT_Plugin_Update_Info::from_json($json, $triggerErrors);
     if (null != $pluginInfo) {
         return self::from_plugin_info($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 RT_Plugin_Update_Info
  */
 public function request_info($queryArgs = array())
 {
     //Query args to append to the URL. Plugins can add their own by using a filter callback (see addQueryArgFilter()).
     $installedVersion = $this->get_installed_version();
     $queryArgs['installed_version'] = null !== $installedVersion ? $installedVersion : '';
     $queryArgs['admin_email'] = get_option('admin_email');
     $queryArgs['slug'] = $this->slug;
     $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, $options);
     //The plugin info should be at 'http://your-api.com/url/here/$slug/info.json'
     $url = $this->metadataUrl;
     if (!empty($queryArgs)) {
         $url = add_query_arg($queryArgs, $url);
     }
     $result = wp_remote_get(esc_url_raw($url), $options);
     //Try to parse the response
     $pluginInfo = null;
     if (!is_wp_error($result) && isset($result['response']['code']) && 200 == $result['response']['code'] && !empty($result['body'])) {
         $pluginInfo = RT_Plugin_Update_Info::from_json($result['body'], $this->debugMode);
     } else {
         if ($this->debugMode) {
             $message = sprintf(__('The URL %s does not point to a valid plugin metadata file.', 'rtmedia'), $url);
             if (is_wp_error($result)) {
                 $message .= sprintf(__('WP HTTP error: %s', 'rtmedia'), $result->get_error_message());
             } else {
                 if (isset($result['response']['code'])) {
                     $message .= sprintf(__('HTTP response code is %s (expected: 200)', 'rtmedia'), $result['response']['code']);
                 } else {
                     $message .= __('wp_remote_get() returned an unexpected result.', 'rtmedia');
                 }
             }
             trigger_error($message, E_USER_WARNING);
         }
     }
     $pluginInfo = apply_filters('puc_request_info_result-' . $this->slug, $pluginInfo, $result);
     return $pluginInfo;
 }