Пример #1
0
 /**
  * Leverage backtrace to find caller plugin file path.
  *
  * @author Vova Feldman (@svovaf)
  * @since  1.0.6
  *
  * @param bool $is_init Is initiation sequence.
  *
  * @return string
  *
  * @uses   fs_find_caller_plugin_file
  */
 private function _find_caller_plugin_file($is_init = false)
 {
     // Try to load the cached value of the file path.
     if (isset($this->_storage->plugin_main_file)) {
         if (file_exists($this->_storage->plugin_main_file->path)) {
             return $this->_storage->plugin_main_file->path;
         }
     }
     /**
      * @since 1.2.1
      *
      * `clear_module_main_file_cache()` is clearing the plugin's cached path on
      * deactivation. Therefore, if any plugin/theme was initiating `Freemius`
      * with that plugin's slug, it was overriding the empty plugin path with a wrong path.
      *
      * So, we've added a special mechanism with a 2nd layer of cache that uses `prev_path`
      * when the class instantiator isn't the module.
      */
     if (!$is_init) {
         // Fetch prev path cache.
         if (isset($this->_storage->plugin_main_file) && isset($this->_storage->plugin_main_file->prev_path)) {
             if (file_exists($this->_storage->plugin_main_file->prev_path)) {
                 return $this->_storage->plugin_main_file->prev_path;
             }
         }
         wp_die(__fs('failed-finding-main-path', $this->_slug), __fs('error'), array('back_link' => true));
     }
     /**
      * @since 1.2.1
      *
      * Only the original instantiator that calls dynamic_init can modify the module's path.
      */
     // Find caller module.
     $plugin_file = fs_find_caller_plugin_file();
     $this->_storage->plugin_main_file = (object) array('path' => fs_normalize_path($plugin_file));
     return $plugin_file;
 }
 /**
  * Leverage backtrace to find caller plugin file path.
  *
  * @author Vova Feldman (@svovaf)
  * @since  1.0.6
  *
  * @return string
  *
  * @uses   fs_find_caller_plugin_file
  */
 private function _find_caller_plugin_file()
 {
     // Try to load the cached value of the file path.
     if (isset($this->_storage->plugin_main_file)) {
         if (file_exists($this->_storage->plugin_main_file->path)) {
             return $this->_storage->plugin_main_file->path;
         }
     }
     $plugin_file = fs_find_caller_plugin_file();
     $this->_storage->plugin_main_file = (object) array('path' => fs_normalize_path($plugin_file));
     return $plugin_file;
 }
Пример #3
0
 * @since 1.1.6
 */
global $fs_active_plugins;
$this_sdk_relative_path = plugin_basename(dirname(__FILE__));
if (!isset($fs_active_plugins)) {
    // Require SDK essentials.
    require_once dirname(__FILE__) . '/includes/fs-essential-functions.php';
    // Load all Freemius powered active plugins.
    $fs_active_plugins = get_option('fs_active_plugins', new stdClass());
    if (!isset($fs_active_plugins->plugins)) {
        $fs_active_plugins->plugins = array();
    }
}
// Update current SDK info based on the SDK path.
if (!isset($fs_active_plugins->plugins[$this_sdk_relative_path]) || $this_sdk_version != $fs_active_plugins->plugins[$this_sdk_relative_path]->version) {
    $fs_active_plugins->plugins[$this_sdk_relative_path] = (object) array('version' => $this_sdk_version, 'timestamp' => time(), 'plugin_path' => plugin_basename(fs_find_caller_plugin_file()));
}
$is_current_sdk_newest = isset($fs_active_plugins->newest) && $this_sdk_relative_path == $fs_active_plugins->newest->sdk_path;
if (!isset($fs_active_plugins->newest)) {
    /**
     * This will be executed only once, for the first time a Freemius powered plugin is activated.
     */
    fs_update_sdk_newest_version($this_sdk_relative_path);
    $is_current_sdk_newest = true;
} else {
    if (version_compare($fs_active_plugins->newest->version, $this_sdk_version, '<')) {
        /**
         * Current SDK is newer than the newest stored SDK.
         */
        fs_update_sdk_newest_version($this_sdk_relative_path);
        if (class_exists('Freemius')) {
/**
 * Update SDK newest version reference.
 *
 * @author Vova Feldman (@svovaf)
 * @since  1.1.6
 *
 * @param string      $sdk_relative_path
 * @param string|bool $plugin_file
 *
 * @global            $fs_active_plugins
 */
function fs_update_sdk_newest_version($sdk_relative_path, $plugin_file = false)
{
    global $fs_active_plugins;
    if (!is_string($plugin_file)) {
        $plugin_file = plugin_basename(fs_find_caller_plugin_file());
    }
    $fs_active_plugins->newest = (object) array('plugin_path' => $plugin_file, 'sdk_path' => $sdk_relative_path, 'version' => $fs_active_plugins->plugins[$sdk_relative_path]->version, 'in_activation' => !is_plugin_active($plugin_file), 'timestamp' => time());
    // Update DB with latest SDK version and path.
    update_option('fs_active_plugins', $fs_active_plugins);
}