/** * Create a new instance of PluginUpdate from its JSON-encoded representation. * * @param string $json * @param bool $triggerErrors * @return PluginUpdate|null */ public static function fromJson($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 = PluginInfo::fromJson($json, $triggerErrors); if ($pluginInfo != null) { return PluginUpdate::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 = 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()); //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($url, $options); //Try to parse the response $pluginInfo = null; if (!is_wp_error($result) && isset($result['response']['code']) && $result['response']['code'] == 200 && !empty($result['body'])) { $pluginInfo = PluginInfo::fromJson($result['body']); } $pluginInfo = apply_filters('puc_request_info_result-' . $this->slug, $pluginInfo, $result); return $pluginInfo; }