/**
 * Go over all Freemius SDKs in the system and find and "remember"
 * the newest SDK which is associated with an active plugin.
 *
 * @author Vova Feldman (@svovaf)
 * @since  1.1.6
 *
 * @global $fs_active_plugins
 */
function fs_fallback_to_newest_active_sdk()
{
    global $fs_active_plugins;
    $newest_sdk_data = null;
    $newest_sdk_path = null;
    foreach ($fs_active_plugins->plugins as $sdk_relative_path => $data) {
        if (is_null($newest_sdk_data) || version_compare($data->version, $newest_sdk_data->version, '>')) {
            // If plugin inactive or SDK starter file doesn't exist, remove SDK reference.
            if (!is_plugin_active($data->plugin_path) || !file_exists(fs_normalize_path(WP_PLUGIN_DIR . '/' . $sdk_relative_path . '/start.php'))) {
                unset($fs_active_plugins->plugins[$sdk_relative_path]);
                // No need to store the data since it will be stored in fs_update_sdk_newest_version()
                // or explicitly with update_option().
            } else {
                $newest_sdk_data = $data;
                $newest_sdk_path = $sdk_relative_path;
            }
        }
    }
    if (is_null($newest_sdk_data)) {
        // Couldn't find any SDK reference.
        $fs_active_plugins = new stdClass();
        update_option('fs_active_plugins', $fs_active_plugins);
    } else {
        fs_update_sdk_newest_version($newest_sdk_path, $newest_sdk_data->plugin_path);
    }
}
Пример #2
0
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')) {
            // Older SDK version was already loaded.
            if (!$fs_active_plugins->newest->in_activation) {
                // Re-order plugins to load this plugin first.
                fs_newest_sdk_plugin_first();
            }
            // Refresh page.
            if (fs_redirect($_SERVER['REQUEST_URI'])) {
                exit;
            }
        }
    } else {
        if (!function_exists('get_plugins')) {
            require_once ABSPATH . 'wp-admin/includes/plugin.php';
        }
Пример #3
0
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_direct_caller_plugin_file(__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, $fs_active_plugins->plugins[$this_sdk_relative_path]->plugin_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, $fs_active_plugins->plugins[$this_sdk_relative_path]->plugin_path);
        if (class_exists('Freemius')) {
            // Older SDK version was already loaded.
            if (!$fs_active_plugins->newest->in_activation) {
                // Re-order plugins to load this plugin first.
                fs_newest_sdk_plugin_first();
            }
            // Refresh page.
            if (fs_redirect($_SERVER['REQUEST_URI'])) {
                exit;
            }
        }
    } else {
        if (!function_exists('get_plugins')) {
            require_once ABSPATH . 'wp-admin/includes/plugin.php';
        }