Blocksy Companion - Version 1.8.20

Version Description

Download this release

Release Info

Developer creativethemeshq
Plugin Icon wp plugin Blocksy Companion
Version 1.8.20
Comparing to
See all releases

Code changes from version 1.8.19 to 1.8.20

blocksy-companion.php CHANGED
@@ -3,7 +3,7 @@
3
  /*
4
  Plugin Name: Blocksy Companion
5
  Description: This plugin is the companion for the Blocksy theme, it runs and adds its enhacements only if the Blocksy theme is installed and active.
6
- Version: 1.8.19
7
  Author: CreativeThemes
8
  Author URI: https://creativethemes.com
9
  Text Domain: blocksy-companion
3
  /*
4
  Plugin Name: Blocksy Companion
5
  Description: This plugin is the companion for the Blocksy theme, it runs and adds its enhacements only if the Blocksy theme is installed and active.
6
+ Version: 1.8.20
7
  Author: CreativeThemes
8
  Author URI: https://creativethemes.com
9
  Text Domain: blocksy-companion
framework/extensions/cookies-consent/helpers.php CHANGED
@@ -52,10 +52,10 @@ function blocksy_ext_cookies_consent_output($forced = false) {
52
  <div class="ct-cookies-content"><?php echo wp_kses_post($content) ?></div>
53
  <?php } ?>
54
 
55
- <button type="submit" class="ct-button ct-accept" tabindex="10"><?php echo esc_html($button_text) ?></button>
56
 
57
  <?php if ($type === 'type-1' || is_customize_preview()) { ?>
58
- <button class="ct-close" tabindex="10">×</button>
59
  <?php } ?>
60
 
61
  </div>
52
  <div class="ct-cookies-content"><?php echo wp_kses_post($content) ?></div>
53
  <?php } ?>
54
 
55
+ <button type="submit" class="ct-button ct-accept"><?php echo esc_html($button_text) ?></button>
56
 
57
  <?php if ($type === 'type-1' || is_customize_preview()) { ?>
58
+ <button class="ct-close">×</button>
59
  <?php } ?>
60
 
61
  </div>
framework/extensions/cookies-consent/static/bundle/main.min.css CHANGED
@@ -1,5 +1,5 @@
1
  /**
2
- * - v1.8.19
3
  *
4
  * Copyright (c) 2022
5
  * Licensed GPLv2+
1
  /**
2
+ * - v1.8.20
3
  *
4
  * Copyright (c) 2022
5
  * Licensed GPLv2+
framework/extensions/newsletter-subscribe/static/bundle/main.min.css CHANGED
@@ -1,5 +1,5 @@
1
  /**
2
- * - v1.8.19
3
  *
4
  * Copyright (c) 2022
5
  * Licensed GPLv2+
1
  /**
2
+ * - v1.8.20
3
  *
4
  * Copyright (c) 2022
5
  * Licensed GPLv2+
framework/extensions/product-reviews/static/bundle/main-admin.min.css CHANGED
@@ -1,5 +1,5 @@
1
  /**
2
- * - v1.8.19
3
  *
4
  * Copyright (c) 2022
5
  * Licensed GPLv2+
1
  /**
2
+ * - v1.8.20
3
  *
4
  * Copyright (c) 2022
5
  * Licensed GPLv2+
framework/extensions/product-reviews/static/bundle/main.min.css CHANGED
@@ -1,5 +1,5 @@
1
  /**
2
- * - v1.8.19
3
  *
4
  * Copyright (c) 2022
5
  * Licensed GPLv2+
1
  /**
2
+ * - v1.8.20
3
  *
4
  * Copyright (c) 2022
5
  * Licensed GPLv2+
framework/extensions/trending/static/bundle/main.min.css CHANGED
@@ -1,5 +1,5 @@
1
  /**
2
- * - v1.8.19
3
  *
4
  * Copyright (c) 2022
5
  * Licensed GPLv2+
1
  /**
2
+ * - v1.8.20
3
  *
4
  * Copyright (c) 2022
5
  * Licensed GPLv2+
framework/extensions/widgets/static/bundle/main.min.css CHANGED
@@ -1,5 +1,5 @@
1
  /**
2
- * - v1.8.19
3
  *
4
  * Copyright (c) 2022
5
  * Licensed GPLv2+
1
  /**
2
+ * - v1.8.20
3
  *
4
  * Copyright (c) 2022
5
  * Licensed GPLv2+
freemius/assets/img/blocksy-companion.jpg DELETED
Binary file
freemius/includes/class-freemius.php CHANGED
@@ -1,26181 +1,26206 @@
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
- if ( ! defined( 'ABSPATH' ) ) {
9
- exit;
10
- }
11
-
12
- // "final class"
13
- class Freemius extends Freemius_Abstract {
14
- /**
15
- * SDK Version
16
- *
17
- * @var string
18
- */
19
- public $version = WP_FS__SDK_VERSION;
20
-
21
- #region Plugin Info
22
-
23
- /**
24
- * @since 1.0.1
25
- *
26
- * @var string
27
- */
28
- private $_slug;
29
-
30
- /**
31
- * @since 1.0.0
32
- *
33
- * @var string
34
- */
35
- private $_plugin_basename;
36
- /**
37
- * @since 2.2.1
38
- *
39
- * @var string
40
- */
41
- private $_premium_plugin_basename;
42
- /**
43
- * @since 1.0.0
44
- *
45
- * @var string
46
- */
47
- private $_free_plugin_basename;
48
- /**
49
- * @since 1.0.0
50
- *
51
- * @var string
52
- */
53
- private $_plugin_dir_path;
54
- /**
55
- * @since 1.0.0
56
- *
57
- * @var string
58
- */
59
- private $_plugin_dir_name;
60
- /**
61
- * @since 1.0.0
62
- *
63
- * @var string
64
- */
65
- private $_plugin_main_file_path;
66
- /**
67
- * @var string[]
68
- */
69
- private $_plugin_data;
70
- /**
71
- * @since 1.0.9
72
- *
73
- * @var string
74
- */
75
- private $_plugin_name;
76
- /**
77
- * @since 1.2.2
78
- *
79
- * @var string
80
- */
81
- private $_module_type;
82
-
83
- #endregion Plugin Info
84
-
85
- /**
86
- * @since 1.0.9
87
- *
88
- * @var bool If false, don't turn Freemius on.
89
- */
90
- private $_is_on;
91
-
92
- /**
93
- * @since 1.1.3
94
- *
95
- * @var bool If false, don't turn Freemius on.
96
- */
97
- private $_is_anonymous;
98
-
99
- /**
100
- * @since 1.0.9
101
- * @var bool If false, issues with connectivity to Freemius API.
102
- */
103
- private $_has_api_connection;
104
-
105
- /**
106
- * @since 1.0.9
107
- * @since 2.0.0 Default to true since we need the property during the instance construction, prior to the dynamic_init() execution.
108
- * @var bool Hints the SDK if plugin can support anonymous mode (if skip connect is visible).
109
- */
110
- private $_enable_anonymous = true;
111
-
112
- /**
113
- * @since 1.1.7.5
114
- * @var bool Hints the SDK if plugin should run in anonymous mode (only adds feedback form).
115
- */
116
- private $_anonymous_mode;
117
-
118
- /**
119
- * @since 1.1.9
120
- * @var bool Hints the SDK if plugin have any free plans.
121
- */
122
- private $_is_premium_only;
123
-
124
- /**
125
- * @since 1.2.1.6
126
- * @var bool Hints the SDK if plugin have premium code version at all.
127
- */
128
- private $_has_premium_version;
129
-
130
- /**
131
- * @since 1.2.1.6
132
- * @var bool Hints the SDK if plugin should ignore pending mode by simulating a skip.
133
- */
134
- private $_ignore_pending_mode;
135
-
136
- /**
137
- * @since 1.0.8
138
- * @var bool Hints the SDK if the plugin has any paid plans.
139
- */
140
- private $_has_paid_plans;
141
-
142
- /**
143
- * @since 1.2.1.5
144
- * @var int Hints the SDK if the plugin offers a trial period. If negative, no trial, if zero - has a trial but
145
- * without a specified period, if positive - the number of trial days.
146
- */
147
- private $_trial_days = - 1;
148
-
149
- /**
150
- * @since 1.2.1.5
151
- * @var bool Hints the SDK if the trial requires a payment method or not.
152
- */
153
- private $_is_trial_require_payment = false;
154
-
155
- /**
156
- * @since 1.0.7
157
- * @var bool Hints the SDK if the plugin is WordPress.org compliant.
158
- */
159
- private $_is_org_compliant;
160
-
161
- /**
162
- * @since 1.0.7
163
- * @var bool Hints the SDK if the plugin is has add-ons.
164
- */
165
- private $_has_addons;
166
-
167
- /**
168
- * @since 2.4.5
169
- * @var string Navigation type: 'menu' or 'tabs'.
170
- */
171
- private $_navigation;
172
-
173
- const NAVIGATION_MENU = 'menu';
174
- const NAVIGATION_TABS = 'tabs';
175
-
176
- /**
177
- * @since 1.1.6
178
- * @var string[]bool.
179
- */
180
- private $_permissions;
181
-
182
- /**
183
- * @var FS_Storage
184
- */
185
- private $_storage;
186
-
187
- /**
188
- * @since 1.2.2.7
189
- * @var FS_Cache_Manager
190
- */
191
- private $_cache;
192
-
193
- /**
194
- * @since 1.0.0
195
- *
196
- * @var FS_Logger
197
- */
198
- private $_logger;
199
- /**
200
- * @since 1.0.4
201
- *
202
- * @var FS_Plugin
203
- */
204
- private $_plugin = false;
205
- /**
206
- * @since 1.0.4
207
- *
208
- * @var FS_Plugin|false
209
- */
210
- private $_parent_plugin = false;
211
- /**
212
- * @since 1.1.1
213
- *
214
- * @var Freemius
215
- */
216
- private $_parent = false;
217
- /**
218
- * @since 1.0.1
219
- *
220
- * @var FS_User
221
- */
222
- private $_user = false;
223
- /**
224
- * @since 1.0.1
225
- *
226
- * @var FS_Site
227
- */
228
- private $_site = false;
229
- /**
230
- * @since 1.0.1
231
- *
232
- * @var FS_Plugin_License
233
- */
234
- private $_license;
235
- /**
236
- * @since 1.0.2
237
- *
238
- * @var FS_Plugin_Plan[]
239
- */
240
- private $_plans = false;
241
- /**
242
- * @var FS_Plugin_License[]
243
- * @since 1.0.5
244
- */
245
- private $_licenses = false;
246
-
247
- /**
248
- * @since 1.0.1
249
- *
250
- * @var FS_Admin_Menu_Manager
251
- */
252
- private $_menu;
253
-
254
- /**
255
- * @var FS_Admin_Notices
256
- */
257
- private $_admin_notices;
258
-
259
- /**
260
- * @since 1.1.6
261
- *
262
- * @var FS_Admin_Notices
263
- */
264
- private static $_global_admin_notices;
265
-
266
- /**
267
- * @var FS_Logger
268
- * @since 1.0.0
269
- */
270
- private static $_static_logger;
271
-
272
- /**
273
- * @var FS_Options
274
- * @since 1.0.2
275
- */
276
- private static $_accounts;
277
-
278
- /**
279
- * @since 1.2.2
280
- *
281
- * @var number
282
- */
283
- private $_module_id;
284
-
285
- /**
286
- * @var Freemius[]
287
- */
288
- private static $_instances = array();
289
-
290
- /**
291
- * @since 1.2.3
292
- *
293
- * @var FS_Affiliate
294
- */
295
- private $affiliate = null;
296
-
297
- /**
298
- * @since 1.2.3
299
- *
300
- * @var FS_AffiliateTerms
301
- */
302
- private $plugin_affiliate_terms = null;
303
-
304
- /**
305
- * @since 1.2.3
306
- *
307
- * @var FS_AffiliateTerms
308
- */
309
- private $custom_affiliate_terms = null;
310
-
311
- /**
312
- * @since 2.0.0
313
- *
314
- * @var bool
315
- */
316
- private $_is_multisite_integrated;
317
-
318
- /**
319
- * @since 2.0.0
320
- *
321
- * @var bool True if the current request is for a network admin screen and the plugin is network active.
322
- */
323
- private $_is_network_active;
324
-
325
- /**
326
- * @since 2.0.0
327
- *
328
- * @var int|null The original blog ID the plugin was loaded with.
329
- */
330
- private $_blog_id = null;
331
-
332
- /**
333
- * @since 2.0.0
334
- *
335
- * @var int|null The current execution context. When true, run on network context. When int, run on the specified blog context.
336
- */
337
- private $_context_is_network_or_blog_id = null;
338
-
339
- /**
340
- * @since 2.0.0
341
- *
342
- * @var string
343
- */
344
- private $_dynamically_added_top_level_page_hook_name = '';
345
-
346
- /**
347
- * @author Leo Fajardo (@leorw)
348
- * @since 2.3.1
349
- *
350
- * @var bool
351
- */
352
- private $is_whitelabeled;
353
-
354
- /**
355
- * @author Leo Fajardo (@leorw)
356
- * @since 2.4.0
357
- *
358
- * @var bool
359
- */
360
- private $_is_bundle_license_auto_activation_enabled = false;
361
-
362
- #region Uninstall Reasons IDs
363
-
364
- const REASON_NO_LONGER_NEEDED = 1;
365
- const REASON_FOUND_A_BETTER_PLUGIN = 2;
366
- const REASON_NEEDED_FOR_A_SHORT_PERIOD = 3;
367
- const REASON_BROKE_MY_SITE = 4;
368
- const REASON_SUDDENLY_STOPPED_WORKING = 5;
369
- const REASON_CANT_PAY_ANYMORE = 6;
370
- const REASON_OTHER = 7;
371
- const REASON_DIDNT_WORK = 8;
372
- const REASON_DONT_LIKE_TO_SHARE_MY_INFORMATION = 9;
373
- const REASON_COULDNT_MAKE_IT_WORK = 10;
374
- const REASON_GREAT_BUT_NEED_SPECIFIC_FEATURE = 11;
375
- const REASON_NOT_WORKING = 12;
376
- const REASON_NOT_WHAT_I_WAS_LOOKING_FOR = 13;
377
- const REASON_DIDNT_WORK_AS_EXPECTED = 14;
378
- const REASON_TEMPORARY_DEACTIVATION = 15;
379
-
380
- /**
381
- * @author Leo Fajardo (@leorw)
382
- * @since 2.3.1
383
- *
384
- * @var boolean|null
385
- */
386
- private $_use_external_pricing = null;
387
- /**
388
- * @author Leo Fajardo (@leorw)
389
- * @since 2.4.2
390
- *
391
- * @var string|null
392
- */
393
- private $_pricing_js_path = null;
394
-
395
- #endregion
396
-
397
- /* Ctor
398
- ------------------------------------------------------------------------------------------------------------------*/
399
-
400
- /**
401
- * Main singleton instance.
402
- *
403
- * @author Vova Feldman (@svovaf)
404
- * @since 1.0.0
405
- *
406
- * @param number $module_id
407
- * @param string|bool $slug
408
- * @param bool $is_init Since 1.2.1 Is initiation sequence.
409
- */
410
- private function __construct( $module_id, $slug = false, $is_init = false ) {
411
- $main_file = false;
412
-
413
- if ( $is_init && is_numeric( $module_id ) && is_string( $slug ) ) {
414
- $main_file = $this->store_id_slug_type_path_map( $module_id, $slug );
415
- }
416
-
417
- $this->_module_id = $module_id;
418
- $this->_slug = $this->get_slug();
419
- $this->_module_type = $this->get_module_type();
420
-
421
- $this->_blog_id = is_multisite() ? get_current_blog_id() : null;
422
-
423
- $this->_storage = FS_Storage::instance( $this->_module_type, $this->_slug );
424
-
425
- $this->_cache = FS_Cache_Manager::get_manager( WP_FS___OPTION_PREFIX . "cache_{$module_id}" );
426
-
427
- $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $this->get_unique_affix(), WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
428
-
429
- $this->_plugin_main_file_path = $this->_find_caller_plugin_file( $is_init, $main_file );
430
- $this->_plugin_dir_path = plugin_dir_path( $this->_plugin_main_file_path );
431
- $this->_plugin_basename = $this->get_plugin_basename();
432
- $this->_free_plugin_basename = str_replace( '-premium/', '/', $this->_plugin_basename );
433
-
434
- $this->_is_multisite_integrated = (
435
- defined( "WP_FS__PRODUCT_{$module_id}_MULTISITE" ) &&
436
- ( true === constant( "WP_FS__PRODUCT_{$module_id}_MULTISITE" ) )
437
- );
438
-
439
- $this->_is_network_active = (
440
- is_multisite() &&
441
- $this->_is_multisite_integrated &&
442
- // Themes are always network activated, but the ACTUAL activation is per site.
443
- $this->is_plugin() &&
444
- (
445
- is_plugin_active_for_network( $this->_plugin_basename ) ||
446
- // Plugin network level activation or uninstall.
447
- ( fs_is_network_admin() && is_plugin_inactive( $this->_plugin_basename ) )
448
- )
449
- );
450
-
451
- $this->_storage->set_network_active(
452
- $this->_is_network_active,
453
- $this->is_delegated_connection()
454
- );
455
-
456
- if ( ! isset( $this->_storage->is_network_activated ) ) {
457
- $this->_storage->is_network_activated = $this->_is_network_active;
458
- }
459
-
460
- if ( $this->_storage->is_network_activated != $this->_is_network_active ) {
461
- // Update last activation level.
462
- $this->_storage->is_network_activated = $this->_is_network_active;
463
-
464
- $this->maybe_adjust_storage();
465
- }
466
-
467
- #region Migration
468
-
469
- if ( is_multisite() ) {
470
- /**
471
- * If the install_timestamp exists on the site level but doesn't exist on the
472
- * network level storage, it means that we need to process the storage with migration.
473
- *
474
- * The code in this `if` scope will only be executed once and only for the first site that will execute it because once we migrate the storage data, install_timestamp will be already set in the network level storage.
475
- *
476
- * @author Vova Feldman (@svovaf)
477
- * @since 2.0.0
478
- */
479
- if ( false === $this->_storage->get( 'install_timestamp', false, true ) &&
480
- false !== $this->_storage->get( 'install_timestamp', false, false )
481
- ) {
482
- // Initiate storage migration.
483
- $this->_storage->migrate_to_network();
484
-
485
- // Migrate module cache to network level storage.
486
- $this->_cache->migrate_to_network();
487
- }
488
- }
489
-
490
- #endregion
491
-
492
- $base_name_split = explode( '/', $this->_plugin_basename );
493
- $this->_plugin_dir_name = $base_name_split[0];
494
-
495
- if ( $this->_logger->is_on() ) {
496
- $this->_logger->info( 'plugin_main_file_path = ' . $this->_plugin_main_file_path );
497
- $this->_logger->info( 'plugin_dir_path = ' . $this->_plugin_dir_path );
498
- $this->_logger->info( 'plugin_basename = ' . $this->_plugin_basename );
499
- $this->_logger->info( 'free_plugin_basename = ' . $this->_free_plugin_basename );
500
- $this->_logger->info( 'plugin_dir_name = ' . $this->_plugin_dir_name );
501
- }
502
-
503
- // Remember link between file to slug.
504
- $this->store_file_slug_map();
505
-
506
- // Store plugin's initial install timestamp.
507
- if ( ! isset( $this->_storage->install_timestamp ) ) {
508
- $this->_storage->install_timestamp = WP_FS__SCRIPT_START_TIME;
509
- }
510
-
511
- if ( ! is_object( $this->_plugin ) ) {
512
- $this->_plugin = FS_Plugin_Manager::instance( $this->_module_id )->get();
513
- }
514
-
515
- $this->_admin_notices = FS_Admin_Notices::instance(
516
- $this->_slug . ( $this->is_theme() ? ':theme' : '' ),
517
- /**
518
- * Ensure that the admin notice will always have a title by using the stored plugin title if available and
519
- * retrieving the title via the "get_plugin_name" method if there is no stored plugin title available.
520
- *
521
- * @author Leo Fajardo (@leorw)
522
- * @since 1.2.2
523
- */
524
- ( is_object( $this->_plugin ) && isset( $this->_plugin->title ) ?
525
- $this->_plugin->title :
526
- $this->get_plugin_name()
527
- ),
528
- $this->get_unique_affix()
529
- );
530
-
531
- if ( 'true' === fs_request_get( 'fs_clear_api_cache' ) ||
532
- fs_request_is_action( 'restart_freemius' )
533
- ) {
534
- FS_Api::clear_cache();
535
- $this->_cache->clear();
536
- }
537
-
538
- $this->register_constructor_hooks();
539
-
540
- /**
541
- * Starting from version 2.0.0, `FS_Site` entities no longer have the `plan` property and have `plan_id`
542
- * instead. This should be called before calling `_load_account()`, otherwise, `$this->_site` will not be
543
- * loaded in `_load_account` for versions of SDK starting from 2.0.0.
544
- *
545
- * @author Leo Fajardo (@leorw)
546
- */
547
- self::migrate_install_plan_to_plan_id( $this->_storage );
548
-
549
- $this->_load_account();
550
-
551
- $this->_version_updates_handler();
552
- }
553
-
554
- /**
555
- * @author Leo Fajardo (@leorw)
556
- * @since 2.3.0
557
- */
558
- private function maybe_adjust_storage() {
559
- $install_timestamp = null;
560
- $prev_is_premium = null;
561
-
562
- $options_to_update = array();
563
-
564
- $is_network_admin = fs_is_network_admin();
565
-
566
- $network_install_timestamp = $this->_storage->get( 'install_timestamp', null, true );
567
-
568
- if ( ! $is_network_admin ) {
569
- if ( is_null( $network_install_timestamp ) ) {
570
- // Plugin was not network-activated before.
571
- return;
572
- }
573
-
574
- if ( is_null( $this->_storage->get( 'install_timestamp', null, false ) ) ) {
575
- // Set the `install_timestamp` only if it's not yet set.
576
- $install_timestamp = $network_install_timestamp;
577
- }
578
-
579
- $prev_is_premium = $this->_storage->get( 'prev_is_premium', null, true );
580
- } else {
581
- $current_wp_user = self::_get_current_wp_user();
582
- $current_fs_user = self::_get_user_by_email( $current_wp_user->user_email );
583
- $network_user_info = array();
584
-
585
- $skips_count = 0;
586
-
587
- $sites = self::get_sites();
588
- $sites_count = count( $sites );
589
-
590
- $blog_id_2_install_map = array();
591
-
592
- $is_first_non_ignored_blog = true;
593
-
594
- foreach ( $sites as $site ) {
595
- $blog_id = self::get_site_blog_id( $site );
596
-
597
- $blog_install_timestamp = $this->_storage->get( 'install_timestamp', null, $blog_id );
598
-
599
- if ( is_null( $blog_install_timestamp ) ) {
600
- // Plugin has not been installed on this blog.
601
- continue;
602
- }
603
-
604
- $is_earlier_install = (
605
- ! is_null( $install_timestamp ) &&
606
- $blog_install_timestamp < $install_timestamp
607
- );
608
-
609
- $install = $this->get_install_by_blog_id( $blog_id );
610
-
611
- $update_network_user_info = false;
612
-
613
- if ( ! is_object( $install ) ) {
614
- if ( ! $this->_storage->get( 'is_anonymous', false, $blog_id ) ) {
615
- // The opt-in decision (whether to skip or opt in) is yet to be made.
616
- continue;
617
- }
618
-
619
- $skips_count ++;
620
- } else {
621
- $blog_id_2_install_map[ $blog_id ] = $install;
622
-
623
- if ( empty( $network_user_info ) ) {
624
- // Set the network user info for the 1st time. Choose any user information whether or not it is for the current WP user.
625
- $update_network_user_info = true;
626
- }
627
-
628
- if ( ! $update_network_user_info &&
629
- is_object( $current_fs_user ) &&
630
- $network_user_info['user_id'] != $current_fs_user->id &&
631
- $install->user_id == $current_fs_user->id
632
- ) {
633
- // If an install that is owned by the current WP user is found, use its user information instead.
634
- $update_network_user_info = true;
635
- }
636
-
637
- if ( ! $update_network_user_info &&
638
- $is_earlier_install &&
639
- ( ! is_object( $current_fs_user ) || $current_fs_user->id == $install->user_id )
640
- ) {
641
- // Update to the earliest install info if there's no install found so far that is owned by the current WP user; OR only if the found install is owned by the current WP user.
642
- $update_network_user_info = true;
643
- }
644
- }
645
-
646
- if ( $update_network_user_info ) {
647
- $network_user_info = array(
648
- 'user_id' => $install->user_id,
649
- 'blog_id' => $blog_id
650
- );
651
- }
652
-
653
- $site_prev_is_premium = $this->_storage->get( 'prev_is_premium', null, $blog_id );
654
-
655
- if ( $is_first_non_ignored_blog ) {
656
- $prev_is_premium = $site_prev_is_premium;
657
-
658
- if ( is_null( $network_install_timestamp ) ) {
659
- $install_timestamp = $blog_install_timestamp;
660
- }
661
-
662
- $is_first_non_ignored_blog = false;
663
-
664
- continue;
665
- }
666
-
667
- if ( ! is_null( $prev_is_premium ) && $prev_is_premium !== $site_prev_is_premium ) {
668
- // If a different `$site_prev_is_premium` value is found, do not include the option in the collection of options to update.
669
- $prev_is_premium = null;
670
- }
671
-
672
- if ( $is_earlier_install ) {
673
- // If an earlier install timestamp is found.
674
- $install_timestamp = $blog_install_timestamp;
675
- }
676
- }
677
-
678
- $installs_count = count( $blog_id_2_install_map );
679
-
680
- if ( $sites_count === ( $installs_count + $skips_count ) ) {
681
- if ( ! empty( $network_user_info ) ) {
682
- $options_to_update['network_user_id'] = $network_user_info['user_id'];
683
- $options_to_update['network_install_blog_id'] = $network_user_info['blog_id'];
684
-
685
- foreach ( $blog_id_2_install_map as $blog_id => $install ) {
686
- if ( $install->user_id == $network_user_info['user_id'] ) {
687
- continue;
688
- }
689
-
690
- $this->_storage->store( 'is_delegated_connection', true, $blog_id );
691
- }
692
- }
693
-
694
- if ( $sites_count === $skips_count ) {
695
- /**
696
- * Assume network-level skipping as the intended action if all actions identified were only
697
- * skipping of the connection (i.e., no opt-ins and delegated connections so far).
698
- */
699
- $options_to_update['is_anonymous_ms'] = true;
700
- } else if ( $sites_count === $installs_count ) {
701
- /**
702
- * Assume network-level opt-in as the intended action if all actions identified were only opt-ins
703
- * (i.e., no delegation and skipping of the connections so far).
704
- */
705
- $options_to_update['is_network_connected'] = true;
706
- }
707
- }
708
- }
709
-
710
- if ( ! is_null( $install_timestamp ) ) {
711
- $options_to_update['install_timestamp'] = $install_timestamp;
712
- }
713
-
714
- if ( ! is_null( $prev_is_premium ) ) {
715
- $options_to_update['prev_is_premium'] = $prev_is_premium;
716
- }
717
-
718
- if ( ! empty( $options_to_update ) ) {
719
- $this->adjust_storage( $options_to_update, $is_network_admin );
720
- }
721
- }
722
-
723
- /**
724
- * @author Leo Fajardo (@leorw)
725
- * @since 2.3.0
726
- *
727
- * @param array $options
728
- * @param bool $is_network_admin
729
- */
730
- private function adjust_storage( $options, $is_network_admin ) {
731
- foreach ( $options as $name => $value ) {
732
- $this->_storage->store( $name, $value, $is_network_admin ? true : null );
733
- }
734
- }
735
-
736
- /**
737
- * Checks whether this module has a settings menu.
738
- *
739
- * @author Leo Fajardo (@leorw)
740
- * @since 1.2.2
741
- *
742
- * @return bool
743
- */
744
- function has_settings_menu() {
745
- return ( $this->_is_network_active && fs_is_network_admin() ) ?
746
- $this->_menu->has_network_menu() :
747
- $this->_menu->has_menu();
748
- }
749
-
750
- /**
751
- * If `true` the opt-in should be shown as a modal dialog box on the themes.php page. WordPress.org themes guidelines prohibit from redirecting the user from the themes.php page after activating a theme.
752
- *
753
- * @author Vova Feldman (@svovaf)
754
- * @since 2.4.5
755
- *
756
- * @return bool
757
- */
758
- function show_opt_in_on_themes_page() {
759
- if ( ! $this->is_free_wp_org_theme() ) {
760
- return false;
761
- }
762
-
763
- if ( ! $this->has_settings_menu() ) {
764
- return true;
765
- }
766
-
767
- return $this->show_settings_with_tabs();
768
- }
769
-
770
- /**
771
- * If `true` the opt-in should be shown on the product's main setting page.
772
- *
773
- * @author Vova Feldman (@svovaf)
774
- * @since 2.4.5
775
- *
776
- * @return bool
777
- *
778
- * @uses show_opt_in_on_themes_page();
779
- */
780
- function show_opt_in_on_setting_page() {
781
- return ! $this->show_opt_in_on_themes_page();
782
- }
783
-
784
- /**
785
- * If `true` the settings should be shown using tabs.
786
- *
787
- * @author Vova Feldman (@svovaf)
788
- * @since 2.4.5
789
- *
790
- * @return bool
791
- */
792
- function show_settings_with_tabs() {
793
- return ( self::NAVIGATION_TABS === $this->_navigation );
794
- }
795
-
796
- /**
797
- * Check if the context module is free wp.org theme.
798
- *
799
- * This method is helpful because:
800
- * 1. wp.org themes are limited to a single submenu item,
801
- * and sub-submenu items are most likely not allowed (never verified).
802
- * 2. wp.org themes are not allowed to redirect the user
803
- * after the theme activation, therefore, the agreed UX
804
- * is showing the opt-in as a modal dialog box after
805
- * activation (approved by @otto42, @emiluzelac, @greenshady, @grapplerulrich).
806
- *
807
- * @author Vova Feldman (@svovaf)
808
- * @since 1.2.2.7
809
- *
810
- * @return bool
811
- */
812
- function is_free_wp_org_theme() {
813
- return (
814
- $this->is_theme() &&
815
- $this->is_org_repo_compliant() &&
816
- ! $this->is_premium()
817
- );
818
- }
819
-
820
- /**
821
- * Checks whether this a submenu item is visible.
822
- *
823
- * @author Vova Feldman (@svovaf)
824
- * @since 1.2.2.6
825
- * @since 1.2.2.7 Even if the menu item was specified to be hidden, when it is the context page, then show the submenu item so the user will have the right context page.
826
- *
827
- * @param string $slug
828
- * @param bool $is_tabs_visibility_check This is used to decide if the associated tab should be shown or hidden.
829
- *
830
- * @return bool
831
- */
832
- function is_submenu_item_visible( $slug, $is_tabs_visibility_check = false ) {
833
- if ( $this->is_admin_page( $slug ) ) {
834
- /**
835
- * It is the current context page, so show the submenu item
836
- * so the user will have the right context page, even if it
837
- * was set to hidden.
838
- */
839
- return true;
840
- }
841
-
842
- if ( ! $this->has_settings_menu() ) {
843
- // No menu settings at all.
844
- return false;
845
- }
846
-
847
- if (
848
- ! $is_tabs_visibility_check &&
849
- $this->is_org_repo_compliant() &&
850
- $this->show_settings_with_tabs()
851
- ) {
852
- /**
853
- * wp.org themes are limited to a single submenu item, and
854
- * sub-submenu items are most likely not allowed (never verified).
855
- */
856
- return false;
857
- }
858
-
859
- return $this->_menu->is_submenu_item_visible( $slug );
860
- }
861
-
862
- /**
863
- * Check if a Freemius page should be accessible via the UI.
864
- *
865
- * @author Vova Feldman (@svovaf)
866
- * @since 1.2.2.7
867
- *
868
- * @param string $slug
869
- *
870
- * @return bool
871
- */
872
- function is_page_visible( $slug ) {
873
- if ( $this->is_admin_page( $slug ) ) {
874
- return true;
875
- }
876
-
877
- return $this->_menu->is_submenu_item_visible( $slug, true, true );
878
- }
879
-
880
- /**
881
- * @author Vova Feldman (@svovaf)
882
- * @since 1.0.9
883
- */
884
- private function _version_updates_handler() {
885
- if ( ! isset( $this->_storage->sdk_version ) || $this->_storage->sdk_version != $this->version ) {
886
- // Freemius version upgrade mode.
887
- $this->_storage->sdk_last_version = $this->_storage->sdk_version;
888
- $this->_storage->sdk_version = $this->version;
889
-
890
- if ( empty( $this->_storage->sdk_last_version ) ||
891
- version_compare( $this->_storage->sdk_last_version, $this->version, '<' )
892
- ) {
893
- $this->_storage->sdk_upgrade_mode = true;
894
- $this->_storage->sdk_downgrade_mode = false;
895
- } else {
896
- $this->_storage->sdk_downgrade_mode = true;
897
- $this->_storage->sdk_upgrade_mode = false;
898
-
899
- }
900
-
901
- $this->do_action( 'sdk_version_update', $this->_storage->sdk_last_version, $this->version );
902
- }
903
-
904
- $plugin_version = $this->get_plugin_version();
905
- if ( ! isset( $this->_storage->plugin_version ) || $this->_storage->plugin_version != $plugin_version ) {
906
- // Plugin version upgrade mode.
907
- $this->_storage->plugin_last_version = $this->_storage->plugin_version;
908
- $this->_storage->plugin_version = $plugin_version;
909
-
910
- if ( empty( $this->_storage->plugin_last_version ) ||
911
- version_compare( $this->_storage->plugin_last_version, $plugin_version, '<' )
912
- ) {
913
- $this->_storage->plugin_upgrade_mode = true;
914
- $this->_storage->plugin_downgrade_mode = false;
915
- } else {
916
- $this->_storage->plugin_downgrade_mode = true;
917
- $this->_storage->plugin_upgrade_mode = false;
918
- }
919
-
920
- if ( ! empty( $this->_storage->plugin_last_version ) ) {
921
- // Different version of the plugin was installed before, therefore it's an update.
922
- $this->_storage->is_plugin_new_install = false;
923
- }
924
-
925
- $this->do_action( 'plugin_version_update', $this->_storage->plugin_last_version, $plugin_version );
926
- }
927
- }
928
-
929
- #--------------------------------------------------------------------------------
930
- #region Data Migration on SDK Update
931
- #--------------------------------------------------------------------------------
932
-
933
- /**
934
- * @author Vova Feldman (@svovaf)
935
- * @since 1.1.5
936
- *
937
- * @param string $sdk_prev_version
938
- * @param string $sdk_version
939
- */
940
- function _sdk_version_update( $sdk_prev_version, $sdk_version ) {
941
- /**
942
- * @since 1.1.7.3 Fixed unwanted connectivity test cleanup.
943
- */
944
- if ( empty( $sdk_prev_version ) ) {
945
- return;
946
- }
947
-
948
- if ( version_compare( $sdk_prev_version, '2.1.0', '<' ) &&
949
- version_compare( $sdk_version, '2.1.0', '>=' )
950
- ) {
951
- $this->_storage->handle_gdpr_admin_notice = true;
952
- }
953
-
954
- if ( version_compare( $sdk_prev_version, '2.0.0', '<' ) &&
955
- version_compare( $sdk_version, '2.0.0', '>=' )
956
- ) {
957
- $this->migrate_to_subscriptions_collection();
958
-
959
- $this->consolidate_licenses();
960
-
961
- // Clear trial_plan since it's now loaded from the plans collection when needed.
962
- $this->_storage->remove( 'trial_plan', true, false );
963
- }
964
-
965
- if ( version_compare( $sdk_prev_version, '1.2.3', '<' ) &&
966
- version_compare( $sdk_version, '1.2.3', '>=' )
967
- ) {
968
- /**
969
- * Starting from version 1.2.3, paths are stored as relative instead of absolute and some of them can be
970
- * invalid.
971
- *
972
- * @author Leo Fajardo (@leorw)
973
- */
974
- $this->remove_invalid_paths();
975
- }
976
-
977
- if ( version_compare( $sdk_prev_version, '1.1.5', '<' ) &&
978
- version_compare( $sdk_version, '1.1.5', '>=' )
979
- ) {
980
- // On version 1.1.5 merged connectivity and is_on data.
981
- if ( isset( $this->_storage->connectivity_test ) ) {
982
- if ( ! isset( $this->_storage->is_on ) ) {
983
- unset( $this->_storage->connectivity_test );
984
- } else {
985
- $connectivity_data = $this->_storage->connectivity_test;
986
- $connectivity_data['is_active'] = $this->_storage->is_on['is_active'];
987
- $connectivity_data['timestamp'] = $this->_storage->is_on['timestamp'];
988
-
989
- // Override.
990
- $this->_storage->connectivity_test = $connectivity_data;
991
-
992
- // Remove previous structure.
993
- unset( $this->_storage->is_on );
994
- }
995
-
996
- }
997
- }
998
-
999
- if (
1000
- version_compare( $sdk_prev_version, '2.2.1', '<' ) &&
1001
- version_compare( $sdk_version, '2.2.1', '>=' )
1002
- ) {
1003
- /**
1004
- * Clear the file cache without storing the previous path since it could be a wrong path. For example,
1005
- * in the versions of the SDK lower than 2.2.1, it's possible for the path of an add-on to be the same
1006
- * as the parent plugin's when the add-on was auto-installed since the relevant method names were not
1007
- * skipped in the logic that determines the right path in the `get_caller_main_file_and_type` method
1008
- * (e.g. `try_activate_plugin`). Since it was an auto-installation, the caller was the parent plugin
1009
- * and so its path was used. In case the stored path is wrong, clearing the cache will resolve issues
1010
- * related to data mix-up between plugins (e.g. titles and versions of an add-on and its parent plugin).
1011
- *
1012
- * @author Leo Fajardo (@leorw)
1013
- * @since 2.2.1
1014
- */
1015
- $this->clear_module_main_file_cache( false );
1016
- }
1017
- }
1018
-
1019
- /**
1020
- * @author Leo Fajardo (@leorw)
1021
- * @since 2.0.0
1022
- *
1023
- * @param \FS_Storage $storage
1024
- * @param bool|int|null $blog_id
1025
- */
1026
- private static function migrate_install_plan_to_plan_id( FS_Storage $storage, $blog_id = null ) {
1027
- if ( empty( $storage->sdk_version ) ) {
1028
- // New installation of the plugin, no need to upgrade.
1029
- return;
1030
- }
1031
-
1032
- if ( ! version_compare( $storage->sdk_version, '2.0.0', '<' ) ) {
1033
- // Previous version is >= 2.0.0, so no need to migrate.
1034
- return;
1035
- }
1036
-
1037
- // Alias.
1038
- $module_type = $storage->get_module_type();
1039
- $module_slug = $storage->get_module_slug();
1040
-
1041
- $installs = self::get_all_sites( $module_type, $blog_id );
1042
- $install = isset( $installs[ $module_slug ] ) ? $installs[ $module_slug ] : null;
1043
-
1044
- if ( ! is_object( $install ) ) {
1045
- return;
1046
- }
1047
-
1048
- if ( isset( $install->plan ) && is_object( $install->plan ) ) {
1049
- if ( isset( $install->plan->id ) && ! empty( $install->plan->id ) ) {
1050
- $install->plan_id = self::_decrypt( $install->plan->id );
1051
- }
1052
-
1053
- unset( $install->plan );
1054
-
1055
- $installs[ $module_slug ] = clone $install;
1056
-
1057
- self::set_account_option_by_module(
1058
- $module_type,
1059
- 'sites',
1060
- $installs,
1061
- true,
1062
- $blog_id
1063
- );
1064
- }
1065
- }
1066
-
1067
- /**
1068
- * @author Leo Fajardo (@leorw)
1069
- * @since 2.0.0
1070
- */
1071
- private function migrate_to_subscriptions_collection() {
1072
- if ( ! is_object( $this->_site ) ) {
1073
- return;
1074
- }
1075
-
1076
- if ( isset( $this->_storage->subscription ) && is_object( $this->_storage->subscription ) ) {
1077
- $this->_storage->subscriptions = array( fs_get_entity( $this->_storage->subscription, FS_Subscription::get_class_name() ) );
1078
- }
1079
- }
1080
-
1081
- /**
1082
- * @author Leo Fajardo (@leorw)
1083
- * @since 2.0.0
1084
- */
1085
- private function consolidate_licenses() {
1086
- $plugin_licenses = self::get_account_option( 'licenses', WP_FS__MODULE_TYPE_PLUGIN );
1087
- if ( isset( $plugin_licenses[ $this->_slug ] ) ) {
1088
- $plugin_licenses = $plugin_licenses[ $this->_slug ];
1089
- } else {
1090
- $plugin_licenses = array();
1091
- }
1092
-
1093
- $theme_licenses = self::get_account_option( 'licenses', WP_FS__MODULE_TYPE_THEME );
1094
- if ( isset( $theme_licenses[ $this->_slug ] ) ) {
1095
- $theme_licenses = $theme_licenses[ $this->_slug ];
1096
- } else {
1097
- $theme_licenses = array();
1098
- }
1099
-
1100
- if ( empty( $plugin_licenses ) && empty( $theme_licenses ) ) {
1101
- return;
1102
- }
1103
-
1104
- $all_licenses = array();
1105
- $user_id_license_ids_map = array();
1106
-
1107
- foreach ( $plugin_licenses as $user_id => $user_licenses ) {
1108
- if ( is_array( $user_licenses ) ) {
1109
- if ( ! isset( $user_license_ids[ $user_id ] ) ) {
1110
- $user_id_license_ids_map[ $user_id ] = array();
1111
- }
1112
-
1113
- foreach ( $user_licenses as $user_license ) {
1114
- $all_licenses[] = $user_license;
1115
- $user_id_license_ids_map[ $user_id ][] = $user_license->id;
1116
- }
1117
- }
1118
- }
1119
-
1120
- foreach ( $theme_licenses as $user_id => $user_licenses ) {
1121
- if ( is_array( $user_licenses ) ) {
1122
- if ( ! isset( $user_license_ids[ $user_id ] ) ) {
1123
- $user_id_license_ids_map[ $user_id ] = array();
1124
- }
1125
-
1126
- foreach ( $user_licenses as $user_license ) {
1127
- $all_licenses[] = $user_license;
1128
- $user_id_license_ids_map[ $user_id ][] = $user_license->id;
1129
- }
1130
- }
1131
- }
1132
-
1133
- self::store_user_id_license_ids_map(
1134
- $user_id_license_ids_map,
1135
- $this->_module_id
1136
- );
1137
-
1138
- $this->_store_licenses( true, $this->_module_id, $all_licenses );
1139
- }
1140
-
1141
- /**
1142
- * Remove invalid paths.
1143
- *
1144
- * @author Leo Fajardo (@leorw)
1145
- * @since 1.2.3
1146
- */
1147
- private function remove_invalid_paths() {
1148
- // Remove invalid path that is still associated with the current slug if there's any.
1149
- $file_slug_map = self::$_accounts->get_option( 'file_slug_map', array() );
1150
- foreach ( $file_slug_map as $plugin_basename => $slug ) {
1151
- if ( $slug === $this->_slug &&
1152
- $plugin_basename !== $this->_plugin_basename &&
1153
- ! file_exists( $this->get_absolute_path( $plugin_basename ) )
1154
- ) {
1155
- unset( $file_slug_map[ $plugin_basename ] );
1156
- self::$_accounts->set_option( 'file_slug_map', $file_slug_map, true );
1157
-
1158
- break;
1159
- }
1160
- }
1161
- }
1162
-
1163
- /**
1164
- * @author Vova Feldman (@svovaf)
1165
- * @since 1.2.2.7
1166
- *
1167
- * @param string $plugin_prev_version
1168
- * @param string $plugin_version
1169
- */
1170
- function _after_version_update( $plugin_prev_version, $plugin_version ) {
1171
- if ( $this->is_theme() ) {
1172
- // Expire the cache of the previous tabs since the theme may
1173
- // have setting updates.
1174
- $this->_cache->expire( 'tabs' );
1175
- $this->_cache->expire( 'tabs_stylesheets' );
1176
- }
1177
- }
1178
-
1179
- /**
1180
- * A special migration logic for the $_accounts, executed for all the plugins in the system:
1181
- * - Moves some data to the network level storage.
1182
- * - If the plugin's connection was skipped for all sites, set the plugin as if it was network skipped.
1183
- * - If the plugin's connection was ignored for all sites, don't do anything in terms of the network connection.
1184
- * - If the plugin was connected to all sites by the same super-admin, set the plugin as if was network opted-in for all sites.
1185
- * - If there's at least one site that was connected by a super-admin, find the "main super-admin" (the one that installed the majority of the plugin installs) and set the plugin as if was network activated with the main super-admin, set all the sites that were skipped or opted-in with a different user to delegated mode. Then, prompt the currently logged super-admin to choose what to do with the ignored sites.
1186
- * - If there are any sites in the network which the connection decision was not yet taken for, set this plugin into network activation mode so a super-admin can choose what to do with the rest of the sites.
1187
- *
1188
- * @author Vova Feldman (@svovaf)
1189
- * @since 2.0.0
1190
- */
1191
- private static function migrate_accounts_to_network() {
1192
- $sites = self::get_sites();
1193
- $sites_count = count( $sites );
1194
- $connection_status = array();
1195
- $plugin_slugs = array();
1196
- foreach ( $sites as $site ) {
1197
- $blog_id = self::get_site_blog_id( $site );
1198
-
1199
- self::$_accounts->migrate_to_network( $blog_id );
1200
-
1201
- /**
1202
- * Build a list of all Freemius powered plugins slugs.
1203
- */
1204
- $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array(), $blog_id );
1205
- foreach ( $id_slug_type_path_map as $module_id => $data ) {
1206
- if ( WP_FS__MODULE_TYPE_PLUGIN === $data['type'] ) {
1207
- $plugin_slugs[ $data['slug'] ] = true;
1208
- }
1209
- }
1210
-
1211
- $installs = self::get_account_option( 'sites', WP_FS__MODULE_TYPE_PLUGIN, $blog_id );
1212
-
1213
- if ( is_array( $installs ) ) {
1214
- foreach ( $installs as $slug => $install ) {
1215
- if ( ! isset( $connection_status[ $slug ] ) ) {
1216
- $connection_status[ $slug ] = array();
1217
- }
1218
-
1219
- if ( is_object( $install ) &&
1220
- FS_Site::is_valid_id( $install->id ) &&
1221
- FS_User::is_valid_id( $install->user_id )
1222
- ) {
1223
- $connection_status[ $slug ][ $blog_id ] = $install->user_id;
1224
- }
1225
- }
1226
- }
1227
- }
1228
-
1229
- foreach ( $plugin_slugs as $slug => $true ) {
1230
- if ( ! isset( $connection_status[ $slug ] ) ) {
1231
- $connection_status[ $slug ] = array();
1232
- }
1233
-
1234
- foreach ( $sites as $site ) {
1235
- $blog_id = self::get_site_blog_id( $site );
1236
-
1237
- if ( isset( $connection_status[ $slug ][ $blog_id ] ) ) {
1238
- continue;
1239
- }
1240
-
1241
- $storage = FS_Storage::instance( WP_FS__MODULE_TYPE_PLUGIN, $slug );
1242
-
1243
- $is_anonymous = $storage->get( 'is_anonymous', null, $blog_id );
1244
-
1245
- if ( ! is_null( $is_anonymous ) ) {
1246
- // Since 1.1.3 is_anonymous is an array.
1247
- if ( is_array( $is_anonymous ) && isset( $is_anonymous['is'] ) ) {
1248
- $is_anonymous = $is_anonymous['is'];
1249
- }
1250
-
1251
- if ( is_bool( $is_anonymous ) && true === $is_anonymous ) {
1252
- $connection_status[ $slug ][ $blog_id ] = 'skipped';
1253
- }
1254
- }
1255
-
1256
- if ( ! isset( $connection_status[ $slug ][ $blog_id ] ) ) {
1257
- $connection_status[ $slug ][ $blog_id ] = 'ignored';
1258
- }
1259
- }
1260
- }
1261
-
1262
- $super_admins = array();
1263
-
1264
- foreach ( $connection_status as $slug => $blogs_status ) {
1265
- $skips = 0;
1266
- $ignores = 0;
1267
- $connections = 0;
1268
- $opted_in_users = array();
1269
- $opted_in_super_admins = array();
1270
-
1271
- $storage = FS_Storage::instance( WP_FS__MODULE_TYPE_PLUGIN, $slug );
1272
-
1273
- foreach ( $blogs_status as $blog_id => $status_or_user_id ) {
1274
- if ( 'skipped' === $status_or_user_id ) {
1275
- $skips ++;
1276
- } else if ( 'ignored' === $status_or_user_id ) {
1277
- $ignores ++;
1278
- } else if ( FS_User::is_valid_id( $status_or_user_id ) ) {
1279
- $connections ++;
1280
-
1281
- if ( ! isset( $opted_in_users[ $status_or_user_id ] ) ) {
1282
- $opted_in_users[ $status_or_user_id ] = array();
1283
- }
1284
-
1285
- $opted_in_users[ $status_or_user_id ][] = $blog_id;
1286
-
1287
- if ( isset( $super_admins[ $status_or_user_id ] ) ||
1288
- self::is_super_admin( $status_or_user_id )
1289
- ) {
1290
- // Cache super-admin data.
1291
- $super_admins[ $status_or_user_id ] = true;
1292
-
1293
- // Remember opted-in super-admins for the plugin.
1294
- $opted_in_super_admins[ $status_or_user_id ] = true;
1295
- }
1296
- }
1297
- }
1298
-
1299
- $main_super_admin_user_id = null;
1300
- $all_migrated = false;
1301
- if ( $sites_count == $skips ) {
1302
- // All sites were skipped -> network skip by copying the anonymous mode from any of the sites.
1303
- $storage->is_anonymous_ms = $storage->is_anonymous;
1304
-
1305
- $all_migrated = true;
1306
- } else if ( $sites_count == $ignores ) {
1307
- // Don't do anything, still in activation mode.
1308
-
1309
- $all_migrated = true;
1310
- } else if ( 0 < count( $opted_in_super_admins ) ) {
1311
- // Find the super-admin with the majority of installs.
1312
- $max_installs_by_super_admin = 0;
1313
- foreach ( $opted_in_super_admins as $user_id => $true ) {
1314
- $installs_count = count( $opted_in_users[ $user_id ] );
1315
-
1316
- if ( $installs_count > $max_installs_by_super_admin ) {
1317
- $max_installs_by_super_admin = $installs_count;
1318
- $main_super_admin_user_id = $user_id;
1319
- }
1320
- }
1321
-
1322
- if ( $sites_count == $connections && 1 == count( $opted_in_super_admins ) ) {
1323
- // Super-admin opted-in for all sites in the network.
1324
- $storage->is_network_connected = true;
1325
-
1326
- $all_migrated = true;
1327
- }
1328
-
1329
- // Store network user.
1330
- $storage->network_user_id = $main_super_admin_user_id;
1331
-
1332
- $storage->network_install_blog_id = ( $sites_count == $connections ) ?
1333
- // Since all sites are opted-in, associating with the main site.
1334
- get_current_blog_id() :
1335
- // Associating with the 1st found opted-in site.
1336
- $opted_in_users[ $main_super_admin_user_id ][0];
1337
-
1338
- /**
1339
- * Make sure we migrate the plan ID of the network install, otherwise, if after the migration
1340
- * the 1st page that will be loaded is the network level WP Admin and $storage->network_install_blog_id
1341
- * is different than the main site of the network, the $this->_site will not be set since the plan_id
1342
- * will be empty.
1343
- */
1344
- $storage->migrate_to_network();
1345
- self::migrate_install_plan_to_plan_id( $storage, $storage->network_install_blog_id );
1346
- } else {
1347
- // At least one opt-in. All the opt-in were created by a non-super-admin.
1348
- if ( 0 == $ignores ) {
1349
- // All sites were opted-in or skipped, all by non-super-admin. So delegate all.
1350
- $storage->store( 'is_delegated_connection', true, true );
1351
-
1352
- $all_migrated = true;
1353
- }
1354
- }
1355
-
1356
- if ( ! $all_migrated ) {
1357
- /**
1358
- * Delegate all sites that were:
1359
- * 1) Opted-in by a user that is NOT the main-super-admin.
1360
- * 2) Skipped and non of the sites was opted-in by a super-admin. If any site was opted-in by a super-admin, there will be a main-super-admin, and we consider the skip as if it was done by that user.
1361
- */
1362
- foreach ( $blogs_status as $blog_id => $status_or_user_id ) {
1363
- if ( $status_or_user_id == $main_super_admin_user_id ) {
1364
- continue;
1365
- }
1366
-
1367
- if ( FS_User::is_valid_id( $status_or_user_id ) ||
1368
- ( 'skipped' === $status_or_user_id && is_null( $main_super_admin_user_id ) )
1369
- ) {
1370
- $storage->store( 'is_delegated_connection', true, $blog_id );
1371
- }
1372
- }
1373
- }
1374
-
1375
-
1376
- if ( ( $connections + $skips > 0 ) ) {
1377
- if ( $ignores > 0 ) {
1378
- /**
1379
- * If admin already opted-in or skipped in any of the network sites, and also
1380
- * have sites which the connection decision was not yet taken, set this plugin
1381
- * into network activation mode so the super-admin can choose what to do with
1382
- * the rest of the sites.
1383
- */
1384
- self::set_network_upgrade_mode( $storage );
1385
- }
1386
- }
1387
- }
1388
- }
1389
-
1390
- /**
1391
- * Set a module into network upgrade mode.
1392
- *
1393
- * @author Vova Feldman (@svovaf)
1394
- * @since 2.0.0
1395
- *
1396
- * @param \FS_Storage $storage
1397
- *
1398
- * @return bool
1399
- */
1400
- private static function set_network_upgrade_mode( FS_Storage $storage ) {
1401
- return $storage->is_network_activation = true;
1402
- }
1403
-
1404
- /**
1405
- * Will return true after upgrading to the SDK with the network level integration,
1406
- * when the super-admin involvement is required regarding the rest of the sites.
1407
- *
1408
- * @author Vova Feldman (@svovaf)
1409
- * @since 2.0.0
1410
- *
1411
- * @return bool
1412
- */
1413
- function is_network_upgrade_mode() {
1414
- return $this->_storage->get( 'is_network_activation' );
1415
- }
1416
-
1417
- /**
1418
- * Clear flag after the upgrade mode completion.
1419
- *
1420
- * @author Vova Feldman (@svovaf)
1421
- * @since 2.0.0
1422
- *
1423
- * @return bool True if network activation was on and now completed.
1424
- */
1425
- private function network_upgrade_mode_completed() {
1426
- if ( fs_is_network_admin() && $this->is_network_upgrade_mode() ) {
1427
- $this->_storage->remove( 'is_network_activation' );
1428
-
1429
- return true;
1430
- }
1431
-
1432
- return false;
1433
- }
1434
-
1435
- #endregion
1436
-
1437
- /**
1438
- * This action is connected to the 'plugins_loaded' hook and helps to determine
1439
- * if this is a new plugin installation or a plugin update.
1440
- *
1441
- * There are 3 different use-cases:
1442
- * 1) New plugin installation right with Freemius:
1443
- * 1.1 _activate_plugin_event_hook() will be executed first
1444
- * 1.2 Since $this->_storage->is_plugin_new_install is not set,
1445
- * and $this->_storage->plugin_last_version is not set,
1446
- * $this->_storage->is_plugin_new_install will be set to TRUE.
1447
- * 1.3 When _plugins_loaded() will be executed, $this->_storage->is_plugin_new_install will
1448
- * be already set to TRUE.
1449
- *
1450
- * 2) Plugin update, didn't have Freemius before, and now have the SDK:
1451
- * 2.1 _activate_plugin_event_hook() will not be executed, because
1452
- * the activation hook do NOT fires on updates since WP 3.1.
1453
- * 2.2 When _plugins_loaded() will be executed, $this->_storage->is_plugin_new_install will
1454
- * be empty, therefore, it will be set to FALSE.
1455
- *
1456
- * 3) Plugin update, had Freemius in prev version as well:
1457
- * 3.1 _version_updates_handler() will be executed 1st, since FS was installed
1458
- * before, $this->_storage->plugin_last_version will NOT be empty,
1459
- * therefore, $this->_storage->is_plugin_new_install will be set to FALSE.
1460
- * 3.2 When _plugins_loaded() will be executed, $this->_storage->is_plugin_new_install is
1461
- * already set, therefore, it will not be modified.
1462
- *
1463
- * Use-case #3 is backward compatible, #3.1 will be executed since 1.0.9.
1464
- *
1465
- * NOTE:
1466
- * The only fallback of this mechanism is if an admin updates a plugin based on use-case #2,
1467
- * and then, the next immediate PageView is the plugin's main settings page, it will not
1468
- * show the opt-in right away. The reason it will happen is because Freemius execution
1469
- * will be turned off till the plugin is fully loaded at least once
1470
- * (till $this->_storage->was_plugin_loaded is TRUE).
1471
- *
1472
- * @author Vova Feldman (@svovaf)
1473
- * @since 1.1.9
1474
- *
1475
- */
1476
- function _plugins_loaded() {
1477
- // Update flag that plugin was loaded with Freemius at least once.
1478
- $this->_storage->was_plugin_loaded = true;
1479
-
1480
- /**
1481
- * Bug fix - only set to false when it's a plugin, due to the
1482
- * execution sequence of the theme hooks and our methods, if
1483
- * this will be set for themes, Freemius will always assume
1484
- * it's a theme update.
1485
- *
1486
- * @author Vova Feldman (@svovaf)
1487
- * @since 1.2.2.2
1488
- */
1489
- if ( $this->is_plugin() &&
1490
- ! isset( $this->_storage->is_plugin_new_install )
1491
- ) {
1492
- $this->_storage->is_plugin_new_install = (
1493
- ! is_plugin_active( $this->_plugin_basename ) &&
1494
- empty( $this->_storage->plugin_last_version )
1495
- );
1496
- }
1497
- }
1498
-
1499
- /**
1500
- * Add special parameter to WP admin AJAX calls so when we
1501
- * process AJAX calls we can identify its source properly.
1502
- *
1503
- * @author Leo Fajardo (@leorw)
1504
- * @since 2.0.0
1505
- */
1506
- static function _enrich_ajax_url() {
1507
- $admin_param = is_network_admin() ?
1508
- '_fs_network_admin' :
1509
- '_fs_blog_admin';
1510
- ?>
1511
- <script type="text/javascript">
1512
- (function ($) {
1513
- $(document).ajaxSend(function (event, jqxhr, settings) {
1514
- if (settings.url &&
1515
- -1 < settings.url.indexOf('admin-ajax.php') &&
1516
- ! ( settings.url.indexOf( '<?php echo $admin_param ?>' ) > 0 )
1517
- ) {
1518
- if (
1519
- 'string' === typeof settings.data &&
1520
- settings.data.indexOf( 'action=heartbeat' ) > 0
1521
- ) {
1522
- return;
1523
- }
1524
-
1525
- if (settings.url.indexOf('?') > 0) {
1526
- settings.url += '&';
1527
- } else {
1528
- settings.url += '?';
1529
- }
1530
-
1531
- settings.url += '<?php echo $admin_param ?>=true';
1532
- }
1533
- });
1534
- })(jQuery);
1535
- </script>
1536
- <?php
1537
- }
1538
-
1539
- /**
1540
- * Opens the support forum subemenu item in a new browser page.
1541
- *
1542
- * @author Vova Feldman (@svovaf)
1543
- * @since 2.1.4
1544
- */
1545
- static function _open_support_forum_in_new_page() {
1546
- ?>
1547
- <script type="text/javascript">
1548
- (function ($) {
1549
- $('.fs-submenu-item.wp-support-forum').parent().attr( { target: '_blank', rel: 'noopener noreferrer' } );
1550
- })(jQuery);
1551
- </script>
1552
- <?php
1553
- }
1554
-
1555
- /**
1556
- * @author Vova Feldman (@svovaf)
1557
- * @since 1.0.9
1558
- */
1559
- private function register_constructor_hooks() {
1560
- $this->_logger->entrance();
1561
-
1562
- if ( is_admin() ) {
1563
- add_action( 'admin_init', array( &$this, '_hook_action_links_and_register_account_hooks' ) );
1564
-
1565
- if ( $this->is_plugin() ) {
1566
- if ( self::is_plugin_install_page() && true !== fs_request_get_bool( 'fs_allow_updater_and_dialog' ) ) {
1567
- /**
1568
- * Unless the `fs_allow_updater_and_dialog` URL param exists and its value is `true`, make
1569
- * Freemius-related updates unavailable on the "Add Plugins" admin page (/plugin-install.php)
1570
- * so that they won't interfere with the .org plugins' functionalities on that page (e.g.
1571
- * updating of a .org plugin).
1572
- */
1573
- add_filter( 'site_transient_update_plugins', array( 'Freemius', '_remove_fs_updates_from_plugin_install_page' ), 10, 2 );
1574
- } else if ( self::is_plugins_page() || self::is_updates_page() ) {
1575
- /**
1576
- * On the "Plugins" and "Updates" admin pages, if there are premium or non–org-compliant plugins, modify their details dialog URLs (add a Freemius-specific param) so that the SDK can determine if the plugin information dialog should show information from Freemius.
1577
- *
1578
- * @author Leo Fajardo (@leorw)
1579
- * @since 2.2.3
1580
- */
1581
- add_action( 'admin_footer', array( 'Freemius', '_prepend_fs_allow_updater_and_dialog_flag_url_param' ) );
1582
- }
1583
-
1584
- $plugin_dir = dirname( $this->_plugin_dir_path ) . '/';
1585
-
1586
- /**
1587
- * @since 1.2.2
1588
- *
1589
- * Hook to both free and premium version activations to support
1590
- * auto deactivation on the other version activation.
1591
- */
1592
- register_activation_hook(
1593
- $plugin_dir . $this->_free_plugin_basename,
1594
- array( &$this, '_activate_plugin_event_hook' )
1595
- );
1596
-
1597
- register_activation_hook(
1598
- $plugin_dir . $this->premium_plugin_basename(),
1599
- array( &$this, '_activate_plugin_event_hook' )
1600
- );
1601
- } else {
1602
- add_action( 'after_switch_theme', array( &$this, '_activate_theme_event_hook' ), 10, 2 );
1603
-
1604
- add_action( 'admin_footer', array( &$this, '_style_premium_theme' ) );
1605
- }
1606
-
1607
- /**
1608
- * Part of the mechanism to identify new plugin install vs. plugin update.
1609
- *
1610
- * @author Vova Feldman (@svovaf)
1611
- * @since 1.1.9
1612
- */
1613
- if ( empty( $this->_storage->was_plugin_loaded ) ) {
1614
- /**
1615
- * During the plugin activation (not theme), 'plugins_loaded' will be already executed
1616
- * when the logic gets here since the activation logic first add the activate plugins,
1617
- * then triggers 'plugins_loaded', and only then include the code of the plugin that
1618
- * is activated. Which means that _plugins_loaded() will NOT be executed during the
1619
- * plugin activation, and that IS intentional.
1620
- *
1621
- * @author Vova Feldman (@svovaf)
1622
- */
1623
- if ( $this->is_plugin() &&
1624
- $this->is_activation_mode( false ) &&
1625
- 0 == did_action( 'plugins_loaded' )
1626
- ) {
1627
- add_action( 'plugins_loaded', array( &$this, '_plugins_loaded' ) );
1628
- } else {
1629
- // If was activated before, then it was already loaded before.
1630
- $this->_plugins_loaded();
1631
- }
1632
- }
1633
-
1634
- if ( ! self::is_ajax() ) {
1635
- if ( ! $this->is_addon() ) {
1636
- add_action( 'init', array( &$this, '_add_default_submenu_items' ), WP_FS__LOWEST_PRIORITY );
1637
- }
1638
- }
1639
-
1640
- if ( $this->_storage->handle_gdpr_admin_notice ) {
1641
- add_action( 'init', array( &$this, '_maybe_show_gdpr_admin_notice' ) );
1642
- }
1643
-
1644
- add_action( 'init', array( &$this, '_maybe_add_gdpr_optin_ajax_handler') );
1645
- add_action( 'init', array( &$this, '_maybe_add_pricing_ajax_handler' ) );
1646
- }
1647
-
1648
- if ( $this->is_plugin() ) {
1649
- if ( version_compare( $GLOBALS['wp_version'], '5.1', '<' ) ) {
1650
- add_action( 'wpmu_new_blog', array( $this, '_after_new_blog_callback' ), 10, 6 );
1651
- } else {
1652
- add_action( 'wp_initialize_site', array( $this, '_after_wp_initialize_site_callback' ), 11, 2 );
1653
- }
1654
-
1655
- register_deactivation_hook( $this->_plugin_main_file_path, array( &$this, '_deactivate_plugin_hook' ) );
1656
- }
1657
-
1658
- if ( is_multisite() ) {
1659
- add_action( 'deactivate_blog', array( &$this, '_after_site_deactivated_callback' ) );
1660
- add_action( 'archive_blog', array( &$this, '_after_site_deactivated_callback' ) );
1661
- add_action( 'make_spam_blog', array( &$this, '_after_site_deactivated_callback' ) );
1662
-
1663
- if ( version_compare( $GLOBALS['wp_version'], '5.1', '<' ) ) {
1664
- add_action( 'deleted_blog', array( $this, '_after_site_deleted_callback' ), 10, 2 );
1665
- } else {
1666
- add_action( 'wp_delete_site', array( $this, '_after_wpsite_deleted_callback' ) );
1667
- }
1668
-
1669
- add_action( 'activate_blog', array( &$this, '_after_site_reactivated_callback' ) );
1670
- add_action( 'unarchive_blog', array( &$this, '_after_site_reactivated_callback' ) );
1671
- add_action( 'make_ham_blog', array( &$this, '_after_site_reactivated_callback' ) );
1672
- }
1673
-
1674
- if ( $this->is_theme() &&
1675
- self::is_customizer() &&
1676
- $this->apply_filters( 'show_customizer_upsell', true )
1677
- ) {
1678
- // Register customizer upsell.
1679
- add_action( 'customize_register', array( &$this, '_customizer_register' ) );
1680
- }
1681
-
1682
- add_action( 'admin_init', array( &$this, '_redirect_on_clicked_menu_link' ), WP_FS__LOWEST_PRIORITY );
1683
-
1684
- if ( $this->is_theme() && ! $this->is_migration() ) {
1685
- add_action( 'admin_init', array( &$this, '_add_tracking_links' ) );
1686
- }
1687
-
1688
- add_action( 'admin_init', array( &$this, '_add_license_activation' ) );
1689
- add_action( 'admin_init', array( &$this, '_add_premium_version_upgrade_selection' ) );
1690
- add_action( 'admin_init', array( &$this, '_add_beta_mode_update_handler' ) );
1691
- add_action( 'admin_init', array( &$this, '_add_user_change_option' ) );
1692
- add_action( 'admin_init', array( &$this, '_add_email_address_update_option' ) );
1693
-
1694
- $this->add_ajax_action( 'update_billing', array( &$this, '_update_billing_ajax_action' ) );
1695
- $this->add_ajax_action( 'start_trial', array( &$this, '_start_trial_ajax_action' ) );
1696
- $this->add_ajax_action( 'set_data_debug_mode', array( &$this, '_set_data_debug_mode' ) );
1697
- $this->add_ajax_action( 'toggle_whitelabel_mode', array( &$this, '_toggle_whitelabel_mode_ajax_handler' ) );
1698
-
1699
- if ( $this->_is_network_active && fs_is_network_admin() ) {
1700
- $this->add_ajax_action( 'network_activate', array( &$this, '_network_activate_ajax_action' ) );
1701
- }
1702
-
1703
- $this->add_ajax_action( 'install_premium_version', array(
1704
- &$this,
1705
- '_install_premium_version_ajax_action'
1706
- ) );
1707
-
1708
- $this->add_ajax_action( 'submit_affiliate_application', array( &$this, '_submit_affiliate_application' ) );
1709
-
1710
- $this->add_action( 'after_plans_sync', array( &$this, '_check_for_trial_plans' ) );
1711
-
1712
- $this->add_action( 'sdk_version_update', array( &$this, '_sdk_version_update' ), WP_FS__DEFAULT_PRIORITY, 2 );
1713
-
1714
- $this->add_action(
1715
- 'plugin_version_update',
1716
- array( &$this, '_after_version_update' ),
1717
- WP_FS__DEFAULT_PRIORITY,
1718
- 2
1719
- );
1720
- $this->add_filter( 'after_code_type_change', array( &$this, '_after_code_type_change' ) );
1721
-
1722
- add_action( 'admin_init', array( &$this, '_add_trial_notice' ) );
1723
- add_action( 'admin_init', array( &$this, '_add_affiliate_program_notice' ) );
1724
- add_action( 'admin_enqueue_scripts', array( &$this, '_enqueue_common_css' ) );
1725
-
1726
- /**
1727
- * Handle request to reset anonymous mode for `get_reconnect_url()`.
1728
- *
1729
- * @author Vova Feldman (@svovaf)
1730
- * @since 1.2.1.5
1731
- */
1732
- if ( fs_request_is_action( 'reset_anonymous_mode' ) &&
1733
- $this->get_unique_affix() === fs_request_get( 'fs_unique_affix' )
1734
- ) {
1735
- add_action( 'admin_init', array( &$this, 'connect_again' ) );
1736
- }
1737
- }
1738
-
1739
- /**
1740
- * Register the required hooks right after the settings parse is completed.
1741
- *
1742
- * @author Vova Feldman (@svovaf)
1743
- * @since 2.3.1
1744
- */
1745
- private function register_after_settings_parse_hooks() {
1746
- if ( is_admin() &&
1747
- $this->is_theme() &&
1748
- $this->is_premium() &&
1749
- ! $this->has_active_valid_license()
1750
- ) {
1751
- $this->add_ajax_action(
1752
- 'delete_theme_update_data',
1753
- array( &$this, '_delete_theme_update_data_action' )
1754
- );
1755
- }
1756
-
1757
- if ( $this->show_settings_with_tabs() ) {
1758
- /**
1759
- * Include the required hooks to capture the theme settings' page tabs
1760
- * and cache them.
1761
- *
1762
- * @author Vova Feldman (@svovaf)
1763
- * @since 1.2.2.7
1764
- */
1765
- if ( ! $this->_cache->has_valid( 'tabs' ) ) {
1766
- add_action( 'admin_footer', array( &$this, '_tabs_capture' ) );
1767
- // Add license activation AJAX callback.
1768
- $this->add_ajax_action( 'store_tabs', array( &$this, '_store_tabs_ajax_action' ) );
1769
-
1770
- add_action( 'admin_enqueue_scripts', array( &$this, '_store_tabs_styles' ), 9999999 );
1771
- }
1772
-
1773
- add_action(
1774
- 'admin_footer',
1775
- array( &$this, '_add_freemius_tabs' ),
1776
- /**
1777
- * The tabs JS code must be executed after the tabs capture logic (_tabs_capture()).
1778
- * That's why the priority is 11 while the tabs capture logic is added
1779
- * with priority 10.
1780
- *
1781
- * @author Vova Feldman (@svovaf)
1782
- */
1783
- 11
1784
- );
1785
- }
1786
-
1787
- if ( ! self::is_ajax() ) {
1788
- if ( ! $this->is_addon() || $this->is_only_premium() ) {
1789
- add_action(
1790
- ( $this->_is_network_active && fs_is_network_admin() ? 'network_' : '' ) . 'admin_menu',
1791
- array( &$this, '_prepare_admin_menu' ),
1792
- WP_FS__LOWEST_PRIORITY
1793
- );
1794
- }
1795
- }
1796
- }
1797
-
1798
- /**
1799
- * Makes Freemius-related updates unavailable on the "Add Plugins" admin page (/plugin-install.php) so that
1800
- * they won't interfere with the .org plugins' functionalities on that page (e.g. updating of a .org plugin).
1801
- *
1802
- * @author Leo Fajardo (@leorw)
1803
- * @since 2.2.3
1804
- *
1805
- * @param object $updates
1806
- * @param string|null $transient
1807
- *
1808
- * @return object
1809
- */
1810
- static function _remove_fs_updates_from_plugin_install_page( $updates, $transient = null ) {
1811
- if ( is_object( $updates ) && isset( $updates->response ) ) {
1812
- foreach ( $updates->response as $file => $plugin ) {
1813
- if ( isset( $plugin->package ) && false !== strpos( $plugin->package, 'api.freemius' ) ) {
1814
- unset( $updates->response[ $file ] );
1815
- }
1816
- }
1817
- }
1818
-
1819
- return $updates;
1820
- }
1821
-
1822
- /**
1823
- * Prepends the `fs_allow_updater_and_dialog` param to the plugin information URLs to tell the SDK to handle
1824
- * the information that is shown on the plugin details dialog that is shown when the relevant link is clicked.
1825
- *
1826
- * @author Leo Fajardo (@leorw)
1827
- * @since 2.2.3
1828
- *
1829
- * @return string
1830
- */
1831
- static function _prepend_fs_allow_updater_and_dialog_flag_url_param() {
1832
- $slug_basename_map = array();
1833
- foreach ( self::$_instances as $instance ) {
1834
- if ( ! $instance->is_plugin() ) {
1835
- continue;
1836
- }
1837
-
1838
- $slug_basename_map[ $instance->get_slug() ] = $instance->premium_plugin_basename();
1839
- }
1840
- ?>
1841
- <script type="text/javascript">
1842
- (function( $ ) {
1843
- var slugBasenameMap = <?php echo json_encode( $slug_basename_map ) ?>;
1844
- for ( var slug in slugBasenameMap ) {
1845
- var basename = slugBasenameMap[ slug ];
1846
-
1847
- // Try to get the plugin rows if on the "Plugins" page.
1848
- var $pluginRows = $( '.wp-list-table.plugins tr[data-plugin="' + basename + '"]');
1849
-
1850
- if ( 0 === $pluginRows.length ) {
1851
- // Try to get the plugin rows if on the "Updates" page.
1852
- var $pluginCheckbox = $( '#update-plugins-table input[type="checkbox"][value="' + basename + '"]' );
1853
- if ( 0 !== $pluginCheckbox.length ) {
1854
- $pluginRows = $pluginCheckbox.parents( 'tr:first' );
1855
- }
1856
- }
1857
-
1858
- if ( 0 === $pluginRows.length ) {
1859
- // No plugin rows found.
1860
- continue;
1861
- }
1862
-
1863
- // Find the "View details" links and add the `fs_allow_updater_and_dialog` param to the URL.
1864
- $pluginRows.find( 'a[href*="plugin-install.php?tab=plugin-information"]' ).each(function() {
1865
- var $this = $( this ),
1866
- href = $this.attr( 'href' ).replace( '?tab=', '?fs_allow_updater_and_dialog=true&tab=');
1867
-
1868
- $this.attr( 'href', href );
1869
- });
1870
- }
1871
- })( jQuery );
1872
- </script>
1873
- <?php
1874
- }
1875
-
1876
- /**
1877
- * @author Leo Fajardo (@leorw)
1878
- * @since 2.3.0
1879
- */
1880
- static function _maybe_add_beta_label_styles() {
1881
- $has_any_beta_version = false;
1882
-
1883
- foreach ( self::$_instances as $instance ) {
1884
- if ( $instance->is_beta() ) {
1885
- $has_any_beta_version = true;
1886
- break;
1887
- }
1888
- }
1889
-
1890
- if ( $has_any_beta_version ) {
1891
- fs_enqueue_local_style( 'fs_plugins', '/admin/plugins.css' );
1892
- }
1893
- }
1894
-
1895
- /**
1896
- * @author Leo Fajardo (@leorw)
1897
- * @since 2.3.0
1898
- */
1899
- static function _maybe_add_beta_label_to_plugins_and_handle_confirmation() {
1900
- $beta_data = array();
1901
-
1902
- foreach ( self::$_instances as $instance ) {
1903
- if ( ! $instance->is_premium() ) {
1904
- continue;
1905
- }
1906
-
1907
- /**
1908
- * If there's an available beta version update, a confirmation message will be shown when the
1909
- * "Update now" link on the "Plugins" or "Themes" page is clicked.
1910
- */
1911
- $has_beta_update = $instance->has_beta_update();
1912
-
1913
- $is_beta = (
1914
- // The "Beta" label is added separately for themes.
1915
- $instance->is_plugin() &&
1916
- $instance->is_beta()
1917
- );
1918
-
1919
- if ( ! $is_beta && ! $has_beta_update ) {
1920
- continue;
1921
- }
1922
-
1923
- $beta_data[ $instance->get_plugin_basename() ] = array( 'is_installed_version_beta' => $is_beta );
1924
-
1925
- if ( ! $has_beta_update ) {
1926
- continue;
1927
- }
1928
-
1929
- $beta_data[ $instance->get_plugin_basename() ]['beta_version_update_confirmation_message'] = sprintf(
1930
- '%s %s',
1931
- sprintf(
1932
- fs_esc_attr_inline(
1933
- 'An update to a Beta version will replace your installed version of %s with the latest Beta release - use with caution, and not on production sites. You have been warned.',
1934
- 'beta-version-update-caution',
1935
- $instance->get_slug()
1936
- ),
1937
- $instance->get_plugin_title()
1938
- ),
1939
- fs_esc_attr_inline( 'Would you like to proceed with the update?', 'update-confirmation', $instance->get_slug() )
1940
- );
1941
- }
1942
-
1943
- if ( empty( $beta_data ) ) {
1944
- return;
1945
- }
1946
- ?>
1947
- <script type="text/javascript">
1948
- ( function( $ ) {
1949
- var betaData = <?php echo json_encode( $beta_data ) ?>;
1950
-
1951
- for ( var pluginBasename in betaData ) {
1952
- if ( ! betaData.hasOwnProperty( pluginBasename ) ) {
1953
- continue;
1954
- }
1955
-
1956
- if ( ! betaData[ pluginBasename ].is_installed_version_beta ) {
1957
- continue;
1958
- }
1959
-
1960
- var $parentContainer = $( '.wp-list-table.plugins tr[data-plugin="' + pluginBasename + '"]' );
1961
- if ( 0 === $parentContainer.length ) {
1962
- continue;
1963
- }
1964
-
1965
- $parentContainer.find( '.plugin-title > strong:first-child').append(
1966
- '<span class="fs-tag fs-info"><?php fs_esc_js_echo_inline( 'Beta', 'beta' ) ?></span>'
1967
- );
1968
- }
1969
-
1970
- setTimeout( function() {
1971
- // Wait a little bit before adding the event handler, otherwise, it will be overridden by the core WP logic.
1972
- $( '.plugins .update-message .update-link, .themes .theme .update-message' ).on( 'click', function() {
1973
- var $parentContainer = $( this ).parents( 'tr:first' );
1974
- pluginBasename = ( 0 !== $parentContainer.length ) ?
1975
- $parentContainer.data( 'plugin' ) :
1976
- $( this ).parents( '.theme:first' ).data( 'slug' );
1977
-
1978
- if (
1979
- betaData[ pluginBasename ] &&
1980
- betaData[ pluginBasename ].beta_version_update_confirmation_message &&
1981
- ! confirm( betaData[ pluginBasename ].beta_version_update_confirmation_message )
1982
- ) {
1983
- return false;
1984
- }
1985
- } );
1986
- }, 20 );
1987
- } )( jQuery );
1988
- </script>
1989
- <?php
1990
- }
1991
-
1992
- /**
1993
- * Keeping the uninstall hook registered for free or premium plugin version may result to a fatal error that
1994
- * could happen when a user tries to uninstall either version while one of them is still active. Uninstalling a
1995
- * plugin will trigger inclusion of the free or premium version and if one of them is active during the
1996
- * uninstallation, a fatal error may occur in case the plugin's class or functions are already defined.
1997
- *
1998
- * @author Leo Fajardo (@leorw)
1999
- *
2000
- * @since 1.2.0
2001
- */
2002
- private function unregister_uninstall_hook() {
2003
- $uninstallable_plugins = (array) get_option( 'uninstall_plugins' );
2004
- unset( $uninstallable_plugins[ $this->_free_plugin_basename ] );
2005
- unset( $uninstallable_plugins[ $this->premium_plugin_basename() ] );
2006
-
2007
- update_option( 'uninstall_plugins', $uninstallable_plugins );
2008
- }
2009
-
2010
- /**
2011
- * @since 1.2.0 Invalidate module's main file cache, otherwise, FS_Plugin_Updater will not fetch updates.
2012
- *
2013
- * @param bool $store_prev_path
2014
- */
2015
- private function clear_module_main_file_cache( $store_prev_path = true ) {
2016
- if ( ! isset( $this->_storage->plugin_main_file ) ||
2017
- empty( $this->_storage->plugin_main_file->path )
2018
- ) {
2019
- return;
2020
- }
2021
-
2022
- if ( ! $store_prev_path ) {
2023
- /**
2024
- * Storing the previous path is not needed when clearing the cache after an SDK version update since
2025
- * the main purpose of the cache clearing in that event is to correct a wrong plugin main file path
2026
- * which causes data mix-up between plugins (e.g. titles and versions of an add-on and its parent plugin).
2027
- *
2028
- * @author Leo Fajardo (@leorw)
2029
- * @since 2.2.1
2030
- */
2031
- unset( $this->_storage->plugin_main_file->path );
2032
- } else {
2033
- $plugin_main_file = clone $this->_storage->plugin_main_file;
2034
-
2035
- // Store cached path (2nd layer cache).
2036
- $plugin_main_file->prev_path = $plugin_main_file->path;
2037
-
2038
- // Clear cached path.
2039
- unset( $plugin_main_file->path );
2040
-
2041
- $this->_storage->plugin_main_file = $plugin_main_file;
2042
- }
2043
-
2044
- /**
2045
- * Clear global cached path.
2046
- *
2047
- * @author Leo Fajardo (@leorw)
2048
- * @since 1.2.2
2049
- */
2050
- $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map' );
2051
- unset( $id_slug_type_path_map[ $this->_module_id ]['path'] );
2052
- self::$_accounts->set_option( 'id_slug_type_path_map', $id_slug_type_path_map, true );
2053
- }
2054
-
2055
- /**
2056
- * @author Leo Fajardo (@leorw)
2057
- * @since 2.0.0
2058
- */
2059
- function _hook_action_links_and_register_account_hooks() {
2060
- if ( $this->is_migration() ) {
2061
- return;
2062
- }
2063
-
2064
- $this->_add_tracking_links();
2065
-
2066
- if ( self::is_plugins_page() && $this->is_plugin() ) {
2067
- $this->hook_plugin_action_links();
2068
- }
2069
-
2070
- $this->_register_account_hooks();
2071
- }
2072
-
2073
- /**
2074
- * @author Vova Feldman (@svovaf)
2075
- * @since 1.0.9
2076
- */
2077
- private function _register_account_hooks() {
2078
- if ( ! is_admin() ) {
2079
- return;
2080
- }
2081
-
2082
- /**
2083
- * Always show the deactivation feedback form since we added
2084
- * automatic free version deactivation upon premium code activation.
2085
- *
2086
- * @since 1.2.1.6
2087
- */
2088
- $this->add_ajax_action(
2089
- 'submit_uninstall_reason',
2090
- array( &$this, '_submit_uninstall_reason_action' )
2091
- );
2092
-
2093
- $this->add_ajax_action(
2094
- 'cancel_subscription_or_trial',
2095
- array( &$this, 'cancel_subscription_or_trial_ajax_action' )
2096
- );
2097
-
2098
- if ( ! $this->is_addon() || $this->is_parent_plugin_installed() ) {
2099
- if ( ( $this->is_plugin() && self::is_plugins_page() ) ||
2100
- ( $this->is_theme() && self::is_themes_page() )
2101
- ) {
2102
- add_action( 'admin_footer', array( &$this, '_add_deactivation_feedback_dialog_box' ) );
2103
- }
2104
- }
2105
- }
2106
-
2107
- /**
2108
- * Leverage backtrace to find caller plugin file path.
2109
- *
2110
- * @param bool $is_init Is initiation sequence.
2111
- * @param string $main_file Since 2.5.0 expects the module's main file path to potentially purge the cached path.
2112
- *
2113
- * @return string
2114
- * @since 1.0.6
2115
- *
2116
- * @author Vova Feldman (@svovaf)
2117
- */
2118
- private function _find_caller_plugin_file( $is_init = false, $main_file = '' ) {
2119
- // Try to load the cached value of the file path.
2120
- if ( isset( $this->_storage->plugin_main_file ) ) {
2121
- $plugin_main_file = $this->_storage->plugin_main_file;
2122
- if ( ! empty( $plugin_main_file->path ) ) {
2123
- $absolute_path = $this->get_absolute_path( $plugin_main_file->path );
2124
- if ( file_exists( $absolute_path ) ) {
2125
- if ( $is_init && $absolute_path !== $this->get_absolute_path( $main_file ) ) {
2126
- // Update cached path if not matching the actual path.
2127
- $plugin_main_file->path = $main_file;
2128
- $this->_storage->plugin_main_file = $plugin_main_file;
2129
- }
2130
-
2131
- return $absolute_path;
2132
- }
2133
- }
2134
- }
2135
-
2136
- /**
2137
- * @since 1.2.1
2138
- *
2139
- * `clear_module_main_file_cache()` is clearing the plugin's cached path on
2140
- * deactivation. Therefore, if any plugin/theme was initiating `Freemius`
2141
- * with that plugin's slug, it was overriding the empty plugin path with a wrong path.
2142
- *
2143
- * So, we've added a special mechanism with a 2nd layer of cache that uses `prev_path`
2144
- * when the class instantiator isn't the module.
2145
- */
2146
- if ( ! $is_init ) {
2147
- // Fetch prev path cache.
2148
- if ( isset( $this->_storage->plugin_main_file ) &&
2149
- ! empty( $this->_storage->plugin_main_file->prev_path )
2150
- ) {
2151
- $absolute_path = $this->get_absolute_path( $this->_storage->plugin_main_file->prev_path );
2152
- if ( file_exists( $absolute_path ) ) {
2153
- return $absolute_path;
2154
- }
2155
- }
2156
-
2157
- wp_die(
2158
- $this->get_text_inline( 'Freemius SDK couldn\'t find the plugin\'s main file. Please contact sdk@freemius.com with the current error.', 'failed-finding-main-path' ) .
2159
- " Module: {$this->_slug}; SDK: " . WP_FS__SDK_VERSION . ";",
2160
- $this->get_text_inline( 'Error', 'error' ),
2161
- array( 'back_link' => true )
2162
- );
2163
- }
2164
-
2165
- /**
2166
- * @since 1.2.1
2167
- *
2168
- * Only the original instantiator that calls dynamic_init can modify the module's path.
2169
- */
2170
- // Find caller module.
2171
- $this->_storage->plugin_main_file = (object) array(
2172
- 'path' => $main_file,
2173
- );
2174
-
2175
- return $this->get_absolute_path( $main_file );
2176
- }
2177
-
2178
- /**
2179
- * @author Leo Fajardo (@leorw)
2180
- * @since 1.2.3
2181
- *
2182
- * @param string $path
2183
- *
2184
- * @return string
2185
- */
2186
- private function get_relative_path( $path ) {
2187
- $module_root_dir = $this->get_module_root_dir_path();
2188
- if ( 0 === strpos( $path, $module_root_dir ) ) {
2189
- $path = substr( $path, strlen( $module_root_dir ) );
2190
- }
2191
-
2192
- return $path;
2193
- }
2194
-
2195
- /**
2196
- * @author Leo Fajardo (@leorw)
2197
- * @since 1.2.3
2198
- *
2199
- * @param string $path
2200
- * @param string|bool $module_type
2201
- *
2202
- * @return string
2203
- */
2204
- private function get_absolute_path( $path, $module_type = false ) {
2205
- $module_root_dir = $this->get_module_root_dir_path( $module_type );
2206
- if ( 0 !== strpos( $path, $module_root_dir ) ) {
2207
- $path = fs_normalize_path( $module_root_dir . $path );
2208
- }
2209
-
2210
- return $path;
2211
- }
2212
-
2213
- /**
2214
- * @author Leo Fajardo (@leorw)
2215
- * @since 1.2.3
2216
- *
2217
- * @param string|bool $module_type
2218
- *
2219
- * @return string
2220
- */
2221
- private function get_module_root_dir_path( $module_type = false ) {
2222
- $is_plugin = empty( $module_type ) ?
2223
- $this->is_plugin() :
2224
- ( WP_FS__MODULE_TYPE_PLUGIN === $module_type );
2225
-
2226
- return fs_normalize_path( trailingslashit( $is_plugin ?
2227
- WP_PLUGIN_DIR :
2228
- get_theme_root( get_stylesheet() ) ) );
2229
- }
2230
-
2231
- /**
2232
- * @author Leo Fajardo (@leorw)
2233
- *
2234
- * @param number $module_id
2235
- * @param string $slug
2236
- *
2237
- * @return string Since 2.5.0 return the module's main file path.
2238
- *
2239
- * @since 1.2.2
2240
- */
2241
- private function store_id_slug_type_path_map( $module_id, $slug ) {
2242
- $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array() );
2243
-
2244
- $store_option = false;
2245
-
2246
- if ( ! isset( $id_slug_type_path_map[ $module_id ] ) ) {
2247
- $id_slug_type_path_map[ $module_id ] = array(
2248
- 'slug' => $slug
2249
- );
2250
-
2251
- $store_option = true;
2252
- } else if (
2253
- isset( $id_slug_type_path_map[ $module_id ]['slug'] ) &&
2254
- $slug !== $id_slug_type_path_map[ $module_id ]['slug']
2255
- ) {
2256
- $id_slug_type_path_map[ $module_id ]['slug'] = $slug;
2257
- $store_option = true;
2258
- }
2259
-
2260
- $find_caller = empty( $id_slug_type_path_map[ $module_id ]['path'] );
2261
-
2262
- if ( ! $find_caller ) {
2263
- /**
2264
- * This verification is for cases when suddenly the same module
2265
- * is installed but with a different folder name.
2266
- *
2267
- * @author Vova Feldman (@svovaf)
2268
- * @since 1.2.3
2269
- */
2270
- $find_caller = ! file_exists( $this->get_absolute_path(
2271
- $id_slug_type_path_map[ $module_id ]['path'],
2272
- $id_slug_type_path_map[ $module_id ]['type']
2273
- ) );
2274
- }
2275
-
2276
- foreach ( $id_slug_type_path_map as $id => $data ) {
2277
- if ( empty( $id ) ) {
2278
- // Remove maps with empty module ID.
2279
- unset( $id_slug_type_path_map[ $id ] );
2280
- $store_option = true;
2281
- continue;
2282
- }
2283
-
2284
- /**
2285
- * If the module's main file path is identical to the main file path of another module then it means that the cached path of the current module or the other one with the same path is wrong, and therefore, we need to recalculate those paths.
2286
- *
2287
- * @author Vova Feldman (@svovaf)
2288
- * @since 2.5.0
2289
- */
2290
- if ( ! $find_caller ) {
2291
- if ( $id == $module_id ) {
2292
- continue;
2293
- }
2294
-
2295
- if (
2296
- isset( $data['path'] ) &&
2297
- $data['path'] === $id_slug_type_path_map[ $module_id ]['path']
2298
- ) {
2299
- $find_caller = true;
2300
- }
2301
- }
2302
- }
2303
-
2304
- if ( $find_caller ) {
2305
- $caller_main_file_and_type = $this->get_caller_main_file_and_type( $module_id );
2306
-
2307
- $id_slug_type_path_map[ $module_id ]['type'] = $caller_main_file_and_type->module_type;
2308
- $id_slug_type_path_map[ $module_id ]['path'] = $caller_main_file_and_type->path;
2309
-
2310
- $store_option = true;
2311
- }
2312
-
2313
- if ( $store_option ) {
2314
- self::$_accounts->set_option( 'id_slug_type_path_map', $id_slug_type_path_map, true );
2315
- }
2316
-
2317
- return $id_slug_type_path_map[ $module_id ]['path'];
2318
- }
2319
-
2320
- /**
2321
- * Identifies the caller type: plugin or theme.
2322
- *
2323
- * @author Leo Fajardo (@leorw)
2324
- * @since 1.2.2
2325
- *
2326
- * @author Vova Feldman (@svovaf)
2327
- * @since 1.2.2.3 Find the earliest module in the call stack that calls to the SDK. This fix is for cases when
2328
- * add-ons are relying on loading the SDK from the parent module, and also allows themes including the
2329
- * SDK an internal file instead of directly from functions.php.
2330
- * @since 1.2.1.7 Knows how to handle cases when an add-on includes the parent module logic.
2331
- *
2332
- * @param number $module_id @since 2.5.0
2333
- */
2334
- private function get_caller_main_file_and_type( $module_id ) {
2335
- self::require_plugin_essentials();
2336
-
2337
- $all_plugins = fs_get_plugins( true );
2338
- $all_plugins_paths = array();
2339
-
2340
- // Get active plugin's main files real full names (might be symlinks).
2341
- foreach ( $all_plugins as $relative_path => $data ) {
2342
- if ( false === strpos( fs_normalize_path( $relative_path ), '/' ) ) {
2343
- /**
2344
- * Ignore plugins that don't have a folder (e.g. Hello Dolly) since they
2345
- * can't really include the SDK.
2346
- *
2347
- * @author Vova Feldman
2348
- * @since 1.2.1.7
2349
- */
2350
- continue;
2351
- }
2352
-
2353
- $all_plugins_paths[] = fs_normalize_path( realpath( WP_PLUGIN_DIR . '/' . $relative_path ) );
2354
- }
2355
-
2356
- $caller_file_candidate = false;
2357
- $caller_map = array();
2358
- $module_type = WP_FS__MODULE_TYPE_PLUGIN;
2359
- $themes_dir = fs_normalize_path( get_theme_root( get_stylesheet() ) );
2360
- $plugin_dir_to_skip = false;
2361
-
2362
- for ( $i = 1, $bt = debug_backtrace(), $len = count( $bt ); $i < $len; $i ++ ) {
2363
- if ( empty( $bt[ $i ]['file'] ) ) {
2364
- continue;
2365
- }
2366
-
2367
- if ( $i > 1 && ! empty( $bt[ $i - 1 ]['file'] ) && $bt[ $i ]['file'] === $bt[ $i - 1 ]['file'] ) {
2368
- // If file same as the prev file in the stack, skip it.
2369
- continue;
2370
- }
2371
-
2372
- if ( ! empty( $bt[ $i ]['function'] ) && in_array( $bt[ $i ]['function'], array(
2373
- 'do_action',
2374
- 'apply_filter',
2375
- // The string split is stupid, but otherwise, theme check
2376
- // throws info notices.
2377
- 'requir' . 'e_once',
2378
- 'requir' . 'e',
2379
- 'includ' . 'e_once',
2380
- 'includ' . 'e',
2381
- 'install_and_activate_plugin',
2382
- 'try_activate_plugin',
2383
- 'activate_plugin'
2384
- ) )
2385
- ) {
2386
- if ( 'activate_plugin' === $bt[ $i ]['function'] ) {
2387
- /**
2388
- * Store the directory of the activator plugin so that any other file that starts with it
2389
- * cannot be mistakenly chosen as a candidate caller file.
2390
- *
2391
- * @author Leo Fajardo
2392
- *
2393
- * @since 2.3.0
2394
- */
2395
- $caller_file_path = fs_normalize_path( $bt[ $i ]['file'] );
2396
-
2397
- foreach ( $all_plugins_paths as $plugin_path ) {
2398
- $plugin_dir = fs_normalize_path( dirname( $plugin_path ) . '/' );
2399
- if ( false !== strpos( $caller_file_path, $plugin_dir ) ) {
2400
- $plugin_dir_to_skip = $plugin_dir;
2401
-
2402
- break;
2403
- }
2404
- }
2405
- }
2406
-
2407
- // Ignore call stack hooks and files inclusion.
2408
- continue;
2409
- }
2410
-
2411
- $caller_file_path = fs_normalize_path( $bt[ $i ]['file'] );
2412
-
2413
- if ( ! empty( $plugin_dir_to_skip ) ) {
2414
- /**
2415
- * Skip if it's an activator plugin file to avoid mistakenly choosing it as a candidate caller file.
2416
- *
2417
- * @author Leo Fajardo
2418
- *
2419
- * @since 2.3.0
2420
- */
2421
- if ( 0 === strpos( $caller_file_path, $plugin_dir_to_skip ) ) {
2422
- continue;
2423
- }
2424
- }
2425
-
2426
- if ( 'functions.php' === basename( $caller_file_path ) ) {
2427
- /**
2428
- * 1. Assumes that theme's starting execution file is functions.php.
2429
- * 2. This complex logic fixes symlink issues (e.g. with Vargant).
2430
- *
2431
- * @author Vova Feldman (@svovaf)
2432
- * @since 1.2.2.5
2433
- */
2434
-
2435
- if ( $caller_file_path == fs_normalize_path( realpath( trailingslashit( $themes_dir ) . basename( dirname( $caller_file_path ) ) . '/' . basename( $caller_file_path ) ) ) ) {
2436
- $module_type = WP_FS__MODULE_TYPE_THEME;
2437
-
2438
- /**
2439
- * Relative path of the theme, e.g.:
2440
- * `my-theme/functions.php`
2441
- *
2442
- * @author Leo Fajardo (@leorw)
2443
- */
2444
- $caller_file_candidate = basename( dirname( $caller_file_path ) ) .
2445
- '/' .
2446
- basename( $caller_file_path );
2447
-
2448
- continue;
2449
- }
2450
- }
2451
-
2452
- $caller_file_hash = md5( $caller_file_path );
2453
-
2454
- if ( ! isset( $caller_map[ $caller_file_hash ] ) ) {
2455
- foreach ( $all_plugins_paths as $plugin_path ) {
2456
- if ( empty( $plugin_path ) ) {
2457
- continue;
2458
- }
2459
-
2460
- if ( false !== strpos( $caller_file_path, fs_normalize_path( dirname( $plugin_path ) . '/' ) ) ) {
2461
- $caller_map[ $caller_file_hash ] = fs_normalize_path( $plugin_path );
2462
- break;
2463
- }
2464
- }
2465
- }
2466
-
2467
- if ( isset( $caller_map[ $caller_file_hash ] ) ) {
2468
- $module_type = WP_FS__MODULE_TYPE_PLUGIN;
2469
- $caller_file_candidate = plugin_basename( $caller_map[ $caller_file_hash ] );
2470
- }
2471
- }
2472
-
2473
- $caller_main_file_and_type = (object) array(
2474
- 'module_type' => $module_type,
2475
- 'path' => $caller_file_candidate
2476
- );
2477
-
2478
- return apply_filters( "fs_{$module_id}_caller_main_file_and_type", $caller_main_file_and_type );
2479
- }
2480
-
2481
- #----------------------------------------------------------------------------------
2482
- #region Deactivation Feedback Form
2483
- #----------------------------------------------------------------------------------
2484
-
2485
- /**
2486
- * Displays a confirmation and feedback dialog box when the user clicks on the "Deactivate" link on the plugins
2487
- * page.
2488
- *
2489
- * @author Vova Feldman (@svovaf)
2490
- * @author Leo Fajardo (@leorw)
2491
- *
2492
- * @since 1.1.2
2493
- */
2494
- function _add_deactivation_feedback_dialog_box() {
2495
- if (
2496
- $this->is_clone() ||
2497
- ( is_object( $this->_site ) && ! $this->is_registered() )
2498
- ) {
2499
- return;
2500
- }
2501
-
2502
- $subscription_cancellation_dialog_box_template_params = $this->apply_filters( 'show_deactivation_subscription_cancellation', true ) ?
2503
- $this->_get_subscription_cancellation_dialog_box_template_params() :
2504
- array();
2505
-
2506
- /**
2507
- * @since 2.3.0 Developers can optionally hide the deactivation feedback form using the 'show_deactivation_feedback_form' filter.
2508
- */
2509
- $show_deactivation_feedback_form = ! self::is_deactivation_snoozed();
2510
- if ( $this->has_filter( 'show_deactivation_feedback_form' ) ) {
2511
- $show_deactivation_feedback_form = $this->apply_filters( 'show_deactivation_feedback_form', true );
2512
- } else if ( $this->is_addon() ) {
2513
- /**
2514
- * If the add-on's 'show_deactivation_feedback_form' is not set, try to inherit the value from the parent.
2515
- */
2516
- $show_deactivation_feedback_form = $this->get_parent_instance()->apply_filters( 'show_deactivation_feedback_form', true );
2517
- }
2518
-
2519
- $uninstall_confirmation_message = $this->apply_filters( 'uninstall_confirmation_message', '' );
2520
-
2521
- if (
2522
- empty( $subscription_cancellation_dialog_box_template_params ) &&
2523
- ! $show_deactivation_feedback_form &&
2524
- empty( $uninstall_confirmation_message )
2525
- ) {
2526
- return;
2527
- }
2528
-
2529
- $vars = array( 'id' => $this->_module_id );
2530
-
2531
- if ( $show_deactivation_feedback_form ) {
2532
- /* Check the type of user:
2533
- * 1. Long-term (long-term)
2534
- * 2. Non-registered and non-anonymous short-term (non-registered-and-non-anonymous-short-term).
2535
- * 3. Short-term (short-term)
2536
- */
2537
- $is_long_term_user = true;
2538
-
2539
- // Check if the site is at least 2 days old.
2540
- $time_installed = $this->_storage->install_timestamp;
2541
-
2542
- // Difference in seconds.
2543
- $date_diff = time() - $time_installed;
2544
-
2545
- // Convert seconds to days.
2546
- $date_diff_days = floor( $date_diff / ( 60 * 60 * 24 ) );
2547
-
2548
- if ( $date_diff_days < 2 ) {
2549
- $is_long_term_user = false;
2550
- }
2551
-
2552
- $is_long_term_user = $this->apply_filters( 'is_long_term_user', $is_long_term_user );
2553
-
2554
- if ( $is_long_term_user ) {
2555
- $user_type = 'long-term';
2556
- } else {
2557
- if ( ! $this->is_registered() && ! $this->is_anonymous() ) {
2558
- $user_type = 'non-registered-and-non-anonymous-short-term';
2559
- } else {
2560
- $user_type = 'short-term';
2561
- }
2562
- }
2563
-
2564
- $uninstall_reasons = $this->_get_uninstall_reasons( $user_type );
2565
-
2566
- $vars['reasons'] = $uninstall_reasons;
2567
- }
2568
-
2569
- $vars['subscription_cancellation_dialog_box_template_params'] = &$subscription_cancellation_dialog_box_template_params;
2570
- $vars['show_deactivation_feedback_form'] = $show_deactivation_feedback_form;
2571
- $vars['uninstall_confirmation_message'] = $uninstall_confirmation_message;
2572
-
2573
- /**
2574
- * Load the HTML template for the deactivation feedback dialog box.
2575
- *
2576
- * @todo Deactivation form core functions should be loaded only once! Otherwise, when there are multiple Freemius powered plugins the same code is loaded multiple times. The only thing that should be loaded differently is the various deactivation reasons object based on the state of the plugin.
2577
- */
2578
- fs_require_template( 'forms/deactivation/form.php', $vars );
2579
- }
2580
-
2581
- /**
2582
- * @author Leo Fajardo (@leorw)
2583
- * @since 1.1.2
2584
- *
2585
- * @param string $user_type
2586
- *
2587
- * @return array The uninstall reasons for the specified user type.
2588
- */
2589
- function _get_uninstall_reasons( $user_type = 'long-term' ) {
2590
- $module_type = $this->_module_type;
2591
-
2592
- $internal_message_template_var = array(
2593
- 'id' => $this->_module_id
2594
- );
2595
-
2596
- $plan = $this->get_plan();
2597
-
2598
- if ( $this->is_registered() && is_object( $plan ) && $plan->has_technical_support() ) {
2599
- $contact_support_template = fs_get_template( 'forms/deactivation/contact.php', $internal_message_template_var );
2600
- } else {
2601
- $contact_support_template = '';
2602
- }
2603
-
2604
- $reason_found_better_plugin = array(
2605
- 'id' => self::REASON_FOUND_A_BETTER_PLUGIN,
2606
- 'text' => sprintf( $this->get_text_inline( 'I found a better %s', 'reason-found-a-better-plugin' ), $module_type ),
2607
- 'input_type' => 'textfield',
2608
- 'input_placeholder' => sprintf( $this->get_text_inline( "What's the %s's name?", 'placeholder-plugin-name' ), $module_type ),
2609
- );
2610
-
2611
- $reason_temporary_deactivation = array(
2612
- 'id' => self::REASON_TEMPORARY_DEACTIVATION,
2613
- 'text' => sprintf(
2614
- $this->get_text_inline( "It's a temporary %s - I'm troubleshooting an issue", 'reason-temporary-x' ),
2615
- strtolower( $this->is_plugin() ?
2616
- $this->get_text_inline( 'Deactivation', 'deactivation' ) :
2617
- $this->get_text_inline( 'Theme Switch', 'theme-switch' )
2618
- )
2619
- ),
2620
- 'input_type' => '',
2621
- 'input_placeholder' => ''
2622
- );
2623
-
2624
- $reason_other = array(
2625
- 'id' => self::REASON_OTHER,
2626
- 'text' => $this->get_text_inline( 'Other', 'reason-other' ),
2627
- 'input_type' => 'textfield',
2628
- 'input_placeholder' => ''
2629
- );
2630
-
2631
- $long_term_user_reasons = array(
2632
- array(
2633
- 'id' => self::REASON_NO_LONGER_NEEDED,
2634
- 'text' => sprintf( $this->get_text_inline( 'I no longer need the %s', 'reason-no-longer-needed' ), $module_type ),
2635
- 'input_type' => '',
2636
- 'input_placeholder' => ''
2637
- ),
2638
- $reason_found_better_plugin,
2639
- array(
2640
- 'id' => self::REASON_NEEDED_FOR_A_SHORT_PERIOD,
2641
- 'text' => sprintf( $this->get_text_inline( 'I only needed the %s for a short period', 'reason-needed-for-a-short-period' ), $module_type ),
2642
- 'input_type' => '',
2643
- 'input_placeholder' => ''
2644
- ),
2645
- array(
2646
- 'id' => self::REASON_BROKE_MY_SITE,
2647
- 'text' => sprintf( $this->get_text_inline( 'The %s broke my site', 'reason-broke-my-site' ), $module_type ),
2648
- 'input_type' => '',
2649
- 'input_placeholder' => '',
2650
- 'internal_message' => $contact_support_template
2651
- ),
2652
- array(
2653
- 'id' => self::REASON_SUDDENLY_STOPPED_WORKING,
2654
- 'text' => sprintf( $this->get_text_inline( 'The %s suddenly stopped working', 'reason-suddenly-stopped-working' ), $module_type ),
2655
- 'input_type' => '',
2656
- 'input_placeholder' => '',
2657
- 'internal_message' => $contact_support_template
2658
- )
2659
- );
2660
-
2661
- if ( $this->is_paying() ) {
2662
- $long_term_user_reasons[] = array(
2663
- 'id' => self::REASON_CANT_PAY_ANYMORE,
2664
- 'text' => $this->get_text_inline( "I can't pay for it anymore", 'reason-cant-pay-anymore' ),
2665
- 'input_type' => 'textfield',
2666
- 'input_placeholder' => $this->get_text_inline( 'What price would you feel comfortable paying?', 'placeholder-comfortable-price' )
2667
- );
2668
- }
2669
-
2670
- $reason_dont_share_info = array(
2671
- 'id' => self::REASON_DONT_LIKE_TO_SHARE_MY_INFORMATION,
2672
- 'text' => $this->get_text_inline( "I don't like to share my information with you", 'reason-dont-like-to-share-my-information' ),
2673
- 'input_type' => '',
2674
- 'input_placeholder' => ''
2675
- );
2676
-
2677
- /**
2678
- * If the current user has selected the "don't share data" reason in the deactivation feedback modal, inform the
2679
- * user by showing additional message that he doesn't have to share data and can just choose to skip the opt-in
2680
- * (the Skip button is included in the message to show). This message will only be shown if anonymous mode is
2681
- * enabled and the user's account is currently not in pending activation state (similar to the way the Skip
2682
- * button in the opt-in form is shown/hidden).
2683
- */
2684
- if ( $this->is_enable_anonymous() && ! $this->is_pending_activation() ) {
2685
- $reason_dont_share_info['internal_message'] = fs_get_template( 'forms/deactivation/retry-skip.php', $internal_message_template_var );
2686
- }
2687
-
2688
- $uninstall_reasons = array(
2689
- 'long-term' => $long_term_user_reasons,
2690
- 'non-registered-and-non-anonymous-short-term' => array(
2691
- array(
2692
- 'id' => self::REASON_DIDNT_WORK,
2693
- 'text' => sprintf( $this->get_text_inline( "The %s didn't work", 'reason-didnt-work' ), $module_type ),
2694
- 'input_type' => '',
2695
- 'input_placeholder' => ''
2696
- ),
2697
- $reason_dont_share_info,
2698
- $reason_found_better_plugin
2699
- ),
2700
- 'short-term' => array(
2701
- array(
2702
- 'id' => self::REASON_COULDNT_MAKE_IT_WORK,
2703
- 'text' => $this->get_text_inline( "I couldn't understand how to make it work", 'reason-couldnt-make-it-work' ),
2704
- 'input_type' => '',
2705
- 'input_placeholder' => '',
2706
- 'internal_message' => $contact_support_template
2707
- ),
2708
- $reason_found_better_plugin,
2709
- array(
2710
- 'id' => self::REASON_GREAT_BUT_NEED_SPECIFIC_FEATURE,
2711
- 'text' => sprintf( $this->get_text_inline( "The %s is great, but I need specific feature that you don't support", 'reason-great-but-need-specific-feature' ), $module_type ),
2712
- 'input_type' => 'textarea',
2713
- 'input_placeholder' => $this->get_text_inline( 'What feature?', 'placeholder-feature' )
2714
- ),
2715
- array(
2716
- 'id' => self::REASON_NOT_WORKING,
2717
- 'text' => sprintf( $this->get_text_inline( 'The %s is not working', 'reason-not-working' ), $module_type ),
2718
- 'input_type' => 'textarea',
2719
- 'input_placeholder' => $this->get_text_inline( "Kindly share what didn't work so we can fix it for future users...", 'placeholder-share-what-didnt-work' )
2720
- ),
2721
- array(
2722
- 'id' => self::REASON_NOT_WHAT_I_WAS_LOOKING_FOR,
2723
- 'text' => $this->get_text_inline( "It's not what I was looking for", 'reason-not-what-i-was-looking-for' ),
2724
- 'input_type' => 'textarea',
2725
- 'input_placeholder' => $this->get_text_inline( "What you've been looking for?", 'placeholder-what-youve-been-looking-for' )
2726
- ),
2727
- array(
2728
- 'id' => self::REASON_DIDNT_WORK_AS_EXPECTED,
2729
- 'text' => sprintf( $this->get_text_inline( "The %s didn't work as expected", 'reason-didnt-work-as-expected' ), $module_type ),
2730
- 'input_type' => 'textarea',
2731
- 'input_placeholder' => $this->get_text_inline( 'What did you expect?', 'placeholder-what-did-you-expect' )
2732
- )
2733
- )
2734
- );
2735
-
2736
- // Randomize the reasons for the current user type.
2737
- shuffle( $uninstall_reasons[ $user_type ] );
2738
-
2739
- // Keep the following reasons as the last items in the list.
2740
- $uninstall_reasons[ $user_type ][] = $reason_temporary_deactivation;
2741
- $uninstall_reasons[ $user_type ][] = $reason_other;
2742
-
2743
- $uninstall_reasons = $this->apply_filters( 'uninstall_reasons', $uninstall_reasons );
2744
-
2745
- return $uninstall_reasons[ $user_type ];
2746
- }
2747
-
2748
- /**
2749
- * Called after the user has submitted his reason for deactivating the plugin.
2750
- *
2751
- * @author Leo Fajardo (@leorw)
2752
- * @since 1.1.2
2753
- */
2754
- function _submit_uninstall_reason_action() {
2755
- $this->_logger->entrance();
2756
-
2757
- $this->check_ajax_referer( 'submit_uninstall_reason' );
2758
-
2759
- $reason_id = fs_request_get( 'reason_id' );
2760
-
2761
- // Check if the given reason ID is an unsigned integer.
2762
- if ( ! ctype_digit( $reason_id ) ) {
2763
- exit;
2764
- }
2765
-
2766
- $reason_info = trim( fs_request_get( 'reason_info', '' ) );
2767
- if ( ! empty( $reason_info ) ) {
2768
- $reason_info = substr( $reason_info, 0, 128 );
2769
- }
2770
-
2771
- $reason = (object) array(
2772
- 'id' => $reason_id,
2773
- 'info' => $reason_info,
2774
- 'is_anonymous' => fs_request_get_bool( 'is_anonymous' )
2775
- );
2776
-
2777
- $this->_storage->store( 'uninstall_reason', $reason );
2778
-
2779
- if ( self::REASON_TEMPORARY_DEACTIVATION == $reason->id ) {
2780
- $snooze_period = fs_request_get( 'snooze_period' );
2781
-
2782
- if ( is_numeric( $snooze_period ) && 0 < $snooze_period ) {
2783
- self::snooze_deactivation_form( (int) $snooze_period );
2784
- }
2785
- }
2786
-
2787
- /**
2788
- * If the module type is "theme", trigger the uninstall event here (on theme deactivation) since themes do
2789
- * not support uninstall hook.
2790
- *
2791
- * @author Leo Fajardo (@leorw)
2792
- * @since 1.2.2
2793
- */
2794
- if ( $this->is_theme() ) {
2795
- if ( $this->is_premium() && ! $this->has_active_valid_license() ) {
2796
- FS_Plugin_Updater::instance( $this )->delete_update_data();
2797
- }
2798
-
2799
- $this->_uninstall_plugin_event( false );
2800
- $this->remove_sdk_reference();
2801
- }
2802
-
2803
- // Print '1' for successful operation.
2804
- echo 1;
2805
- exit;
2806
- }
2807
-
2808
- #--------------------------------------------------------------------------------
2809
- #region Deactivation Feedback Snoozing
2810
- #--------------------------------------------------------------------------------
2811
-
2812
- /**
2813
- * @author Vova Feldman (@svovaf)