function __construct(Freemius $fs) { $this->_fs = $fs; $this->_logger = FS_Logger::get_logger(WP_FS__SLUG . '_' . $fs->get_slug() . '_info', WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK); // Remove default plugin information action. remove_all_actions('install_plugins_pre_plugin-information'); // Override action with custom plugins function for add-ons. add_action('install_plugins_pre_plugin-information', array(&$this, 'install_plugin_information')); // Override request for plugin information for Add-ons. add_filter('fs_plugins_api', array(&$this, '_get_addon_info_filter'), WP_FS__DEFAULT_PRIORITY, 3); }
/** * Updates information on the "View version x.x details" page with custom data. * * @author Vova Feldman (@svovaf) * @since 1.0.4 * * @uses FS_Api * * @param object $data * @param string $action * @param mixed $args * * @return object */ function plugins_api_filter($data, $action = '', $args = null) { $this->_logger->entrance(); if ('plugin_information' !== $action || !isset($args->slug)) { return $data; } $addon = false; $is_addon = false; if ($this->_fs->get_slug() !== $args->slug) { $addon = $this->_fs->get_addon_by_slug($args->slug); if (!is_object($addon)) { return $data; } $is_addon = true; } $plugin_in_repo = false; if (!$is_addon) { // Try to fetch info from .org repository. $data = self::_fetch_plugin_info_from_repository($action, $args); $plugin_in_repo = false !== $data; } if (!$plugin_in_repo) { $data = $args; // Fetch as much as possible info from local files. $plugin_local_data = $this->_fs->get_plugin_data(); $data->name = $plugin_local_data['Name']; $data->author = $plugin_local_data['Author']; $data->sections = array('description' => 'Upgrade ' . $plugin_local_data['Name'] . ' to latest.'); // @todo Store extra plugin info on Freemius or parse readme.txt markup. /*$info = $this->_fs->get_api_site_scope()->call('/information.json'); if ( !isset($info->error) ) { $data = $info; }*/ } // Get plugin's newest update. $new_version = $this->_fs->_fetch_latest_version($is_addon ? $addon->id : false); if ($is_addon) { $data->name = $addon->title . ' ' . __fs('addon', $this->_fs->get_slug()); $data->slug = $addon->slug; $data->url = WP_FS__ADDRESS; $data->package = $new_version->url; } if (!$plugin_in_repo) { $data->last_updated = !is_null($new_version->updated) ? $new_version->updated : $new_version->created; $data->requires = $new_version->requires_platform_version; $data->tested = $new_version->tested_up_to_version; } $data->version = $new_version->version; $data->download_link = $new_version->url; return $data; }