Post SMTP Mailer/Email Log - Version 2.1.2-rc.1

Version Description

Download this release

Release Info

Developer wpexpertsio
Plugin Icon 128x128 Post SMTP Mailer/Email Log
Version 2.1.2-rc.1
Comparing to
See all releases

Code changes from version 2.1.2-beta.1 to 2.1.2-rc.1

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