| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package Freemius |
| 4 |
* @copyright Copyright (c) 2015, Freemius, Inc. |
| 5 |
* @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3 |
| 6 |
* @since 1.0.3 |
| 7 |
*/ |
| 8 |
|
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
return; |
| 11 |
} |
| 12 |
|
| 13 |
/** |
| 14 |
* Freemius SDK Version. |
| 15 |
* |
| 16 |
* @var string |
| 17 |
*/ |
| 18 |
$this_sdk_version = '2.13.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 |
if ( ! function_exists( 'fs_find_caller_plugin_file' ) ) { |
| 35 |
// Require SDK essentials. |
| 36 |
require_once dirname( __FILE__ ) . '/includes/fs-essential-functions.php'; |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* We updated the logic to support SDK loading from a subfolder of a theme as well as from a parent theme |
| 41 |
* If the SDK is found in the active theme, it sets the relative path accordingly. |
| 42 |
* If not, it checks the parent theme and sets the relative path if found there. |
| 43 |
* This allows the SDK to be loaded from composer dependencies or from a custom `vendor/freemius` folder. |
| 44 |
* |
| 45 |
* @author Daniele Alessandra (@DanieleAlessandra) |
| 46 |
* @since 2.9.0.5 |
| 47 |
* |
| 48 |
* |
| 49 |
* This complex logic fixes symlink issues (e.g. with Vargant). The logic assumes |
| 50 |
* that if it's a file from an SDK running in a theme, the location of the SDK |
| 51 |
* is in the main theme's folder. |
| 52 |
* |
| 53 |
* @author Vova Feldman (@svovaf) |
| 54 |
* @since 1.2.2.6 |
| 55 |
*/ |
| 56 |
$file_path = fs_normalize_path( __FILE__ ); |
| 57 |
$fs_root_path = dirname( $file_path ); |
| 58 |
|
| 59 |
// @todo: Remove this code after a few months when WP 6.3 usage is low enough. |
| 60 |
global $wp_version; |
| 61 |
|
| 62 |
if ( |
| 63 |
! function_exists( 'wp_get_current_user' ) && |
| 64 |
/** |
| 65 |
* `get_stylesheet()` will rely on `wp_get_current_user()` when it is being filtered by `theme-previews.php`. That happens only when the site editor is loaded or when the site editor is sending REST requests. |
| 66 |
* @see theme-previews.php:wp_get_theme_preview_path() |
| 67 |
* |
| 68 |
* @todo This behavior is already fixed in the core (WP 6.3.2+), and this code can be removed after a few months when WP 6.3 usage is low enough. |
| 69 |
* @since WP 6.3.0 |
| 70 |
*/ |
| 71 |
version_compare( $wp_version, '6.3', '>=' ) && |
| 72 |
version_compare( $wp_version, '6.3.1', '<=' ) && |
| 73 |
( |
| 74 |
'site-editor.php' === basename( $_SERVER['SCRIPT_FILENAME'] ) || |
| 75 |
( |
| 76 |
function_exists( 'wp_is_json_request' ) && |
| 77 |
wp_is_json_request() && |
| 78 |
! empty( $_GET['wp_theme_preview'] ) |
| 79 |
) |
| 80 |
) |
| 81 |
) { |
| 82 |
// Requiring this file since the call to get_stylesheet() below can trigger a call to wp_get_current_user() when previewing a theme. |
| 83 |
require_once ABSPATH . 'wp-includes/pluggable.php'; |
| 84 |
} |
| 85 |
|
| 86 |
/** |
| 87 |
* Get the themes directory where the active theme is located (not passing the stylesheet will make WordPress |
| 88 |
* assume that the themes directory is inside `wp-content`. |
| 89 |
* |
| 90 |
* @author Leo Fajardo (@leorw) |
| 91 |
* @since 2.2.3 |
| 92 |
*/ |
| 93 |
$themes_directory = fs_normalize_path( get_theme_root( get_stylesheet() ) ); |
| 94 |
$themes_directory_name = basename( $themes_directory ); |
| 95 |
|
| 96 |
// This change ensures that the condition works even if the SDK is located in a subdirectory (e.g., vendor) |
| 97 |
$theme_candidate_sdk_basename = str_replace( $themes_directory . '/' . get_stylesheet() . '/', '', $fs_root_path ); |
| 98 |
|
| 99 |
// Check if the current file is part of the active theme. |
| 100 |
$is_current_sdk_from_active_theme = $file_path == $themes_directory . '/' . get_stylesheet() . '/' . $theme_candidate_sdk_basename . '/' . basename( $file_path ); |
| 101 |
$is_current_sdk_from_parent_theme = false; |
| 102 |
|
| 103 |
// Check if the current file is part of the parent theme. |
| 104 |
if ( ! $is_current_sdk_from_active_theme ) { |
| 105 |
$theme_candidate_sdk_basename = str_replace( $themes_directory . '/' . get_template() . '/', |
| 106 |
'', |
| 107 |
$fs_root_path ); |
| 108 |
$is_current_sdk_from_parent_theme = $file_path == $themes_directory . '/' . get_template() . '/' . $theme_candidate_sdk_basename . '/' . basename( $file_path ); |
| 109 |
} |
| 110 |
|
| 111 |
$theme_name = null; |
| 112 |
if ( $is_current_sdk_from_active_theme ) { |
| 113 |
$theme_name = get_stylesheet(); |
| 114 |
$this_sdk_relative_path = '../' . $themes_directory_name . '/' . $theme_name . '/' . $theme_candidate_sdk_basename; |
| 115 |
$is_theme = true; |
| 116 |
} else if ( $is_current_sdk_from_parent_theme ) { |
| 117 |
$theme_name = get_template(); |
| 118 |
$this_sdk_relative_path = '../' . $themes_directory_name . '/' . $theme_name . '/' . $theme_candidate_sdk_basename; |
| 119 |
$is_theme = true; |
| 120 |
} else { |
| 121 |
$this_sdk_relative_path = plugin_basename( $fs_root_path ); |
| 122 |
$is_theme = false; |
| 123 |
|
| 124 |
/** |
| 125 |
* If this file was included from another plugin with lower SDK version, and if this plugin is symlinked, then we need to get the actual plugin path, |
| 126 |
* as the value right now will be wrong, it will only remove the directory separator from the file_path. |
| 127 |
* |
| 128 |
* The check of `fs_find_direct_caller_plugin_file` determines that this file was indeed included by a different plugin than the main plugin. |
| 129 |
*/ |
| 130 |
if ( DIRECTORY_SEPARATOR . $this_sdk_relative_path === $fs_root_path && function_exists( 'fs_find_direct_caller_plugin_file' ) ) { |
| 131 |
$direct_caller_plugin_file = fs_find_direct_caller_plugin_file( $file_path ); |
| 132 |
|
| 133 |
if ( ! empty( $direct_caller_plugin_file ) ) { |
| 134 |
$original_plugin_dir_name = dirname( $direct_caller_plugin_file ); |
| 135 |
|
| 136 |
// Remove everything before the original plugin directory name. |
| 137 |
$this_sdk_relative_path = substr( $this_sdk_relative_path, strpos( $this_sdk_relative_path, $original_plugin_dir_name ) ); |
| 138 |
|
| 139 |
unset( $original_plugin_dir_name ); |
| 140 |
} |
| 141 |
} |
| 142 |
} |
| 143 |
|
| 144 |
if ( ! isset( $fs_active_plugins ) ) { |
| 145 |
// Load all Freemius powered active plugins. |
| 146 |
$fs_active_plugins = get_option( 'fs_active_plugins' ); |
| 147 |
|
| 148 |
if ( ! is_object( $fs_active_plugins ) ) { |
| 149 |
$fs_active_plugins = new stdClass(); |
| 150 |
} |
| 151 |
|
| 152 |
if ( ! isset( $fs_active_plugins->plugins ) ) { |
| 153 |
$fs_active_plugins->plugins = array(); |
| 154 |
} |
| 155 |
} |
| 156 |
|
| 157 |
if ( empty( $fs_active_plugins->abspath ) ) { |
| 158 |
/** |
| 159 |
* Store the WP install absolute path reference to identify environment change |
| 160 |
* while replicating the storage. |
| 161 |
* |
| 162 |
* @author Vova Feldman (@svovaf) |
| 163 |
* @since 1.2.1.7 |
| 164 |
*/ |
| 165 |
$fs_active_plugins->abspath = ABSPATH; |
| 166 |
} else { |
| 167 |
if ( ABSPATH !== $fs_active_plugins->abspath ) { |
| 168 |
/** |
| 169 |
* WordPress path has changed, cleanup the SDK references cache. |
| 170 |
* This resolves issues triggered when spinning a staging environments |
| 171 |
* while replicating the database. |
| 172 |
* |
| 173 |
* @author Vova Feldman (@svovaf) |
| 174 |
* @since 1.2.1.7 |
| 175 |
*/ |
| 176 |
$fs_active_plugins->abspath = ABSPATH; |
| 177 |
$fs_active_plugins->plugins = array(); |
| 178 |
unset( $fs_active_plugins->newest ); |
| 179 |
} else { |
| 180 |
/** |
| 181 |
* Make sure SDK references are still valid. This resolves |
| 182 |
* issues when users hard delete modules via FTP. |
| 183 |
* |
| 184 |
* @author Vova Feldman (@svovaf) |
| 185 |
* @since 1.2.1.7 |
| 186 |
*/ |
| 187 |
$has_changes = false; |
| 188 |
foreach ( $fs_active_plugins->plugins as $sdk_path => $data ) { |
| 189 |
if ( ! file_exists( ( isset( $data->type ) && 'theme' === $data->type ? $themes_directory : WP_PLUGIN_DIR ) . '/' . $sdk_path ) ) { |
| 190 |
unset( $fs_active_plugins->plugins[ $sdk_path ] ); |
| 191 |
|
| 192 |
if ( |
| 193 |
! empty( $fs_active_plugins->newest ) && |
| 194 |
$sdk_path === $fs_active_plugins->newest->sdk_path |
| 195 |
) { |
| 196 |
unset( $fs_active_plugins->newest ); |
| 197 |
} |
| 198 |
|
| 199 |
$has_changes = true; |
| 200 |
} |
| 201 |
} |
| 202 |
|
| 203 |
if ( $has_changes ) { |
| 204 |
if ( empty( $fs_active_plugins->plugins ) ) { |
| 205 |
unset( $fs_active_plugins->newest ); |
| 206 |
} |
| 207 |
|
| 208 |
update_option( 'fs_active_plugins', $fs_active_plugins ); |
| 209 |
} |
| 210 |
} |
| 211 |
} |
| 212 |
|
| 213 |
if ( ! function_exists( 'fs_find_direct_caller_plugin_file' ) ) { |
| 214 |
require_once dirname( __FILE__ ) . '/includes/supplements/fs-essential-functions-1.1.7.1.php'; |
| 215 |
} |
| 216 |
|
| 217 |
if ( ! function_exists( 'fs_get_plugins' ) ) { |
| 218 |
require_once dirname( __FILE__ ) . '/includes/supplements/fs-essential-functions-2.2.1.php'; |
| 219 |
} |
| 220 |
|
| 221 |
// Update current SDK info based on the SDK path. |
| 222 |
if ( ! isset( $fs_active_plugins->plugins[ $this_sdk_relative_path ] ) || |
| 223 |
$this_sdk_version != $fs_active_plugins->plugins[ $this_sdk_relative_path ]->version |
| 224 |
) { |
| 225 |
if ( $is_theme ) { |
| 226 |
// Saving relative path and not only directory name as it could be a subfolder |
| 227 |
$plugin_path = $theme_name; |
| 228 |
} else { |
| 229 |
$plugin_path = plugin_basename( fs_find_direct_caller_plugin_file( $file_path ) ); |
| 230 |
} |
| 231 |
|
| 232 |
$fs_active_plugins->plugins[ $this_sdk_relative_path ] = (object) array( |
| 233 |
'version' => $this_sdk_version, |
| 234 |
'type' => ( $is_theme ? 'theme' : 'plugin' ), |
| 235 |
'timestamp' => time(), |
| 236 |
'plugin_path' => $plugin_path, |
| 237 |
); |
| 238 |
} |
| 239 |
|
| 240 |
$is_current_sdk_newest = isset( $fs_active_plugins->newest ) && ( $this_sdk_relative_path == $fs_active_plugins->newest->sdk_path ); |
| 241 |
|
| 242 |
if ( ! isset( $fs_active_plugins->newest ) ) { |
| 243 |
/** |
| 244 |
* This will be executed only once, for the first time a Freemius powered plugin is activated. |
| 245 |
*/ |
| 246 |
fs_update_sdk_newest_version( $this_sdk_relative_path, $fs_active_plugins->plugins[ $this_sdk_relative_path ]->plugin_path ); |
| 247 |
|
| 248 |
$is_current_sdk_newest = true; |
| 249 |
} else if ( version_compare( $fs_active_plugins->newest->version, $this_sdk_version, '<' ) ) { |
| 250 |
/** |
| 251 |
* Current SDK is newer than the newest stored SDK. |
| 252 |
*/ |
| 253 |
fs_update_sdk_newest_version( $this_sdk_relative_path, $fs_active_plugins->plugins[ $this_sdk_relative_path ]->plugin_path ); |
| 254 |
|
| 255 |
if ( class_exists( 'Freemius' ) ) { |
| 256 |
// Older SDK version was already loaded. |
| 257 |
|
| 258 |
if ( ! $fs_active_plugins->newest->in_activation ) { |
| 259 |
// Re-order plugins to load this plugin first. |
| 260 |
fs_newest_sdk_plugin_first(); |
| 261 |
} |
| 262 |
|
| 263 |
// Refresh page. |
| 264 |
fs_redirect( $_SERVER['REQUEST_URI'] ); |
| 265 |
} |
| 266 |
} else { |
| 267 |
if ( ! function_exists( 'get_plugins' ) ) { |
| 268 |
require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 269 |
} |
| 270 |
|
| 271 |
$fs_newest_sdk = $fs_active_plugins->newest; |
| 272 |
$fs_newest_sdk = $fs_active_plugins->plugins[ $fs_newest_sdk->sdk_path ]; |
| 273 |
|
| 274 |
$is_newest_sdk_type_theme = ( isset( $fs_newest_sdk->type ) && 'theme' === $fs_newest_sdk->type ); |
| 275 |
|
| 276 |
/** |
| 277 |
* @var bool $is_newest_sdk_module_active |
| 278 |
* True if the plugin with the newest SDK is active. |
| 279 |
* True if the newest SDK is part of the current theme or current theme's parent. |
| 280 |
* False otherwise. |
| 281 |
*/ |
| 282 |
if ( ! $is_newest_sdk_type_theme ) { |
| 283 |
$is_newest_sdk_module_active = is_plugin_active( $fs_newest_sdk->plugin_path ); |
| 284 |
} else { |
| 285 |
$current_theme = wp_get_theme(); |
| 286 |
// Detect if current theme is the one registered as newer SDK |
| 287 |
$is_newest_sdk_module_active = ( |
| 288 |
strpos( |
| 289 |
$fs_newest_sdk->plugin_path, |
| 290 |
'../' . $themes_directory_name . '/' . $current_theme->get_stylesheet() . '/' |
| 291 |
) === 0 |
| 292 |
); |
| 293 |
|
| 294 |
$current_theme_parent = $current_theme->parent(); |
| 295 |
|
| 296 |
/** |
| 297 |
* If the current theme is a child of the theme that has the newest SDK, this prevents a redirects loop |
| 298 |
* from happening by keeping the SDK info stored in the `fs_active_plugins` option. |
| 299 |
*/ |
| 300 |
if ( ! $is_newest_sdk_module_active && $current_theme_parent instanceof WP_Theme ) { |
| 301 |
// Detect if current theme parent is the one registered as newer SDK |
| 302 |
$is_newest_sdk_module_active = ( |
| 303 |
strpos( |
| 304 |
$fs_newest_sdk->plugin_path, |
| 305 |
'../' . $themes_directory_name . '/' . $current_theme_parent->get_stylesheet() . '/' |
| 306 |
) === 0 |
| 307 |
); |
| 308 |
} |
| 309 |
} |
| 310 |
|
| 311 |
if ( $is_current_sdk_newest && |
| 312 |
! $is_newest_sdk_module_active && |
| 313 |
! $fs_active_plugins->newest->in_activation |
| 314 |
) { |
| 315 |
// If current SDK is the newest and the plugin is NOT active, it means |
| 316 |
// that the current plugin in activation mode. |
| 317 |
$fs_active_plugins->newest->in_activation = true; |
| 318 |
update_option( 'fs_active_plugins', $fs_active_plugins ); |
| 319 |
} |
| 320 |
|
| 321 |
if ( ! $is_theme ) { |
| 322 |
$sdk_starter_path = fs_normalize_path( WP_PLUGIN_DIR . '/' . $this_sdk_relative_path . '/start.php' ); |
| 323 |
} else { |
| 324 |
$sdk_starter_path = fs_normalize_path( |
| 325 |
$themes_directory |
| 326 |
. '/' |
| 327 |
. str_replace( "../{$themes_directory_name}/", '', $this_sdk_relative_path ) |
| 328 |
. '/start.php' ); |
| 329 |
} |
| 330 |
|
| 331 |
$is_newest_sdk_path_valid = ( $is_newest_sdk_module_active || $fs_active_plugins->newest->in_activation ) && file_exists( $sdk_starter_path ); |
| 332 |
|
| 333 |
if ( ! $is_newest_sdk_path_valid && ! $is_current_sdk_newest ) { |
| 334 |
// Plugin with newest SDK is no longer active, or SDK was moved to a different location. |
| 335 |
unset( $fs_active_plugins->plugins[ $fs_active_plugins->newest->sdk_path ] ); |
| 336 |
} |
| 337 |
|
| 338 |
if ( ! ( $is_newest_sdk_module_active || $fs_active_plugins->newest->in_activation ) || |
| 339 |
! $is_newest_sdk_path_valid || |
| 340 |
// Is newest SDK downgraded. |
| 341 |
( $this_sdk_relative_path == $fs_active_plugins->newest->sdk_path && |
| 342 |
version_compare( $fs_active_plugins->newest->version, $this_sdk_version, '>' ) ) |
| 343 |
) { |
| 344 |
/** |
| 345 |
* Plugin with newest SDK is no longer active. |
| 346 |
* OR |
| 347 |
* The newest SDK was in the current plugin. BUT, seems like the version of |
| 348 |
* the SDK was downgraded to a lower SDK. |
| 349 |
*/ |
| 350 |
// Find the active plugin with the newest SDK version and update the newest reference. |
| 351 |
fs_fallback_to_newest_active_sdk(); |
| 352 |
} else { |
| 353 |
if ( $is_newest_sdk_module_active && |
| 354 |
$this_sdk_relative_path == $fs_active_plugins->newest->sdk_path && |
| 355 |
( $fs_active_plugins->newest->in_activation || |
| 356 |
( class_exists( 'Freemius' ) && ( ! defined( 'WP_FS__SDK_VERSION' ) || version_compare( WP_FS__SDK_VERSION, $this_sdk_version, '<' ) ) ) |
| 357 |
) |
| 358 |
|
| 359 |
) { |
| 360 |
if ( $fs_active_plugins->newest->in_activation && ! $is_newest_sdk_type_theme ) { |
| 361 |
// Plugin no more in activation. |
| 362 |
$fs_active_plugins->newest->in_activation = false; |
| 363 |
update_option( 'fs_active_plugins', $fs_active_plugins ); |
| 364 |
} |
| 365 |
|
| 366 |
// Reorder plugins to load plugin with newest SDK first. |
| 367 |
if ( fs_newest_sdk_plugin_first() ) { |
| 368 |
// Refresh page after re-order to make sure activated plugin loads newest SDK. |
| 369 |
if ( class_exists( 'Freemius' ) ) { |
| 370 |
fs_redirect( $_SERVER['REQUEST_URI'] ); |
| 371 |
} |
| 372 |
} |
| 373 |
} |
| 374 |
} |
| 375 |
} |
| 376 |
|
| 377 |
if ( class_exists( 'Freemius' ) ) { |
| 378 |
// SDK was already loaded. |
| 379 |
return; |
| 380 |
} |
| 381 |
|
| 382 |
if ( isset( $fs_active_plugins->newest ) && version_compare( $this_sdk_version, $fs_active_plugins->newest->version, '<' ) ) { |
| 383 |
$newest_sdk = $fs_active_plugins->plugins[ $fs_active_plugins->newest->sdk_path ]; |
| 384 |
|
| 385 |
$plugins_or_theme_dir_path = ( ! isset( $newest_sdk->type ) || 'theme' !== $newest_sdk->type ) ? |
| 386 |
WP_PLUGIN_DIR : |
| 387 |
$themes_directory; |
| 388 |
|
| 389 |
$newest_sdk_starter = fs_normalize_path( |
| 390 |
$plugins_or_theme_dir_path |
| 391 |
. '/' |
| 392 |
. str_replace( "../{$themes_directory_name}/", '', $fs_active_plugins->newest->sdk_path ) |
| 393 |
. '/start.php' ); |
| 394 |
|
| 395 |
if ( file_exists( $newest_sdk_starter ) ) { |
| 396 |
// Reorder plugins to load plugin with newest SDK first. |
| 397 |
fs_newest_sdk_plugin_first(); |
| 398 |
|
| 399 |
// There's a newer SDK version, load it instead of the current one! |
| 400 |
require_once $newest_sdk_starter; |
| 401 |
|
| 402 |
return; |
| 403 |
} |
| 404 |
} |
| 405 |
|
| 406 |
#endregion SDK Selection Logic -------------------------------------------------------------------- |
| 407 |
|
| 408 |
#region Hooks & Filters Collection -------------------------------------------------------------------- |
| 409 |
|
| 410 |
/** |
| 411 |
* Freemius hooks (actions & filters) tags structure: |
| 412 |
* |
| 413 |
* fs_{filter/action_name}_{plugin_slug} |
| 414 |
* |
| 415 |
* -------------------------------------------------------- |
| 416 |
* |
| 417 |
* Usage with WordPress' add_action() / add_filter(): |
| 418 |
* |
| 419 |
* add_action('fs_{filter/action_name}_{plugin_slug}', $callable); |
| 420 |
* |
| 421 |
* -------------------------------------------------------- |
| 422 |
* |
| 423 |
* Usage with Freemius' instance add_action() / add_filter(): |
| 424 |
* |
| 425 |
* // No need to add 'fs_' prefix nor '_{plugin_slug}' suffix. |
| 426 |
* my_freemius()->add_action('{action_name}', $callable); |
| 427 |
* |
| 428 |
* -------------------------------------------------------- |
| 429 |
* |
| 430 |
* Freemius filters collection: |
| 431 |
* |
| 432 |
* fs_connect_url_{plugin_slug} |
| 433 |
* fs_trial_promotion_message_{plugin_slug} |
| 434 |
* fs_is_long_term_user_{plugin_slug} |
| 435 |
* fs_uninstall_reasons_{plugin_slug} |
| 436 |
* fs_is_plugin_update_{plugin_slug} |
| 437 |
* fs_api_domains_{plugin_slug} |
| 438 |
* fs_email_template_sections_{plugin_slug} |
| 439 |
* fs_support_forum_submenu_{plugin_slug} |
| 440 |
* fs_support_forum_url_{plugin_slug} |
| 441 |
* fs_connect_message_{plugin_slug} |
| 442 |
* fs_connect_message_on_update_{plugin_slug} |
| 443 |
* fs_uninstall_confirmation_message_{plugin_slug} |
| 444 |
* fs_pending_activation_message_{plugin_slug} |
| 445 |
* fs_is_submenu_visible_{plugin_slug} |
| 446 |
* fs_plugin_icon_{plugin_slug} |
| 447 |
* fs_show_trial_{plugin_slug} |
| 448 |
* fs_is_pricing_page_visible_{plugin_slug} |
| 449 |
* fs_checkout/parameters_{plugin_slug} |
| 450 |
* |
| 451 |
* -------------------------------------------------------- |
| 452 |
* |
| 453 |
* Freemius actions collection: |
| 454 |
* |
| 455 |
* fs_after_license_loaded_{plugin_slug} |
| 456 |
* fs_after_license_change_{plugin_slug} |
| 457 |
* fs_after_license_activation_{plugin_slug} |
| 458 |
* fs_after_license_deactivation_{plugin_slug} |
| 459 |
* fs_after_plans_sync_{plugin_slug} |
| 460 |
* |
| 461 |
* fs_after_account_details_{plugin_slug} |
| 462 |
* fs_after_account_user_sync_{plugin_slug} |
| 463 |
* fs_after_account_plan_sync_{plugin_slug} |
| 464 |
* fs_before_account_load_{plugin_slug} |
| 465 |
* fs_after_account_connection_{plugin_slug} |
| 466 |
* fs_account_property_edit_{plugin_slug} |
| 467 |
* fs_account_email_verified_{plugin_slug} |
| 468 |
* fs_account_page_load_before_departure_{plugin_slug} |
| 469 |
* fs_before_account_delete_{plugin_slug} |
| 470 |
* fs_after_account_delete_{plugin_slug} |
| 471 |
* |
| 472 |
* fs_sdk_version_update_{plugin_slug} |
| 473 |
* fs_plugin_version_update_{plugin_slug} |
| 474 |
* |
| 475 |
* fs_initiated_{plugin_slug} |
| 476 |
* fs_after_init_plugin_registered_{plugin_slug} |
| 477 |
* fs_after_init_plugin_anonymous_{plugin_slug} |
| 478 |
* fs_after_init_plugin_pending_activations_{plugin_slug} |
| 479 |
* fs_after_init_addon_registered_{plugin_slug} |
| 480 |
* fs_after_init_addon_anonymous_{plugin_slug} |
| 481 |
* fs_after_init_addon_pending_activations_{plugin_slug} |
| 482 |
* |
| 483 |
* fs_after_premium_version_activation_{plugin_slug} |
| 484 |
* fs_after_free_version_reactivation_{plugin_slug} |
| 485 |
* |
| 486 |
* fs_after_uninstall_{plugin_slug} |
| 487 |
* fs_before_admin_menu_init_{plugin_slug} |
| 488 |
*/ |
| 489 |
|
| 490 |
#endregion Hooks & Filters Collection -------------------------------------------------------------------- |
| 491 |
|
| 492 |
if ( ! class_exists( 'Freemius' ) ) { |
| 493 |
|
| 494 |
if ( ! defined( 'WP_FS__SDK_VERSION' ) ) { |
| 495 |
define( 'WP_FS__SDK_VERSION', $this_sdk_version ); |
| 496 |
} |
| 497 |
|
| 498 |
$plugins_or_theme_dir_path = fs_normalize_path( trailingslashit( $is_theme ? |
| 499 |
$themes_directory : |
| 500 |
WP_PLUGIN_DIR ) ); |
| 501 |
|
| 502 |
if ( 0 === strpos( $file_path, $plugins_or_theme_dir_path ) ) { |
| 503 |
// No symlinks |
| 504 |
} else { |
| 505 |
/** |
| 506 |
* This logic finds the SDK symlink and set WP_FS__DIR to use it. |
| 507 |
* |
| 508 |
* @author Vova Feldman (@svovaf) |
| 509 |
* @since 1.2.2.5 |
| 510 |
*/ |
| 511 |
$sdk_symlink = null; |
| 512 |
|
| 513 |
// Try to load SDK's symlink from cache. |
| 514 |
if ( isset( $fs_active_plugins->plugins[ $this_sdk_relative_path ] ) && |
| 515 |
is_object( $fs_active_plugins->plugins[ $this_sdk_relative_path ] ) && |
| 516 |
! empty( $fs_active_plugins->plugins[ $this_sdk_relative_path ]->sdk_symlink ) |
| 517 |
) { |
| 518 |
$sdk_symlink = $fs_active_plugins->plugins[ $this_sdk_relative_path ]->sdk_symlink; |
| 519 |
if ( 0 === strpos( $sdk_symlink, $plugins_or_theme_dir_path ) ) { |
| 520 |
/** |
| 521 |
* Make the symlink path relative. |
| 522 |
* |
| 523 |
* @author Leo Fajardo (@leorw) |
| 524 |
*/ |
| 525 |
$sdk_symlink = substr( $sdk_symlink, strlen( $plugins_or_theme_dir_path ) ); |
| 526 |
|
| 527 |
$fs_active_plugins->plugins[ $this_sdk_relative_path ]->sdk_symlink = $sdk_symlink; |
| 528 |
update_option( 'fs_active_plugins', $fs_active_plugins ); |
| 529 |
} |
| 530 |
|
| 531 |
$realpath = realpath( $plugins_or_theme_dir_path . $sdk_symlink ); |
| 532 |
if ( ! is_string( $realpath ) || ! file_exists( $realpath ) ) { |
| 533 |
$sdk_symlink = null; |
| 534 |
} |
| 535 |
} |
| 536 |
|
| 537 |
if ( empty( $sdk_symlink ) ) // Has symlinks, therefore, we need to configure WP_FS__DIR based on the symlink. |
| 538 |
{ |
| 539 |
$partial_path_right = basename( $file_path ); |
| 540 |
$partial_path_left = dirname( $file_path ); |
| 541 |
$realpath = realpath( $plugins_or_theme_dir_path . $partial_path_right ); |
| 542 |
|
| 543 |
while ( '/' !== $partial_path_left && |
| 544 |
( false === $realpath || $file_path !== fs_normalize_path( $realpath ) ) |
| 545 |
) { |
| 546 |
$partial_path_right = trailingslashit( basename( $partial_path_left ) ) . $partial_path_right; |
| 547 |
$partial_path_left_prev = $partial_path_left; |
| 548 |
$partial_path_left = dirname( $partial_path_left_prev ); |
| 549 |
|
| 550 |
/** |
| 551 |
* Avoid infinite loop if for example `$partial_path_left_prev` is `C:/`, in this case, |
| 552 |
* `dirname( 'C:/' )` will return `C:/`. |
| 553 |
* |
| 554 |
* @author Leo Fajardo (@leorw) |
| 555 |
*/ |
| 556 |
if ( $partial_path_left === $partial_path_left_prev ) { |
| 557 |
$partial_path_left = ''; |
| 558 |
break; |
| 559 |
} |
| 560 |
|
| 561 |
$realpath = realpath( $plugins_or_theme_dir_path . $partial_path_right ); |
| 562 |
} |
| 563 |
|
| 564 |
if ( ! empty( $partial_path_left ) && '/' !== $partial_path_left ) { |
| 565 |
$sdk_symlink = fs_normalize_path( dirname( $partial_path_right ) ); |
| 566 |
|
| 567 |
// Cache value. |
| 568 |
if ( isset( $fs_active_plugins->plugins[ $this_sdk_relative_path ] ) && |
| 569 |
is_object( $fs_active_plugins->plugins[ $this_sdk_relative_path ] ) |
| 570 |
) { |
| 571 |
$fs_active_plugins->plugins[ $this_sdk_relative_path ]->sdk_symlink = $sdk_symlink; |
| 572 |
update_option( 'fs_active_plugins', $fs_active_plugins ); |
| 573 |
} |
| 574 |
} |
| 575 |
} |
| 576 |
|
| 577 |
if ( ! empty( $sdk_symlink ) ) { |
| 578 |
// Set SDK dir to the symlink path. |
| 579 |
define( 'WP_FS__DIR', $plugins_or_theme_dir_path . $sdk_symlink ); |
| 580 |
} |
| 581 |
} |
| 582 |
|
| 583 |
// Load SDK files. |
| 584 |
require_once dirname( __FILE__ ) . '/require.php'; |
| 585 |
|
| 586 |
/** |
| 587 |
* Quick shortcut to get Freemius for specified plugin. |
| 588 |
* Used by various templates. |
| 589 |
* |
| 590 |
* @param number $module_id |
| 591 |
* |
| 592 |
* @return Freemius |
| 593 |
*/ |
| 594 |
function freemius( $module_id ) { |
| 595 |
return Freemius::instance( $module_id ); |
| 596 |
} |
| 597 |
|
| 598 |
/** |
| 599 |
* @param string $slug |
| 600 |
* @param number $plugin_id |
| 601 |
* @param string $public_key |
| 602 |
* @param bool $is_live Is live or test plugin. |
| 603 |
* @param bool $is_premium Hints freemius if running the premium plugin or not. |
| 604 |
* |
| 605 |
* @return Freemius |
| 606 |
* |
| 607 |
* @deprecated Please use fs_dynamic_init(). |
| 608 |
*/ |
| 609 |
function fs_init( $slug, $plugin_id, $public_key, $is_live = true, $is_premium = true ) { |
| 610 |
$fs = Freemius::instance( $plugin_id, $slug, true ); |
| 611 |
$fs->init( $plugin_id, $public_key, $is_live, $is_premium ); |
| 612 |
|
| 613 |
return $fs; |
| 614 |
} |
| 615 |
|
| 616 |
/** |
| 617 |
* @param array <string,string|bool|array> $module Plugin or Theme details. |
| 618 |
* |
| 619 |
* @return Freemius |
| 620 |
* @throws Freemius_Exception |
| 621 |
*/ |
| 622 |
function fs_dynamic_init( $module ) { |
| 623 |
$fs = Freemius::instance( $module['id'], $module['slug'], true ); |
| 624 |
$fs->dynamic_init( $module ); |
| 625 |
|
| 626 |
return $fs; |
| 627 |
} |
| 628 |
|
| 629 |
function fs_dump_log() { |
| 630 |
FS_Logger::dump(); |
| 631 |
} |
| 632 |
} |
| 633 |
|