assets
9 years ago
includes
9 years ago
languages
9 years ago
templates
9 years ago
LICENSE.txt
9 years ago
README.md
9 years ago
config.php
9 years ago
index.php
9 years ago
package.json
9 years ago
require.php
9 years ago
start.php
9 years ago
start.php
308 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @package Freemius |
| 4 | * @copyright Copyright (c) 2015, Freemius, Inc. |
| 5 | * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 6 | * @since 1.0.3 |
| 7 | */ |
| 8 | |
| 9 | if ( ! defined( 'ABSPATH' ) ) { |
| 10 | exit; |
| 11 | } |
| 12 | |
| 13 | /** |
| 14 | * Freemius SDK Version. |
| 15 | * |
| 16 | * @var string |
| 17 | */ |
| 18 | $this_sdk_version = '1.2.1.6.1'; |
| 19 | |
| 20 | #region SDK Selection Logic -------------------------------------------------------------------- |
| 21 | |
| 22 | /** |
| 23 | * Special logic added on 1.1.6 to make sure that every Freemius powered plugin |
| 24 | * will ALWAYS be loaded with the newest SDK from the active Freemius powered plugins. |
| 25 | * |
| 26 | * Since Freemius SDK is backward compatible, this will make sure that all Freemius powered |
| 27 | * plugins will run correctly. |
| 28 | * |
| 29 | * @since 1.1.6 |
| 30 | */ |
| 31 | |
| 32 | global $fs_active_plugins; |
| 33 | |
| 34 | $this_sdk_relative_path = plugin_basename( dirname( __FILE__ ) ); |
| 35 | |
| 36 | if ( ! isset( $fs_active_plugins ) ) { |
| 37 | // Require SDK essentials. |
| 38 | require_once dirname( __FILE__ ) . '/includes/fs-essential-functions.php'; |
| 39 | |
| 40 | // Load all Freemius powered active plugins. |
| 41 | $fs_active_plugins = get_option( 'fs_active_plugins', new stdClass() ); |
| 42 | |
| 43 | if ( ! isset( $fs_active_plugins->plugins ) ) { |
| 44 | $fs_active_plugins->plugins = array(); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | if ( ! function_exists( 'fs_find_direct_caller_plugin_file' ) ) { |
| 49 | require_once dirname( __FILE__ ) . '/includes/supplements/fs-essential-functions-1.1.7.1.php'; |
| 50 | } |
| 51 | |
| 52 | // Update current SDK info based on the SDK path. |
| 53 | if ( ! isset( $fs_active_plugins->plugins[ $this_sdk_relative_path ] ) || |
| 54 | $this_sdk_version != $fs_active_plugins->plugins[ $this_sdk_relative_path ]->version |
| 55 | ) { |
| 56 | $fs_active_plugins->plugins[ $this_sdk_relative_path ] = (object) array( |
| 57 | 'version' => $this_sdk_version, |
| 58 | 'timestamp' => time(), |
| 59 | 'plugin_path' => plugin_basename( fs_find_direct_caller_plugin_file( __FILE__ ) ), |
| 60 | ); |
| 61 | } |
| 62 | |
| 63 | $is_current_sdk_newest = isset( $fs_active_plugins->newest ) && ( $this_sdk_relative_path == $fs_active_plugins->newest->sdk_path ); |
| 64 | |
| 65 | if ( ! isset( $fs_active_plugins->newest ) ) { |
| 66 | /** |
| 67 | * This will be executed only once, for the first time a Freemius powered plugin is activated. |
| 68 | */ |
| 69 | fs_update_sdk_newest_version( $this_sdk_relative_path, $fs_active_plugins->plugins[ $this_sdk_relative_path ]->plugin_path ); |
| 70 | |
| 71 | $is_current_sdk_newest = true; |
| 72 | } else if ( version_compare( $fs_active_plugins->newest->version, $this_sdk_version, '<' ) ) { |
| 73 | /** |
| 74 | * Current SDK is newer than the newest stored SDK. |
| 75 | */ |
| 76 | fs_update_sdk_newest_version( $this_sdk_relative_path, $fs_active_plugins->plugins[ $this_sdk_relative_path ]->plugin_path ); |
| 77 | |
| 78 | if ( class_exists( 'Freemius' ) ) { |
| 79 | // Older SDK version was already loaded. |
| 80 | |
| 81 | if ( ! $fs_active_plugins->newest->in_activation ) { |
| 82 | // Re-order plugins to load this plugin first. |
| 83 | fs_newest_sdk_plugin_first(); |
| 84 | } |
| 85 | |
| 86 | // Refresh page. |
| 87 | fs_redirect( $_SERVER['REQUEST_URI'] ); |
| 88 | } |
| 89 | } else { |
| 90 | if ( ! function_exists( 'get_plugins' ) ) { |
| 91 | require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 92 | } |
| 93 | |
| 94 | $is_newest_sdk_plugin_activate = is_plugin_active( $fs_active_plugins->newest->plugin_path ); |
| 95 | |
| 96 | if ( $is_current_sdk_newest && |
| 97 | ! $is_newest_sdk_plugin_activate && |
| 98 | ! $fs_active_plugins->newest->in_activation |
| 99 | ) { |
| 100 | // If current SDK is the newest and the plugin is NOT active, it means |
| 101 | // that the current plugin in activation mode. |
| 102 | $fs_active_plugins->newest->in_activation = true; |
| 103 | update_option( 'fs_active_plugins', $fs_active_plugins ); |
| 104 | } |
| 105 | |
| 106 | $is_newest_sdk_path_valid = ( $is_newest_sdk_plugin_activate || $fs_active_plugins->newest->in_activation ) && file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $this_sdk_relative_path . '/start.php' ) ); |
| 107 | |
| 108 | if ( ! $is_newest_sdk_path_valid && ! $is_current_sdk_newest ) { |
| 109 | // Plugin with newest SDK is no longer active, or SDK was moved to a different location. |
| 110 | unset( $fs_active_plugins->plugins[ $fs_active_plugins->newest->sdk_path ] ); |
| 111 | } |
| 112 | |
| 113 | if ( ! ( $is_newest_sdk_plugin_activate || $fs_active_plugins->newest->in_activation ) || |
| 114 | ! $is_newest_sdk_path_valid || |
| 115 | // Is newest SDK downgraded. |
| 116 | ( $this_sdk_relative_path == $fs_active_plugins->newest->sdk_path && |
| 117 | version_compare( $fs_active_plugins->newest->version, $this_sdk_version, '>' ) ) |
| 118 | ) { |
| 119 | /** |
| 120 | * Plugin with newest SDK is no longer active. |
| 121 | * OR |
| 122 | * The newest SDK was in the current plugin. BUT, seems like the version of |
| 123 | * the SDK was downgraded to a lower SDK. |
| 124 | */ |
| 125 | // Find the active plugin with the newest SDK version and update the newest reference. |
| 126 | fs_fallback_to_newest_active_sdk(); |
| 127 | } else { |
| 128 | if ( $is_newest_sdk_plugin_activate && |
| 129 | $this_sdk_relative_path == $fs_active_plugins->newest->sdk_path && |
| 130 | ( $fs_active_plugins->newest->in_activation || |
| 131 | ( class_exists( 'Freemius' ) && ( ! defined( 'WP_FS__SDK_VERSION' ) || version_compare( WP_FS__SDK_VERSION, $this_sdk_version, '<' ) ) ) |
| 132 | ) |
| 133 | |
| 134 | ) { |
| 135 | if ( $fs_active_plugins->newest->in_activation ) { |
| 136 | // Plugin no more in activation. |
| 137 | $fs_active_plugins->newest->in_activation = false; |
| 138 | update_option( 'fs_active_plugins', $fs_active_plugins ); |
| 139 | } |
| 140 | |
| 141 | // Reorder plugins to load plugin with newest SDK first. |
| 142 | if ( fs_newest_sdk_plugin_first() ) { |
| 143 | // Refresh page after re-order to make sure activated plugin loads newest SDK. |
| 144 | if ( class_exists( 'Freemius' ) ) { |
| 145 | fs_redirect( $_SERVER['REQUEST_URI'] ); |
| 146 | } |
| 147 | } |
| 148 | } |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | if ( class_exists( 'Freemius' ) ) { |
| 153 | // SDK was already loaded. |
| 154 | return; |
| 155 | } |
| 156 | |
| 157 | if ( version_compare( $this_sdk_version, $fs_active_plugins->newest->version, '<' ) ) { |
| 158 | $newest_sdk_starter = fs_normalize_path( WP_PLUGIN_DIR . '/' . $fs_active_plugins->newest->sdk_path . '/start.php' ); |
| 159 | |
| 160 | if ( file_exists( $newest_sdk_starter ) ) { |
| 161 | // Reorder plugins to load plugin with newest SDK first. |
| 162 | fs_newest_sdk_plugin_first(); |
| 163 | |
| 164 | // There's a newer SDK version, load it instead of the current one! |
| 165 | require_once $newest_sdk_starter; |
| 166 | |
| 167 | return; |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | #endregion SDK Selection Logic -------------------------------------------------------------------- |
| 172 | |
| 173 | #region Hooks & Filters Collection -------------------------------------------------------------------- |
| 174 | |
| 175 | /** |
| 176 | * Freemius hooks (actions & filters) tags structure: |
| 177 | * |
| 178 | * fs_{filter/action_name}_{plugin_slug} |
| 179 | * |
| 180 | * -------------------------------------------------------- |
| 181 | * |
| 182 | * Usage with WordPress' add_action() / add_filter(): |
| 183 | * |
| 184 | * add_action('fs_{filter/action_name}_{plugin_slug}', $callable); |
| 185 | * |
| 186 | * -------------------------------------------------------- |
| 187 | * |
| 188 | * Usage with Freemius' instance add_action() / add_filter(): |
| 189 | * |
| 190 | * // No need to add 'fs_' prefix nor '_{plugin_slug}' suffix. |
| 191 | * my_freemius()->add_action('{action_name}', $callable); |
| 192 | * |
| 193 | * -------------------------------------------------------- |
| 194 | * |
| 195 | * Freemius filters collection: |
| 196 | * |
| 197 | * fs_connect_url_{plugin_slug} |
| 198 | * fs_trial_promotion_message_{plugin_slug} |
| 199 | * fs_is_long_term_user_{plugin_slug} |
| 200 | * fs_uninstall_reasons_{plugin_slug} |
| 201 | * fs_is_plugin_update_{plugin_slug} |
| 202 | * fs_api_domains_{plugin_slug} |
| 203 | * fs_email_template_sections_{plugin_slug} |
| 204 | * fs_support_forum_submenu_{plugin_slug} |
| 205 | * fs_support_forum_url_{plugin_slug} |
| 206 | * fs_connect_message_{plugin_slug} |
| 207 | * fs_connect_message_on_update_{plugin_slug} |
| 208 | * fs_uninstall_confirmation_message_{plugin_slug} |
| 209 | * fs_pending_activation_message_{plugin_slug} |
| 210 | * fs_is_submenu_visible_{plugin_slug} |
| 211 | * fs_plugin_icon_{plugin_slug} |
| 212 | * fs_show_trial_{plugin_slug} |
| 213 | * |
| 214 | * -------------------------------------------------------- |
| 215 | * |
| 216 | * Freemius actions collection: |
| 217 | * |
| 218 | * fs_after_license_loaded_{plugin_slug} |
| 219 | * fs_after_license_change_{plugin_slug} |
| 220 | * fs_after_plans_sync_{plugin_slug} |
| 221 | * |
| 222 | * fs_after_account_details_{plugin_slug} |
| 223 | * fs_after_account_user_sync_{plugin_slug} |
| 224 | * fs_after_account_plan_sync_{plugin_slug} |
| 225 | * fs_before_account_load_{plugin_slug} |
| 226 | * fs_after_account_connection_{plugin_slug} |
| 227 | * fs_account_property_edit_{plugin_slug} |
| 228 | * fs_account_email_verified_{plugin_slug} |
| 229 | * fs_account_page_load_before_departure_{plugin_slug} |
| 230 | * fs_before_account_delete_{plugin_slug} |
| 231 | * fs_after_account_delete_{plugin_slug} |
| 232 | * |
| 233 | * fs_sdk_version_update_{plugin_slug} |
| 234 | * fs_plugin_version_update_{plugin_slug} |
| 235 | * |
| 236 | * fs_initiated_{plugin_slug} |
| 237 | * fs_after_init_plugin_registered_{plugin_slug} |
| 238 | * fs_after_init_plugin_anonymous_{plugin_slug} |
| 239 | * fs_after_init_plugin_pending_activations_{plugin_slug} |
| 240 | * fs_after_init_addon_registered_{plugin_slug} |
| 241 | * fs_after_init_addon_anonymous_{plugin_slug} |
| 242 | * fs_after_init_addon_pending_activations_{plugin_slug} |
| 243 | * |
| 244 | * fs_after_premium_version_activation_{plugin_slug} |
| 245 | * fs_after_free_version_reactivation_{plugin_slug} |
| 246 | * |
| 247 | * fs_after_uninstall_{plugin_slug} |
| 248 | * fs_before_admin_menu_init_{plugin_slug} |
| 249 | */ |
| 250 | |
| 251 | #endregion Hooks & Filters Collection -------------------------------------------------------------------- |
| 252 | |
| 253 | if ( ! class_exists( 'Freemius' ) ) { |
| 254 | |
| 255 | if ( ! defined( 'WP_FS__SDK_VERSION' ) ) { |
| 256 | define( 'WP_FS__SDK_VERSION', $this_sdk_version ); |
| 257 | } |
| 258 | |
| 259 | // Load SDK files. |
| 260 | require_once dirname( __FILE__ ) . '/require.php'; |
| 261 | |
| 262 | /** |
| 263 | * Quick shortcut to get Freemius for specified plugin. |
| 264 | * Used by various templates. |
| 265 | * |
| 266 | * @param string $slug |
| 267 | * |
| 268 | * @return Freemius |
| 269 | */ |
| 270 | function freemius( $slug ) { |
| 271 | return Freemius::instance( $slug ); |
| 272 | } |
| 273 | |
| 274 | /** |
| 275 | * @param string $slug |
| 276 | * @param number $plugin_id |
| 277 | * @param string $public_key |
| 278 | * @param bool $is_live Is live or test plugin. |
| 279 | * @param bool $is_premium Hints freemius if running the premium plugin or not. |
| 280 | * |
| 281 | * @return Freemius |
| 282 | * |
| 283 | * @deprecated Please use fs_dynamic_init(). |
| 284 | */ |
| 285 | function fs_init( $slug, $plugin_id, $public_key, $is_live = true, $is_premium = true ) { |
| 286 | $fs = Freemius::instance( $slug, true ); |
| 287 | $fs->init( $plugin_id, $public_key, $is_live, $is_premium ); |
| 288 | |
| 289 | return $fs; |
| 290 | } |
| 291 | |
| 292 | /** |
| 293 | * @param array<string,string> $module Plugin or Theme details. |
| 294 | * |
| 295 | * @return Freemius |
| 296 | * @throws Freemius_Exception |
| 297 | */ |
| 298 | function fs_dynamic_init( $module ) { |
| 299 | $fs = Freemius::instance( $module['slug'], true ); |
| 300 | $fs->dynamic_init( $module ); |
| 301 | |
| 302 | return $fs; |
| 303 | } |
| 304 | |
| 305 | function fs_dump_log() { |
| 306 | FS_Logger::dump(); |
| 307 | } |
| 308 | } |