/**
  * Provides download package when installing and information on the "View version x.x details" page.
  *
  * @uses api_request()
  *
  * @param mixed $_data
  * @param string $_action
  * @param object $_args
  * @return object $_data
  */
 public function perks_plugins_api_filter($_data, $_action = '', $_args = null)
 {
     GravityPerks::log_debug('perks_plugins_api_filter() start. Retrieves download package and plugin info.');
     $plugin_file = isset($_args->slug) ? $_args->slug : gwget('plugin');
     if (strpos($plugin_file, '/') === false) {
         $plugin_file = sprintf('%1$s/%1$s.php', $plugin_file);
     }
     $is_perk = gwget('from') == 'gwp';
     if (!$is_perk) {
         $is_perk = GWPerk::is_perk($plugin_file);
     }
     GravityPerks::log_debug(print_r(compact('slug', 'is_perk'), true));
     if ($_action != 'plugin_information' || !$is_perk || !$plugin_file) {
         return $_data;
     }
     GravityPerks::log_debug('Yes! This is a perk.');
     $api_params = self::get_api_args(array('edd_action' => 'get_perk', 'plugin_file' => $plugin_file, 'license' => $this->license_key));
     $request_args = self::get_request_args(array('body' => urlencode_deep($api_params)));
     $request = wp_remote_post(GW_STORE_URL, $request_args);
     GravityPerks::log_debug('API Parameters: ' . print_r($api_params, true));
     GravityPerks::log_debug('Request Arguments: ' . print_r($request_args, true));
     GravityPerks::log_debug('Response from GW API: ' . print_r($request, true));
     if (is_wp_error($request)) {
         GravityPerks::log_debug('Rats! There was an error with the GW API response');
         return $_data;
     }
     $request = json_decode(wp_remote_retrieve_body($request));
     if (!$request) {
         GravityPerks::log_debug('Rats! There was an error with the GW API response');
         return $_data;
     }
     GravityPerks::log_debug('Ok! Everything looks good. Let\'s build the response needed for WordPress.');
     $request->is_perk = true;
     $request->sections = (array) maybe_unserialize($request->sections);
     $request->sections['changelog'] = GWPerks::format_changelog($request->sections['changelog']);
     // don't allow other plugins to override the $request this function returns, several plugins use the 'plugins_api'
     // filter incorrectly and return a hard 'false' rather than returning the $_data object when they do not need to modify
     // the request which results in our customized $request being overwritten (WPMU Dev Dashboard v3.3.2 is one example)
     remove_all_filters('plugins_api');
     // remove all the filters causes an infinite loop so add one dummy function so the loop can break itself
     add_filter('plugins_api', create_function('$_data', 'return $_data;'));
     // needed for testing on local
     add_filter('http_request_args', array($this, 'allow_unsecure_urls_on_localhost'));
     return $request;
 }
 public static function is_plugin_file_perk($plugin)
 {
     $plugins = is_array($plugin) ? $plugin : array($plugin);
     foreach ($plugins as $plugin) {
         if (GWPerk::is_perk($plugin)) {
             return true;
         }
     }
     return false;
 }