Repository URL to install this package:
<?php
/**
* @package Freemius
* @copyright Copyright (c) 2015, Freemius, Inc.
* @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
* @since 1.0.3
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Freemius SDK Version.
*
* @var string
*/
$this_sdk_version = '2.5.3';
#region SDK Selection Logic --------------------------------------------------------------------
/**
* Special logic added on 1.1.6 to make sure that every Freemius powered plugin
* will ALWAYS be loaded with the newest SDK from the active Freemius powered plugins.
*
* Since Freemius SDK is backward compatible, this will make sure that all Freemius powered
* plugins will run correctly.
*
* @since 1.1.6
*/
global $fs_active_plugins;
if ( ! function_exists( 'fs_find_caller_plugin_file' ) ) {
// Require SDK essentials.
require_once dirname( __FILE__ ) . '/includes/fs-essential-functions.php';
}
/**
* This complex logic fixes symlink issues (e.g. with Vargant). The logic assumes
* that if it's a file from an SDK running in a theme, the location of the SDK
* is in the main theme's folder.
*
* @author Vova Feldman (@svovaf)
* @since 1.2.2.6
*/
$file_path = fs_normalize_path( __FILE__ );
$fs_root_path = dirname( $file_path );
/**
* Get the themes directory where the active theme is located (not passing the stylesheet will make WordPress
* assume that the themes directory is inside `wp-content`.
*
* @author Leo Fajardo (@leorw)
* @since 2.2.3
*/
$themes_directory = get_theme_root( get_stylesheet() );
$themes_directory_name = basename( $themes_directory );
$theme_candidate_basename = basename( dirname( $fs_root_path ) ) . '/' . basename( $fs_root_path );
if ( $file_path == fs_normalize_path( realpath( trailingslashit( $themes_directory ) . $theme_candidate_basename . '/' . basename( $file_path ) ) )
) {
$this_sdk_relative_path = '../' . $themes_directory_name . '/' . $theme_candidate_basename;
$is_theme = true;
} else {
$this_sdk_relative_path = plugin_basename( $fs_root_path );
$is_theme = false;
}
if ( ! isset( $fs_active_plugins ) ) {
// Load all Freemius powered active plugins.
$fs_active_plugins = get_option( 'fs_active_plugins' );
if ( ! is_object( $fs_active_plugins ) ) {
$fs_active_plugins = new stdClass();
}
if ( ! isset( $fs_active_plugins->plugins ) ) {
$fs_active_plugins->plugins = array();
}
}
if ( empty( $fs_active_plugins->abspath ) ) {
/**
* Store the WP install absolute path reference to identify environment change
* while replicating the storage.
*
* @author Vova Feldman (@svovaf)
* @since 1.2.1.7
*/
$fs_active_plugins->abspath = ABSPATH;
} else {
if ( ABSPATH !== $fs_active_plugins->abspath ) {
/**
* WordPress path has changed, cleanup the SDK references cache.
* This resolves issues triggered when spinning a staging environments
* while replicating the database.
*
* @author Vova Feldman (@svovaf)
* @since 1.2.1.7
*/
$fs_active_plugins->abspath = ABSPATH;
$fs_active_plugins->plugins = array();
unset( $fs_active_plugins->newest );
} else {
/**
* Make sure SDK references are still valid. This resolves
* issues when users hard delete modules via FTP.
*
* @author Vova Feldman (@svovaf)
* @since 1.2.1.7
*/
$has_changes = false;
foreach ( $fs_active_plugins->plugins as $sdk_path => $data ) {
if ( ! file_exists( ( isset( $data->type ) && 'theme' === $data->type ? $themes_directory : WP_PLUGIN_DIR ) . '/' . $sdk_path ) ) {
unset( $fs_active_plugins->plugins[ $sdk_path ] );
if (
! empty( $fs_active_plugins->newest ) &&
$sdk_path === $fs_active_plugins->newest->sdk_path
) {
unset( $fs_active_plugins->newest );
}
$has_changes = true;
}
}
if ( $has_changes ) {
if ( empty( $fs_active_plugins->plugins ) ) {
unset( $fs_active_plugins->newest );
}
update_option( 'fs_active_plugins', $fs_active_plugins );
}
}
}
if ( ! function_exists( 'fs_find_direct_caller_plugin_file' ) ) {
require_once dirname( __FILE__ ) . '/includes/supplements/fs-essential-functions-1.1.7.1.php';
}
if ( ! function_exists( 'fs_get_plugins' ) ) {
require_once dirname( __FILE__ ) . '/includes/supplements/fs-essential-functions-2.2.1.php';
}
// 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
) {
if ( $is_theme ) {
$plugin_path = basename( dirname( $this_sdk_relative_path ) );
} else {
$plugin_path = plugin_basename( fs_find_direct_caller_plugin_file( $file_path ) );
}
$fs_active_plugins->plugins[ $this_sdk_relative_path ] = (object) array(
'version' => $this_sdk_version,
'type' => ( $is_theme ? 'theme' : 'plugin' ),
'timestamp' => time(),
'plugin_path' => $plugin_path,
);
}
$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.
fs_redirect( $_SERVER['REQUEST_URI'] );
}
} else {
if ( ! function_exists( 'get_plugins' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
$fs_newest_sdk = $fs_active_plugins->newest;
$fs_newest_sdk = $fs_active_plugins->plugins[ $fs_newest_sdk->sdk_path ];
$is_newest_sdk_type_theme = ( isset( $fs_newest_sdk->type ) && 'theme' === $fs_newest_sdk->type );
if ( ! $is_newest_sdk_type_theme ) {
$is_newest_sdk_plugin_active = is_plugin_active( $fs_newest_sdk->plugin_path );
} else {
$current_theme = wp_get_theme();
$is_newest_sdk_plugin_active = ( $current_theme->stylesheet === $fs_newest_sdk->plugin_path );
$current_theme_parent = $current_theme->parent();
/**
* If the current theme is a child of the theme that has the newest SDK, this prevents a redirects loop
* from happening by keeping the SDK info stored in the `fs_active_plugins` option.
*/
if ( ! $is_newest_sdk_plugin_active && $current_theme_parent instanceof WP_Theme ) {
$is_newest_sdk_plugin_active = ( $fs_newest_sdk->plugin_path === $current_theme_parent->stylesheet );
}
}
if ( $is_current_sdk_newest &&
! $is_newest_sdk_plugin_active &&
! $fs_active_plugins->newest->in_activation
) {
// If current SDK is the newest and the plugin is NOT active, it means
// that the current plugin in activation mode.
$fs_active_plugins->newest->in_activation = true;
update_option( 'fs_active_plugins', $fs_active_plugins );
}
if ( ! $is_theme ) {
$sdk_starter_path = fs_normalize_path( WP_PLUGIN_DIR . '/' . $this_sdk_relative_path . '/start.php' );
} else {
$sdk_starter_path = fs_normalize_path(
$themes_directory
. '/'
. str_replace( "../{$themes_directory_name}/", '', $this_sdk_relative_path )
. '/start.php' );
}
$is_newest_sdk_path_valid = ( $is_newest_sdk_plugin_active || $fs_active_plugins->newest->in_activation ) && file_exists( $sdk_starter_path );
if ( ! $is_newest_sdk_path_valid && ! $is_current_sdk_newest ) {
// Plugin with newest SDK is no longer active, or SDK was moved to a different location.
unset( $fs_active_plugins->plugins[ $fs_active_plugins->newest->sdk_path ] );
}
if ( ! ( $is_newest_sdk_plugin_active || $fs_active_plugins->newest->in_activation ) ||
! $is_newest_sdk_path_valid ||
// Is newest SDK downgraded.
( $this_sdk_relative_path == $fs_active_plugins->newest->sdk_path &&
version_compare( $fs_active_plugins->newest->version, $this_sdk_version, '>' ) )
) {
/**
* Plugin with newest SDK is no longer active.
* OR
* The newest SDK was in the current plugin. BUT, seems like the version of
* the SDK was downgraded to a lower SDK.
*/
// Find the active plugin with the newest SDK version and update the newest reference.
fs_fallback_to_newest_active_sdk();
} else {
if ( $is_newest_sdk_plugin_active &&
$this_sdk_relative_path == $fs_active_plugins->newest->sdk_path &&
( $fs_active_plugins->newest->in_activation ||
( class_exists( 'Freemius' ) && ( ! defined( 'WP_FS__SDK_VERSION' ) || version_compare( WP_FS__SDK_VERSION, $this_sdk_version, '<' ) ) )
)
) {
if ( $fs_active_plugins->newest->in_activation && ! $is_newest_sdk_type_theme ) {
// Plugin no more in activation.
$fs_active_plugins->newest->in_activation = false;
update_option( 'fs_active_plugins', $fs_active_plugins );
}
// Reorder plugins to load plugin with newest SDK first.
if ( fs_newest_sdk_plugin_first() ) {
// Refresh page after re-order to make sure activated plugin loads newest SDK.
if ( class_exists( 'Freemius' ) ) {
fs_redirect( $_SERVER['REQUEST_URI'] );
}
}
}
}
}
if ( class_exists( 'Freemius' ) ) {
// SDK was already loaded.
return;
}
if ( version_compare( $this_sdk_version, $fs_active_plugins->newest->version, '<' ) ) {
$newest_sdk = $fs_active_plugins->plugins[ $fs_active_plugins->newest->sdk_path ];
$plugins_or_theme_dir_path = ( ! isset( $newest_sdk->type ) || 'theme' !== $newest_sdk->type ) ?
WP_PLUGIN_DIR :
$themes_directory;
$newest_sdk_starter = fs_normalize_path(
$plugins_or_theme_dir_path
. '/'
. str_replace( "../{$themes_directory_name}/", '', $fs_active_plugins->newest->sdk_path )
. '/start.php' );
if ( file_exists( $newest_sdk_starter ) ) {
// Reorder plugins to load plugin with newest SDK first.
fs_newest_sdk_plugin_first();
// There's a newer SDK version, load it instead of the current one!
require_once $newest_sdk_starter;
return;
}
}
#endregion SDK Selection Logic --------------------------------------------------------------------
#region Hooks & Filters Collection --------------------------------------------------------------------
/**
* Freemius hooks (actions & filters) tags structure:
*
* fs_{filter/action_name}_{plugin_slug}
*
* --------------------------------------------------------
*
* Usage with WordPress' add_action() / add_filter():
*
* add_action('fs_{filter/action_name}_{plugin_slug}', $callable);
*
* --------------------------------------------------------
*
* Usage with Freemius' instance add_action() / add_filter():
*
* // No need to add 'fs_' prefix nor '_{plugin_slug}' suffix.
* my_freemius()->add_action('{action_name}', $callable);
*
* --------------------------------------------------------
*
* Freemius filters collection:
*
* fs_connect_url_{plugin_slug}
* fs_trial_promotion_message_{plugin_slug}
* fs_is_long_term_user_{plugin_slug}
* fs_uninstall_reasons_{plugin_slug}
* fs_is_plugin_update_{plugin_slug}
* fs_api_domains_{plugin_slug}
* fs_email_template_sections_{plugin_slug}
* fs_support_forum_submenu_{plugin_slug}
Loading ...