| @@ -6,9 +6,9 @@ | ||
| 6 | 6 | * @since 1.0.3 |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | if ( ! defined( 'ABSPATH' ) ) { |
| 10 | - return; | |
| 10 | + exit; | |
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | 14 | * Freemius SDK Version. |
| @@ -14,9 +14,9 @@ | ||
| 14 | 14 | * Freemius SDK Version. |
| 15 | 15 | * |
| 16 | 16 | * @var string |
| 17 | 17 | */ |
| 18 | - $this_sdk_version = '2.13.4'; | |
| 18 | + $this_sdk_version = '2.4.2'; | |
| 19 | 19 | |
| 20 | 20 | #region SDK Selection Logic -------------------------------------------------------------------- |
| 21 | 21 | |
| 22 | 22 | /** |
| @@ -35,18 +35,9 @@ | ||
| 35 | 35 | // Require SDK essentials. |
| 36 | 36 | require_once dirname( __FILE__ ) . '/includes/fs-essential-functions.php'; |
| 37 | 37 | } |
| 38 | 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 | - * | |
| 39 | + /** | |
| 49 | 40 | * This complex logic fixes symlink issues (e.g. with Vargant). The logic assumes |
| 50 | 41 | * that if it's a file from an SDK running in a theme, the location of the SDK |
| 51 | 42 | * is in the main theme's folder. |
| 52 | 43 | * |
| @@ -54,36 +45,8 @@ | ||
| 54 | 45 | * @since 1.2.2.6 |
| 55 | 46 | */ |
| 56 | 47 | $file_path = fs_normalize_path( __FILE__ ); |
| 57 | 48 | $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 | 49 | /** |
| 87 | 50 | * Get the themes directory where the active theme is located (not passing the stylesheet will make WordPress |
| 88 | 51 | * assume that the themes directory is inside `wp-content`. |
| 89 | 52 | * |
| @@ -89,67 +52,25 @@ | ||
| 89 | 52 | * |
| 90 | 53 | * @author Leo Fajardo (@leorw) |
| 91 | 54 | * @since 2.2.3 |
| 92 | 55 | */ |
| 93 | - $themes_directory = fs_normalize_path( get_theme_root( get_stylesheet() ) ); | |
| 94 | - $themes_directory_name = basename( $themes_directory ); | |
| 56 | + $themes_directory = get_theme_root( get_stylesheet() ); | |
| 57 | + $themes_directory_name = basename( $themes_directory ); | |
| 58 | + $theme_candidate_basename = basename( dirname( $fs_root_path ) ) . '/' . basename( $fs_root_path ); | |
| 95 | 59 | |
| 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 ); | |
| 60 | + if ( $file_path == fs_normalize_path( realpath( trailingslashit( $themes_directory ) . $theme_candidate_basename . '/' . basename( $file_path ) ) ) | |
| 61 | + ) { | |
| 62 | + $this_sdk_relative_path = '../' . $themes_directory_name . '/' . $theme_candidate_basename; | |
| 63 | + $is_theme = true; | |
| 64 | + } else { | |
| 65 | + $this_sdk_relative_path = plugin_basename( $fs_root_path ); | |
| 66 | + $is_theme = false; | |
| 67 | + } | |
| 98 | 68 | |
| 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 | 69 | if ( ! isset( $fs_active_plugins ) ) { |
| 145 | 70 | // Load all Freemius powered active plugins. |
| 146 | - $fs_active_plugins = get_option( 'fs_active_plugins' ); | |
| 71 | + $fs_active_plugins = get_option( 'fs_active_plugins', new stdClass() ); | |
| 147 | 72 | |
| 148 | - if ( ! is_object( $fs_active_plugins ) ) { | |
| 149 | - $fs_active_plugins = new stdClass(); | |
| 150 | - } | |
| 151 | - | |
| 152 | 73 | if ( ! isset( $fs_active_plugins->plugins ) ) { |
| 153 | 74 | $fs_active_plugins->plugins = array(); |
| 154 | 75 | } |
| 155 | 76 | } |
| @@ -222,10 +143,9 @@ | ||
| 222 | 143 | if ( ! isset( $fs_active_plugins->plugins[ $this_sdk_relative_path ] ) || |
| 223 | 144 | $this_sdk_version != $fs_active_plugins->plugins[ $this_sdk_relative_path ]->version |
| 224 | 145 | ) { |
| 225 | 146 | if ( $is_theme ) { |
| 226 | - // Saving relative path and not only directory name as it could be a subfolder | |
| 227 | - $plugin_path = $theme_name; | |
| 147 | + $plugin_path = basename( dirname( $this_sdk_relative_path ) ); | |
| 228 | 148 | } else { |
| 229 | 149 | $plugin_path = plugin_basename( fs_find_direct_caller_plugin_file( $file_path ) ); |
| 230 | 150 | } |
| 231 | 151 | |
| @@ -272,25 +192,13 @@ | ||
| 272 | 192 | $fs_newest_sdk = $fs_active_plugins->plugins[ $fs_newest_sdk->sdk_path ]; |
| 273 | 193 | |
| 274 | 194 | $is_newest_sdk_type_theme = ( isset( $fs_newest_sdk->type ) && 'theme' === $fs_newest_sdk->type ); |
| 275 | 195 | |
| 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 | - ); | |
| 196 | + if ( ! $is_newest_sdk_type_theme ) { | |
| 197 | + $is_newest_sdk_plugin_active = is_plugin_active( $fs_newest_sdk->plugin_path ); | |
| 198 | + } else { | |
| 199 | + $current_theme = wp_get_theme(); | |
| 200 | + $is_newest_sdk_plugin_active = ( $current_theme->stylesheet === $fs_newest_sdk->plugin_path ); | |
| 293 | 201 | |
| 294 | 202 | $current_theme_parent = $current_theme->parent(); |
| 295 | 203 | |
| 296 | 204 | /** |
| @@ -296,21 +204,15 @@ | ||
| 296 | 204 | /** |
| 297 | 205 | * If the current theme is a child of the theme that has the newest SDK, this prevents a redirects loop |
| 298 | 206 | * from happening by keeping the SDK info stored in the `fs_active_plugins` option. |
| 299 | 207 | */ |
| 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 | - ); | |
| 208 | + if ( ! $is_newest_sdk_plugin_active && $current_theme_parent instanceof WP_Theme ) { | |
| 209 | + $is_newest_sdk_plugin_active = ( $fs_newest_sdk->plugin_path === $current_theme_parent->stylesheet ); | |
| 308 | 210 | } |
| 309 | 211 | } |
| 310 | 212 | |
| 311 | 213 | if ( $is_current_sdk_newest && |
| 312 | - ! $is_newest_sdk_module_active && | |
| 214 | + ! $is_newest_sdk_plugin_active && | |
| 313 | 215 | ! $fs_active_plugins->newest->in_activation |
| 314 | 216 | ) { |
| 315 | 217 | // If current SDK is the newest and the plugin is NOT active, it means |
| 316 | 218 | // that the current plugin in activation mode. |
| @@ -327,9 +229,9 @@ | ||
| 327 | 229 | . str_replace( "../{$themes_directory_name}/", '', $this_sdk_relative_path ) |
| 328 | 230 | . '/start.php' ); |
| 329 | 231 | } |
| 330 | 232 | |
| 331 | - $is_newest_sdk_path_valid = ( $is_newest_sdk_module_active || $fs_active_plugins->newest->in_activation ) && file_exists( $sdk_starter_path ); | |
| 233 | + $is_newest_sdk_path_valid = ( $is_newest_sdk_plugin_active || $fs_active_plugins->newest->in_activation ) && file_exists( $sdk_starter_path ); | |
| 332 | 234 | |
| 333 | 235 | if ( ! $is_newest_sdk_path_valid && ! $is_current_sdk_newest ) { |
| 334 | 236 | // Plugin with newest SDK is no longer active, or SDK was moved to a different location. |
| 335 | 237 | unset( $fs_active_plugins->plugins[ $fs_active_plugins->newest->sdk_path ] ); |
| @@ -334,9 +236,9 @@ | ||
| 334 | 236 | // Plugin with newest SDK is no longer active, or SDK was moved to a different location. |
| 335 | 237 | unset( $fs_active_plugins->plugins[ $fs_active_plugins->newest->sdk_path ] ); |
| 336 | 238 | } |
| 337 | 239 | |
| 338 | - if ( ! ( $is_newest_sdk_module_active || $fs_active_plugins->newest->in_activation ) || | |
| 240 | + if ( ! ( $is_newest_sdk_plugin_active || $fs_active_plugins->newest->in_activation ) || | |
| 339 | 241 | ! $is_newest_sdk_path_valid || |
| 340 | 242 | // Is newest SDK downgraded. |
| 341 | 243 | ( $this_sdk_relative_path == $fs_active_plugins->newest->sdk_path && |
| 342 | 244 | version_compare( $fs_active_plugins->newest->version, $this_sdk_version, '>' ) ) |
| @@ -349,9 +251,9 @@ | ||
| 349 | 251 | */ |
| 350 | 252 | // Find the active plugin with the newest SDK version and update the newest reference. |
| 351 | 253 | fs_fallback_to_newest_active_sdk(); |
| 352 | 254 | } else { |
| 353 | - if ( $is_newest_sdk_module_active && | |
| 255 | + if ( $is_newest_sdk_plugin_active && | |
| 354 | 256 | $this_sdk_relative_path == $fs_active_plugins->newest->sdk_path && |
| 355 | 257 | ( $fs_active_plugins->newest->in_activation || |
| 356 | 258 | ( class_exists( 'Freemius' ) && ( ! defined( 'WP_FS__SDK_VERSION' ) || version_compare( WP_FS__SDK_VERSION, $this_sdk_version, '<' ) ) ) |
| 357 | 259 | ) |
| @@ -378,9 +280,9 @@ | ||
| 378 | 280 | // SDK was already loaded. |
| 379 | 281 | return; |
| 380 | 282 | } |
| 381 | 283 | |
| 382 | - if ( isset( $fs_active_plugins->newest ) && version_compare( $this_sdk_version, $fs_active_plugins->newest->version, '<' ) ) { | |
| 284 | + if ( version_compare( $this_sdk_version, $fs_active_plugins->newest->version, '<' ) ) { | |
| 383 | 285 | $newest_sdk = $fs_active_plugins->plugins[ $fs_active_plugins->newest->sdk_path ]; |
| 384 | 286 | |
| 385 | 287 | $plugins_or_theme_dir_path = ( ! isset( $newest_sdk->type ) || 'theme' !== $newest_sdk->type ) ? |
| 386 | 288 | WP_PLUGIN_DIR : |
| @@ -444,10 +346,8 @@ | ||
| 444 | 346 | * fs_pending_activation_message_{plugin_slug} |
| 445 | 347 | * fs_is_submenu_visible_{plugin_slug} |
| 446 | 348 | * fs_plugin_icon_{plugin_slug} |
| 447 | 349 | * fs_show_trial_{plugin_slug} |
| 448 | - * fs_is_pricing_page_visible_{plugin_slug} | |
| 449 | - * fs_checkout/parameters_{plugin_slug} | |
| 450 | 350 | * |
| 451 | 351 | * -------------------------------------------------------- |
| 452 | 352 | * |
| 453 | 353 | * Freemius actions collection: |
| @@ -453,10 +353,8 @@ | ||
| 453 | 353 | * Freemius actions collection: |
| 454 | 354 | * |
| 455 | 355 | * fs_after_license_loaded_{plugin_slug} |
| 456 | 356 | * fs_after_license_change_{plugin_slug} |
| 457 | - * fs_after_license_activation_{plugin_slug} | |
| 458 | - * fs_after_license_deactivation_{plugin_slug} | |
| 459 | 357 | * fs_after_plans_sync_{plugin_slug} |
| 460 | 358 | * |
| 461 | 359 | * fs_after_account_details_{plugin_slug} |
| 462 | 360 | * fs_after_account_user_sync_{plugin_slug} |