コード例 #1
0
 /**
  * Create a new instance of TribePluginUpdateUtility from its JSON-encoded representation.
  *
  * @param string $json
  * @return TribePluginUpdateUtility
  */
 public static function from_json($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 = Tribe_PU_PluginInfo::from_json($json);
     if ($pluginInfo != null) {
         return TribePluginUpdateUtility::from_plugin_info($pluginInfo);
     } else {
         return null;
     }
 }
コード例 #2
0
 /**
  * Retrieve plugin info from the configured API endpoint.
  *
  * @param array $queryArgs Additional query arguments to append to the request. Optional.
  *
  * @uses wp_remote_get()
  * @return string $pluginInfo
  */
 function request_info($queryArgs = array())
 {
     //Query args to append to the URL. Plugins can add their own by using a filter callback (see add_query_arg_filter()).
     $queryArgs['installed_version'] = $this->get_installed_version();
     $queryArgs['pu_request_plugin'] = $this->get_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->get_installed_version();
     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->get_plugin_file());
         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('tribe_puc_request_info_query_args-' . $this->get_slug(), $queryArgs);
     //Various options for the wp_remote_get() call. Plugins can filter these, too.
     $options = array('timeout' => 15, 'headers' => array('Accept' => 'application/json'));
     $options = apply_filters('tribe_puc_request_info_options-' . $this->get_slug(), $options);
     $url = $this->get_pue_update_url();
     if (!empty($queryArgs)) {
         $url = add_query_arg($queryArgs, $url);
     }
     // 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);
     //Try to parse the response
     $pluginInfo = null;
     if (!is_wp_error($result) && isset($result['response']['code']) && $result['response']['code'] == 200 && !empty($result['body'])) {
         $pluginInfo = Tribe_PU_PluginInfo::from_json($result['body']);
     }
     $pluginInfo = apply_filters('tribe_puc_request_info_result-' . $this->get_slug(), $pluginInfo, $result);
     $plugin_info_cache[$key] = $pluginInfo;
     return $pluginInfo;
 }