Blocksy Companion - Version 1.8.47

Version Description

Download this release

Release Info

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

Code changes from version 1.8.46 to 1.8.47

Files changed (45) hide show
  1. blocksy-companion.php +20 -4
  2. framework/dashboard.php +114 -79
  3. framework/extensions-manager.php +1 -1
  4. framework/extensions/cookies-consent/static/bundle/main.min.css +1 -1
  5. framework/extensions/newsletter-subscribe/static/bundle/main.min.css +1 -1
  6. framework/extensions/product-reviews/static/bundle/main-admin.min.css +1 -1
  7. framework/extensions/product-reviews/static/bundle/main.min.css +1 -1
  8. framework/extensions/trending/customizer.php +1 -1
  9. framework/extensions/trending/extension.php +2 -2
  10. framework/extensions/trending/static/bundle/main.min.css +1 -1
  11. framework/extensions/widgets/static/bundle/main.min.css +1 -1
  12. framework/extensions/widgets/widgets/ct-contact-info/options.php +24 -24
  13. framework/features/header.php +6 -2
  14. framework/features/header/items/account/options.php +1 -1
  15. framework/features/header/modal/login.php +1 -1
  16. framework/features/header/modal/register.php +3 -2
  17. framework/features/opengraph-meta-data.php +2 -0
  18. framework/theme-integration.php +2 -0
  19. freemius/LICENSE.txt +0 -674
  20. freemius/assets/css/admin/account.css +0 -1
  21. freemius/assets/css/admin/add-ons.css +0 -1
  22. freemius/assets/css/admin/affiliation.css +0 -1
  23. freemius/assets/css/admin/checkout.css +0 -1
  24. freemius/assets/css/admin/clone-resolution.css +0 -1
  25. freemius/assets/css/admin/common.css +0 -1
  26. freemius/assets/css/admin/connect.css +0 -1
  27. freemius/assets/css/admin/debug.css +0 -1
  28. freemius/assets/css/admin/dialog-boxes.css +0 -1
  29. freemius/assets/css/admin/gdpr-optin-notice.css +0 -1
  30. freemius/assets/css/admin/index.php +0 -3
  31. freemius/assets/css/admin/plugins.css +0 -1
  32. freemius/assets/css/customizer.css +0 -1
  33. freemius/assets/css/index.php +0 -3
  34. freemius/assets/img/blocksy-companion.jpg +0 -0
  35. freemius/assets/img/index.php +0 -3
  36. freemius/assets/img/plugin-icon.png +0 -0
  37. freemius/assets/img/theme-icon.png +0 -0
  38. freemius/assets/index.php +0 -3
  39. freemius/assets/js/index.php +0 -3
  40. freemius/assets/js/nojquery.ba-postmessage.js +0 -140
  41. freemius/assets/js/nojquery.ba-postmessage.min.js +0 -12
  42. freemius/assets/js/postmessage.js +0 -135
  43. freemius/config.php +0 -391
  44. freemius/includes/class-freemius-abstract.php +0 -597
  45. freemius/includes/class-freemius.php +0 -23083
blocksy-companion.php CHANGED
@@ -3,7 +3,7 @@
3
  /*
4
  Plugin Name: Blocksy Companion
5
  Description: This plugin is the companion for the Blocksy theme, it runs and adds its enhacements only if the Blocksy theme is installed and active.
6
- Version: 1.8.46
7
  Author: CreativeThemes
8
  Author URI: https://creativethemes.com
9
  Text Domain: blocksy-companion
@@ -17,12 +17,28 @@ if ( !defined( 'ABSPATH' ) ) {
17
  // Exit if accessed directly.
18
  }
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
- if ( function_exists( 'blc_fs' ) ) {
22
- blc_fs()->set_basename( false, __FILE__ );
 
 
23
  } else {
24
 
25
- if ( !function_exists( 'blc_fs' ) ) {
26
  global $blc_fs ;
27
 
28
  if ( !isset( $blc_fs ) ) {
3
  /*
4
  Plugin Name: Blocksy Companion
5
  Description: This plugin is the companion for the Blocksy theme, it runs and adds its enhacements only if the Blocksy theme is installed and active.
6
+ Version: 1.8.47
7
  Author: CreativeThemes
8
  Author URI: https://creativethemes.com
9
  Text Domain: blocksy-companion
17
  // Exit if accessed directly.
18
  }
19
 
20
+ register_activation_hook( __FILE__, function () {
21
+
22
+ if ( class_exists( '\\Blocksy\\Plugin' ) && !function_exists( 'blc_fs' ) ) {
23
+ $to_deactivate = plugin_basename( str_replace( '-pro/', '/', __FILE__ ) );
24
+ if ( is_plugin_active( $to_deactivate ) ) {
25
+ deactivate_plugins( $to_deactivate );
26
+ }
27
+ }
28
+
29
+ if ( isset( $_REQUEST['action'] ) && 'activate-selected' === $_REQUEST['action'] && isset( $_POST['checked'] ) && count( $_POST['checked'] ) > 1 ) {
30
+ return;
31
+ }
32
+ add_option( 'blc_activation_redirect', wp_get_current_user()->ID );
33
+ } );
34
 
35
+ if ( function_exists( 'blc_fs' ) || class_exists( '\\Blocksy\\Plugin' ) ) {
36
+ if ( function_exists( 'blc_fs' ) ) {
37
+ blc_fs()->set_basename( false, __FILE__ );
38
+ }
39
  } else {
40
 
41
+ if ( !function_exists( 'blc_fs' ) && file_exists( dirname( __FILE__ ) . '/freemius/start.php' ) ) {
42
  global $blc_fs ;
43
 
44
  if ( !isset( $blc_fs ) ) {
framework/dashboard.php CHANGED
@@ -11,107 +11,131 @@ class Dashboard {
11
  );
12
 
13
  add_action('admin_body_class', function ($class) {
14
- if (blc_fs()->is_activation_mode()) {
15
  $class .= ' blocksy-fs-optin-dashboard';
16
  }
17
 
18
  return $class;
19
  });
20
 
21
- blc_fs()->add_filter(
22
- 'connect-message_on-premium',
23
- function ($text) {
24
- if (strpos($text, '<br>') !== false) {
25
- $exploded_message = explode('<br>', $text);
26
-
27
- $text = '<span>' . $exploded_message[0] . '</span>' . $exploded_message[1];
28
  }
 
29
 
30
- return $text;
31
- }
32
- );
33
-
34
- blc_fs()->add_filter(
35
- 'connect_message_on_update',
36
- function (
37
- $message,
38
- $user_first_name,
39
- $product_title,
40
- $user_login,
41
- $site_link,
42
- $freemius_link
43
- ) {
44
- $is_network_upgrade_mode = ( fs_is_network_admin() && blc_fs()->is_network_upgrade_mode() );
45
- $slug = blc_fs()->get_slug();
46
- $is_gdpr_required = \FS_GDPR_Manager::instance()->is_required();
47
- $hey_x_text = esc_html( sprintf( fs_text_x_inline( 'Hey %s,', 'greeting', 'hey-x', $slug ), $user_first_name ) );
48
-
49
- $default_optin_message = $is_gdpr_required ?
50
- fs_text_inline( 'Never miss an important update - opt in to our security & feature updates notifications, educational content, offers, and non-sensitive diagnostic tracking with %4$s. If you skip this, that\'s okay! %1$s will still work just fine.', 'connect-message_on-update', $slug ) :
51
- fs_text_inline( 'Never miss an important update - opt in to our security & feature updates notifications, and non-sensitive diagnostic tracking with %4$s. If you skip this, that\'s okay! %1$s will still work just fine.', 'connect-message_on-update', $slug );
52
-
53
- $default_optin_message = 'Never miss an important update - opt in to our security & feature updates notifications, educational content, offers, and non-sensitive diagnostic tracking with.';
54
-
55
- return (($is_network_upgrade_mode ?
56
- '' :
57
- /* translators: %s: name (e.g. Hey John,) */
58
- '<span>' . $hey_x_text . '</span>'
59
- ) .
60
- sprintf(
61
- esc_html( $default_optin_message ),
62
- '<b>' . esc_html( blc_fs()->get_plugin_name() ) . '</b>',
63
- '<b>' . $user_login . '</b>',
64
- $site_link,
65
- $freemius_link
66
- ));
67
 
68
- }, 10, 6
69
- );
 
 
 
70
 
71
- blc_fs()->add_action('connect/before', function () {
72
- $path = dirname(__FILE__) . '/views/optin.php';
73
 
74
- echo blc_call_fn(
75
- ['fn' => 'blocksy_render_view'],
76
- $path,
77
- []
78
  );
79
- });
80
 
81
- blc_fs()->add_action('connect/after', function () {
82
- echo '</div>';
83
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
 
85
- add_action(
86
- 'wp_ajax_blocksy_fs_connect_again',
87
- function () {
88
- if (! current_user_can('edit_theme_options')) {
89
- wp_send_json_error();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
  }
91
-
92
- blc_fs()->connect_again();
93
- wp_send_json_success();
94
- }
95
- );
96
 
97
  add_filter(
98
  'blocksy_dashboard_localizations',
99
  function ($d) {
100
- $is_anonymous = blc_fs()->is_anonymous();
101
- $connect_template = '';
102
-
103
- if ($is_anonymous) {
104
- ob_start();
105
- blc_fs()->_connect_page_render();
106
- $connect_template = ob_get_clean();
107
- }
108
-
109
  $result = [
110
- 'is_pro' => blc_fs()->can_use_premium_code(),
111
- 'is_anonymous' => $is_anonymous,
112
- 'connect_template' => $connect_template
113
  ];
114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  if (
116
  Plugin::instance()->premium
117
  &&
@@ -126,6 +150,17 @@ class Dashboard {
126
  return array_merge($result, $d);
127
  }
128
  );
 
 
 
 
 
 
 
 
 
 
 
129
  }
130
 
131
  public function enqueue_static() {
11
  );
12
 
13
  add_action('admin_body_class', function ($class) {
14
+ if (function_exists('blc_fs') && blc_fs()->is_activation_mode()) {
15
  $class .= ' blocksy-fs-optin-dashboard';
16
  }
17
 
18
  return $class;
19
  });
20
 
21
+ if (function_exists('blc_fs')) {
22
+ blc_fs()->add_filter(
23
+ 'show_deactivation_feedback_form',
24
+ function ($res) {
25
+ return false;
 
 
26
  }
27
+ );
28
 
29
+ blc_fs()->add_filter(
30
+ 'hide_freemius_powered_by',
31
+ function ($res) {
32
+ return true;
33
+ }
34
+ );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
+ blc_fs()->add_filter(
37
+ 'connect-message_on-premium',
38
+ function ($text) {
39
+ if (strpos($text, '<br>') !== false) {
40
+ $exploded_message = explode('<br>', $text);
41
 
42
+ $text = '<span>' . $exploded_message[0] . '</span>' . $exploded_message[1];
43
+ }
44
 
45
+ return $text;
46
+ }
 
 
47
  );
 
48
 
49
+ blc_fs()->add_filter(
50
+ 'connect_message_on_update',
51
+ function (
52
+ $message,
53
+ $user_first_name,
54
+ $product_title,
55
+ $user_login,
56
+ $site_link,
57
+ $freemius_link
58
+ ) {
59
+ $is_network_upgrade_mode = ( fs_is_network_admin() && blc_fs()->is_network_upgrade_mode() );
60
+ $slug = blc_fs()->get_slug();
61
+ $is_gdpr_required = \FS_GDPR_Manager::instance()->is_required();
62
+ $hey_x_text = esc_html( sprintf( fs_text_x_inline( 'Hey %s,', 'greeting', 'hey-x', $slug ), $user_first_name ) );
63
+
64
+ $default_optin_message = $is_gdpr_required ?
65
+ fs_text_inline( 'Never miss an important update - opt in to our security & feature updates notifications, educational content, offers, and non-sensitive diagnostic tracking with %4$s. If you skip this, that\'s okay! %1$s will still work just fine.', 'connect-message_on-update', $slug ) :
66
+ fs_text_inline( 'Never miss an important update - opt in to our security & feature updates notifications, and non-sensitive diagnostic tracking with %4$s. If you skip this, that\'s okay! %1$s will still work just fine.', 'connect-message_on-update', $slug );
67
+
68
+ $default_optin_message = 'Never miss an important update - opt in to our security & feature updates notifications, educational content, offers, and non-sensitive diagnostic tracking with.';
69
+
70
+ return (($is_network_upgrade_mode ?
71
+ '' :
72
+ /* translators: %s: name (e.g. Hey John,) */
73
+ '<span>' . $hey_x_text . '</span>'
74
+ ) .
75
+ sprintf(
76
+ esc_html( $default_optin_message ),
77
+ '<b>' . esc_html( blc_fs()->get_plugin_name() ) . '</b>',
78
+ '<b>' . $user_login . '</b>',
79
+ $site_link,
80
+ $freemius_link
81
+ ));
82
+
83
+ }, 10, 6
84
+ );
85
 
86
+ blc_fs()->add_action('connect/before', function () {
87
+ $path = dirname(__FILE__) . '/views/optin.php';
88
+
89
+ echo blc_call_fn(
90
+ ['fn' => 'blocksy_render_view'],
91
+ $path,
92
+ []
93
+ );
94
+ });
95
+
96
+ blc_fs()->add_action('connect/after', function () {
97
+ echo '</div>';
98
+ });
99
+
100
+ add_action(
101
+ 'wp_ajax_blocksy_fs_connect_again',
102
+ function () {
103
+ if (! current_user_can('edit_theme_options')) {
104
+ wp_send_json_error();
105
+ }
106
+
107
+ blc_fs()->connect_again();
108
+ wp_send_json_success();
109
  }
110
+ );
111
+ }
 
 
 
112
 
113
  add_filter(
114
  'blocksy_dashboard_localizations',
115
  function ($d) {
 
 
 
 
 
 
 
 
 
116
  $result = [
117
+ 'is_pro' => false,
118
+ 'is_anonymous' => false,
119
+ 'connect_template' => ''
120
  ];
121
 
122
+ if (function_exists('blc_fs')) {
123
+ $is_anonymous = blc_fs()->is_anonymous();
124
+ $connect_template = '';
125
+
126
+ if ($is_anonymous) {
127
+ ob_start();
128
+ blc_fs()->_connect_page_render();
129
+ $connect_template = ob_get_clean();
130
+ }
131
+
132
+ $result = [
133
+ 'is_pro' => blc_fs()->can_use_premium_code(),
134
+ 'is_anonymous' => $is_anonymous,
135
+ 'connect_template' => $connect_template
136
+ ];
137
+ }
138
+
139
  if (
140
  Plugin::instance()->premium
141
  &&
150
  return array_merge($result, $d);
151
  }
152
  );
153
+
154
+ add_action('admin_init', function ($plugin) {
155
+ if (wp_doing_ajax()) {
156
+ return;
157
+ }
158
+
159
+ if (intval(get_option('blc_activation_redirect', false)) === wp_get_current_user()->ID) {
160
+ delete_option('blc_activation_redirect');
161
+ exit(wp_redirect(admin_url('admin.php?page=ct-dashboard')));
162
+ }
163
+ });
164
  }
165
 
166
  public function enqueue_static() {
framework/extensions-manager.php CHANGED
@@ -234,7 +234,7 @@ class ExtensionsManager {
234
  }
235
 
236
  private function register_fake_extensions() {
237
- if (blc_fs()->can_use_premium_code()) {
238
  return;
239
  }
240
 
234
  }
235
 
236
  private function register_fake_extensions() {
237
+ if (function_exists('blc_fs') && blc_fs()->can_use_premium_code()) {
238
  return;
239
  }
240
 
framework/extensions/cookies-consent/static/bundle/main.min.css CHANGED
@@ -1,5 +1,5 @@
1
  /**
2
- * - v1.8.46
3
  *
4
  * Copyright (c) 2022
5
  * Licensed GPLv2+
1
  /**
2
+ * - v1.8.47
3
  *
4
  * Copyright (c) 2022
5
  * Licensed GPLv2+
framework/extensions/newsletter-subscribe/static/bundle/main.min.css CHANGED
@@ -1,5 +1,5 @@
1
  /**
2
- * - v1.8.46
3
  *
4
  * Copyright (c) 2022
5
  * Licensed GPLv2+
1
  /**
2
+ * - v1.8.47
3
  *
4
  * Copyright (c) 2022
5
  * Licensed GPLv2+
framework/extensions/product-reviews/static/bundle/main-admin.min.css CHANGED
@@ -1,5 +1,5 @@
1
  /**
2
- * - v1.8.46
3
  *
4
  * Copyright (c) 2022
5
  * Licensed GPLv2+
1
  /**
2
+ * - v1.8.47
3
  *
4
  * Copyright (c) 2022
5
  * Licensed GPLv2+
framework/extensions/product-reviews/static/bundle/main.min.css CHANGED
@@ -1,5 +1,5 @@
1
  /**
2
- * - v1.8.46
3
  *
4
  * Copyright (c) 2022
5
  * Licensed GPLv2+
1
  /**
2
+ * - v1.8.47
3
  *
4
  * Copyright (c) 2022
5
  * Licensed GPLv2+
framework/extensions/trending/customizer.php CHANGED
@@ -283,7 +283,7 @@ $options = [
283
  ],
284
  ],
285
 
286
- blc_fs()->can_use_premium_code() ? [
287
  'trending_block_location' => [
288
  'label' => __('Display Location', 'blocksy-companion'),
289
  'type' => 'ct-select',
283
  ],
284
  ],
285
 
286
+ function_exists('blc_fs') && blc_fs()->can_use_premium_code() ? [
287
  'trending_block_location' => [
288
  'label' => __('Display Location', 'blocksy-companion'),
289
  'type' => 'ct-select',
framework/extensions/trending/extension.php CHANGED
@@ -59,7 +59,7 @@ class BlocksyExtensionTrending {
59
  add_action('wp', function () {
60
  $location = 'blocksy:template:after';
61
 
62
- if (blc_fs()->can_use_premium_code()) {
63
  $location = get_theme_mod(
64
  'trending_block_location',
65
  'blocksy:content:bottom'
@@ -69,7 +69,7 @@ class BlocksyExtensionTrending {
69
  add_action(
70
  $location,
71
  function () {
72
- if (blc_fs()->can_use_premium_code()) {
73
  $conditions = get_theme_mod(
74
  'trending_block_conditions',
75
  [
59
  add_action('wp', function () {
60
  $location = 'blocksy:template:after';
61
 
62
+ if (function_exists('blc_fs') && blc_fs()->can_use_premium_code()) {
63
  $location = get_theme_mod(
64
  'trending_block_location',
65
  'blocksy:content:bottom'
69
  add_action(
70
  $location,
71
  function () {
72
+ if (function_exists('blc_fs') && blc_fs()->can_use_premium_code()) {
73
  $conditions = get_theme_mod(
74
  'trending_block_conditions',
75
  [
framework/extensions/trending/static/bundle/main.min.css CHANGED
@@ -1,5 +1,5 @@
1
  /**
2
- * - v1.8.46
3
  *
4
  * Copyright (c) 2022
5
  * Licensed GPLv2+
1
  /**
2
+ * - v1.8.47
3
  *
4
  * Copyright (c) 2022
5
  * Licensed GPLv2+
framework/extensions/widgets/static/bundle/main.min.css CHANGED
@@ -1,5 +1,5 @@
1
  /**
2
- * - v1.8.46
3
  *
4
  * Copyright (c) 2022
5
  * Licensed GPLv2+
1
  /**
2
+ * - v1.8.47
3
  *
4
  * Copyright (c) 2022
5
  * Licensed GPLv2+
framework/extensions/widgets/widgets/ct-contact-info/options.php CHANGED
@@ -7,7 +7,7 @@
7
  * @package Blocksy
8
  */
9
 
10
- $is_pro = blc_fs()->can_use_premium_code();
11
 
12
  $options = [
13
 
@@ -74,21 +74,21 @@ $options = [
74
  'value' => __('Address:', 'blocksy-companion'),
75
  'design' => 'inline',
76
  ],
77
-
78
  'content' => [
79
  'type' => 'text',
80
  'label' => __('Content', 'blocksy-companion'),
81
  'value' => 'Street Name, NY 38954',
82
  'design' => 'inline',
83
  ],
84
-
85
  'link' => [
86
  'type' => 'text',
87
  'label' => __('Link (optional)', 'blocksy-companion'),
88
  'design' => 'inline',
89
  ],
90
  ],
91
-
92
  $is_pro ? [
93
  'icon_source' => [
94
  'label' => __( 'Icon Source', 'blocksy' ),
@@ -102,7 +102,7 @@ $options = [
102
  'custom' => __( 'Custom', 'blocksy' ),
103
  ],
104
  ],
105
-
106
  blocksy_rand_md5() => [
107
  'type' => 'ct-condition',
108
  'condition' => ['icon_source' => 'custom'],
@@ -135,14 +135,14 @@ $options = [
135
  'value' => __('Phone:', 'blocksy-companion'),
136
  'design' => 'inline',
137
  ],
138
-
139
  'content' => [
140
  'type' => 'text',
141
  'label' => __('Content', 'blocksy-companion'),
142
  'value' => '578-393-4937',
143
  'design' => 'inline',
144
  ],
145
-
146
  'link' => [
147
  'type' => 'text',
148
  'label' => __('Link (optional)', 'blocksy-companion'),
@@ -164,7 +164,7 @@ $options = [
164
  'custom' => __( 'Custom', 'blocksy' ),
165
  ],
166
  ],
167
-
168
  blocksy_rand_md5() => [
169
  'type' => 'ct-condition',
170
  'condition' => ['icon_source' => 'custom'],
@@ -195,14 +195,14 @@ $options = [
195
  'value' => __('Mobile:', 'blocksy-companion'),
196
  'design' => 'inline',
197
  ],
198
-
199
  'content' => [
200
  'type' => 'text',
201
  'label' => __('Content', 'blocksy-companion'),
202
  'value' => '578-393-4937',
203
  'design' => 'inline',
204
  ],
205
-
206
  'link' => [
207
  'type' => 'text',
208
  'label' => __('Link (optional)', 'blocksy-companion'),
@@ -224,7 +224,7 @@ $options = [
224
  'custom' => __( 'Custom', 'blocksy' ),
225
  ],
226
  ],
227
-
228
  blocksy_rand_md5() => [
229
  'type' => 'ct-condition',
230
  'condition' => ['icon_source' => 'custom'],
@@ -255,14 +255,14 @@ $options = [
255
  'value' => __('Opening hours', 'blocksy-companion'),
256
  'design' => 'inline',
257
  ],
258
-
259
  'content' => [
260
  'type' => 'text',
261
  'label' => __('Content', 'blocksy-companion'),
262
  'value' => '9AM - 5PM',
263
  'design' => 'inline',
264
  ],
265
-
266
  'link' => [
267
  'type' => 'text',
268
  'label' => __('Link (optional)', 'blocksy-companion'),
@@ -284,7 +284,7 @@ $options = [
284
  'custom' => __( 'Custom', 'blocksy' ),
285
  ],
286
  ],
287
-
288
  blocksy_rand_md5() => [
289
  'type' => 'ct-condition',
290
  'condition' => ['icon_source' => 'custom'],
@@ -315,14 +315,14 @@ $options = [
315
  'value' => __('Fax:', 'blocksy-companion'),
316
  'design' => 'inline',
317
  ],
318
-
319
  'content' => [
320
  'type' => 'text',
321
  'label' => __('Content', 'blocksy-companion'),
322
  'value' => '578-393-4937',
323
  'design' => 'inline',
324
  ],
325
-
326
  'link' => [
327
  'type' => 'text',
328
  'label' => __('Link (optional)', 'blocksy-companion'),
@@ -344,7 +344,7 @@ $options = [
344
  'custom' => __( 'Custom', 'blocksy' ),
345
  ],
346
  ],
347
-
348
  blocksy_rand_md5() => [
349
  'type' => 'ct-condition',
350
  'condition' => ['icon_source' => 'custom'],
@@ -375,14 +375,14 @@ $options = [
375
  'value' => __('Email:', 'blocksy-companion'),
376
  'design' => 'inline',
377
  ],
378
-
379
  'content' => [
380
  'type' => 'text',
381
  'label' => __('Content', 'blocksy-companion'),
382
  'value' => 'contact@yourwebsite.com',
383
  'design' => 'inline',
384
  ],
385
-
386
  'link' => [
387
  'type' => 'text',
388
  'label' => __('Link (optional)', 'blocksy-companion'),
@@ -404,7 +404,7 @@ $options = [
404
  'custom' => __( 'Custom', 'blocksy' ),
405
  ],
406
  ],
407
-
408
  blocksy_rand_md5() => [
409
  'type' => 'ct-condition',
410
  'condition' => ['icon_source' => 'custom'],
@@ -435,14 +435,14 @@ $options = [
435
  'value' => __('Website:', 'blocksy-companion'),
436
  'design' => 'inline',
437
  ],
438
-
439
  'content' => [
440
  'type' => 'text',
441
  'label' => __('Content', 'blocksy-companion'),
442
  'value' => 'creativethemes.com',
443
  'design' => 'inline',
444
  ],
445
-
446
  'link' => [
447
  'type' => 'text',
448
  'label' => __('Link (optional)', 'blocksy-companion'),
@@ -450,7 +450,7 @@ $options = [
450
  'design' => 'inline',
451
  ],
452
  ],
453
-
454
  $is_pro ? [
455
  'icon_source' => [
456
  'label' => __( 'Icon Source', 'blocksy' ),
@@ -464,7 +464,7 @@ $options = [
464
  'custom' => __( 'Custom', 'blocksy' ),
465
  ],
466
  ],
467
-
468
  blocksy_rand_md5() => [
469
  'type' => 'ct-condition',
470
  'condition' => ['icon_source' => 'custom'],
7
  * @package Blocksy
8
  */
9
 
10
+ $is_pro = function_exists('blc_fs') && blc_fs()->can_use_premium_code();
11
 
12
  $options = [
13
 
74
  'value' => __('Address:', 'blocksy-companion'),
75
  'design' => 'inline',
76
  ],
77
+
78
  'content' => [
79
  'type' => 'text',
80
  'label' => __('Content', 'blocksy-companion'),
81
  'value' => 'Street Name, NY 38954',
82
  'design' => 'inline',
83
  ],
84
+
85
  'link' => [
86
  'type' => 'text',
87
  'label' => __('Link (optional)', 'blocksy-companion'),
88
  'design' => 'inline',
89
  ],
90
  ],
91
+
92
  $is_pro ? [
93
  'icon_source' => [
94
  'label' => __( 'Icon Source', 'blocksy' ),
102
  'custom' => __( 'Custom', 'blocksy' ),
103
  ],
104
  ],
105
+
106
  blocksy_rand_md5() => [
107
  'type' => 'ct-condition',
108
  'condition' => ['icon_source' => 'custom'],
135
  'value' => __('Phone:', 'blocksy-companion'),
136
  'design' => 'inline',
137
  ],
138
+
139
  'content' => [
140
  'type' => 'text',
141
  'label' => __('Content', 'blocksy-companion'),
142
  'value' => '578-393-4937',
143
  'design' => 'inline',
144
  ],
145
+
146
  'link' => [
147
  'type' => 'text',
148
  'label' => __('Link (optional)', 'blocksy-companion'),
164
  'custom' => __( 'Custom', 'blocksy' ),
165
  ],
166
  ],
167
+
168
  blocksy_rand_md5() => [
169
  'type' => 'ct-condition',
170
  'condition' => ['icon_source' => 'custom'],
195
  'value' => __('Mobile:', 'blocksy-companion'),
196
  'design' => 'inline',
197
  ],
198
+
199
  'content' => [
200
  'type' => 'text',
201
  'label' => __('Content', 'blocksy-companion'),
202
  'value' => '578-393-4937',
203
  'design' => 'inline',
204
  ],
205
+
206
  'link' => [
207
  'type' => 'text',
208
  'label' => __('Link (optional)', 'blocksy-companion'),
224
  'custom' => __( 'Custom', 'blocksy' ),
225
  ],
226
  ],
227
+
228
  blocksy_rand_md5() => [
229
  'type' => 'ct-condition',
230
  'condition' => ['icon_source' => 'custom'],
255
  'value' => __('Opening hours', 'blocksy-companion'),
256
  'design' => 'inline',
257
  ],
258
+
259
  'content' => [
260
  'type' => 'text',
261
  'label' => __('Content', 'blocksy-companion'),
262
  'value' => '9AM - 5PM',
263
  'design' => 'inline',
264
  ],
265
+
266
  'link' => [
267
  'type' => 'text',
268
  'label' => __('Link (optional)', 'blocksy-companion'),
284
  'custom' => __( 'Custom', 'blocksy' ),
285
  ],
286
  ],
287
+
288
  blocksy_rand_md5() => [
289
  'type' => 'ct-condition',
290
  'condition' => ['icon_source' => 'custom'],
315
  'value' => __('Fax:', 'blocksy-companion'),
316
  'design' => 'inline',
317
  ],
318
+
319
  'content' => [
320
  'type' => 'text',
321
  'label' => __('Content', 'blocksy-companion'),
322
  'value' => '578-393-4937',
323
  'design' => 'inline',
324
  ],
325
+
326
  'link' => [
327
  'type' => 'text',
328
  'label' => __('Link (optional)', 'blocksy-companion'),
344
  'custom' => __( 'Custom', 'blocksy' ),
345
  ],
346
  ],
347
+
348
  blocksy_rand_md5() => [
349
  'type' => 'ct-condition',
350
  'condition' => ['icon_source' => 'custom'],
375
  'value' => __('Email:', 'blocksy-companion'),
376
  'design' => 'inline',
377
  ],
378
+
379
  'content' => [
380
  'type' => 'text',
381
  'label' => __('Content', 'blocksy-companion'),
382
  'value' => 'contact@yourwebsite.com',
383
  'design' => 'inline',
384
  ],
385
+
386
  'link' => [
387
  'type' => 'text',
388
  'label' => __('Link (optional)', 'blocksy-companion'),
404
  'custom' => __( 'Custom', 'blocksy' ),
405
  ],
406
  ],
407
+
408
  blocksy_rand_md5() => [
409
  'type' => 'ct-condition',
410
  'condition' => ['icon_source' => 'custom'],
435
  'value' => __('Website:', 'blocksy-companion'),
436
  'design' => 'inline',
437
  ],
438
+
439
  'content' => [
440
  'type' => 'text',
441
  'label' => __('Content', 'blocksy-companion'),
442
  'value' => 'creativethemes.com',
443
  'design' => 'inline',
444
  ],
445
+
446
  'link' => [
447
  'type' => 'text',
448
  'label' => __('Link (optional)', 'blocksy-companion'),
450
  'design' => 'inline',
451
  ],
452
  ],
453
+
454
  $is_pro ? [
455
  'icon_source' => [
456
  'label' => __( 'Icon Source', 'blocksy' ),
464
  'custom' => __( 'Custom', 'blocksy' ),
465
  ],
466
  ],
467
+
468
  blocksy_rand_md5() => [
469
  'type' => 'ct-condition',
470
  'condition' => ['icon_source' => 'custom'],
framework/features/header.php CHANGED
@@ -567,7 +567,9 @@ class HeaderAdditions {
567
  }
568
 
569
  public function retrieve_account_modal() {
570
- remove_filter('lostpassword_url', 'wc_lostpassword_url', 10, 1);
 
 
571
 
572
  $body = json_decode(file_get_contents('php://input'), true);
573
 
@@ -593,7 +595,9 @@ class HeaderAdditions {
593
  ]
594
  );
595
 
596
- add_filter('lostpassword_url', 'wc_lostpassword_url', 10, 1);
 
 
597
 
598
  return $html;
599
  }
567
  }
568
 
569
  public function retrieve_account_modal() {
570
+ if (function_exists('wc_lostpassword_url')) {
571
+ remove_filter('lostpassword_url', 'wc_lostpassword_url', 10, 1);
572
+ }
573
 
574
  $body = json_decode(file_get_contents('php://input'), true);
575
 
595
  ]
596
  );
597
 
598
+ if (function_exists('wc_lostpassword_url')) {
599
+ add_filter('lostpassword_url', 'wc_lostpassword_url', 10, 1);
600
+ }
601
 
602
  return $html;
603
  }
framework/features/header/items/account/options.php CHANGED
@@ -18,7 +18,7 @@ if (class_exists('WooCommerce')) {
18
  $logout_link_options['woocommerce_account'] = __('WooCommerce Account', 'blocksy-companion');
19
  }
20
 
21
- $is_pro = blc_fs()->can_use_premium_code();
22
 
23
  $options = [
24
  blocksy_rand_md5() => [
18
  $logout_link_options['woocommerce_account'] = __('WooCommerce Account', 'blocksy-companion');
19
  }
20
 
21
+ $is_pro = function_exists('blc_fs') && blc_fs()->can_use_premium_code();
22
 
23
  $options = [
24
  blocksy_rand_md5() => [
framework/features/header/modal/login.php CHANGED
@@ -46,7 +46,7 @@ if (! $forgot_password_inline) {
46
  </p>
47
 
48
  <?php
49
- if (blc_fs()->can_use_premium_code()) {
50
  if (class_exists('NextendSocialLogin')) {
51
  \NextendSocialLogin::addLoginFormButtons();
52
  }
46
  </p>
47
 
48
  <?php
49
+ if (function_exists('blc_fs') && blc_fs()->can_use_premium_code()) {
50
  if (class_exists('NextendSocialLogin')) {
51
  \NextendSocialLogin::addLoginFormButtons();
52
  }
framework/features/header/modal/register.php CHANGED
@@ -45,13 +45,14 @@ if (
45
  <?php } ?>
46
 
47
  <?php
48
- if (blc_fs()->can_use_premium_code()) {
49
  if (class_exists('NextendSocialLogin')) {
50
  \NextendSocialLogin::addRegisterFormButtons();
51
  }
52
  }
53
 
54
- do_action('register_form')
 
55
  ?>
56
 
57
  <p id="reg_passmail">
45
  <?php } ?>
46
 
47
  <?php
48
+ if (function_exists('blc_fs') && blc_fs()->can_use_premium_code()) {
49
  if (class_exists('NextendSocialLogin')) {
50
  \NextendSocialLogin::addRegisterFormButtons();
51
  }
52
  }
53
 
54
+ do_action('register_form');
55
+ do_action('woocommerce_register_form');
56
  ?>
57
 
58
  <p id="reg_passmail">
framework/features/opengraph-meta-data.php CHANGED
@@ -91,6 +91,8 @@ class OpenGraphMetaData {
91
  $title = get_the_archive_title();
92
  }
93
 
 
 
94
  // Description
95
  if (is_category() || is_tag() || is_tax()) {
96
  $description = wp_strip_all_tags(term_description());
91
  $title = get_the_archive_title();
92
  }
93
 
94
+ $title = wp_strip_all_tags($title);
95
+
96
  // Description
97
  if (is_category() || is_tag() || is_tax()) {
98
  $description = wp_strip_all_tags(term_description());
framework/theme-integration.php CHANGED
@@ -399,6 +399,8 @@ class ThemeIntegration {
399
  }
400
 
401
  if (
 
 
402
  blc_fs()->can_use_premium_code()
403
  &&
404
  BLOCKSY_PATH . '/framework/premium/changelog.txt'
399
  }
400
 
401
  if (
402
+ function_exists('blc_fs')
403
+ &&
404
  blc_fs()->can_use_premium_code()
405
  &&
406
  BLOCKSY_PATH . '/framework/premium/changelog.txt'
freemius/LICENSE.txt DELETED
@@ -1,674 +0,0 @@
1
- GNU GENERAL PUBLIC LICENSE
2
- Version 3, 29 June 2007
3
-
4
- Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
- Everyone is permitted to copy and distribute verbatim copies
6
- of this license document, but changing it is not allowed.
7
-
8
- Preamble
9
-
10
- The GNU General Public License is a free, copyleft license for
11
- software and other kinds of works.
12
-
13
- The licenses for most software and other practical works are designed
14
- to take away your freedom to share and change the works. By contrast,
15
- the GNU General Public License is intended to guarantee your freedom to
16
- share and change all versions of a program--to make sure it remains free
17
- software for all its users. We, the Free Software Foundation, use the
18
- GNU General Public License for most of our software; it applies also to
19
- any other work released this way by its authors. You can apply it to
20
- your programs, too.
21
-
22
- When we speak of free software, we are referring to freedom, not
23
- price. Our General Public Licenses are designed to make sure that you
24
- have the freedom to distribute copies of free software (and charge for
25
- them if you wish), that you receive source code or can get it if you
26
- want it, that you can change the software or use pieces of it in new
27
- free programs, and that you know you can do these things.
28
-
29
- To protect your rights, we need to prevent others from denying you
30
- these rights or asking you to surrender the rights. Therefore, you have
31
- certain responsibilities if you distribute copies of the software, or if
32
- you modify it: responsibilities to respect the freedom of others.
33
-
34
- For example, if you distribute copies of such a program, whether
35
- gratis or for a fee, you must pass on to the recipients the same
36
- freedoms that you received. You must make sure that they, too, receive
37
- or can get the source code. And you must show them these terms so they
38
- know their rights.
39
-
40
- Developers that use the GNU GPL protect your rights with two steps:
41
- (1) assert copyright on the software, and (2) offer you this License
42
- giving you legal permission to copy, distribute and/or modify it.
43
-
44
- For the developers' and authors' protection, the GPL clearly explains
45
- that there is no warranty for this free software. For both users' and
46
- authors' sake, the GPL requires that modified versions be marked as
47
- changed, so that their problems will not be attributed erroneously to
48
- authors of previous versions.
49
-
50
- Some devices are designed to deny users access to install or run
51
- modified versions of the software inside them, although the manufacturer
52
- can do so. This is fundamentally incompatible with the aim of
53
- protecting users' freedom to change the software. The systematic
54
- pattern of such abuse occurs in the area of products for individuals to
55
- use, which is precisely where it is most unacceptable. Therefore, we
56
- have designed this version of the GPL to prohibit the practice for those
57
- products. If such problems arise substantially in other domains, we
58
- stand ready to extend this provision to those domains in future versions
59
- of the GPL, as needed to protect the freedom of users.
60
-
61
- Finally, every program is threatened constantly by software patents.
62
- States should not allow patents to restrict development and use of
63
- software on general-purpose computers, but in those that do, we wish to
64
- avoid the special danger that patents applied to a free program could
65
- make it effectively proprietary. To prevent this, the GPL assures that
66
- patents cannot be used to render the program non-free.
67
-
68
- The precise terms and conditions for copying, distribution and
69
- modification follow.
70
-
71
- TERMS AND CONDITIONS
72
-
73
- 0. Definitions.
74
-
75
- "This License" refers to version 3 of the GNU General Public License.
76
-
77
- "Copyright" also means copyright-like laws that apply to other kinds of
78
- works, such as semiconductor masks.
79
-
80
- "The Program" refers to any copyrightable work licensed under this
81
- License. Each licensee is addressed as "you". "Licensees" and
82
- "recipients" may be individuals or organizations.
83
-
84
- To "modify" a work means to copy from or adapt all or part of the work
85
- in a fashion requiring copyright permission, other than the making of an
86
- exact copy. The resulting work is called a "modified version" of the
87
- earlier work or a work "based on" the earlier work.
88
-
89
- A "covered work" means either the unmodified Program or a work based
90
- on the Program.
91
-
92
- To "propagate" a work means to do anything with it that, without
93
- permission, would make you directly or secondarily liable for
94
- infringement under applicable copyright law, except executing it on a
95
- computer or modifying a private copy. Propagation includes copying,
96
- distribution (with or without modification), making available to the
97
- public, and in some countries other activities as well.
98
-
99
- To "convey" a work means any kind of propagation that enables other
100
- parties to make or receive copies. Mere interaction with a user through
101
- a computer network, with no transfer of a copy, is not conveying.
102
-
103
- An interactive user interface displays "Appropriate Legal Notices"
104
- to the extent that it includes a convenient and prominently visible
105
- feature that (1) displays an appropriate copyright notice, and (2)
106
- tells the user that there is no warranty for the work (except to the
107
- extent that warranties are provided), that licensees may convey the
108
- work under this License, and how to view a copy of this License. If
109
- the interface presents a list of user commands or options, such as a
110
- menu, a prominent item in the list meets this criterion.
111
-
112
- 1. Source Code.
113
-
114
- The "source code" for a work means the preferred form of the work
115
- for making modifications to it. "Object code" means any non-source
116
- form of a work.
117
-
118
- A "Standard Interface" means an interface that either is an official
119
- standard defined by a recognized standards body, or, in the case of
120
- interfaces specified for a particular programming language, one that
121
- is widely used among developers working in that language.
122
-
123
- The "System Libraries" of an executable work include anything, other
124
- than the work as a whole, that (a) is included in the normal form of
125
- packaging a Major Component, but which is not part of that Major
126
- Component, and (b) serves only to enable use of the work with that
127
- Major Component, or to implement a Standard Interface for which an
128
- implementation is available to the public in source code form. A
129
- "Major Component", in this context, means a major essential component
130
- (kernel, window system, and so on) of the specific operating system
131
- (if any) on which the executable work runs, or a compiler used to
132
- produce the work, or an object code interpreter used to run it.
133
-
134
- The "Corresponding Source" for a work in object code form means all
135
- the source code needed to generate, install, and (for an executable
136
- work) run the object code and to modify the work, including scripts to
137
- control those activities. However, it does not include the work's
138
- System Libraries, or general-purpose tools or generally available free
139
- programs which are used unmodified in performing those activities but
140
- which are not part of the work. For example, Corresponding Source
141
- includes interface definition files associated with source files for
142
- the work, and the source code for shared libraries and dynamically
143
- linked subprograms that the work is specifically designed to require,
144
- such as by intimate data communication or control flow between those
145
- subprograms and other parts of the work.
146
-
147
- The Corresponding Source need not include anything that users
148
- can regenerate automatically from other parts of the Corresponding
149
- Source.
150
-
151
- The Corresponding Source for a work in source code form is that
152
- same work.
153
-
154
- 2. Basic Permissions.
155
-
156
- All rights granted under this License are granted for the term of
157
- copyright on the Program, and are irrevocable provided the stated
158
- conditions are met. This License explicitly affirms your unlimited
159
- permission to run the unmodified Program. The output from running a
160
- covered work is covered by this License only if the output, given its
161
- content, constitutes a covered work. This License acknowledges your
162
- rights of fair use or other equivalent, as provided by copyright law.
163
-
164
- You may make, run and propagate covered works that you do not
165
- convey, without conditions so long as your license otherwise remains
166
- in force. You may convey covered works to others for the sole purpose
167
- of having them make modifications exclusively for you, or provide you
168
- with facilities for running those works, provided that you comply with
169
- the terms of this License in conveying all material for which you do
170
- not control copyright. Those thus making or running the covered works
171
- for you must do so exclusively on your behalf, under your direction
172
- and control, on terms that prohibit them from making any copies of
173
- your copyrighted material outside their relationship with you.
174
-
175
- Conveying under any other circumstances is permitted solely under
176
- the conditions stated below. Sublicensing is not allowed; section 10
177
- makes it unnecessary.
178
-
179
- 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180
-
181
- No covered work shall be deemed part of an effective technological
182
- measure under any applicable law fulfilling obligations under article
183
- 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184
- similar laws prohibiting or restricting circumvention of such
185
- measures.
186
-
187
- When you convey a covered work, you waive any legal power to forbid
188
- circumvention of technological measures to the extent such circumvention
189
- is effected by exercising rights under this License with respect to
190
- the covered work, and you disclaim any intention to limit operation or
191
- modification of the work as a means of enforcing, against the work's
192
- users, your or third parties' legal rights to forbid circumvention of
193
- technological measures.
194
-
195
- 4. Conveying Verbatim Copies.
196
-
197
- You may convey verbatim copies of the Program's source code as you
198
- receive it, in any medium, provided that you conspicuously and
199
- appropriately publish on each copy an appropriate copyright notice;
200
- keep intact all notices stating that this License and any
201
- non-permissive terms added in accord with section 7 apply to the code;
202
- keep intact all notices of the absence of any warranty; and give all
203
- recipients a copy of this License along with the Program.
204
-
205
- You may charge any price or no price for each copy that you convey,
206
- and you may offer support or warranty protection for a fee.
207
-
208
- 5. Conveying Modified Source Versions.
209
-
210
- You may convey a work based on the Program, or the modifications to
211
- produce it from the Program, in the form of source code under the
212
- terms of section 4, provided that you also meet all of these conditions:
213
-
214
- a) The work must carry prominent notices stating that you modified
215
- it, and giving a relevant date.
216
-
217
- b) The work must carry prominent notices stating that it is
218
- released under this License and any conditions added under section
219
- 7. This requirement modifies the requirement in section 4 to
220
- "keep intact all notices".
221
-
222
- c) You must license the entire work, as a whole, under this
223
- License to anyone who comes into possession of a copy. This
224
- License will therefore apply, along with any applicable section 7
225
- additional terms, to the whole of the work, and all its parts,
226
- regardless of how they are packaged. This License gives no
227
- permission to license the work in any other way, but it does not
228
- invalidate such permission if you have separately received it.
229
-
230
- d) If the work has interactive user interfaces, each must display
231
- Appropriate Legal Notices; however, if the Program has interactive
232
- interfaces that do not display Appropriate Legal Notices, your
233
- work need not make them do so.
234
-
235
- A compilation of a covered work with other separate and independent
236
- works, which are not by their nature extensions of the covered work,
237
- and which are not combined with it such as to form a larger program,
238
- in or on a volume of a storage or distribution medium, is called an
239
- "aggregate" if the compilation and its resulting copyright are not
240
- used to limit the access or legal rights of the compilation's users
241
- beyond what the individual works permit. Inclusion of a covered work
242
- in an aggregate does not cause this License to apply to the other
243
- parts of the aggregate.
244
-
245
- 6. Conveying Non-Source Forms.
246
-
247
- You may convey a covered work in object code form under the terms
248
- of sections 4 and 5, provided that you also convey the
249
- machine-readable Corresponding Source under the terms of this License,
250
- in one of these ways:
251
-
252
- a) Convey the object code in, or embodied in, a physical product
253
- (including a physical distribution medium), accompanied by the
254
- Corresponding Source fixed on a durable physical medium
255
- customarily used for software interchange.
256
-
257
- b) Convey the object code in, or embodied in, a physical product
258
- (including a physical distribution medium), accompanied by a
259
- written offer, valid for at least three years and valid for as
260
- long as you offer spare parts or customer support for that product
261
- model, to give anyone who possesses the object code either (1) a
262
- copy of the Corresponding Source for all the software in the
263
- product that is covered by this License, on a durable physical
264
- medium customarily used for software interchange, for a price no
265
- more than your reasonable cost of physically performing this
266
- conveying of source, or (2) access to copy the
267
- Corresponding Source from a network server at no charge.
268
-
269
- c) Convey individual copies of the object code with a copy of the
270
- written offer to provide the Corresponding Source. This
271
- alternative is allowed only occasionally and noncommercially, and
272
- only if you received the object code with such an offer, in accord
273
- with subsection 6b.
274
-
275
- d) Convey the object code by offering access from a designated
276
- place (gratis or for a charge), and offer equivalent access to the
277
- Corresponding Source in the same way through the same place at no
278
- further charge. You need not require recipients to copy the
279
- Corresponding Source along with the object code. If the place to
280
- copy the object code is a network server, the Corresponding Source
281
- may be on a different server (operated by you or a third party)
282
- that supports equivalent copying facilities, provided you maintain
283
- clear directions next to the object code saying where to find the
284
- Corresponding Source. Regardless of what server hosts the
285
- Corresponding Source, you remain obligated to ensure that it is
286
- available for as long as needed to satisfy these requirements.
287
-
288
- e) Convey the object code using peer-to-peer transmission, provided
289
- you inform other peers where the object code and Corresponding
290
- Source of the work are being offered to the general public at no
291
- charge under subsection 6d.
292
-
293
- A separable portion of the object code, whose source code is excluded
294
- from the Corresponding Source as a System Library, need not be
295
- included in conveying the object code work.
296
-
297
- A "User Product" is either (1) a "consumer product", which means any
298
- tangible personal property which is normally used for personal, family,
299
- or household purposes, or (2) anything designed or sold for incorporation
300
- into a dwelling. In determining whether a product is a consumer product,
301
- doubtful cases shall be resolved in favor of coverage. For a particular
302
- product received by a particular user, "normally used" refers to a
303
- typical or common use of that class of product, regardless of the status
304
- of the particular user or of the way in which the particular user
305
- actually uses, or expects or is expected to use, the product. A product
306
- is a consumer product regardless of whether the product has substantial
307
- commercial, industrial or non-consumer uses, unless such uses represent
308
- the only significant mode of use of the product.
309
-
310
- "Installation Information" for a User Product means any methods,
311
- procedures, authorization keys, or other information required to install
312
- and execute modified versions of a covered work in that User Product from
313
- a modified version of its Corresponding Source. The information must
314
- suffice to ensure that the continued functioning of the modified object
315
- code is in no case prevented or interfered with solely because
316
- modification has been made.
317
-
318
- If you convey an object code work under this section in, or with, or
319
- specifically for use in, a User Product, and the conveying occurs as
320
- part of a transaction in which the right of possession and use of the
321
- User Product is transferred to the recipient in perpetuity or for a
322
- fixed term (regardless of how the transaction is characterized), the
323
- Corresponding Source conveyed under this section must be accompanied
324
- by the Installation Information. But this requirement does not apply
325
- if neither you nor any third party retains the ability to install
326
- modified object code on the User Product (for example, the work has
327
- been installed in ROM).
328
-
329
- The requirement to provide Installation Information does not include a
330
- requirement to continue to provide support service, warranty, or updates
331
- for a work that has been modified or installed by the recipient, or for
332
- the User Product in which it has been modified or installed. Access to a
333
- network may be denied when the modification itself materially and
334
- adversely affects the operation of the network or violates the rules and
335
- protocols for communication across the network.
336
-
337
- Corresponding Source conveyed, and Installation Information provided,
338
- in accord with this section must be in a format that is publicly
339
- documented (and with an implementation available to the public in
340
- source code form), and must require no special password or key for
341
- unpacking, reading or copying.
342
-
343
- 7. Additional Terms.
344
-
345
- "Additional permissions" are terms that supplement the terms of this
346
- License by making exceptions from one or more of its conditions.
347
- Additional permissions that are applicable to the entire Program shall
348
- be treated as though they were included in this License, to the extent
349
- that they are valid under applicable law. If additional permissions
350
- apply only to part of the Program, that part may be used separately
351
- under those permissions, but the entire Program remains governed by
352
- this License without regard to the additional permissions.
353
-
354
- When you convey a copy of a covered work, you may at your option
355
- remove any additional permissions from that copy, or from any part of
356
- it. (Additional permissions may be written to require their own
357
- removal in certain cases when you modify the work.) You may place
358
- additional permissions on material, added by you to a covered work,
359
- for which you have or can give appropriate copyright permission.
360
-
361
- Notwithstanding any other provision of this License, for material you
362
- add to a covered work, you may (if authorized by the copyright holders of
363
- that material) supplement the terms of this License with terms:
364
-
365
- a) Disclaiming warranty or limiting liability differently from the
366
- terms of sections 15 and 16 of this License; or
367
-
368
- b) Requiring preservation of specified reasonable legal notices or
369
- author attributions in that material or in the Appropriate Legal
370
- Notices displayed by works containing it; or
371
-
372
- c) Prohibiting misrepresentation of the origin of that material, or
373
- requiring that modified versions of such material be marked in
374
- reasonable ways as different from the original version; or
375
-
376
- d) Limiting the use for publicity purposes of names of licensors or
377
- authors of the material; or
378
-
379
- e) Declining to grant rights under trademark law for use of some
380
- trade names, trademarks, or service marks; or
381
-
382
- f) Requiring indemnification of licensors and authors of that
383
- material by anyone who conveys the material (or modified versions of
384
- it) with contractual assumptions of liability to the recipient, for
385
- any liability that these contractual assumptions directly impose on
386
- those licensors and authors.
387
-
388
- All other non-permissive additional terms are considered "further
389
- restrictions" within the meaning of section 10. If the Program as you
390
- received it, or any part of it, contains a notice stating that it is
391
- governed by this License along with a term that is a further
392
- restriction, you may remove that term. If a license document contains
393
- a further restriction but permits relicensing or conveying under this
394
- License, you may add to a covered work material governed by the terms
395
- of that license document, provided that the further restriction does
396
- not survive such relicensing or conveying.
397
-
398
- If you add terms to a covered work in accord with this section, you
399
- must place, in the relevant source files, a statement of the
400
- additional terms that apply to those files, or a notice indicating
401
- where to find the applicable terms.
402
-
403
- Additional terms, permissive or non-permissive, may be stated in the
404
- form of a separately written license, or stated as exceptions;
405
- the above requirements apply either way.
406
-
407
- 8. Termination.
408
-
409
- You may not propagate or modify a covered work except as expressly
410
- provided under this License. Any attempt otherwise to propagate or
411
- modify it is void, and will automatically terminate your rights under
412
- this License (including any patent licenses granted under the third
413
- paragraph of section 11).
414
-
415
- However, if you cease all violation of this License, then your
416
- license from a particular copyright holder is reinstated (a)
417
- provisionally, unless and until the copyright holder explicitly and
418
- finally terminates your license, and (b) permanently, if the copyright
419
- holder fails to notify you of the violation by some reasonable means
420
- prior to 60 days after the cessation.
421
-
422
- Moreover, your license from a particular copyright holder is
423
- reinstated permanently if the copyright holder notifies you of the
424
- violation by some reasonable means, this is the first time you have
425
- received notice of violation of this License (for any work) from that
426
- copyright holder, and you cure the violation prior to 30 days after
427
- your receipt of the notice.
428
-
429
- Termination of your rights under this section does not terminate the
430
- licenses of parties who have received copies or rights from you under
431
- this License. If your rights have been terminated and not permanently
432
- reinstated, you do not qualify to receive new licenses for the same
433
- material under section 10.
434
-
435
- 9. Acceptance Not Required for Having Copies.
436
-
437
- You are not required to accept this License in order to receive or
438
- run a copy of the Program. Ancillary propagation of a covered work
439
- occurring solely as a consequence of using peer-to-peer transmission
440
- to receive a copy likewise does not require acceptance. However,
441
- nothing other than this License grants you permission to propagate or
442
- modify any covered work. These actions infringe copyright if you do
443
- not accept this License. Therefore, by modifying or propagating a
444
- covered work, you indicate your acceptance of this License to do so.
445
-
446
- 10. Automatic Licensing of Downstream Recipients.
447
-
448
- Each time you convey a covered work, the recipient automatically
449
- receives a license from the original licensors, to run, modify and
450
- propagate that work, subject to this License. You are not responsible
451
- for enforcing compliance by third parties with this License.
452
-
453
- An "entity transaction" is a transaction transferring control of an
454
- organization, or substantially all assets of one, or subdividing an
455
- organization, or merging organizations. If propagation of a covered
456
- work results from an entity transaction, each party to that
457
- transaction who receives a copy of the work also receives whatever
458
- licenses to the work the party's predecessor in interest had or could
459
- give under the previous paragraph, plus a right to possession of the
460
- Corresponding Source of the work from the predecessor in interest, if
461
- the predecessor has it or can get it with reasonable efforts.
462
-
463
- You may not impose any further restrictions on the exercise of the
464
- rights granted or affirmed under this License. For example, you may
465
- not impose a license fee, royalty, or other charge for exercise of
466
- rights granted under this License, and you may not initiate litigation
467
- (including a cross-claim or counterclaim in a lawsuit) alleging that
468
- any patent claim is infringed by making, using, selling, offering for
469
- sale, or importing the Program or any portion of it.
470
-
471
- 11. Patents.
472
-
473
- A "contributor" is a copyright holder who authorizes use under this
474
- License of the Program or a work on which the Program is based. The
475
- work thus licensed is called the contributor's "contributor version".
476
-
477
- A contributor's "essential patent claims" are all patent claims
478
- owned or controlled by the contributor, whether already acquired or
479
- hereafter acquired, that would be infringed by some manner, permitted
480
- by this License, of making, using, or selling its contributor version,
481
- but do not include claims that would be infringed only as a
482
- consequence of further modification of the contributor version. For
483
- purposes of this definition, "control" includes the right to grant
484
- patent sublicenses in a manner consistent with the requirements of
485
- this License.
486
-
487
- Each contributor grants you a non-exclusive, worldwide, royalty-free
488
- patent license under the contributor's essential patent claims, to
489
- make, use, sell, offer for sale, import and otherwise run, modify and
490
- propagate the contents of its contributor version.
491
-
492
- In the following three paragraphs, a "patent license" is any express
493
- agreement or commitment, however denominated, not to enforce a patent
494
- (such as an express permission to practice a patent or covenant not to
495
- sue for patent infringement). To "grant" such a patent license to a
496
- party means to make such an agreement or commitment not to enforce a
497
- patent against the party.
498
-
499
- If you convey a covered work, knowingly relying on a patent license,
500
- and the Corresponding Source of the work is not available for anyone
501
- to copy, free of charge and under the terms of this License, through a
502
- publicly available network server or other readily accessible means,
503
- then you must either (1) cause the Corresponding Source to be so
504
- available, or (2) arrange to deprive yourself of the benefit of the
505
- patent license for this particular work, or (3) arrange, in a manner
506
- consistent with the requirements of this License, to extend the patent
507
- license to downstream recipients. "Knowingly relying" means you have
508
- actual knowledge that, but for the patent license, your conveying the
509
- covered work in a country, or your recipient's use of the covered work
510
- in a country, would infringe one or more identifiable patents in that
511
- country that you have reason to believe are valid.
512
-
513
- If, pursuant to or in connection with a single transaction or
514
- arrangement, you convey, or propagate by procuring conveyance of, a
515
- covered work, and grant a patent license to some of the parties
516
- receiving the covered work authorizing them to use, propagate, modify
517
- or convey a specific copy of the covered work, then the patent license
518
- you grant is automatically extended to all recipients of the covered
519
- work and works based on it.
520
-
521
- A patent license is "discriminatory" if it does not include within
522
- the scope of its coverage, prohibits the exercise of, or is
523
- conditioned on the non-exercise of one or more of the rights that are
524
- specifically granted under this License. You may not convey a covered
525
- work if you are a party to an arrangement with a third party that is
526
- in the business of distributing software, under which you make payment
527
- to the third party based on the extent of your activity of conveying
528
- the work, and under which the third party grants, to any of the
529
- parties who would receive the covered work from you, a discriminatory
530
- patent license (a) in connection with copies of the covered work
531
- conveyed by you (or copies made from those copies), or (b) primarily
532
- for and in connection with specific products or compilations that
533
- contain the covered work, unless you entered into that arrangement,
534
- or that patent license was granted, prior to 28 March 2007.
535
-
536
- Nothing in this License shall be construed as excluding or limiting
537
- any implied license or other defenses to infringement that may
538
- otherwise be available to you under applicable patent law.
539
-
540
- 12. No Surrender of Others' Freedom.
541
-
542
- If conditions are imposed on you (whether by court order, agreement or
543
- otherwise) that contradict the conditions of this License, they do not
544
- excuse you from the conditions of this License. If you cannot convey a
545
- covered work so as to satisfy simultaneously your obligations under this
546
- License and any other pertinent obligations, then as a consequence you may
547
- not convey it at all. For example, if you agree to terms that obligate you
548
- to collect a royalty for further conveying from those to whom you convey
549
- the Program, the only way you could satisfy both those terms and this
550
- License would be to refrain entirely from conveying the Program.
551
-
552
- 13. Use with the GNU Affero General Public License.
553
-
554
- Notwithstanding any other provision of this License, you have
555
- permission to link or combine any covered work with a work licensed
556
- under version 3 of the GNU Affero General Public License into a single
557
- combined work, and to convey the resulting work. The terms of this
558
- License will continue to apply to the part which is the covered work,
559
- but the special requirements of the GNU Affero General Public License,
560
- section 13, concerning interaction through a network will apply to the
561
- combination as such.
562
-
563
- 14. Revised Versions of this License.
564
-
565
- The Free Software Foundation may publish revised and/or new versions of
566
- the GNU General Public License from time to time. Such new versions will
567
- be similar in spirit to the present version, but may differ in detail to
568
- address new problems or concerns.
569
-
570
- Each version is given a distinguishing version number. If the
571
- Program specifies that a certain numbered version of the GNU General
572
- Public License "or any later version" applies to it, you have the
573
- option of following the terms and conditions either of that numbered
574
- version or of any later version published by the Free Software
575
- Foundation. If the Program does not specify a version number of the
576
- GNU General Public License, you may choose any version ever published
577
- by the Free Software Foundation.
578
-
579
- If the Program specifies that a proxy can decide which future
580
- versions of the GNU General Public License can be used, that proxy's
581
- public statement of acceptance of a version permanently authorizes you
582
- to choose that version for the Program.
583
-
584
- Later license versions may give you additional or different
585
- permissions. However, no additional obligations are imposed on any
586
- author or copyright holder as a result of your choosing to follow a
587
- later version.
588
-
589
- 15. Disclaimer of Warranty.
590
-
591
- THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592
- APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593
- HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594
- OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595
- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596
- PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597
- IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598
- ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599
-
600
- 16. Limitation of Liability.
601
-
602
- IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603
- WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604
- THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605
- GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606
- USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607
- DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608
- PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609
- EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610
- SUCH DAMAGES.
611
-
612
- 17. Interpretation of Sections 15 and 16.
613
-
614
- If the disclaimer of warranty and limitation of liability provided
615
- above cannot be given local legal effect according to their terms,
616
- reviewing courts shall apply local law that most closely approximates
617
- an absolute waiver of all civil liability in connection with the
618
- Program, unless a warranty or assumption of liability accompanies a
619
- copy of the Program in return for a fee.
620
-
621
- END OF TERMS AND CONDITIONS
622
-
623
- How to Apply These Terms to Your New Programs
624
-
625
- If you develop a new program, and you want it to be of the greatest
626
- possible use to the public, the best way to achieve this is to make it
627
- free software which everyone can redistribute and change under these terms.
628
-
629
- To do so, attach the following notices to the program. It is safest
630
- to attach them to the start of each source file to most effectively
631
- state the exclusion of warranty; and each file should have at least
632
- the "copyright" line and a pointer to where the full notice is found.
633
-
634
- {one line to give the program's name and a brief idea of what it does.}
635
- Copyright (C) {year} {name of author}
636
-
637
- This program is free software: you can redistribute it and/or modify
638
- it under the terms of the GNU General Public License as published by
639
- the Free Software Foundation, either version 3 of the License, or
640
- (at your option) any later version.
641
-
642
- This program is distributed in the hope that it will be useful,
643
- but WITHOUT ANY WARRANTY; without even the implied warranty of
644
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645
- GNU General Public License for more details.
646
-
647
- You should have received a copy of the GNU General Public License
648
- along with this program. If not, see <http://www.gnu.org/licenses/>.
649
-
650
- Also add information on how to contact you by electronic and paper mail.
651
-
652
- If the program does terminal interaction, make it output a short
653
- notice like this when it starts in an interactive mode:
654
-
655
- {project} Copyright (C) {year} {fullname}
656
- This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657
- This is free software, and you are welcome to redistribute it
658
- under certain conditions; type `show c' for details.
659
-
660
- The hypothetical commands `show w' and `show c' should show the appropriate
661
- parts of the General Public License. Of course, your program's commands
662
- might be different; for a GUI interface, you would use an "about box".
663
-
664
- You should also get your employer (if you work as a programmer) or school,
665
- if any, to sign a "copyright disclaimer" for the program, if necessary.
666
- For more information on this, and how to apply and follow the GNU GPL, see
667
- <http://www.gnu.org/licenses/>.
668
-
669
- The GNU General Public License does not permit incorporating your program
670
- into proprietary programs. If your program is a subroutine library, you
671
- may consider it more useful to permit linking proprietary applications with
672
- the library. If this is what you want to do, use the GNU Lesser General
673
- Public License instead of this License. But first, please read
674
- <http://www.gnu.org/philosophy/why-not-lgpl.html>.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
freemius/assets/css/admin/account.css DELETED
@@ -1 +0,0 @@
1
- label.fs-tag,span.fs-tag{background:#ffba00;color:#fff;display:inline-block;border-radius:3px;padding:5px;font-size:11px;line-height:11px;vertical-align:baseline}label.fs-tag.fs-warn,span.fs-tag.fs-warn{background:#ffba00}label.fs-tag.fs-info,span.fs-tag.fs-info{background:#00a0d2}label.fs-tag.fs-success,span.fs-tag.fs-success{background:#46b450}label.fs-tag.fs-error,span.fs-tag.fs-error{background:#dc3232}.fs-notice[data-id=license_not_whitelabeled].success,.fs-notice[data-id=license_whitelabeled].success{color:inherit;border-left-color:#00a0d2}.fs-notice[data-id=license_not_whitelabeled].success label.fs-plugin-title,.fs-notice[data-id=license_whitelabeled].success label.fs-plugin-title{display:none}#fs_account .postbox,#fs_account .widefat{max-width:800px}#fs_account h3{font-size:1.3em;padding:12px 15px;margin:0 0 12px 0;line-height:1.4;border-bottom:1px solid #f1f1f1}#fs_account h3 .dashicons{width:26px;height:26px;font-size:1.3em}#fs_account i.dashicons{font-size:1.2em;height:1.2em;width:1.2em}#fs_account .dashicons{vertical-align:middle}#fs_account .fs-header-actions{position:absolute;top:17px;right:15px;font-size:.9em}#fs_account .fs-header-actions ul{margin:0}#fs_account .fs-header-actions li{float:left}#fs_account .fs-header-actions li form{display:inline-block}#fs_account .fs-header-actions li a{text-decoration:none}#fs_account_details .button-group{float:right}.rtl #fs_account .fs-header-actions{left:15px;right:auto}.fs-key-value-table{width:100%}.fs-key-value-table form{display:inline-block}.fs-key-value-table tr td:first-child{text-align:right}.fs-key-value-table tr td:first-child nobr{font-weight:bold}.fs-key-value-table tr td:first-child form{display:block}.fs-key-value-table tr td.fs-right{text-align:right}.fs-key-value-table tr.fs-odd{background:#ebebeb}.fs-key-value-table td,.fs-key-value-table th{padding:10px}.fs-key-value-table code{line-height:28px}.fs-key-value-table var,.fs-key-value-table code,.fs-key-value-table input[type=text]{color:#0073aa;font-size:16px;background:none}.fs-key-value-table input[type=text]{width:100%;font-weight:bold}.fs-field-beta_program label{margin-left:7px}label.fs-tag{background:#ffba00;color:#fff;display:inline-block;border-radius:3px;padding:5px;font-size:11px;line-height:11px;vertical-align:baseline}label.fs-tag.fs-warn{background:#ffba00}label.fs-tag.fs-success{background:#46b450}label.fs-tag.fs-error{background:#dc3232}#fs_sites .fs-scrollable-table .fs-table-body{max-height:200px;overflow:auto;border:1px solid #e5e5e5}#fs_sites .fs-scrollable-table .fs-table-body>table.widefat{border:none !important}#fs_sites .fs-scrollable-table .fs-main-column{width:100%}#fs_sites .fs-scrollable-table .fs-site-details td:first-of-type{text-align:right;color:gray;width:1px}#fs_sites .fs-scrollable-table .fs-site-details td:last-of-type{text-align:right}#fs_sites .fs-scrollable-table .fs-install-details table tr td{width:1px;white-space:nowrap}#fs_sites .fs-scrollable-table .fs-install-details table tr td:last-of-type{width:auto}#fs_addons h3{border:none;margin-bottom:0;padding:4px 5px}#fs_addons td{vertical-align:middle}#fs_addons thead{white-space:nowrap}#fs_addons td:first-child,#fs_addons th:first-child{text-align:left;font-weight:bold}#fs_addons td:last-child,#fs_addons th:last-child{text-align:right}#fs_addons th{font-weight:bold}#fs_billing_address{width:100%}#fs_billing_address tr td{width:50%;padding:5px}#fs_billing_address tr:first-of-type td{padding-top:0}#fs_billing_address span{font-weight:bold}#fs_billing_address input,#fs_billing_address select{display:block;width:100%;margin-top:5px}#fs_billing_address input::-moz-placeholder,#fs_billing_address select::-moz-placeholder{color:transparent;opacity:1}#fs_billing_address input:-ms-input-placeholder,#fs_billing_address select:-ms-input-placeholder{color:transparent}#fs_billing_address input::-webkit-input-placeholder,#fs_billing_address select::-webkit-input-placeholder{color:transparent}#fs_billing_address input.fs-read-mode,#fs_billing_address select.fs-read-mode{border-color:transparent;color:#777;border-bottom:1px dashed #ccc;padding-left:0;background:none}#fs_billing_address.fs-read-mode td span{display:none}#fs_billing_address.fs-read-mode input,#fs_billing_address.fs-read-mode select{border-color:transparent;color:#777;border-bottom:1px dashed #ccc;padding-left:0;background:none}#fs_billing_address.fs-read-mode input::-moz-placeholder,#fs_billing_address.fs-read-mode select::-moz-placeholder{color:#ccc;opacity:1}#fs_billing_address.fs-read-mode input:-ms-input-placeholder,#fs_billing_address.fs-read-mode select:-ms-input-placeholder{color:#ccc}#fs_billing_address.fs-read-mode input::-webkit-input-placeholder,#fs_billing_address.fs-read-mode select::-webkit-input-placeholder{color:#ccc}#fs_billing_address button{display:block;width:100%}@media screen and (max-width: 639px){#fs_account .fs-header-actions{position:static;padding:0 15px 12px 15px;margin:0 0 12px 0}#fs_account .fs-header-actions li{float:none;display:inline-block}#fs_account #fs_account_details{display:block}#fs_account #fs_account_details tbody,#fs_account #fs_account_details tr,#fs_account #fs_account_details td,#fs_account #fs_account_details th{display:block}#fs_account #fs_account_details tr td:first-child{text-align:left}#fs_account #fs_account_details tr td:nth-child(2){padding:0 12px}#fs_account #fs_account_details tr td:nth-child(2) code{margin:0;padding:0}#fs_account #fs_account_details tr td:nth-child(2) label{margin-left:0}#fs_account #fs_account_details tr td:nth-child(3){text-align:left}#fs_account #fs_account_details tr.fs-field-plan td:nth-child(2) .button-group{float:none;margin:12px 0}}/*# sourceMappingURL=account.css.map */
 
freemius/assets/css/admin/add-ons.css DELETED
@@ -1 +0,0 @@
1
- .fs-badge{position:absolute;top:10px;right:0;background:#71ae00;color:#fff;text-transform:uppercase;padding:5px 10px;-moz-border-radius:3px 0 0 3px;-webkit-border-radius:3px 0 0 3px;border-radius:3px 0 0 3px;font-weight:bold;border-right:0;-moz-box-shadow:0 2px 1px -1px rgba(0,0,0,.3);-webkit-box-shadow:0 2px 1px -1px rgba(0,0,0,.3);box-shadow:0 2px 1px -1px rgba(0,0,0,.3)}#fs_addons .fs-cards-list{list-style:none}#fs_addons .fs-cards-list .fs-card{float:left;height:152px;width:310px;padding:0;margin:0 0 30px 30px;font-size:14px;list-style:none;border:1px solid #ddd;cursor:pointer;position:relative}#fs_addons .fs-cards-list .fs-card .fs-overlay{position:absolute;left:0;right:0;bottom:0;top:0;z-index:9}#fs_addons .fs-cards-list .fs-card .fs-inner{background-color:#fff;overflow:hidden;height:100%;position:relative}#fs_addons .fs-cards-list .fs-card .fs-inner>ul{-moz-transition:all,.15s;-o-transition:all,.15s;-ms-transition:all,.15s;-webkit-transition:all,.15s;transition:all,.15s;left:0;right:0;top:0;position:absolute}#fs_addons .fs-cards-list .fs-card .fs-inner>ul>li{list-style:none;line-height:18px;padding:0 15px;width:100%;display:block;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-card-banner{padding:0;margin:0;line-height:0;display:block;height:100px;background-repeat:repeat-x;background-size:100% 100%;-moz-transition:all,.15s;-o-transition:all,.15s;-ms-transition:all,.15s;-webkit-transition:all,.15s;transition:all,.15s}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-card-banner .fs-badge.fs-installed-addon-badge{font-size:1.02em;line-height:1.3em}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-title{margin:10px 0 0 0;height:18px;overflow:hidden;color:#000;white-space:nowrap;text-overflow:ellipsis;font-weight:bold}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-offer{font-size:.9em}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-description{background-color:#f9f9f9;padding:10px 15px 100px 15px;border-top:1px solid #eee;margin:0 0 10px 0;color:#777}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-tag{position:absolute;top:10px;right:0px;background:#adff2f;display:block;padding:2px 10px;-moz-box-shadow:1px 1px 1px rgba(0,0,0,.3);-webkit-box-shadow:1px 1px 1px rgba(0,0,0,.3);box-shadow:1px 1px 1px rgba(0,0,0,.3);text-transform:uppercase;font-size:.9em;font-weight:bold}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-cta .button,#fs_addons .fs-cards-list .fs-card .fs-inner .fs-cta .button-group{position:absolute;top:112px;right:10px}@media screen and (min-width: 960px){#fs_addons .fs-cards-list .fs-card:hover .fs-overlay{border:2px solid #29abe1;margin-left:-1px;margin-top:-1px}#fs_addons .fs-cards-list .fs-card:hover .fs-inner ul{top:-100px}#fs_addons .fs-cards-list .fs-card:hover .fs-inner .fs-title,#fs_addons .fs-cards-list .fs-card:hover .fs-inner .fs-offer{color:#29abe1}}#TB_window,#TB_window iframe{width:821px !important}#plugin-information .fyi{width:266px !important}#plugin-information #section-holder{margin-right:299px}#plugin-information #section-description h2,#plugin-information #section-description h3,#plugin-information #section-description p,#plugin-information #section-description b,#plugin-information #section-description i,#plugin-information #section-description blockquote,#plugin-information #section-description li,#plugin-information #section-description ul,#plugin-information #section-description ol{clear:none}#plugin-information #section-description iframe{max-width:100%}#plugin-information #section-description .fs-selling-points{padding-bottom:10px;border-bottom:1px solid #ddd}#plugin-information #section-description .fs-selling-points ul{margin:0}#plugin-information #section-description .fs-selling-points ul li{padding:0;list-style:none outside none}#plugin-information #section-description .fs-selling-points ul li i.dashicons{color:#71ae00;font-size:3em;vertical-align:middle;line-height:30px;float:left;margin:0 0 0 -15px}#plugin-information #section-description .fs-selling-points ul li h3{margin:1em 30px !important}#plugin-information #section-description .fs-screenshots:after{content:"";display:table;clear:both}#plugin-information #section-description .fs-screenshots ul{list-style:none;margin:0}#plugin-information #section-description .fs-screenshots ul li{width:225px;height:225px;float:left;margin-bottom:20px;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;box-sizing:content-box}#plugin-information #section-description .fs-screenshots ul li a{display:block;width:100%;height:100%;border:1px solid;-moz-box-shadow:1px 1px 1px rgba(0,0,0,.2);-webkit-box-shadow:1px 1px 1px rgba(0,0,0,.2);box-shadow:1px 1px 1px rgba(0,0,0,.2);background-size:cover}#plugin-information #section-description .fs-screenshots ul li.odd{margin-right:20px}#plugin-information .plugin-information-pricing{margin:-16px;border-bottom:1px solid #ddd}#plugin-information .plugin-information-pricing .fs-plan h3{margin-top:0;padding:20px;font-size:16px}#plugin-information .plugin-information-pricing .fs-plan .nav-tab-wrapper{border-bottom:1px solid #ddd}#plugin-information .plugin-information-pricing .fs-plan .nav-tab-wrapper .nav-tab{cursor:pointer;position:relative;padding:0 10px;font-size:.9em}#plugin-information .plugin-information-pricing .fs-plan .nav-tab-wrapper .nav-tab label{text-transform:uppercase;color:green;background:#adff2f;position:absolute;left:-1px;right:-1px;bottom:100%;border:1px solid #006400;padding:2px;text-align:center;font-size:.9em;line-height:1em}#plugin-information .plugin-information-pricing .fs-plan .nav-tab-wrapper .nav-tab.nav-tab-active{cursor:default;background:#fffeec;border-bottom-color:#fffeec}#plugin-information .plugin-information-pricing .fs-plan.fs-single-cycle h3{background:#fffeec;margin:0;padding-bottom:0;color:#0073aa}#plugin-information .plugin-information-pricing .fs-plan.fs-single-cycle .nav-tab-wrapper,#plugin-information .plugin-information-pricing .fs-plan.fs-single-cycle .fs-billing-frequency{display:none}#plugin-information .plugin-information-pricing .fs-plan .fs-pricing-body{background:#fffeec;padding:20px}#plugin-information .plugin-information-pricing .fs-plan .button{width:100%;text-align:center;font-weight:bold;text-transform:uppercase;font-size:1.1em}#plugin-information .plugin-information-pricing .fs-plan label{white-space:nowrap}#plugin-information .plugin-information-pricing .fs-plan var{font-style:normal}#plugin-information .plugin-information-pricing .fs-plan .fs-billing-frequency,#plugin-information .plugin-information-pricing .fs-plan .fs-annual-discount{text-align:center;display:block;font-weight:bold;margin-bottom:10px;text-transform:uppercase;background:#f3f3f3;padding:2px;border:1px solid #ccc}#plugin-information .plugin-information-pricing .fs-plan .fs-annual-discount{text-transform:none;color:green;background:#adff2f}#plugin-information .plugin-information-pricing .fs-plan ul.fs-trial-terms{font-size:.9em}#plugin-information .plugin-information-pricing .fs-plan ul.fs-trial-terms i{float:left;margin:0 0 0 -15px}#plugin-information .plugin-information-pricing .fs-plan ul.fs-trial-terms li{margin:10px 0 0 0}#plugin-information #section-features .fs-features{margin:-20px -26px}#plugin-information #section-features table{width:100%;border-spacing:0;border-collapse:separate}#plugin-information #section-features table thead th{padding:10px 0}#plugin-information #section-features table thead .fs-price{color:#71ae00;font-weight:normal;display:block;text-align:center}#plugin-information #section-features table tbody td{border-top:1px solid #ccc;padding:10px 0;text-align:center;width:100px;color:#71ae00}#plugin-information #section-features table tbody td:first-child{text-align:left;width:auto;color:inherit;padding-left:26px}#plugin-information #section-features table tbody tr.fs-odd td{background:#fefefe}#plugin-information #section-features .dashicons-yes{width:30px;height:30px;font-size:30px}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-dropdown .button-group .button,#plugin-information .fs-dropdown .button-group .button{position:relative;width:auto;top:0;right:0}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-dropdown .button-group .button:focus,#plugin-information .fs-dropdown .button-group .button:focus{z-index:10}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-dropdown .button-group .fs-dropdown-arrow,#plugin-information .fs-dropdown .button-group .fs-dropdown-arrow{border-top:6px solid #fff;border-right:4px solid transparent;border-left:4px solid transparent;top:12px;position:relative}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-dropdown.active:not(.up) .button:not(.fs-dropdown-arrow-button),#plugin-information .fs-dropdown.active:not(.up) .button:not(.fs-dropdown-arrow-button){border-bottom-left-radius:0}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-dropdown.active:not(.up) .fs-dropdown-arrow-button,#plugin-information .fs-dropdown.active:not(.up) .fs-dropdown-arrow-button{border-bottom-right-radius:0}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-dropdown.active.up .button:not(.fs-dropdown-arrow-button),#plugin-information .fs-dropdown.active.up .button:not(.fs-dropdown-arrow-button){border-top-left-radius:0}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-dropdown.active.up .fs-dropdown-arrow-button,#plugin-information .fs-dropdown.active.up .fs-dropdown-arrow-button{border-top-right-radius:0}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-dropdown .fs-dropdown-list,#plugin-information .fs-dropdown .fs-dropdown-list{position:absolute;right:-1px;top:100%;margin-left:auto;padding:3px 0;border:1px solid #bfbfbf;background-color:#fff;z-index:1;width:230px;text-align:left;-moz-box-shadow:0px 2px 4px -1px rgba(0,0,0,.2),0px 4px 5px 0px rgba(0,0,0,.14),0px 1px 10px 0px rgba(0,0,0,.12);-webkit-box-shadow:0px 2px 4px -1px rgba(0,0,0,.2),0px 4px 5px 0px rgba(0,0,0,.14),0px 1px 10px 0px rgba(0,0,0,.12);box-shadow:0px 2px 4px -1px rgba(0,0,0,.2),0px 4px 5px 0px rgba(0,0,0,.14),0px 1px 10px 0px rgba(0,0,0,.12)}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-dropdown .fs-dropdown-list li,#plugin-information .fs-dropdown .fs-dropdown-list li{margin:0}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-dropdown .fs-dropdown-list li a,#plugin-information .fs-dropdown .fs-dropdown-list li a{display:block;padding:5px 10px;text-decoration:none;text-shadow:none}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-dropdown .fs-dropdown-list li:hover,#plugin-information .fs-dropdown .fs-dropdown-list li:hover{background-color:#0074a3;color:#fff}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-dropdown .fs-dropdown-list li:hover a,#plugin-information .fs-dropdown .fs-dropdown-list li:hover a{color:#fff}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-dropdown:not(.up) .fs-dropdown-list,#plugin-information .fs-dropdown:not(.up) .fs-dropdown-list{-moz-border-radius:3px 0 3px 3px;-webkit-border-radius:3px 0 3px 3px;border-radius:3px 0 3px 3px}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-dropdown.up .fs-dropdown-list,#plugin-information .fs-dropdown.up .fs-dropdown-list{-moz-border-radius:3px 3px 0 3px;-webkit-border-radius:3px 3px 0 3px;border-radius:3px 3px 0 3px}#plugin-information .fs-dropdown .button-group{width:100%}#plugin-information .fs-dropdown .button-group .button{float:none;font-size:14px;font-weight:normal;text-transform:none}#plugin-information .fs-dropdown .fs-dropdown-list{margin-top:1px}#plugin-information .fs-dropdown.up .fs-dropdown-list{top:auto;bottom:100%;margin-bottom:2px}#plugin-information.wp-core-ui .fs-pricing-body .fs-dropdown .button-group{text-align:center;display:table}#plugin-information.wp-core-ui .fs-pricing-body .fs-dropdown .button-group .button{display:table-cell}#plugin-information.wp-core-ui .fs-pricing-body .fs-dropdown .button-group .button:not(.fs-dropdown-arrow-button){left:1px;width:100%}#plugin-information-footer>.button,#plugin-information-footer .fs-dropdown{position:relative;top:3px}#plugin-information-footer>.button.left,#plugin-information-footer .fs-dropdown.left{float:left}#plugin-information-footer>.right,#plugin-information-footer .fs-dropdown{float:right}@media screen and (max-width: 961px){#fs_addons .fs-cards-list .fs-card{height:265px}}/*# sourceMappingURL=add-ons.css.map */
 
freemius/assets/css/admin/affiliation.css DELETED
@@ -1 +0,0 @@
1
- #fs_affiliation_content_wrapper #messages{margin-top:25px}#fs_affiliation_content_wrapper h3{font-size:24px;padding:0;margin-left:0}#fs_affiliation_content_wrapper ul li{-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box;list-style-type:none}#fs_affiliation_content_wrapper ul li:before{content:"✓";margin-right:10px;font-weight:bold}#fs_affiliation_content_wrapper p:not(.description),#fs_affiliation_content_wrapper li,#fs_affiliation_content_wrapper label{font-size:16px !important;line-height:26px !important}#fs_affiliation_content_wrapper .button{margin-top:20px;margin-bottom:7px;line-height:35px;height:40px;font-size:16px}#fs_affiliation_content_wrapper .button#cancel_button{margin-right:5px}#fs_affiliation_content_wrapper form .input-container{margin-bottom:15px}#fs_affiliation_content_wrapper form .input-container .input-label{font-weight:bold;display:block;width:100%}#fs_affiliation_content_wrapper form .input-container.input-container-text label,#fs_affiliation_content_wrapper form .input-container.input-container-text input,#fs_affiliation_content_wrapper form .input-container.input-container-text textarea{display:block}#fs_affiliation_content_wrapper form .input-container #add_domain,#fs_affiliation_content_wrapper form .input-container .remove-domain{text-decoration:none;display:inline-block;margin-top:3px}#fs_affiliation_content_wrapper form .input-container #add_domain:focus,#fs_affiliation_content_wrapper form .input-container .remove-domain:focus{box-shadow:none}#fs_affiliation_content_wrapper form .input-container #add_domain.disabled,#fs_affiliation_content_wrapper form .input-container .remove-domain.disabled{color:#aaa;cursor:default}#fs_affiliation_content_wrapper form #extra_domains_container .description{margin-top:0;position:relative;top:-4px}#fs_affiliation_content_wrapper form #extra_domains_container .extra-domain-input-container{margin-bottom:15px}#fs_affiliation_content_wrapper form #extra_domains_container .extra-domain-input-container .domain{display:inline-block;margin-right:5px}#fs_affiliation_content_wrapper form #extra_domains_container .extra-domain-input-container .domain:last-of-type{margin-bottom:0}/*# sourceMappingURL=affiliation.css.map */
 
freemius/assets/css/admin/checkout.css DELETED
@@ -1 +0,0 @@
1
- @media screen and (max-width: 782px){#wpbody-content{padding-bottom:0 !important}}/*# sourceMappingURL=checkout.css.map */
 
freemius/assets/css/admin/clone-resolution.css DELETED
@@ -1 +0,0 @@
1
- .fs-notice[data-id^=clone_resolution_options_notice]{padding:0;color:inherit !important}.fs-notice[data-id^=clone_resolution_options_notice] .fs-notice-body{padding:0;margin-bottom:0}.fs-notice[data-id^=clone_resolution_options_notice] .fs-notice-header{padding:5px 10px}.fs-notice[data-id^=clone_resolution_options_notice] ol{margin-top:0;margin-bottom:0}.fs-notice[data-id^=clone_resolution_options_notice] .fs-clone-resolution-options-container{display:flex;flex-direction:row;padding:0 10px 10px}@media(max-width: 750px){.fs-notice[data-id^=clone_resolution_options_notice] .fs-clone-resolution-options-container{flex-direction:column}}.fs-notice[data-id^=clone_resolution_options_notice] .fs-clone-resolution-option{border:1px solid #ccc;padding:10px 10px 15px 10px;flex:auto;margin:5px}.fs-notice[data-id^=clone_resolution_options_notice] .fs-clone-resolution-option:first-child{margin-left:0}.fs-notice[data-id^=clone_resolution_options_notice] .fs-clone-resolution-option:last-child{margin-right:0}.fs-notice[data-id^=clone_resolution_options_notice] .fs-clone-resolution-option strong{font-size:1.2em;padding:2px;line-height:1.5em}.fs-notice[data-id^=clone_resolution_options_notice] a{text-decoration:none}.fs-notice[data-id^=clone_resolution_options_notice] .button{margin-right:10px}.rtl .fs-notice[data-id^=clone_resolution_options_notice] .button{margin-right:0;margin-left:10px}.fs-notice[data-id^=clone_resolution_options_notice] .fs-clone-documentation-container{padding:0 10px 15px}.fs-notice[data-id=temporary_duplicate_notice] #fs_clone_resolution_error_message{border:1px solid #d3135a;background:#fee;color:#d3135a;padding:10px}.fs-notice[data-id=temporary_duplicate_notice] ol{margin-top:0}/*# sourceMappingURL=clone-resolution.css.map */
 
freemius/assets/css/admin/common.css DELETED
@@ -1 +0,0 @@
1
- .fs-badge{position:absolute;top:10px;right:0;background:#71ae00;color:#fff;text-transform:uppercase;padding:5px 10px;-moz-border-radius:3px 0 0 3px;-webkit-border-radius:3px 0 0 3px;border-radius:3px 0 0 3px;font-weight:bold;border-right:0;-moz-box-shadow:0 2px 1px -1px rgba(0,0,0,.3);-webkit-box-shadow:0 2px 1px -1px rgba(0,0,0,.3);box-shadow:0 2px 1px -1px rgba(0,0,0,.3)}.theme-browser .theme .fs-premium-theme-badge-container{position:absolute;right:0;top:0}.theme-browser .theme .fs-premium-theme-badge-container .fs-badge{position:relative;top:0;margin-top:10px;text-align:center}.theme-browser .theme .fs-premium-theme-badge-container .fs-badge.fs-premium-theme-badge{font-size:1.1em}.theme-browser .theme .fs-premium-theme-badge-container .fs-badge.fs-beta-theme-badge{background:#00a0d2}.fs-switch{position:relative;display:inline-block;color:#ccc;text-shadow:0 1px 1px rgba(255,255,255,.8);height:18px;padding:6px 6px 5px 6px;border:1px solid #ccc;border:1px solid rgba(0,0,0,.2);background:#ececec;box-shadow:0 0 4px rgba(0,0,0,.1),inset 0 1px 3px 0 rgba(0,0,0,.1);cursor:pointer}.fs-switch span{display:inline-block;width:35px;text-transform:uppercase}.fs-switch .fs-toggle{position:absolute;top:1px;width:37px;height:25px;border:1px solid #ccc;border:1px solid rgba(0,0,0,.3);border-radius:4px;background:#fff;background-color:#fff;background-image:-webkit-gradient(linear, left top, left bottom, color-stop(0, #ececec), color-stop(1, #fff));background-image:-webkit-linear-gradient(top, #ececec, #fff);background-image:-moz-linear-gradient(top, #ececec, #fff);background-image:-ms-linear-gradient(top, #ececec, #fff);background-image:-o-linear-gradient(top, #ececec, #fff);background-image:linear-gradient(top, bottom, #ececec, #fff);box-shadow:inset 0 1px 0 0 rgba(255,255,255,.5);z-index:999;-moz-transition:.4s cubic-bezier(0.54, 1.6, 0.5, 1);-o-transition:.4s cubic-bezier(0.54, 1.6, 0.5, 1);-ms-transition:.4s cubic-bezier(0.54, 1.6, 0.5, 1);-webkit-transition:.4s cubic-bezier(0.54, 1.6, 0.5, 1);transition:.4s cubic-bezier(0.54, 1.6, 0.5, 1)}.fs-switch.fs-off .fs-toggle{left:2%}.fs-switch.fs-on .fs-toggle{left:54%}.fs-switch.fs-round{top:8px;padding:4px 25px;-moz-border-radius:24px;-webkit-border-radius:24px;border-radius:24px}.fs-switch.fs-round .fs-toggle{top:0;width:24px;height:24px;-moz-border-radius:24px;-webkit-border-radius:24px;border-radius:24px}.fs-switch.fs-round.fs-off .fs-toggle{left:-1px}.fs-switch.fs-round.fs-on{background:#0085ba}.fs-switch.fs-round.fs-on .fs-toggle{left:25px}.fs-switch.fs-small.fs-round{padding:1px 19px}.fs-switch.fs-small.fs-round .fs-toggle{top:0;width:18px;height:18px;-moz-border-radius:18px;-webkit-border-radius:18px;border-radius:18px}.fs-switch.fs-small.fs-round.fs-on .fs-toggle{left:19px}.fs-switch-feedback{margin-left:10px}.fs-switch-feedback.success{color:#71ae00}.rtl .fs-switch-feedback{margin-left:0;margin-right:10px}#fs_frame{line-height:0;font-size:0}.fs-full-size-wrapper{margin:40px 0 -65px -20px}@media(max-width: 600px){.fs-full-size-wrapper{margin:0 0 -65px -10px}}.fs-notice{position:relative}.fs-notice.fs-has-title{margin-bottom:30px !important}.fs-notice.success{color:green}.fs-notice.promotion{border-color:#00a0d2 !important;background-color:#f2fcff !important}.fs-notice .fs-notice-body{margin:.5em 0;padding:2px}.fs-notice .fs-close{cursor:pointer;color:#aaa;float:right}.fs-notice .fs-close:hover{color:#666}.fs-notice .fs-close>*{margin-top:7px;display:inline-block}.fs-notice label.fs-plugin-title{background:rgba(0,0,0,.3);color:#fff;padding:2px 10px;position:absolute;top:100%;bottom:auto;right:auto;-moz-border-radius:0 0 3px 3px;-webkit-border-radius:0 0 3px 3px;border-radius:0 0 3px 3px;left:10px;font-size:12px;font-weight:bold;cursor:auto}div.fs-notice.updated,div.fs-notice.success,div.fs-notice.promotion{display:block !important}.rtl .fs-notice .fs-close{float:left}.fs-secure-notice{position:fixed;top:32px;left:160px;right:0;background:#ebfdeb;padding:10px 20px;color:green;z-index:9999;-moz-box-shadow:0 2px 2px rgba(6,113,6,.3);-webkit-box-shadow:0 2px 2px rgba(6,113,6,.3);box-shadow:0 2px 2px rgba(6,113,6,.3);opacity:.95;filter:alpha(opacity=95)}.fs-secure-notice:hover{opacity:1;filter:alpha(opacity=100)}.fs-secure-notice a.fs-security-proof{color:green;text-decoration:none}@media screen and (max-width: 960px){.fs-secure-notice{left:36px}}@media screen and (max-width: 600px){.fs-secure-notice{display:none}}@media screen and (max-width: 1250px){#fs_promo_tab{display:none}}@media screen and (max-width: 782px){.fs-secure-notice{left:0;top:46px;text-align:center}}span.fs-submenu-item.fs-sub:before{content:"↳";padding:0 5px}.rtl span.fs-submenu-item.fs-sub:before{content:"↲"}.fs-submenu-item.pricing.upgrade-mode{color:#adff2f}.fs-submenu-item.pricing.trial-mode{color:#83e2ff}#adminmenu .update-plugins.fs-trial{background-color:#00b9eb}.fs-ajax-spinner{border:0;width:20px;height:20px;margin-right:5px;vertical-align:sub;display:inline-block;background:url("/wp-admin/images/wpspin_light-2x.gif");background-size:contain;margin-bottom:-2px}.wrap.fs-section h2{text-align:left}.plugins p.fs-upgrade-notice{border:0;background-color:#d54e21;padding:10px;color:#f9f9f9;margin-top:10px}/*# sourceMappingURL=common.css.map */
 
freemius/assets/css/admin/connect.css DELETED
@@ -1 +0,0 @@
1
- #fs_connect{width:480px;-moz-box-shadow:0px 1px 2px rgba(0,0,0,.3);-webkit-box-shadow:0px 1px 2px rgba(0,0,0,.3);box-shadow:0px 1px 2px rgba(0,0,0,.3);margin:20px 0}@media screen and (max-width: 479px){#fs_connect{-moz-box-shadow:none;-webkit-box-shadow:none;box-shadow:none;width:auto;margin:0 0 0 -10px}}#fs_connect .fs-content{background:#fff;padding:15px 20px}#fs_connect .fs-content .fs-error{background:snow;color:#d3135a;border:1px solid #d3135a;-moz-box-shadow:0 1px 1px 0 rgba(0,0,0,.1);-webkit-box-shadow:0 1px 1px 0 rgba(0,0,0,.1);box-shadow:0 1px 1px 0 rgba(0,0,0,.1);text-align:center;padding:5px;margin-bottom:10px}#fs_connect .fs-content p{margin:0;padding:0;font-size:1.2em}#fs_connect .fs-license-key-container{position:relative;width:280px;margin:10px auto 0 auto}#fs_connect .fs-license-key-container input{width:100%}#fs_connect .fs-license-key-container .dashicons{position:absolute;top:5px;right:5px}#fs_connect.require-license-key .fs-sites-list-container td{cursor:pointer}#fs_connect #delegate_to_site_admins{margin-right:15px;float:right;height:26px;vertical-align:middle;line-height:37px;font-weight:bold;border-bottom:1px dashed;text-decoration:none}#fs_connect #delegate_to_site_admins.rtl{margin-left:15px;margin-right:0}#fs_connect .fs-actions{padding:10px 20px;background:#c0c7ca}#fs_connect .fs-actions .button{padding:0 10px 1px;line-height:35px;height:37px;font-size:16px;margin-bottom:0}#fs_connect .fs-actions .button .dashicons{font-size:37px;margin-left:-8px;margin-right:12px}#fs_connect .fs-actions .button.button-primary{padding-right:15px;padding-left:15px}#fs_connect .fs-actions .button.button-primary:after{content:" ➜"}#fs_connect .fs-actions .button.button-primary.fs-loading:after{content:""}#fs_connect .fs-actions .button.button-secondary{float:right}#fs_connect.fs-anonymous-disabled .fs-actions .button.button-primary{width:100%}#fs_connect .fs-permissions{padding:10px 20px;background:#fefefe;-moz-transition:background .5s ease;-o-transition:background .5s ease;-ms-transition:background .5s ease;-webkit-transition:background .5s ease;transition:background .5s ease}#fs_connect .fs-permissions .fs-license-sync-disclaimer{text-align:center;margin-top:0}#fs_connect .fs-permissions>.fs-trigger{font-size:.9em;text-decoration:none;text-align:center;display:block}#fs_connect .fs-permissions ul{height:0;overflow:hidden;margin:0}#fs_connect .fs-permissions ul li{margin-bottom:12px}#fs_connect .fs-permissions ul li:last-child{margin-bottom:0}#fs_connect .fs-permissions ul li>i.dashicons{float:left;font-size:40px;width:40px;height:40px}#fs_connect .fs-permissions ul li .fs-switch{float:right}#fs_connect .fs-permissions ul li .fs-permission-description{margin-left:55px}#fs_connect .fs-permissions ul li .fs-permission-description span{font-weight:bold;text-transform:uppercase;color:#23282d}#fs_connect .fs-permissions ul li .fs-permission-description p{margin:2px 0 0 0}#fs_connect .fs-permissions.fs-open{background:#fff}#fs_connect .fs-permissions.fs-open ul{overflow:initial;height:auto;margin:20px 20px 10px 20px}@media screen and (max-width: 479px){#fs_connect .fs-permissions{background:#fff}#fs_connect .fs-permissions .fs-trigger{display:none}#fs_connect .fs-permissions ul{height:auto;margin:20px}}#fs_connect .fs-freemium-licensing{padding:8px;background:#777;color:#fff}#fs_connect .fs-freemium-licensing p{text-align:center;display:block;margin:0;padding:0}#fs_connect .fs-freemium-licensing a{color:#c2eeff;text-decoration:underline}#fs_connect .fs-visual{padding:12px;line-height:0;background:#fafafa;height:80px;position:relative}#fs_connect .fs-visual .fs-site-icon{position:absolute;left:20px;top:10px}#fs_connect .fs-visual .fs-connect-logo{position:absolute;right:20px;top:10px}#fs_connect .fs-visual .fs-plugin-icon{position:absolute;top:10px;left:50%;margin-left:-40px}#fs_connect .fs-visual .fs-plugin-icon,#fs_connect .fs-visual .fs-site-icon,#fs_connect .fs-visual img,#fs_connect .fs-visual object{width:80px;height:80px}#fs_connect .fs-visual .dashicons-wordpress{font-size:64px;background:#01749a;color:#fff;width:64px;height:64px;padding:8px}#fs_connect .fs-visual .dashicons-plus{position:absolute;top:50%;font-size:30px;margin-top:-10px;color:#bbb}#fs_connect .fs-visual .dashicons-plus.fs-first{left:28%}#fs_connect .fs-visual .dashicons-plus.fs-second{left:65%}#fs_connect .fs-visual .fs-plugin-icon,#fs_connect .fs-visual .fs-connect-logo,#fs_connect .fs-visual .fs-site-icon{border:1px solid #ccc;padding:1px;background:#fff}#fs_connect .fs-terms{text-align:center;font-size:.85em;padding:5px;background:rgba(0,0,0,.05)}#fs_connect .fs-terms,#fs_connect .fs-terms a{color:#999}#fs_connect .fs-terms a{text-decoration:none}.fs-multisite-options-container{margin-top:10px;border:1px solid #ccc;padding:5px}.fs-multisite-options-container a{text-decoration:none}.fs-multisite-options-container a:focus{box-shadow:none}.fs-multisite-options-container a.selected{font-weight:bold}.fs-multisite-options-container.fs-apply-on-all-sites{border:0 none;padding:0}.fs-multisite-options-container.fs-apply-on-all-sites .fs-all-sites-options{border-spacing:0}.fs-multisite-options-container.fs-apply-on-all-sites .fs-all-sites-options td:not(:first-child){display:none}.fs-multisite-options-container .fs-sites-list-container{display:none;overflow:auto}.fs-multisite-options-container .fs-sites-list-container table td{border-top:1px solid #ccc;padding:4px 2px}.fs-tooltip-trigger{position:relative}.fs-tooltip-trigger:not(a){cursor:help}.fs-tooltip-trigger .fs-tooltip{opacity:0;visibility:hidden;-moz-transition:opacity .3s ease-in-out;-o-transition:opacity .3s ease-in-out;-ms-transition:opacity .3s ease-in-out;-webkit-transition:opacity .3s ease-in-out;transition:opacity .3s ease-in-out;position:absolute;background:rgba(0,0,0,.8);color:#fff !important;font-family:"arial",serif;font-size:12px;padding:10px;z-index:999999;bottom:100%;margin-bottom:5px;left:-17px;right:0;-moz-border-radius:5px;-webkit-border-radius:5px;border-radius:5px;-moz-box-shadow:1px 1px 1px rgba(0,0,0,.2);-webkit-box-shadow:1px 1px 1px rgba(0,0,0,.2);box-shadow:1px 1px 1px rgba(0,0,0,.2);line-height:1.3em;font-weight:bold;text-align:left;text-transform:none !important}.rtl .fs-tooltip-trigger .fs-tooltip{text-align:right;left:auto;right:-17px}.fs-tooltip-trigger .fs-tooltip::after{content:" ";display:block;width:0;height:0;border-style:solid;border-width:5px 5px 0 5px;border-color:rgba(0,0,0,.8) transparent transparent transparent;position:absolute;top:100%;left:21px}.rtl .fs-tooltip-trigger .fs-tooltip::after{right:21px;left:auto}.fs-tooltip-trigger:hover .fs-tooltip{visibility:visible;opacity:1}#fs_marketing_optin{display:none;margin-top:10px;border:1px solid #ccc;padding:10px;line-height:1.5em}#fs_marketing_optin .fs-message{display:block;margin-bottom:5px;font-size:1.05em;font-weight:600}#fs_marketing_optin.error{border:1px solid #d3135a;background:#fee}#fs_marketing_optin.error .fs-message{color:#d3135a}#fs_marketing_optin .fs-input-container{margin-top:5px}#fs_marketing_optin .fs-input-container label{margin-top:5px;display:block}#fs_marketing_optin .fs-input-container label input{float:left;margin:1px 0 0 0}#fs_marketing_optin .fs-input-container label:first-child{display:block;margin-bottom:2px}#fs_marketing_optin .fs-input-label{display:block;margin-left:20px}#fs_marketing_optin .fs-input-label .underlined{text-decoration:underline}.rtl #fs_marketing_optin .fs-input-container label input{float:right}.rtl #fs_marketing_optin .fs-input-label{margin-left:0;margin-right:20px}.rtl #fs_connect .fs-actions{padding:10px 20px;background:#c0c7ca}.rtl #fs_connect .fs-actions .button .dashicons{font-size:37px;margin-left:-8px;margin-right:12px}.rtl #fs_connect .fs-actions .button.button-primary:after{content:" »"}.rtl #fs_connect .fs-actions .button.button-primary.fs-loading:after{content:""}.rtl #fs_connect .fs-actions .button.button-secondary{float:left}.rtl #fs_connect .fs-permissions ul li .fs-permission-description{margin-right:55px;margin-left:0}.rtl #fs_connect .fs-permissions ul li .fs-switch{float:left}.rtl #fs_connect .fs-permissions ul li i.dashicons{float:right}.rtl #fs_connect .fs-visual .fs-site-icon{right:20px;left:auto}.rtl #fs_connect .fs-visual .fs-connect-logo{right:auto;left:20px}#fs_theme_connect_wrapper{position:fixed;top:0;height:100%;width:100%;z-index:99990;background:rgba(0,0,0,.75);text-align:center;overflow-y:auto}#fs_theme_connect_wrapper:before{content:"";display:inline-block;vertical-align:middle;height:100%}#fs_theme_connect_wrapper>button.close{color:#fff;cursor:pointer;height:40px;width:40px;position:absolute;right:0;border:0;background-color:transparent;top:32px}#fs_theme_connect_wrapper #fs_connect{top:0;text-align:left;display:inline-block;vertical-align:middle;margin-top:52px;margin-bottom:20px}#fs_theme_connect_wrapper #fs_connect .fs-terms{background:rgba(140,140,140,.64)}#fs_theme_connect_wrapper #fs_connect .fs-terms,#fs_theme_connect_wrapper #fs_connect .fs-terms a{color:#c5c5c5}.wp-pointer-content #fs_connect{margin:0;-moz-box-shadow:none;-webkit-box-shadow:none;box-shadow:none}.fs-opt-in-pointer .wp-pointer-content{padding:0}.fs-opt-in-pointer.wp-pointer-top .wp-pointer-arrow{border-bottom-color:#dfdfdf}.fs-opt-in-pointer.wp-pointer-top .wp-pointer-arrow-inner{border-bottom-color:#fafafa}.fs-opt-in-pointer.wp-pointer-bottom .wp-pointer-arrow{border-top-color:#dfdfdf}.fs-opt-in-pointer.wp-pointer-bottom .wp-pointer-arrow-inner{border-top-color:#fafafa}.fs-opt-in-pointer.wp-pointer-left .wp-pointer-arrow{border-right-color:#dfdfdf}.fs-opt-in-pointer.wp-pointer-left .wp-pointer-arrow-inner{border-right-color:#fafafa}.fs-opt-in-pointer.wp-pointer-right .wp-pointer-arrow{border-left-color:#dfdfdf}.fs-opt-in-pointer.wp-pointer-right .wp-pointer-arrow-inner{border-left-color:#fafafa}#license_issues_link{display:block;text-align:center;font-size:.9em;margin-top:10px}/*# sourceMappingURL=connect.css.map */
 
freemius/assets/css/admin/debug.css DELETED
@@ -1 +0,0 @@
1
- .fs-switch-label{font-size:20px;line-height:31px;margin:0 5px}#fs_log_book table{font-family:Consolas,Monaco,monospace;font-size:12px}#fs_log_book table th{color:#ccc}#fs_log_book table tr{background:#232525}#fs_log_book table tr.alternate{background:#2b2b2b}#fs_log_book table tr td.fs-col--logger{color:#5a7435}#fs_log_book table tr td.fs-col--type{color:#ffc861}#fs_log_book table tr td.fs-col--function{color:#a7b7b1;font-weight:bold}#fs_log_book table tr td.fs-col--message,#fs_log_book table tr td.fs-col--message a{color:#9a73ac !important}#fs_log_book table tr td.fs-col--file{color:#d07922}#fs_log_book table tr td.fs-col--timestamp{color:#6596be}/*# sourceMappingURL=debug.css.map */
 
freemius/assets/css/admin/dialog-boxes.css DELETED
@@ -1 +0,0 @@
1
- .fs-modal{position:fixed;overflow:auto;height:100%;width:100%;top:0;z-index:100000;display:none;background:rgba(0,0,0,.6)}.fs-modal .dashicons{vertical-align:middle}.fs-modal .fs-modal-dialog{background:transparent;position:absolute;left:50%;margin-left:-298px;padding-bottom:30px;top:-100%;z-index:100001;width:596px}@media(max-width: 650px){.fs-modal .fs-modal-dialog{margin-left:-50%;box-sizing:border-box;padding-left:10px;padding-right:10px;width:100%}.fs-modal .fs-modal-dialog .fs-modal-panel>h3>strong{font-size:1.3em}}.fs-modal.active{display:block}.fs-modal.active:before{display:block}.fs-modal.active .fs-modal-dialog{top:10%}.fs-modal.fs-success .fs-modal-header{border-bottom-color:#46b450}.fs-modal.fs-success .fs-modal-body{background-color:#f7fff7}.fs-modal.fs-warn .fs-modal-header{border-bottom-color:#ffb900}.fs-modal.fs-warn .fs-modal-body{background-color:#fff8e5}.fs-modal.fs-error .fs-modal-header{border-bottom-color:#dc3232}.fs-modal.fs-error .fs-modal-body{background-color:#ffeaea}.fs-modal .fs-modal-body,.fs-modal .fs-modal-footer{border:0;background:#fefefe;padding:20px}.fs-modal .fs-modal-header{border-bottom:#eee solid 1px;background:#fbfbfb;padding:15px 20px;position:relative;margin-bottom:-10px}.fs-modal .fs-modal-header h4{margin:0;padding:0;text-transform:uppercase;font-size:1.2em;font-weight:bold;color:#cacaca;text-shadow:1px 1px 1px #fff;letter-spacing:.6px;-webkit-font-smoothing:antialiased}.fs-modal .fs-modal-header .fs-close{position:absolute;right:10px;top:12px;cursor:pointer;color:#bbb;-moz-border-radius:20px;-webkit-border-radius:20px;border-radius:20px;padding:3px;-moz-transition:all .2s ease-in-out;-o-transition:all .2s ease-in-out;-ms-transition:all .2s ease-in-out;-webkit-transition:all .2s ease-in-out;transition:all .2s ease-in-out}.fs-modal .fs-modal-header .fs-close:hover{color:#fff;background:#aaa}.fs-modal .fs-modal-header .fs-close .dashicons,.fs-modal .fs-modal-header .fs-close:hover .dashicons{text-decoration:none}.fs-modal .fs-modal-body{border-bottom:0}.fs-modal .fs-modal-body p{font-size:14px}.fs-modal .fs-modal-body h2{font-size:20px;line-height:1.5em}.fs-modal .fs-modal-body>div{margin-top:10px}.fs-modal .fs-modal-body>div h2{font-weight:bold;font-size:20px;margin-top:0}.fs-modal .fs-modal-footer{border-top:#eee solid 1px;text-align:right}.fs-modal .fs-modal-footer>.button{margin:0 7px}.fs-modal .fs-modal-footer>.button:last-of-type{margin:0}.fs-modal .fs-modal-panel>.notice.inline{margin:0;display:none}.fs-modal .fs-modal-panel:not(.active){display:none}.rtl .fs-modal .fs-modal-header .fs-close{right:auto;left:20px}.rtl .fs-modal .fs-modal-footer{text-align:left}body.has-fs-modal{overflow:hidden}.fs-modal.fs-modal-deactivation-feedback .reason-input,.fs-modal.fs-modal-deactivation-feedback .internal-message{margin:3px 0 3px 22px}.fs-modal.fs-modal-deactivation-feedback .reason-input input,.fs-modal.fs-modal-deactivation-feedback .reason-input textarea,.fs-modal.fs-modal-deactivation-feedback .internal-message input,.fs-modal.fs-modal-deactivation-feedback .internal-message textarea{width:100%}.fs-modal.fs-modal-deactivation-feedback li.reason.has-internal-message .internal-message{border:1px solid #ccc;padding:7px;display:none}@media(max-width: 650px){.fs-modal.fs-modal-deactivation-feedback li.reason li.reason{margin-bottom:10px}.fs-modal.fs-modal-deactivation-feedback li.reason li.reason .reason-input,.fs-modal.fs-modal-deactivation-feedback li.reason li.reason .internal-message{margin-left:29px}.fs-modal.fs-modal-deactivation-feedback li.reason li.reason label{display:table}.fs-modal.fs-modal-deactivation-feedback li.reason li.reason label>span{display:table-cell;font-size:1.3em}}.fs-modal.fs-modal-deactivation-feedback .anonymous-feedback-label,.fs-modal.fs-modal-deactivation-feedback .feedback-from-snooze-label{float:left;line-height:30px}.rtl .fs-modal.fs-modal-deactivation-feedback .anonymous-feedback-label,.rtl .fs-modal.fs-modal-deactivation-feedback .feedback-from-snooze-label{float:right}.fs-modal.fs-modal-deactivation-feedback .fs-modal-panel{margin-top:0 !important}.fs-modal.fs-modal-deactivation-feedback .fs-modal-panel h3{margin-top:0;line-height:1.5em}#the-list .deactivate>.fs-slug{display:none}.fs-modal.fs-modal-subscription-cancellation .fs-price-increase-warning{color:red;font-weight:bold;padding:0 25px;margin-bottom:0}.fs-modal.fs-modal-subscription-cancellation ul.subscription-actions label input{float:left;top:5px;position:relative}.rtl .fs-modal.fs-modal-subscription-cancellation ul.subscription-actions label input{float:right}.fs-modal.fs-modal-subscription-cancellation ul.subscription-actions label span{display:block;margin-left:24px}.rtl .fs-modal.fs-modal-subscription-cancellation ul.subscription-actions label span{margin-left:0;margin-right:24px}.fs-modal.fs-modal-license-activation .fs-modal-body input.fs-license-key{width:100%}.fs-license-options-container table,.fs-license-options-container table select,.fs-license-options-container table .fs-available-license-key{width:100%}.fs-license-options-container table td:first-child{width:1%}.fs-license-options-container table .fs-other-license-key-container label{position:relative;top:6px;float:left;margin-right:5px}.fs-license-options-container table .fs-other-license-key-container div{overflow:hidden;width:auto;height:30px;display:block;top:2px;position:relative}.fs-license-options-container table .fs-other-license-key-container div input{margin:0}.fs-sites-list-container td{cursor:pointer}.fs-modal.fs-modal-user-change .fs-modal-body input#fs_other_email_address{width:100%}.fs-user-change-options-container table{width:100%;border-collapse:collapse}.fs-user-change-options-container table tr{display:block;margin-bottom:2px}.fs-user-change-options-container table .fs-email-address-container td{display:inline-block}.fs-user-change-options-container table .fs-email-address-container input[type=radio]{margin-bottom:0;margin-top:0}.fs-user-change-options-container table .fs-other-email-address-container{width:100%}.fs-user-change-options-container table .fs-other-email-address-container>div{display:table;width:100%}.fs-user-change-options-container table .fs-other-email-address-container>div label,.fs-user-change-options-container table .fs-other-email-address-container>div>div{display:table-cell}.fs-user-change-options-container table .fs-other-email-address-container>div label{width:1%;padding-left:3px;padding-right:3px}.fs-user-change-options-container table .fs-other-email-address-container>div>div{width:auto}.fs-user-change-options-container table .fs-other-email-address-container>div>div input{width:100%}.fs-modal.fs-modal-developer-license-debug-mode .fs-modal-body input.fs-license-or-user-key{width:100%}.fs-multisite-options-container{margin-top:10px;border:1px solid #ccc;padding:5px}.fs-multisite-options-container a{text-decoration:none}.fs-multisite-options-container a:focus{box-shadow:none}.fs-multisite-options-container a.selected{font-weight:bold}.fs-multisite-options-container.fs-apply-on-all-sites{border:0 none;padding:0}.fs-multisite-options-container.fs-apply-on-all-sites .fs-all-sites-options{border-spacing:0}.fs-multisite-options-container.fs-apply-on-all-sites .fs-all-sites-options td:not(:first-child){display:none}.fs-multisite-options-container .fs-sites-list-container{display:none;overflow:auto}.fs-multisite-options-container .fs-sites-list-container table td{border-top:1px solid #ccc;padding:4px 2px}.fs-modal.fs-modal-license-key-resend .email-address-container{overflow:hidden;padding-right:2px}.fs-modal.fs-modal-license-key-resend.fs-freemium input.email-address{width:300px}.fs-modal.fs-modal-license-key-resend.fs-freemium label{display:block;margin-bottom:10px}.fs-modal.fs-modal-license-key-resend.fs-premium input.email-address{width:100%}.fs-modal.fs-modal-license-key-resend.fs-premium .button-container{float:right;margin-left:7px}@media(max-width: 650px){.fs-modal.fs-modal-license-key-resend.fs-premium .button-container{margin-top:2px}}.rtl .fs-modal.fs-modal-license-key-resend .fs-modal-body .input-container>.email-address-container{padding-left:2px;padding-right:0}.rtl .fs-modal.fs-modal-license-key-resend .fs-modal-body .button-container{float:left;margin-right:7px;margin-left:0}a.show-license-resend-modal{margin-top:4px;display:inline-block}.fs-modal.fs-modal-email-address-update .fs-modal-body input[type=text]{width:100%}.fs-modal.fs-modal-email-address-update p{margin-bottom:0}.fs-modal.fs-modal-email-address-update ul{margin:1em .5em}.fs-modal.fs-modal-email-address-update ul li label span{float:left;margin-top:0}.fs-modal.fs-modal-email-address-update ul li label span:last-child{display:block;float:none;margin-left:20px}.fs-ajax-loader{position:relative;width:170px;height:20px;margin:auto}.fs-ajax-loader .fs-ajax-loader-bar{position:absolute;top:0;background-color:#0074a3;width:20px;height:20px;-webkit-animation-name:bounce_ajaxLoader;-moz-animation-name:bounce_ajaxLoader;-ms-animation-name:bounce_ajaxLoader;-o-animation-name:bounce_ajaxLoader;animation-name:bounce_ajaxLoader;-webkit-animation-duration:1.5s;-moz-animation-duration:1.5s;-ms-animation-duration:1.5s;-o-animation-duration:1.5s;animation-duration:1.5s;animation-iteration-count:infinite;-o-animation-iteration-count:infinite;-ms-animation-iteration-count:infinite;-webkit-animation-iteration-count:infinite;-moz-animation-iteration-count:infinite;-webkit-animation-direction:normal;-moz-animation-direction:normal;-ms-animation-direction:normal;-o-animation-direction:normal;animation-direction:normal;-moz-transform:.3;-o-transform:.3;-ms-transform:.3;-webkit-transform:.3;transform:.3}.fs-ajax-loader .fs-ajax-loader-bar-1{left:0px;animation-delay:0.6s;-o-animation-delay:0.6s;-ms-animation-delay:0.6s;-webkit-animation-delay:0.6s;-moz-animation-delay:0.6s}.fs-ajax-loader .fs-ajax-loader-bar-2{left:19px;animation-delay:0.75s;-o-animation-delay:0.75s;-ms-animation-delay:0.75s;-webkit-animation-delay:0.75s;-moz-animation-delay:0.75s}.fs-ajax-loader .fs-ajax-loader-bar-3{left:38px;animation-delay:0.9s;-o-animation-delay:0.9s;-ms-animation-delay:0.9s;-webkit-animation-delay:0.9s;-moz-animation-delay:0.9s}.fs-ajax-loader .fs-ajax-loader-bar-4{left:57px;animation-delay:1.05s;-o-animation-delay:1.05s;-ms-animation-delay:1.05s;-webkit-animation-delay:1.05s;-moz-animation-delay:1.05s}.fs-ajax-loader .fs-ajax-loader-bar-5{left:76px;animation-delay:1.2s;-o-animation-delay:1.2s;-ms-animation-delay:1.2s;-webkit-animation-delay:1.2s;-moz-animation-delay:1.2s}.fs-ajax-loader .fs-ajax-loader-bar-6{left:95px;animation-delay:1.35s;-o-animation-delay:1.35s;-ms-animation-delay:1.35s;-webkit-animation-delay:1.35s;-moz-animation-delay:1.35s}.fs-ajax-loader .fs-ajax-loader-bar-7{left:114px;animation-delay:1.5s;-o-animation-delay:1.5s;-ms-animation-delay:1.5s;-webkit-animation-delay:1.5s;-moz-animation-delay:1.5s}.fs-ajax-loader .fs-ajax-loader-bar-8{left:133px;animation-delay:1.65s;-o-animation-delay:1.65s;-ms-animation-delay:1.65s;-webkit-animation-delay:1.65s;-moz-animation-delay:1.65s}@-moz-keyframes bounce_ajaxLoader{0%{-moz-transform:scale(1);-o-transform:scale(1);-ms-transform:scale(1);-webkit-transform:scale(1);transform:scale(1);background-color:#0074a3}100%{-moz-transform:scale(0.3);-o-transform:scale(0.3);-ms-transform:scale(0.3);-webkit-transform:scale(0.3);transform:scale(0.3);background-color:#fff}}@-ms-keyframes bounce_ajaxLoader{0%{-moz-transform:scale(1);-o-transform:scale(1);-ms-transform:scale(1);-webkit-transform:scale(1);transform:scale(1);background-color:#0074a3}100%{-moz-transform:scale(0.3);-o-transform:scale(0.3);-ms-transform:scale(0.3);-webkit-transform:scale(0.3);transform:scale(0.3);background-color:#fff}}@-o-keyframes bounce_ajaxLoader{0%{-moz-transform:scale(1);-o-transform:scale(1);-ms-transform:scale(1);-webkit-transform:scale(1);transform:scale(1);background-color:#0074a3}100%{-moz-transform:scale(0.3);-o-transform:scale(0.3);-ms-transform:scale(0.3);-webkit-transform:scale(0.3);transform:scale(0.3);background-color:#fff}}@-webkit-keyframes bounce_ajaxLoader{0%{-moz-transform:scale(1);-o-transform:scale(1);-ms-transform:scale(1);-webkit-transform:scale(1);transform:scale(1);background-color:#0074a3}100%{-moz-transform:scale(0.3);-o-transform:scale(0.3);-ms-transform:scale(0.3);-webkit-transform:scale(0.3);transform:scale(0.3);background-color:#fff}}@keyframes bounce_ajaxLoader{0%{-moz-transform:scale(1);-o-transform:scale(1);-ms-transform:scale(1);-webkit-transform:scale(1);transform:scale(1);background-color:#0074a3}100%{-moz-transform:scale(0.3);-o-transform:scale(0.3);-ms-transform:scale(0.3);-webkit-transform:scale(0.3);transform:scale(0.3);background-color:#fff}}.fs-modal-auto-install #request-filesystem-credentials-form h2,.fs-modal-auto-install #request-filesystem-credentials-form .request-filesystem-credentials-action-buttons{display:none}.fs-modal-auto-install #request-filesystem-credentials-form input[type=password],.fs-modal-auto-install #request-filesystem-credentials-form input[type=email],.fs-modal-auto-install #request-filesystem-credentials-form input[type=text]{-webkit-appearance:none;padding:10px 10px 5px 10px;width:300px;max-width:100%}.fs-modal-auto-install #request-filesystem-credentials-form>div,.fs-modal-auto-install #request-filesystem-credentials-form label,.fs-modal-auto-install #request-filesystem-credentials-form fieldset{width:300px;max-width:100%;margin:0 auto;display:block}.button-primary.warn{box-shadow:0 1px 0 #d2593c;text-shadow:0 -1px 1px #d2593c,1px 0 1px #d2593c,0 1px 1px #d2593c,-1px 0 1px #d2593c;background:#f56a48;border-color:#ec6544 #d2593c #d2593c}.button-primary.warn:hover{background:#fd6d4a;border-color:#d2593c}.button-primary.warn:focus{box-shadow:0 1px 0 #dd6041,0 0 2px 1px #e4a796}.button-primary.warn:active{background:#dd6041;border-color:#d2593c;box-shadow:inset 0 2px 0 #d2593c}.button-primary.warn.disabled{color:#f5b3a1 !important;background:#e76444 !important;border-color:#d85e40 !important;text-shadow:0 -1px 0 rgba(0,0,0,.1) !important}/*# sourceMappingURL=dialog-boxes.css.map */
 
freemius/assets/css/admin/gdpr-optin-notice.css DELETED
@@ -1 +0,0 @@
1
- .fs-notice[data-id^=gdpr_optin_actions] .underlined{text-decoration:underline}.fs-notice[data-id^=gdpr_optin_actions] ul .button,.fs-notice[data-id^=gdpr_optin_actions] ul .action-description{vertical-align:middle}.fs-notice[data-id^=gdpr_optin_actions] ul .action-description{display:inline-block;margin-left:3px}/*# sourceMappingURL=gdpr-optin-notice.css.map */
 
freemius/assets/css/admin/index.php DELETED
@@ -1,3 +0,0 @@
1
- <?php
2
- // Silence is golden.
3
- // Hide file structure from users on unprotected servers.
 
 
 
freemius/assets/css/admin/plugins.css DELETED
@@ -1 +0,0 @@
1
- label.fs-tag,span.fs-tag{background:#ffba00;color:#fff;display:inline-block;border-radius:3px;padding:5px;font-size:11px;line-height:11px;vertical-align:baseline}label.fs-tag.fs-warn,span.fs-tag.fs-warn{background:#ffba00}label.fs-tag.fs-info,span.fs-tag.fs-info{background:#00a0d2}label.fs-tag.fs-success,span.fs-tag.fs-success{background:#46b450}label.fs-tag.fs-error,span.fs-tag.fs-error{background:#dc3232}.wp-list-table.plugins .plugin-title span.fs-tag{display:inline-block;margin-left:5px;line-height:10px}/*# sourceMappingURL=plugins.css.map */
 
freemius/assets/css/customizer.css DELETED
@@ -1 +0,0 @@
1
- #fs_customizer_upsell .fs-customizer-plan{padding:10px 20px 20px 20px;border-radius:3px;background:#fff}#fs_customizer_upsell .fs-customizer-plan h2{position:relative;margin:0;line-height:2em;text-transform:uppercase}#fs_customizer_upsell .fs-customizer-plan h2 .button-link{top:-2px}#fs_customizer_upsell .fs-feature{position:relative}#fs_customizer_upsell .dashicons-yes{color:#0085ba;font-size:2em;vertical-align:bottom;margin-left:-7px;margin-right:10px}.rtl #fs_customizer_upsell .dashicons-yes{margin-left:10px;margin-right:-7px}#fs_customizer_upsell .dashicons-editor-help{color:#bbb;cursor:help}#fs_customizer_upsell .dashicons-editor-help .fs-feature-desc{opacity:0;visibility:hidden;-moz-transition:opacity .3s ease-in-out;-o-transition:opacity .3s ease-in-out;-ms-transition:opacity .3s ease-in-out;-webkit-transition:opacity .3s ease-in-out;transition:opacity .3s ease-in-out;position:absolute;background:#000;color:#fff;font-family:"arial",serif;font-size:12px;padding:10px;z-index:999999;bottom:100%;margin-bottom:5px;left:0;right:0;-moz-border-radius:5px;-webkit-border-radius:5px;border-radius:5px;-moz-box-shadow:1px 1px 1px rgba(0,0,0,.2);-webkit-box-shadow:1px 1px 1px rgba(0,0,0,.2);box-shadow:1px 1px 1px rgba(0,0,0,.2);line-height:1.3em;font-weight:bold;text-align:left}.rtl #fs_customizer_upsell .dashicons-editor-help .fs-feature-desc{text-align:right}#fs_customizer_upsell .dashicons-editor-help .fs-feature-desc::after{content:" ";display:block;width:0;height:0;border-style:solid;border-width:5px 5px 0 5px;border-color:#000 transparent transparent transparent;position:absolute;top:100%;left:21px}.rtl #fs_customizer_upsell .dashicons-editor-help .fs-feature-desc::after{right:21px;left:auto}#fs_customizer_upsell .dashicons-editor-help:hover .fs-feature-desc{visibility:visible;opacity:1}#fs_customizer_upsell .button-primary{display:block;text-align:center;margin-top:10px}#fs_customizer_support{display:block !important}#fs_customizer_support .button{float:right}#fs_customizer_support .button-group{width:100%;display:block;margin-top:10px}#fs_customizer_support .button-group .button{float:none;width:50%;text-align:center}#customize-theme-controls #accordion-section-freemius_upsell{border-top:1px solid #0085ba !important;border-bottom:1px solid #0085ba !important}#customize-theme-controls #accordion-section-freemius_upsell h3.accordion-section-title{color:#fff;background-color:#0085ba;border-left:4px solid #0085ba;transition:.15s background-color ease-in-out,.15s border-color ease-in-out;outline:none;border-bottom:none !important}#customize-theme-controls #accordion-section-freemius_upsell h3.accordion-section-title:hover{background-color:#008ec2;border-left-color:#0073aa}#customize-theme-controls #accordion-section-freemius_upsell h3.accordion-section-title:after{color:#fff}#customize-theme-controls #accordion-section-freemius_upsell .rtl h3.accordion-section-title{border-left:none;border-right:4px solid #0085ba}#customize-theme-controls #accordion-section-freemius_upsell .rtl h3.accordion-section-title:hover{border-right-color:#0073aa}/*# sourceMappingURL=customizer.css.map */
 
freemius/assets/css/index.php DELETED
@@ -1,3 +0,0 @@
1
- <?php
2
- // Silence is golden.
3
- // Hide file structure from users on unprotected servers.
 
 
 
freemius/assets/img/blocksy-companion.jpg DELETED
Binary file
freemius/assets/img/index.php DELETED
@@ -1,3 +0,0 @@
1
- <?php
2
- // Silence is golden.
3
- // Hide file structure from users on unprotected servers.
 
 
 
freemius/assets/img/plugin-icon.png DELETED
Binary file
freemius/assets/img/theme-icon.png DELETED
Binary file
freemius/assets/index.php DELETED
@@ -1,3 +0,0 @@
1
- <?php
2
- // Silence is golden.
3
- // Hide file structure from users on unprotected servers.
 
 
 
freemius/assets/js/index.php DELETED
@@ -1,3 +0,0 @@
1
- <?php
2
- // Silence is golden.
3
- // Hide file structure from users on unprotected servers.
 
 
 
freemius/assets/js/nojquery.ba-postmessage.js DELETED
@@ -1,140 +0,0 @@
1
- /*!
2
- * jQuery postMessage - v0.5 - 9/11/2009
3
- * http://benalman.com/projects/jquery-postmessage-plugin/
4
- *
5
- * Copyright (c) 2009 "Cowboy" Ben Alman
6
- * Dual licensed under the MIT and GPL licenses.
7
- * http://benalman.com/about/license/
8
- *
9
- * Non-jQuery fork by Jeff Lee
10
- *
11
- * This fork consists of the following changes:
12
- * 1. Basic code cleanup and restructuring, for legibility.
13
- * 2. The `postMessage` and `receiveMessage` functions can be bound arbitrarily,
14
- * in terms of both function names and object scope. Scope is specified by
15
- * the the "this" context of NoJQueryPostMessageMixin();
16
- * 3. I've removed the check for Opera 9.64, which used `$.browser`. There were
17
- * at least three different GitHub users requesting the removal of this
18
- * "Opera sniff" on the original project's Issues page, so I figured this
19
- * would be a relatively safe change.
20
- * 4. `postMessage` no longer uses `$.param` to serialize messages that are not
21
- * strings. I actually prefer this structure anyway. `receiveMessage` does
22
- * not implement a corresponding deserialization step, and as such it seems
23
- * cleaner and more symmetric to leave both data serialization and
24
- * deserialization to the client.
25
- * 5. The use of `$.isFunction` is replaced by a functionally-identical check.
26
- * 6. The `$:nomunge` YUI option is no longer necessary.
27
- */
28
-
29
- function NoJQueryPostMessageMixin(postBinding, receiveBinding) {
30
-
31
- var setMessageCallback, unsetMessageCallback, currentMsgCallback,
32
- intervalId, lastHash, cacheBust = 1;
33
-
34
- if (window.postMessage) {
35
-
36
- if (window.addEventListener) {
37
- setMessageCallback = function(callback) {
38
- window.addEventListener('message', callback, false);
39
- }
40
-
41
- unsetMessageCallback = function(callback) {
42
- window.removeEventListener('message', callback, false);
43
- }
44
- } else {
45
- setMessageCallback = function(callback) {
46
- window.attachEvent('onmessage', callback);
47
- }
48
-
49
- unsetMessageCallback = function(callback) {
50
- window.detachEvent('onmessage', callback);
51
- }
52
- }
53
-
54
- this[postBinding] = function(message, targetUrl, target) {
55
- if (!targetUrl) {
56
- return;
57
- }
58
-
59
- // The browser supports window.postMessage, so call it with a targetOrigin
60
- // set appropriately, based on the targetUrl parameter.
61
- target.postMessage( message, targetUrl.replace( /([^:]+:\/\/[^\/]+).*/, '$1' ) );
62
- }
63
-
64
- // Since the browser supports window.postMessage, the callback will be
65
- // bound to the actual event associated with window.postMessage.
66
- this[receiveBinding] = function(callback, sourceOrigin, delay) {
67
- // Unbind an existing callback if it exists.
68
- if (currentMsgCallback) {
69
- unsetMessageCallback(currentMsgCallback);
70
- currentMsgCallback = null;
71
- }
72
-
73
- if (!callback) {
74
- return false;
75
- }
76
-
77
- // Bind the callback. A reference to the callback is stored for ease of
78
- // unbinding.
79
- currentMsgCallback = setMessageCallback(function(e) {
80
- switch(Object.prototype.toString.call(sourceOrigin)) {
81
- case '[object String]':
82
- if (sourceOrigin !== e.origin) {
83
- return false;
84
- }
85
- break;
86
- case '[object Function]':
87
- if (sourceOrigin(e.origin)) {
88
- return false;
89
- }
90
- break;
91
- }
92
-
93
- callback(e);
94
- });
95
- };
96
-
97
- } else {
98
-
99
- this[postBinding] = function(message, targetUrl, target) {
100
- if (!targetUrl) {
101
- return;
102
- }
103
-
104
- // The browser does not support window.postMessage, so set the location
105
- // of the target to targetUrl#message. A bit ugly, but it works! A cache
106
- // bust parameter is added to ensure that repeat messages trigger the
107
- // callback.
108
- target.location = targetUrl.replace( /#.*$/, '' ) + '#' + (+new Date) + (cacheBust++) + '&' + message;
109
- }
110
-
111
- // Since the browser sucks, a polling loop will be started, and the
112
- // callback will be called whenever the location.hash changes.
113
- this[receiveBinding] = function(callback, sourceOrigin, delay) {
114
- if (intervalId) {
115
- clearInterval(intervalId);
116
- intervalId = null;
117
- }
118
-
119
- if (callback) {
120
- delay = typeof sourceOrigin === 'number'
121
- ? sourceOrigin
122
- : typeof delay === 'number'
123
- ? delay
124
- : 100;
125
-
126
- intervalId = setInterval(function(){
127
- var hash = document.location.hash,
128
- re = /^#?\d+&/;
129
- if ( hash !== lastHash && re.test( hash ) ) {
130
- lastHash = hash;
131
- callback({ data: hash.replace( re, '' ) });
132
- }
133
- }, delay );
134
- }
135
- };
136
-
137
- }
138
-
139
- return this;
140
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
freemius/assets/js/nojquery.ba-postmessage.min.js DELETED
@@ -1,12 +0,0 @@
1
- /*
2
- * nojquery-postmessage by Jeff Lee
3
- * a non-jQuery fork of:
4
- *
5
- * jQuery postMessage - v0.5 - 9/11/2009
6
- * http://benalman.com/projects/jquery-postmessage-plugin/
7
- *
8
- * Copyright (c) 2009 "Cowboy" Ben Alman
9
- * Dual licensed under the MIT and GPL licenses.
10
- * http://benalman.com/about/license/
11
- */
12
- function NoJQueryPostMessageMixin(g,a){var b,h,e,d,f,c=1;if(window.postMessage){if(window.addEventListener){b=function(i){window.addEventListener("message",i,false)};h=function(i){window.removeEventListener("message",i,false)}}else{b=function(i){window.attachEvent("onmessage",i)};h=function(i){window.detachEvent("onmessage",i)}}this[g]=function(i,k,j){if(!k){return}j.postMessage(i,k.replace(/([^:]+:\/\/[^\/]+).*/,"$1"))};this[a]=function(k,j,i){if(e){h(e);e=null}if(!k){return false}e=b(function(l){switch(Object.prototype.toString.call(j)){case"[object String]":if(j!==l.origin){return false}break;case"[object Function]":if(j(l.origin)){return false}break}k(l)})}}else{this[g]=function(i,k,j){if(!k){return}j.location=k.replace(/#.*$/,"")+"#"+(+new Date)+(c++)+"&"+i};this[a]=function(k,j,i){if(d){clearInterval(d);d=null}if(k){i=typeof j==="number"?j:typeof i==="number"?i:100;d=setInterval(function(){var m=document.location.hash,l=/^#?\d+&/;if(m!==f&&l.test(m)){f=m;k({data:m.replace(l,"")})}},i)}}}return this};
 
 
 
 
 
 
 
 
 
 
 
 
freemius/assets/js/postmessage.js DELETED
@@ -1,135 +0,0 @@
1
- (function ($, undef) {
2
- var global = this;
3
-
4
- // Namespace.
5
- global.FS = global.FS || {};
6
-
7
- global.FS.PostMessage = function ()
8
- {
9
- var
10
- _is_child = false,
11
- _postman = new NoJQueryPostMessageMixin('postMessage', 'receiveMessage'),
12
- _callbacks = {},
13
- _base_url,
14
- _parent_url = decodeURIComponent(document.location.hash.replace(/^#/, '')),
15
- _parent_subdomain = _parent_url.substring(0, _parent_url.indexOf('/', ('https://' === _parent_url.substring(0, ('https://').length)) ? 8 : 7)),
16
- _init = function () {
17
- _postman.receiveMessage(function (e) {
18
- var data = JSON.parse(e.data);
19
-
20
- if (_callbacks[data.type]) {
21
- for (var i = 0; i < _callbacks[data.type].length; i++) {
22
- // Execute type callbacks.
23
- _callbacks[data.type][i](data.data);
24
- }
25
- }
26
- }, _base_url);
27
- },
28
- _hasParent = ('' !== _parent_url),
29
- $window = $(window),
30
- $html = $('html');
31
-
32
- return {
33
- init : function (url, iframes)
34
- {
35
- _base_url = url;
36
- _init();
37
-
38
- // Automatically receive forward messages.
39
- FS.PostMessage.receiveOnce('forward', function (data){
40
- window.location = data.url;
41
- });
42
-
43
- iframes = iframes || [];
44
-
45
- if (iframes.length > 0) {
46
- $window.on('scroll', function () {
47
- for (var i = 0; i < iframes.length; i++) {
48
- FS.PostMessage.postScroll(iframes[i]);
49
- }
50
- });
51
- }
52
- },
53
- init_child : function ()
54
- {
55
- this.init(_parent_subdomain);
56
-
57
- _is_child = true;
58
-
59
- // Post height of a child right after window is loaded.
60
- $(window).bind('load', function () {
61
- FS.PostMessage.postHeight();
62
-
63
- // Post message that window was loaded.
64
- FS.PostMessage.post('loaded');
65
- });
66
- },
67
- hasParent : function ()
68
- {
69
- return _hasParent;
70
- },
71
- postHeight : function (diff, wrapper) {
72
- diff = diff || 0;
73
- wrapper = wrapper || '#wrap_section';
74
- this.post('height', {
75
- height: diff + $(wrapper).outerHeight(true)
76
- });
77
- },
78
- postScroll : function (iframe) {
79
- this.post('scroll', {
80
- top: $window.scrollTop(),
81
- height: ($window.height() - parseFloat($html.css('paddingTop')) - parseFloat($html.css('marginTop')))
82
- }, iframe);
83
- },
84
- post : function (type, data, iframe)
85
- {
86
- console.debug('PostMessage.post', type);
87
-
88
- if (iframe)
89
- {
90
- // Post to iframe.
91
- _postman.postMessage(JSON.stringify({
92
- type: type,
93
- data: data
94
- }), iframe.src, iframe.contentWindow);
95
- }
96
- else {
97
- // Post to parent.
98
- _postman.postMessage(JSON.stringify({
99
- type: type,
100
- data: data
101
- }), _parent_url, window.parent);
102
- }
103
- },
104
- receive: function (type, callback)
105
- {
106
- console.debug('PostMessage.receive', type);
107
-
108
- if (undef === _callbacks[type])
109
- _callbacks[type] = [];
110
-
111
- _callbacks[type].push(callback);
112
- },
113
- receiveOnce: function (type, callback)
114
- {
115
- if (this.is_set(type))
116
- return;
117
-
118
- this.receive(type, callback);
119
- },
120
- // Check if any callbacks assigned to a specified message type.
121
- is_set: function (type)
122
- {
123
- return (undef != _callbacks[type]);
124
- },
125
- parent_url: function ()
126
- {
127
- return _parent_url;
128
- },
129
- parent_subdomain: function ()
130
- {
131
- return _parent_subdomain;
132
- }
133
- };
134
- }();
135
- })(jQuery);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
freemius/config.php DELETED
@@ -1,391 +0,0 @@
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.4
7
- */
8
-
9
- if ( ! defined( 'ABSPATH' ) ) {
10
- exit;
11
- }
12
-
13
- if ( ! defined( 'WP_FS__SLUG' ) ) {
14
- define( 'WP_FS__SLUG', 'freemius' );
15
- }
16
- if ( ! defined( 'WP_FS__DEV_MODE' ) ) {
17
- define( 'WP_FS__DEV_MODE', false );
18
- }
19
-
20
- #--------------------------------------------------------------------------------
21
- #region API Connectivity Issues Simulation
22
- #--------------------------------------------------------------------------------
23
-
24
- if ( ! defined( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY' ) ) {
25
- define( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY', false );
26
- }
27
- if ( ! defined( 'WP_FS__SIMULATE_NO_CURL' ) ) {
28
- define( 'WP_FS__SIMULATE_NO_CURL', false );
29
- }
30
- if ( ! defined( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE' ) ) {
31
- define( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE', false );
32
- }
33
- if ( ! defined( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL' ) ) {
34
- define( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL', false );
35
- }
36
- if ( WP_FS__SIMULATE_NO_CURL ) {
37
- define( 'FS_SDK__SIMULATE_NO_CURL', true );
38
- }
39
- if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE ) {
40
- define( 'FS_SDK__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE', true );
41
- }
42
- if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL ) {
43
- define( 'FS_SDK__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL', true );
44
- }
45
-
46
- #endregion
47
-
48
- if ( ! defined( 'WP_FS__SIMULATE_FREEMIUS_OFF' ) ) {
49
- define( 'WP_FS__SIMULATE_FREEMIUS_OFF', false );
50
- }
51
-
52
- if ( ! defined( 'WP_FS__PING_API_ON_IP_OR_HOST_CHANGES' ) ) {
53
- /**
54
- * @since 1.1.7.3
55
- * @author Vova Feldman (@svovaf)
56
- *
57
- * I'm not sure if shared servers periodically change IP, or the subdomain of the
58
- * admin dashboard. Also, I've seen sites that have strange loop of switching
59
- * between domains on a daily basis. Therefore, to eliminate the risk of
60
- * multiple unwanted connectivity test pings, temporary ignore domain or
61
- * server IP changes.
62
- */
63
- define( 'WP_FS__PING_API_ON_IP_OR_HOST_CHANGES', false );
64
- }
65
-
66
- /**
67
- * If your dev environment supports custom public network IP setup
68
- * like VVV, please update WP_FS__LOCALHOST_IP with your public IP
69
- * and uncomment it during dev.
70
- */
71
- if ( ! defined( 'WP_FS__LOCALHOST_IP' ) ) {
72
- // VVV default public network IP.
73
- define( 'WP_FS__VVV_DEFAULT_PUBLIC_IP', '192.168.50.4' );
74
-
75
- // define( 'WP_FS__LOCALHOST_IP', WP_FS__VVV_DEFAULT_PUBLIC_IP );
76
- }
77
-
78
- /**
79
- * If true and running with secret key, the opt-in process
80
- * will skip the email activation process which is invoked
81
- * when the email of the context user already exist in Freemius
82
- * database (as a security precaution, to prevent sharing user
83
- * secret with unauthorized entity).
84
- *
85
- * IMPORTANT:
86
- * AS A SECURITY PRECAUTION, WE VALIDATE THE TIMESTAMP OF THE OPT-IN REQUEST.
87
- * THEREFORE, MAKE SURE THAT WHEN USING THIS PARAMETER,YOUR TESTING ENVIRONMENT'S
88
- * CLOCK IS SYNCED.
89
- */
90
- if ( ! defined( 'WP_FS__SKIP_EMAIL_ACTIVATION' ) ) {
91
- define( 'WP_FS__SKIP_EMAIL_ACTIVATION', false );
92
- }
93
-
94
-
95
- #--------------------------------------------------------------------------------
96
- #region Directories
97
- #--------------------------------------------------------------------------------
98
-
99
- if ( ! defined( 'WP_FS__DIR' ) ) {
100
- define( 'WP_FS__DIR', dirname( __FILE__ ) );
101
- }
102
- if ( ! defined( 'WP_FS__DIR_INCLUDES' ) ) {
103
- define( 'WP_FS__DIR_INCLUDES', WP_FS__DIR . '/includes' );
104
- }
105
- if ( ! defined( 'WP_FS__DIR_TEMPLATES' ) ) {
106
- define( 'WP_FS__DIR_TEMPLATES', WP_FS__DIR . '/templates' );
107
- }
108
- if ( ! defined( 'WP_FS__DIR_ASSETS' ) ) {
109
- define( 'WP_FS__DIR_ASSETS', WP_FS__DIR . '/assets' );
110
- }
111
- if ( ! defined( 'WP_FS__DIR_CSS' ) ) {
112
- define( 'WP_FS__DIR_CSS', WP_FS__DIR_ASSETS . '/css' );
113
- }
114
- if ( ! defined( 'WP_FS__DIR_JS' ) ) {
115
- define( 'WP_FS__DIR_JS', WP_FS__DIR_ASSETS . '/js' );
116
- }
117
- if ( ! defined( 'WP_FS__DIR_IMG' ) ) {
118
- define( 'WP_FS__DIR_IMG', WP_FS__DIR_ASSETS . '/img' );
119
- }
120
- if ( ! defined( 'WP_FS__DIR_SDK' ) ) {
121
- define( 'WP_FS__DIR_SDK', WP_FS__DIR_INCLUDES . '/sdk' );
122
- }
123
-
124
- #endregion
125
-
126
- /**
127
- * Domain / URL / Address
128
- */
129
- define( 'WP_FS__ROOT_DOMAIN_PRODUCTION', 'freemius.com' );
130
- define( 'WP_FS__DOMAIN_PRODUCTION', 'wp.freemius.com' );
131
- define( 'WP_FS__ADDRESS_PRODUCTION', 'https://' . WP_FS__DOMAIN_PRODUCTION );
132
-
133
- if ( ! defined( 'WP_FS__DOMAIN_LOCALHOST' ) ) {
134
- define( 'WP_FS__DOMAIN_LOCALHOST', 'wp.freemius' );
135
- }
136
- if ( ! defined( 'WP_FS__ADDRESS_LOCALHOST' ) ) {
137
- define( 'WP_FS__ADDRESS_LOCALHOST', 'http://' . WP_FS__DOMAIN_LOCALHOST . ':8080' );
138
- }
139
-
140
- if ( ! defined( 'WP_FS__TESTING_DOMAIN' ) ) {
141
- define( 'WP_FS__TESTING_DOMAIN', 'fswp' );
142
- }
143
-
144
- #--------------------------------------------------------------------------------
145
- #region HTTP
146
- #--------------------------------------------------------------------------------
147
-
148
- if ( ! defined( 'WP_FS__IS_HTTP_REQUEST' ) ) {
149
- define( 'WP_FS__IS_HTTP_REQUEST', isset( $_SERVER['HTTP_HOST'] ) );
150
- }
151
-
152
- if ( ! defined( 'WP_FS__IS_HTTPS' ) ) {
153
- define( 'WP_FS__IS_HTTPS', ( WP_FS__IS_HTTP_REQUEST &&
154
- // Checks if CloudFlare's HTTPS (Flexible SSL support).
155
- isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) &&
156
- 'https' === strtolower( $_SERVER['HTTP_X_FORWARDED_PROTO'] )
157
- ) ||
158
- // Check if HTTPS request.
159
- ( isset( $_SERVER['HTTPS'] ) && 'on' == $_SERVER['HTTPS'] ) ||
160
- ( isset( $_SERVER['SERVER_PORT'] ) && 443 == $_SERVER['SERVER_PORT'] )
161
- );
162
- }
163
-
164
- if ( ! defined( 'WP_FS__IS_POST_REQUEST' ) ) {
165
- define( 'WP_FS__IS_POST_REQUEST', ( WP_FS__IS_HTTP_REQUEST &&
166
- strtoupper( $_SERVER['REQUEST_METHOD'] ) == 'POST' ) );
167
- }
168
-
169
- if ( ! defined( 'WP_FS__REMOTE_ADDR' ) ) {
170
- define( 'WP_FS__REMOTE_ADDR', fs_get_ip() );
171
- }
172
-
173
- if ( ! defined( 'WP_FS__IS_LOCALHOST' ) ) {
174
- if ( defined( 'WP_FS__LOCALHOST_IP' ) ) {
175
- define( 'WP_FS__IS_LOCALHOST', ( WP_FS__LOCALHOST_IP === WP_FS__REMOTE_ADDR ) );
176
- } else {
177
- define( 'WP_FS__IS_LOCALHOST', WP_FS__IS_HTTP_REQUEST &&
178
- is_string( WP_FS__REMOTE_ADDR ) &&
179
- ( substr( WP_FS__REMOTE_ADDR, 0, 4 ) === '127.' ||
180
- WP_FS__REMOTE_ADDR === '::1' )
181
- );
182
- }
183
- }
184
-
185
- if ( ! defined( 'WP_FS__IS_LOCALHOST_FOR_SERVER' ) ) {
186
- define( 'WP_FS__IS_LOCALHOST_FOR_SERVER', ( ! WP_FS__IS_HTTP_REQUEST ||
187
- false !== strpos( $_SERVER['HTTP_HOST'], 'localhost' ) ) );
188
- }
189
-
190
- #endregion
191
-
192
- if ( ! defined( 'WP_FS__IS_PRODUCTION_MODE' ) ) {
193
- // By default, run with Freemius production servers.
194
- define( 'WP_FS__IS_PRODUCTION_MODE', true );
195
- }
196
-
197
- if ( ! defined( 'WP_FS__ADDRESS' ) ) {
198
- define( 'WP_FS__ADDRESS', ( WP_FS__IS_PRODUCTION_MODE ? WP_FS__ADDRESS_PRODUCTION : WP_FS__ADDRESS_LOCALHOST ) );
199
- }
200
-
201
-
202
- #--------------------------------------------------------------------------------
203
- #region API
204
- #--------------------------------------------------------------------------------
205
-
206
- if ( ! defined( 'WP_FS__API_ADDRESS_LOCALHOST' ) ) {
207
- define( 'WP_FS__API_ADDRESS_LOCALHOST', 'http://api.freemius-local.com:8080' );
208
- }
209
- if ( ! defined( 'WP_FS__API_SANDBOX_ADDRESS_LOCALHOST' ) ) {
210
- define( 'WP_FS__API_SANDBOX_ADDRESS_LOCALHOST', 'http://sandbox-api.freemius:8080' );
211
- }
212
-
213
- // Set API address for local testing.
214
- if ( ! WP_FS__IS_PRODUCTION_MODE ) {
215
- if ( ! defined( 'FS_API__ADDRESS' ) ) {
216
- define( 'FS_API__ADDRESS', WP_FS__API_ADDRESS_LOCALHOST );
217
- }
218
- if ( ! defined( 'FS_API__SANDBOX_ADDRESS' ) ) {
219
- define( 'FS_API__SANDBOX_ADDRESS', WP_FS__API_SANDBOX_ADDRESS_LOCALHOST );
220
- }
221
- }
222
-
223
- #endregion
224
-
225
- #--------------------------------------------------------------------------------
226
- #region Checkout
227
- #--------------------------------------------------------------------------------
228
-
229
- if ( ! defined( 'FS_CHECKOUT__ADDRESS_PRODUCTION' ) ) {
230
- define( 'FS_CHECKOUT__ADDRESS_PRODUCTION', 'https://checkout.freemius.com' );
231
- }
232
-
233
- if ( ! defined( 'FS_CHECKOUT__ADDRESS_LOCALHOST' ) ) {
234
- define( 'FS_CHECKOUT__ADDRESS_LOCALHOST', 'http://checkout.freemius-local.com:8080' );
235
- }
236
-
237
- if ( ! defined( 'FS_CHECKOUT__ADDRESS' ) ) {
238
- define( 'FS_CHECKOUT__ADDRESS', ( WP_FS__IS_PRODUCTION_MODE ? FS_CHECKOUT__ADDRESS_PRODUCTION : FS_CHECKOUT__ADDRESS_LOCALHOST ) );
239
- }
240
-
241
- #endregion
242
-
243
- define( 'WP_FS___OPTION_PREFIX', 'fs' . ( WP_FS__IS_PRODUCTION_MODE ? '' : '_dbg' ) . '_' );
244
-
245
- if ( ! defined( 'WP_FS__ACCOUNTS_OPTION_NAME' ) ) {
246
- define( 'WP_FS__ACCOUNTS_OPTION_NAME', WP_FS___OPTION_PREFIX . 'accounts' );
247
- }
248
- if ( ! defined( 'WP_FS__API_CACHE_OPTION_NAME' ) ) {
249
- define( 'WP_FS__API_CACHE_OPTION_NAME', WP_FS___OPTION_PREFIX . 'api_cache' );
250
- }
251
- if ( ! defined( 'WP_FS__GDPR_OPTION_NAME' ) ) {
252
- define( 'WP_FS__GDPR_OPTION_NAME', WP_FS___OPTION_PREFIX . 'gdpr' );
253
- }
254
- define( 'WP_FS__OPTIONS_OPTION_NAME', WP_FS___OPTION_PREFIX . 'options' );
255
-
256
- /**
257
- * Module types
258
- *
259
- * @since 1.2.2
260
- */
261
- define( 'WP_FS__MODULE_TYPE_PLUGIN', 'plugin' );
262
- define( 'WP_FS__MODULE_TYPE_THEME', 'theme' );
263
-
264
- /**
265
- * Billing Frequencies
266
- */
267
- define( 'WP_FS__PERIOD_ANNUALLY', 'annual' );
268
- define( 'WP_FS__PERIOD_MONTHLY', 'monthly' );
269
- define( 'WP_FS__PERIOD_LIFETIME', 'lifetime' );
270
-
271
- /**
272
- * Plans
273
- */
274
- define( 'WP_FS__PLAN_DEFAULT_PAID', false );
275
- define( 'WP_FS__PLAN_FREE', 'free' );
276
- define( 'WP_FS__PLAN_TRIAL', 'trial' );
277
-
278
- /**
279
- * Times in seconds
280
- */
281
- if ( ! defined( 'WP_FS__TIME_5_MIN_IN_SEC' ) ) {
282
- define( 'WP_FS__TIME_5_MIN_IN_SEC', 300 );
283
- }
284
- if ( ! defined( 'WP_FS__TIME_10_MIN_IN_SEC' ) ) {
285
- define( 'WP_FS__TIME_10_MIN_IN_SEC', 600 );
286
- }
287
- // define( 'WP_FS__TIME_15_MIN_IN_SEC', 900 );
288
- if ( ! defined( 'WP_FS__TIME_12_HOURS_IN_SEC' ) ) {
289
- define( 'WP_FS__TIME_12_HOURS_IN_SEC', 43200 );
290
- }
291
- if ( ! defined( 'WP_FS__TIME_24_HOURS_IN_SEC' ) ) {
292
- define( 'WP_FS__TIME_24_HOURS_IN_SEC', WP_FS__TIME_12_HOURS_IN_SEC * 2 );
293
- }
294
- if ( ! defined( 'WP_FS__TIME_WEEK_IN_SEC' ) ) {
295
- define( 'WP_FS__TIME_WEEK_IN_SEC', 7 * WP_FS__TIME_24_HOURS_IN_SEC );
296
- }
297
-
298
- #--------------------------------------------------------------------------------
299
- #region Debugging
300
- #--------------------------------------------------------------------------------
301
-
302
- if ( ! defined( 'WP_FS__DEBUG_SDK' ) ) {
303
- $debug_mode = get_option( 'fs_debug_mode', null );
304
-
305
- if ( $debug_mode === null ) {
306
- $debug_mode = false;
307
- add_option( 'fs_debug_mode', $debug_mode );
308
- }
309
-
310
- define( 'WP_FS__DEBUG_SDK', is_numeric( $debug_mode ) ? ( 0 < $debug_mode ) : WP_FS__DEV_MODE );
311
- }
312
-
313
- if ( ! defined( 'WP_FS__ECHO_DEBUG_SDK' ) ) {
314
- define( 'WP_FS__ECHO_DEBUG_SDK', WP_FS__DEV_MODE && ! empty( $_GET['fs_dbg_echo'] ) );
315
- }
316
- if ( ! defined( 'WP_FS__LOG_DATETIME_FORMAT' ) ) {
317
- define( 'WP_FS__LOG_DATETIME_FORMAT', 'Y-m-d H:i:s' );
318
- }
319
- if ( ! defined( 'FS_API__LOGGER_ON' ) ) {
320
- define( 'FS_API__LOGGER_ON', WP_FS__DEBUG_SDK );
321
- }
322
-
323
- if ( WP_FS__ECHO_DEBUG_SDK ) {
324
- error_reporting( E_ALL );
325
- }
326
-
327
- #endregion
328
-
329
- if ( ! defined( 'WP_FS__SCRIPT_START_TIME' ) ) {
330
- define( 'WP_FS__SCRIPT_START_TIME', time() );
331
- }
332
- if ( ! defined( 'WP_FS__DEFAULT_PRIORITY' ) ) {
333
- define( 'WP_FS__DEFAULT_PRIORITY', 10 );
334
- }
335
- if ( ! defined( 'WP_FS__LOWEST_PRIORITY' ) ) {
336
- define( 'WP_FS__LOWEST_PRIORITY', 999999999 );
337
- }
338
-
339
- #--------------------------------------------------------------------------------
340
- #region Multisite Network
341
- #--------------------------------------------------------------------------------
342
-
343
- /**
344
- * Do not use this define directly, it will have the wrong value
345
- * during plugin uninstall/deletion when the inclusion of the plugin
346
- * is triggered due to registration with register_uninstall_hook().
347
- *
348
- * Instead, use fs_is_network_admin().
349
- *
350
- * @author Vova Feldman (@svovaf)
351
- */
352
- if ( ! defined( 'WP_FS__IS_NETWORK_ADMIN' ) ) {
353
- define( 'WP_FS__IS_NETWORK_ADMIN',
354
- is_multisite() &&
355
- ( is_network_admin() ||
356
- ( ( defined( 'DOING_AJAX' ) && DOING_AJAX &&
357
- ( isset( $_REQUEST['_fs_network_admin'] ) && 'true' === $_REQUEST['_fs_network_admin'] /*||
358
- ( ! empty( $_REQUEST['action'] ) && 'delete-plugin' === $_REQUEST['action'] )*/ )
359
- ) ||
360
- // Plugin uninstall.
361
- defined( 'WP_UNINSTALL_PLUGIN' ) )
362
- )
363
- );
364
- }
365
-
366
- /**
367
- * Do not use this define directly, it will have the wrong value
368
- * during plugin uninstall/deletion when the inclusion of the plugin
369
- * is triggered due to registration with register_uninstall_hook().
370
- *
371
- * Instead, use fs_is_blog_admin().
372
- *
373
- * @author Vova Feldman (@svovaf)
374
- */
375
- if ( ! defined( 'WP_FS__IS_BLOG_ADMIN' ) ) {
376
- define( 'WP_FS__IS_BLOG_ADMIN', is_blog_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX && isset( $_REQUEST['_fs_blog_admin'] ) ) );
377
- }
378
-
379
- if ( ! defined( 'WP_FS__SHOW_NETWORK_EVEN_WHEN_DELEGATED' ) ) {
380
- // Set to true to show network level settings even if delegated to site admins.
381
- define( 'WP_FS__SHOW_NETWORK_EVEN_WHEN_DELEGATED', false );
382
- }
383
-
384
- #endregion
385
-
386
- if ( ! defined( 'WP_FS__DEMO_MODE' ) ) {
387
- define( 'WP_FS__DEMO_MODE', false );
388
- }
389
- if ( ! defined( 'FS_SDK__SSLVERIFY' ) ) {
390
- define( 'FS_SDK__SSLVERIFY', false );
391
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
freemius/includes/class-freemius-abstract.php DELETED
@@ -1,597 +0,0 @@
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.7
7
- */
8
-
9
- if ( ! defined( 'ABSPATH' ) ) {
10
- exit;
11
- }
12
-
13
-
14
- /**
15
- * - Each instance of Freemius class represents a single plugin
16
- * install by a single user (the installer of the plugin).
17
- *
18
- * - Each website can only have one install of the same plugin.
19
- *
20
- * - Install entity is only created after a user connects his account with Freemius.
21
- *
22
- * Class Freemius_Abstract
23
- */
24
- abstract class Freemius_Abstract {
25
-
26
- #----------------------------------------------------------------------------------
27
- #region Identity
28
- #----------------------------------------------------------------------------------
29
-
30
- /**
31
- * Check if user has connected his account (opted-in).
32
- *
33
- * Note:
34
- * If the user opted-in and opted-out on a later stage,
35
- * this will still return true. If you want to check if the
36
- * user is currently opted-in, use:
37
- * `$fs->is_registered() && $fs->is_tracking_allowed()`
38
- *
39
- * @since 1.0.1
40
- * @return bool
41
- */
42
- abstract function is_registered();
43
-
44
- /**
45
- * Check if the user skipped connecting the account with Freemius.
46
- *
47
- * @since 1.0.7
48
- *
49
- * @return bool
50
- */
51
- abstract function is_anonymous();
52
-
53
- /**
54
- * Check if the user currently in activation mode.
55
- *
56
- * @since 1.0.7
57
- *
58
- * @return bool
59
- */
60
- abstract function is_activation_mode();
61
-
62
- #endregion
63
-
64
- #----------------------------------------------------------------------------------
65
- #region Usage Tracking
66
- #----------------------------------------------------------------------------------
67
-
68
- /**
69
- * Returns TRUE if the user opted-in and didn't disconnect (opt-out).
70
- *
71
- * @author Leo Fajardo (@leorw)
72
- * @since 1.2.1.5
73
- *
74
- * @return bool
75
- */
76
- abstract function is_tracking_allowed();
77
-
78
- /**
79
- * Returns TRUE if the user never opted-in or manually opted-out.
80
- *
81
- * @author Vova Feldman (@svovaf)
82
- * @since 1.2.1.5
83
- *
84
- * @return bool
85
- */
86
- function is_tracking_prohibited() {
87
- return ! $this->is_registered() || ! $this->is_tracking_allowed();
88
- }
89
-
90
- /**
91
- * Opt-out from usage tracking.
92
- *
93
- * Note: This will not delete the account information but will stop all tracking.
94
- *
95
- * Returns:
96
- * 1. FALSE - If the user never opted-in.
97
- * 2. TRUE - If successfully opted-out.
98
- * 3. object - API Result on failure.
99
- *
100
- * @author Leo Fajardo (@leorw)
101
- * @since 1.2.1.5
102
- *
103
- * @return bool|object
104
- */
105
- abstract function stop_tracking();
106
-
107
- /**
108
- * Opt-in back into usage tracking.
109
- *
110
- * Note: This will only work if the user opted-in previously.
111
- *
112
- * Returns:
113
- * 1. FALSE - If the user never opted-in.
114
- * 2. TRUE - If successfully opted-in back to usage tracking.
115
- * 3. object - API result on failure.
116
- *
117
- * @author Leo Fajardo (@leorw)
118
- * @since 1.2.1.5
119
- *
120
- * @return bool|object
121
- */
122
- abstract function allow_tracking();
123
-
124
- #endregion
125
-
126
- #----------------------------------------------------------------------------------
127
- #region Module Type
128
- #----------------------------------------------------------------------------------
129
-
130
- /**
131
- * Checks if the plugin's type is "plugin". The other type is "theme".
132
- *
133
- * @author Leo Fajardo (@leorw)
134
- * @since 1.2.2
135
- *
136
- * @return bool
137
- */
138
- abstract function is_plugin();
139
-
140
- /**
141
- * Checks if the module type is "theme". The other type is "plugin".
142
- *
143
- * @author Leo Fajardo (@leorw)
144
- * @since 1.2.2
145
- *
146
- * @return bool
147
- */
148
- function is_theme() {
149
- return ( ! $this->is_plugin() );
150
- }
151
-
152
- #endregion
153
-
154
- #----------------------------------------------------------------------------------
155
- #region Permissions
156
- #----------------------------------------------------------------------------------
157
-
158
- /**
159
- * Check if plugin must be WordPress.org compliant.
160
- *
161
- * @since 1.0.7
162
- *
163
- * @return bool
164
- */
165
- abstract function is_org_repo_compliant();
166
-
167
- /**
168
- * Check if plugin is allowed to install executable files.
169
- *
170
- * @author Vova Feldman (@svovaf)
171
- * @since 1.0.5
172
- *
173
- * @return bool
174
- */
175
- function is_allowed_to_install() {
176
- return ( $this->is_premium() || ! $this->is_org_repo_compliant() );
177
- }
178
-
179
- #endregion
180
-
181
- /**
182
- * Check if user in trial or in free plan (not paying).
183
- *
184
- * @author Vova Feldman (@svovaf)
185
- * @since 1.0.4
186
- *
187
- * @return bool
188
- */
189
- function is_not_paying() {
190
- return ( $this->is_trial() || $this->is_free_plan() );
191
- }
192
-
193
- /**
194
- * Check if the user has an activated and valid paid license on current plugin's install.
195
- *
196
- * @since 1.0.9
197
- *
198
- * @return bool
199
- */
200
- abstract function is_paying();
201
-
202
- /**
203
- * Check if the user is paying or in trial.
204
- *
205
- * @since 1.0.9
206
- *
207
- * @return bool
208
- */
209
- function is_paying_or_trial() {
210
- return ( $this->is_paying() || $this->is_trial() );
211
- }
212
-
213
- /**
214
- * Check if user in a trial or have feature enabled license.
215
- *
216
- * @author Vova Feldman (@svovaf)
217
- * @since 1.1.7
218
- *
219
- * @return bool
220
- */
221
- abstract function can_use_premium_code();
222
-
223
- #----------------------------------------------------------------------------------
224
- #region Premium Only
225
- #----------------------------------------------------------------------------------
226
-
227
- /**
228
- * All logic wrapped in methods with "__premium_only()" suffix will be only
229
- * included in the premium code.
230
- *
231
- * Example:
232
- * if ( freemius()->is__premium_only() ) {
233
- * ...
234
- * }
235
- */
236
-
237
- /**
238
- * Returns true when running premium plugin code.
239
- *
240
- * @since 1.0.9
241
- *
242
- * @return bool
243
- */
244
- function is__premium_only() {
245
- return $this->is_premium();
246
- }
247
-
248
- /**
249
- * Check if the user has an activated and valid paid license on current plugin's install.
250
- *
251
- * @since 1.0.9
252
- *
253
- * @return bool
254
- *
255
- */
256
- function is_paying__premium_only() {
257
- return ( $this->is__premium_only() && $this->is_paying() );
258
- }
259
-
260
- /**
261
- * All code wrapped in this statement will be only included in the premium code.
262
- *
263
- * @since 1.0.9
264
- *
265
- * @param string $plan Plan name.
266
- * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
267
- *
268
- * @return bool
269
- */
270
- function is_plan__premium_only( $plan, $exact = false ) {
271
- return ( $this->is_premium() && $this->is_plan( $plan, $exact ) );
272
- }
273
-
274
- /**
275
- * Check if plan matches active license' plan or active trial license' plan.
276
- *
277
- * All code wrapped in this statement will be only included in the premium code.
278
- *
279
- * @since 1.0.9
280
- *
281
- * @param string $plan Plan name.
282
- * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
283
- *
284
- * @return bool
285
- */
286
- function is_plan_or_trial__premium_only( $plan, $exact = false ) {
287
- return ( $this->is_premium() && $this->is_plan_or_trial( $plan, $exact ) );
288
- }
289
-
290
- /**
291
- * Check if the user is paying or in trial.
292
- *
293
- * All code wrapped in this statement will be only included in the premium code.
294
- *
295
- * @since 1.0.9
296
- *
297
- * @return bool
298
- */
299
- function is_paying_or_trial__premium_only() {
300
- return $this->is_premium() && $this->is_paying_or_trial();
301
- }
302
-
303
- /**
304
- * Check if the user has an activated and valid paid license on current plugin's install.
305
- *
306
- * @since 1.0.4
307
- *
308
- * @return bool
309
- *
310
- * @deprecated Method name is confusing since it's not clear from the name the code will be removed.
311
- * @using Alias to is_paying__premium_only()
312
- */
313
- function is_paying__fs__() {
314
- return $this->is_paying__premium_only();
315
- }
316
-
317
- /**
318
- * Check if user in a trial or have feature enabled license.
319
- *
320
- * All code wrapped in this statement will be only included in the premium code.
321
- *
322
- * @author Vova Feldman (@svovaf)
323
- * @since 1.1.9
324
- *
325
- * @return bool
326
- */
327
- function can_use_premium_code__premium_only() {
328
- return $this->is_premium() && $this->can_use_premium_code();
329
- }
330
-
331
- #endregion
332
-
333
- #----------------------------------------------------------------------------------
334
- #region Trial
335
- #----------------------------------------------------------------------------------
336
-
337
- /**
338
- * Check if the user in a trial.
339
- *
340
- * @since 1.0.3
341
- *
342
- * @return bool
343
- */
344
- abstract function is_trial();
345
-
346
- /**
347
- * Check if trial already utilized.
348
- *
349
- * @since 1.0.9
350
- *
351
- * @return bool
352
- */
353
- abstract function is_trial_utilized();
354
-
355
- #endregion
356
-
357
- #----------------------------------------------------------------------------------
358
- #region Plans
359
- #----------------------------------------------------------------------------------
360
-
361
- /**
362
- * Check if the user is on the free plan of the product.
363
- *
364
- * @since 1.0.4
365
- *
366
- * @return bool
367
- */
368
- abstract function is_free_plan();
369
-
370
- /**
371
- * @since 1.0.2
372
- *
373
- * @param string $plan Plan name.
374
- * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
375
- *
376
- * @return bool
377
- */
378
- abstract function is_plan( $plan, $exact = false );
379
-
380
- /**
381
- * Check if plan based on trial. If not in trial mode, should return false.
382
- *
383
- * @since 1.0.9
384
- *
385
- * @param string $plan Plan name.
386
- * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
387
- *
388
- * @return bool
389
- */
390
- abstract function is_trial_plan( $plan, $exact = false );
391
-
392
- /**
393
- * Check if plan matches active license' plan or active trial license' plan.
394
- *
395
- * @since 1.0.9
396
- *
397
- * @param string $plan Plan name.
398
- * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
399
- *
400
- * @return bool
401
- */
402
- function is_plan_or_trial( $plan, $exact = false ) {
403
- return $this->is_plan( $plan, $exact ) ||
404
- $this->is_trial_plan( $plan, $exact );
405
- }
406
-
407
- /**
408
- * Check if plugin has any paid plans.
409
- *
410
- * @author Vova Feldman (@svovaf)
411
- * @since 1.0.7
412
- *
413
- * @return bool
414
- */
415
- abstract function has_paid_plan();
416
-
417
- /**
418
- * Check if plugin has any free plan, or is it premium only.
419
- *
420
- * Note: If no plans configured, assume plugin is free.
421
- *
422
- * @author Vova Feldman (@svovaf)
423
- * @since 1.0.7
424
- *
425
- * @return bool
426
- */
427
- abstract function has_free_plan();
428
-
429
- /**
430
- * Check if plugin is premium only (no free plans).
431
- *
432
- * NOTE: is__premium_only() is very different method, don't get confused.
433
- *
434
- * @author Vova Feldman (@svovaf)
435
- * @since 1.1.9
436
- *
437
- * @return bool
438
- */
439
- abstract function is_only_premium();
440
-
441
- /**
442
- * Check if module has a premium code version.
443
- *
444
- * Serviceware module might be freemium without any
445
- * premium code version, where the paid features
446
- * are all part of the service.
447
- *
448
- * @author Vova Feldman (@svovaf)
449
- * @since 1.2.1.6
450
- *
451
- * @return bool
452
- */
453
- abstract function has_premium_version();
454
-
455
- /**
456
- * Check if module has any release on Freemius,
457
- * or all plugin's code is on WordPress.org (Serviceware).
458
- *
459
- * @return bool
460
- */
461
- function has_release_on_freemius() {
462
- return ! $this->is_org_repo_compliant() ||
463
- $this->has_premium_version();
464
- }
465
-
466
- /**
467
- * Checks if it's a freemium plugin.
468
- *
469
- * @author Vova Feldman (@svovaf)
470
- * @since 1.1.9
471
- *
472
- * @return bool
473
- */
474
- function is_freemium() {
475
- return $this->has_paid_plan() &&
476
- $this->has_free_plan();
477
- }
478
-
479
- /**
480
- * Check if module has only one plan.
481
- *
482
- * @author Vova Feldman (@svovaf)
483
- * @since 1.2.1.7
484
- *
485
- * @return bool
486
- */
487
- abstract function is_single_plan();
488
-
489
- #endregion
490
-
491
- /**
492
- * Check if running payments in sandbox mode.
493
- *
494
- * @since 1.0.4
495
- *
496
- * @return bool
497
- */
498
- abstract function is_payments_sandbox();
499
-
500
- /**
501
- * Check if running test vs. live plugin.
502
- *
503
- * @since 1.0.5
504
- *
505
- * @return bool
506
- */
507
- abstract function is_live();
508
-
509
- /**
510
- * Check if running premium plugin code.
511
- *
512
- * @since 1.0.5
513
- *
514
- * @return bool
515
- */
516
- abstract function is_premium();
517
-
518
- /**
519
- * Get upgrade URL.
520
- *
521
- * @author Vova Feldman (@svovaf)
522
- * @since 1.0.2
523
- *
524
- * @param string $period Billing cycle.
525
- *
526
- * @return string
527
- */
528
- abstract function get_upgrade_url( $period = WP_FS__PERIOD_ANNUALLY );
529
-
530
- /**
531
- * Check if Freemius was first added in a plugin update.
532
- *
533
- * @author Vova Feldman (@svovaf)
534
- * @since 1.1.5
535
- *
536
- * @return bool
537
- */
538
- function is_plugin_update() {
539
- return ! $this->is_plugin_new_install();
540
- }
541
-
542
- /**
543
- * Check if Freemius was part of the plugin when the user installed it first.
544
- *
545
- * @author Vova Feldman (@svovaf)
546
- * @since 1.1.5
547
- *
548
- * @return bool
549
- */
550
- abstract function is_plugin_new_install();
551
-
552
- #----------------------------------------------------------------------------------
553
- #region Marketing
554
- #----------------------------------------------------------------------------------
555
-
556
- /**
557
- * Check if current user purchased any other plugins before.
558
- *
559
- * @author Vova Feldman (@svovaf)
560
- * @since 1.0.9
561
- *
562
- * @return bool
563
- */
564
- abstract function has_purchased_before();
565
-
566
- /**
567
- * Check if current user classified as an agency.
568
- *
569
- * @author Vova Feldman (@svovaf)
570
- * @since 1.0.9
571
- *
572
- * @return bool
573
- */
574
- abstract function is_agency();
575
-
576
- /**
577
- * Check if current user classified as a developer.
578
- *
579
- * @author Vova Feldman (@svovaf)
580
- * @since 1.0.9
581
- *
582
- * @return bool
583
- */
584
- abstract function is_developer();
585
-
586
- /**
587
- * Check if current user classified as a business.
588
- *
589
- * @author Vova Feldman (@svovaf)
590
- * @since 1.0.9
591
- *
592
- * @return bool
593
- */
594
- abstract function is_business();
595
-
596
- #endregion
597
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
freemius/includes/class-freemius.php DELETED
@@ -1,26243 +0,0 @@
1
- <?php
2
- /**
3
- * @package Freemius
4
- * @copyright Copyright (c) 2015, Freemius, Inc.
5
- * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6
- * @since 1.0.3
7
- */
8
- if ( ! defined( 'ABSPATH' ) ) {
9
- exit;
10
- }
11
-
12
- // "final class"
13
- class Freemius extends Freemius_Abstract {
14
- /**
15
- * SDK Version
16
- *
17
- * @var string
18
- */
19
- public $version = WP_FS__SDK_VERSION;
20
-
21
- #region Plugin Info
22
-
23
- /**
24
- * @since 1.0.1
25
- *
26
- * @var string
27
- */
28
- private $_slug;
29
-
30
- /**
31
- * @since 1.0.0
32
- *
33
- * @var string
34
- */
35
- private $_plugin_basename;
36
- /**
37
- * @since 2.2.1
38
- *
39
- * @var string
40
- */
41
- private $_premium_plugin_basename;
42
- /**
43
- * @since 1.0.0
44
- *
45
- * @var string
46
- */
47
- private $_free_plugin_basename;
48
- /**
49
- * @since 1.0.0
50
- *
51
- * @var string
52
- */
53
- private $_plugin_dir_path;
54
- /**
55
- * @since 1.0.0
56
- *
57
- * @var string
58
- */
59
- private $_plugin_dir_name;
60
- /**
61
- * @since 1.0.0
62
- *
63
- * @var string
64
- */
65
- private $_plugin_main_file_path;
66
- /**
67
- * @var string[]
68
- */
69
- private $_plugin_data;
70
- /**
71
- * @since 1.0.9
72
- *
73
- * @var string
74
- */
75
- private $_plugin_name;
76
- /**
77
- * @since 1.2.2
78
- *
79
- * @var string
80
- */
81
- private $_module_type;
82
-
83
- #endregion Plugin Info
84
-
85
- /**
86
- * @since 1.0.9
87
- *
88
- * @var bool If false, don't turn Freemius on.
89
- */
90
- private $_is_on;
91
-
92
- /**
93
- * @since 1.1.3
94
- *
95
- * @var bool If false, don't turn Freemius on.
96
- */
97
- private $_is_anonymous;
98
-
99
- /**
100
- * @since 1.0.9
101
- * @var bool If false, issues with connectivity to Freemius API.
102
- */
103
- private $_has_api_connection;
104
-
105
- /**
106
- * @since 1.0.9
107
- * @since 2.0.0 Default to true since we need the property during the instance construction, prior to the dynamic_init() execution.
108
- * @var bool Hints the SDK if plugin can support anonymous mode (if skip connect is visible).
109
- */
110
- private $_enable_anonymous = true;
111
-
112
- /**
113
- * @since 1.1.7.5
114
- * @var bool Hints the SDK if plugin should run in anonymous mode (only adds feedback form).
115
- */
116
- private $_anonymous_mode;
117
-
118
- /**
119
- * @since 1.1.9
120
- * @var bool Hints the SDK if plugin have any free plans.
121
- */
122
- private $_is_premium_only;
123
-
124
- /**
125
- * @since 1.2.1.6
126
- * @var bool Hints the SDK if plugin have premium code version at all.
127
- */
128
- private $_has_premium_version;
129
-
130
- /**
131
- * @since 1.2.1.6
132
- * @var bool Hints the SDK if plugin should ignore pending mode by simulating a skip.
133
- */
134
- private $_ignore_pending_mode;
135
-
136
- /**
137
- * @since 1.0.8
138
- * @var bool Hints the SDK if the plugin has any paid plans.
139
- */
140
- private $_has_paid_plans;
141
-
142
- /**
143
- * @since 1.2.1.5
144
- * @var int Hints the SDK if the plugin offers a trial period. If negative, no trial, if zero - has a trial but
145
- * without a specified period, if positive - the number of trial days.
146
- */
147
- private $_trial_days = - 1;
148
-
149
- /**
150
- * @since 1.2.1.5
151
- * @var bool Hints the SDK if the trial requires a payment method or not.
152
- */
153
- private $_is_trial_require_payment = false;
154
-
155
- /**
156
- * @since 1.0.7
157
- * @var bool Hints the SDK if the plugin is WordPress.org compliant.
158
- */
159
- private $_is_org_compliant;
160
-
161
- /**
162
- * @since 1.0.7
163
- * @var bool Hints the SDK if the plugin is has add-ons.
164
- */
165
- private $_has_addons;
166
-
167
- /**
168
- * @since 2.4.5
169
- * @var string Navigation type: 'menu' or 'tabs'.
170
- */
171
- private $_navigation;
172
-
173
- const NAVIGATION_MENU = 'menu';
174
- const NAVIGATION_TABS = 'tabs';
175
-
176
- /**
177
- * @since 1.1.6
178
- * @var string[]bool.
179
- */
180
- private $_permissions;
181
-
182
- /**
183
- * @var FS_Storage
184
- */
185
- private $_storage;
186
-
187
- /**
188
- * @since 1.2.2.7
189
- * @var FS_Cache_Manager
190
- */
191
- private $_cache;
192
-
193
- /**
194
- * @since 1.0.0
195
- *
196
- * @var FS_Logger
197
- */
198
- private $_logger;
199
- /**
200
- * @since 1.0.4
201
- *
202
- * @var FS_Plugin
203
- */
204
- private $_plugin = false;
205
- /**
206
- * @since 1.0.4
207
- *
208
- * @var FS_Plugin|false
209
- */
210
- private $_parent_plugin = false;
211
- /**
212
- * @since 1.1.1
213
- *
214
- * @var Freemius
215
- */
216
- private $_parent = false;
217
- /**
218
- * @since 1.0.1
219
- *
220
- * @var FS_User
221
- */
222
- private $_user = false;
223
- /**
224
- * @since 1.0.1
225
- *
226
- * @var FS_Site
227
- */
228
- private $_site = false;
229
- /**
230
- * @since 1.0.1
231
- *
232
- * @var FS_Plugin_License
233
- */
234
- private $_license;
235
- /**
236
- * @since 1.0.2
237
- *
238
- * @var FS_Plugin_Plan[]
239
- */
240
- private $_plans = false;
241
- /**
242
- * @var FS_Plugin_License[]
243
- * @since 1.0.5
244
- */
245
- private $_licenses = false;
246
-
247
- /**
248
- * @since 1.0.1
249
- *
250
- * @var FS_Admin_Menu_Manager
251
- */
252
- private $_menu;
253
-
254
- /**
255
- * @var FS_Admin_Notices
256
- */
257
- private $_admin_notices;
258
-
259
- /**
260
- * @since 1.1.6
261
- *
262
- * @var FS_Admin_Notices
263
- */
264
- private static $_global_admin_notices;
265
-
266
- /**
267
- * @var FS_Logger
268
- * @since 1.0.0
269
- */
270
- private static $_static_logger;
271
-
272
- /**
273
- * @var FS_Options
274
- * @since 1.0.2
275
- */
276
- private static $_accounts;
277
-
278
- /**
279
- * @since 1.2.2
280
- *
281
- * @var number
282
- */
283
- private $_module_id;
284
-
285
- /**
286
- * @var Freemius[]
287
- */
288
- private static $_instances = array();
289
-
290
- /**
291
- * @since 1.2.3
292
- *
293
- * @var FS_Affiliate
294
- */
295
- private $affiliate = null;
296
-
297
- /**
298
- * @since 1.2.3
299
- *
300
- * @var FS_AffiliateTerms
301
- */
302
- private $plugin_affiliate_terms = null;
303
-
304
- /**
305
- * @since 1.2.3
306
- *
307
- * @var FS_AffiliateTerms
308
- */
309
- private $custom_affiliate_terms = null;
310
-
311
- /**
312
- * @since 2.0.0
313
- *
314
- * @var bool
315
- */
316
- private $_is_multisite_integrated;
317
-
318
- /**
319
- * @since 2.0.0
320
- *
321
- * @var bool True if the current request is for a network admin screen and the plugin is network active.
322
- */
323
- private $_is_network_active;
324
-
325
- /**
326
- * @since 2.0.0
327
- *
328
- * @var int|null The original blog ID the plugin was loaded with.
329
- */
330
- private $_blog_id = null;
331
-
332
- /**
333
- * @since 2.0.0
334
- *
335
- * @var int|null The current execution context. When true, run on network context. When int, run on the specified blog context.
336
- */
337
- private $_context_is_network_or_blog_id = null;
338
-
339
- /**
340
- * @since 2.0.0
341
- *
342
- * @var string
343
- */
344
- private $_dynamically_added_top_level_page_hook_name = '';
345
-
346
- /**
347
- * @author Leo Fajardo (@leorw)
348
- * @since 2.3.1
349
- *
350
- * @var bool
351
- */
352
- private $is_whitelabeled;
353
-
354
- /**
355
- * @author Leo Fajardo (@leorw)
356
- * @since 2.4.0
357
- *
358
- * @var bool
359
- */
360
- private $_is_bundle_license_auto_activation_enabled = false;
361
-
362
- #region Uninstall Reasons IDs
363
-
364
- const REASON_NO_LONGER_NEEDED = 1;
365
- const REASON_FOUND_A_BETTER_PLUGIN = 2;
366
- const REASON_NEEDED_FOR_A_SHORT_PERIOD = 3;
367
- const REASON_BROKE_MY_SITE = 4;
368
- const REASON_SUDDENLY_STOPPED_WORKING = 5;
369
- const REASON_CANT_PAY_ANYMORE = 6;
370
- const REASON_OTHER = 7;
371
- const REASON_DIDNT_WORK = 8;
372
- const REASON_DONT_LIKE_TO_SHARE_MY_INFORMATION = 9;
373
- const REASON_COULDNT_MAKE_IT_WORK = 10;
374
- const REASON_GREAT_BUT_NEED_SPECIFIC_FEATURE = 11;
375
- const REASON_NOT_WORKING = 12;
376
- const REASON_NOT_WHAT_I_WAS_LOOKING_FOR = 13;
377
- const REASON_DIDNT_WORK_AS_EXPECTED = 14;
378
- const REASON_TEMPORARY_DEACTIVATION = 15;
379
-
380
- /**
381
- * @author Leo Fajardo (@leorw)
382
- * @since 2.3.1
383
- *
384
- * @var boolean|null
385
- */
386
- private $_use_external_pricing = null;
387
- /**
388
- * @author Leo Fajardo (@leorw)
389
- * @since 2.4.2
390
- *
391
- * @var string|null
392
- */
393
- private $_pricing_js_path = null;
394
-
395
- #endregion
396
-
397
- /* Ctor
398
- ------------------------------------------------------------------------------------------------------------------*/
399
-
400
- /**
401
- * Main singleton instance.
402
- *
403
- * @author Vova Feldman (@svovaf)
404
- * @since 1.0.0
405
- *
406
- * @param number $module_id
407
- * @param string|bool $slug
408
- * @param bool $is_init Since 1.2.1 Is initiation sequence.
409
- */
410
- private function __construct( $module_id, $slug = false, $is_init = false ) {
411
- $main_file = false;
412
-
413
- if ( $is_init && is_numeric( $module_id ) && is_string( $slug ) ) {
414
- $main_file = $this->store_id_slug_type_path_map( $module_id, $slug );
415
- }
416
-
417
- $this->_module_id = $module_id;
418
- $this->_slug = $this->get_slug();
419
- $this->_module_type = $this->get_module_type();
420
-
421
- $this->_blog_id = is_multisite() ? get_current_blog_id() : null;
422
-
423
- $this->_storage = FS_Storage::instance( $this->_module_type, $this->_slug );
424
-
425
- $this->_cache = FS_Cache_Manager::get_manager( WP_FS___OPTION_PREFIX . "cache_{$module_id}" );
426
-
427
- $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $this->get_unique_affix(), WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
428
-
429
- $this->_plugin_main_file_path = $this->_find_caller_plugin_file( $is_init, $main_file );
430
- $this->_plugin_dir_path = plugin_dir_path( $this->_plugin_main_file_path );
431
- $this->_plugin_basename = $this->get_plugin_basename();
432
- $this->_free_plugin_basename = str_replace( '-premium/', '/', $this->_plugin_basename );
433
-
434
- $this->_is_multisite_integrated = (
435
- defined( "WP_FS__PRODUCT_{$module_id}_MULTISITE" ) &&
436
- ( true === constant( "WP_FS__PRODUCT_{$module_id}_MULTISITE" ) )
437
- );
438
-
439
- $this->_is_network_active = (
440
- is_multisite() &&
441
- $this->_is_multisite_integrated &&
442
- // Themes are always network activated, but the ACTUAL activation is per site.
443
- $this->is_plugin() &&
444
- (
445
- is_plugin_active_for_network( $this->_plugin_basename ) ||
446
- // Plugin network level activation or uninstall.
447
- ( fs_is_network_admin() && is_plugin_inactive( $this->_plugin_basename ) )
448
- )
449
- );
450
-
451
- $this->_storage->set_network_active(
452
- $this->_is_network_active,
453
- $this->is_delegated_connection()
454
- );
455
-
456
- if ( ! isset( $this->_storage->is_network_activated ) ) {
457
- $this->_storage->is_network_activated = $this->_is_network_active;
458
- }
459
-
460
- if ( $this->_storage->is_network_activated != $this->_is_network_active ) {
461
- // Update last activation level.
462
- $this->_storage->is_network_activated = $this->_is_network_active;
463
-
464
- $this->maybe_adjust_storage();
465
- }
466
-
467
- #region Migration
468
-
469
- if ( is_multisite() ) {
470
- /**
471
- * If the install_timestamp exists on the site level but doesn't exist on the
472
- * network level storage, it means that we need to process the storage with migration.
473
- *
474
- * The code in this `if` scope will only be executed once and only for the first site that will execute it because once we migrate the storage data, install_timestamp will be already set in the network level storage.
475
- *
476
- * @author Vova Feldman (@svovaf)
477
- * @since 2.0.0
478
- */
479
- if ( false === $this->_storage->get( 'install_timestamp', false, true ) &&
480
- false !== $this->_storage->get( 'install_timestamp', false, false )
481
- ) {
482
- // Initiate storage migration.
483
- $this->_storage->migrate_to_network();
484
-
485
- // Migrate module cache to network level storage.
486
- $this->_cache->migrate_to_network();
487
- }
488
- }
489
-
490
- #endregion
491
-
492
- $base_name_split = explode( '/', $this->_plugin_basename );
493
- $this->_plugin_dir_name = $base_name_split[0];
494
-
495
- if ( $this->_logger->is_on() ) {
496
- $this->_logger->info( 'plugin_main_file_path = ' . $this->_plugin_main_file_path );
497
- $this->_logger->info( 'plugin_dir_path = ' . $this->_plugin_dir_path );
498
- $this->_logger->info( 'plugin_basename = ' . $this->_plugin_basename );
499
- $this->_logger->info( 'free_plugin_basename = ' . $this->_free_plugin_basename );
500
- $this->_logger->info( 'plugin_dir_name = ' . $this->_plugin_dir_name );
501
- }
502
-
503
- // Remember link between file to slug.
504
- $this->store_file_slug_map();
505
-
506
- // Store plugin's initial install timestamp.
507
- if ( ! isset( $this->_storage->install_timestamp ) ) {
508
- $this->_storage->install_timestamp = WP_FS__SCRIPT_START_TIME;
509
- }
510
-
511
- if ( ! is_object( $this->_plugin ) ) {
512
- $this->_plugin = FS_Plugin_Manager::instance( $this->_module_id )->get();
513
- }
514
-
515
- $this->_admin_notices = FS_Admin_Notices::instance(
516
- $this->_slug . ( $this->is_theme() ? ':theme' : '' ),
517
- /**
518
- * Ensure that the admin notice will always have a title by using the stored plugin title if available and
519
- * retrieving the title via the "get_plugin_name" method if there is no stored plugin title available.
520
- *
521
- * @author Leo Fajardo (@leorw)
522
- * @since 1.2.2
523
- */
524
- ( is_object( $this->_plugin ) && isset( $this->_plugin->title ) ?
525
- $this->_plugin->title :
526
- $this->get_plugin_name()
527
- ),
528
- $this->get_unique_affix()
529
- );
530
-
531
- if ( 'true' === fs_request_get( 'fs_clear_api_cache' ) ||
532
- fs_request_is_action( 'restart_freemius' )
533
- ) {
534
- FS_Api::clear_cache();
535
- $this->_cache->clear();
536
- }
537
-
538
- $this->register_constructor_hooks();
539
-
540
- /**
541
- * Starting from version 2.0.0, `FS_Site` entities no longer have the `plan` property and have `plan_id`
542
- * instead. This should be called before calling `_load_account()`, otherwise, `$this->_site` will not be
543
- * loaded in `_load_account` for versions of SDK starting from 2.0.0.
544
- *
545
- * @author Leo Fajardo (@leorw)
546
- */
547
- self::migrate_install_plan_to_plan_id( $this->_storage );
548
-
549
- $this->_load_account();
550
-
551
- $this->_version_updates_handler();
552
- }
553
-
554
- /**
555
- * @author Leo Fajardo (@leorw)
556
- * @since 2.3.0
557
- */
558
- private function maybe_adjust_storage() {
559
- $install_timestamp = null;
560
- $prev_is_premium = null;
561
-
562
- $options_to_update = array();
563
-
564
- $is_network_admin = fs_is_network_admin();
565
-
566
- $network_install_timestamp = $this->_storage->get( 'install_timestamp', null, true );
567
-
568
- if ( ! $is_network_admin ) {
569
- if ( is_null( $network_install_timestamp ) ) {
570
- // Plugin was not network-activated before.
571
- return;
572
- }
573
-
574
- if ( is_null( $this->_storage->get( 'install_timestamp', null, false ) ) ) {
575
- // Set the `install_timestamp` only if it's not yet set.
576
- $install_timestamp = $network_install_timestamp;
577
- }
578
-
579
- $prev_is_premium = $this->_storage->get( 'prev_is_premium', null, true );
580
- } else {
581
- $current_wp_user = self::_get_current_wp_user();
582
- $current_fs_user = self::_get_user_by_email( $current_wp_user->user_email );
583
- $network_user_info = array();
584
-
585
- $skips_count = 0;
586
-
587
- $sites = self::get_sites();
588
- $sites_count = count( $sites );
589
-
590
- $blog_id_2_install_map = array();
591
-
592
- $is_first_non_ignored_blog = true;
593
-
594
- foreach ( $sites as $site ) {
595
- $blog_id = self::get_site_blog_id( $site );
596
-
597
- $blog_install_timestamp = $this->_storage->get( 'install_timestamp', null, $blog_id );
598
-
599
- if ( is_null( $blog_install_timestamp ) ) {
600
- // Plugin has not been installed on this blog.
601
- continue;
602
- }
603
-
604
- $is_earlier_install = (
605
- ! is_null( $install_timestamp ) &&
606
- $blog_install_timestamp < $install_timestamp
607
- );
608
-
609
- $install = $this->get_install_by_blog_id( $blog_id );
610
-
611
- $update_network_user_info = false;
612
-
613
- if ( ! is_object( $install ) ) {
614
- if ( ! $this->_storage->get( 'is_anonymous', false, $blog_id ) ) {
615
- // The opt-in decision (whether to skip or opt in) is yet to be made.
616
- continue;
617
- }
618
-
619
- $skips_count ++;
620
- } else {
621
- $blog_id_2_install_map[ $blog_id ] = $install;
622
-
623
- if ( empty( $network_user_info ) ) {
624
- // Set the network user info for the 1st time. Choose any user information whether or not it is for the current WP user.
625
- $update_network_user_info = true;
626
- }
627
-
628
- if ( ! $update_network_user_info &&
629
- is_object( $current_fs_user ) &&
630
- $network_user_info['user_id'] != $current_fs_user->id &&
631
- $install->user_id == $current_fs_user->id
632
- ) {
633
- // If an install that is owned by the current WP user is found, use its user information instead.
634
- $update_network_user_info = true;
635
- }
636
-
637
- if ( ! $update_network_user_info &&
638
- $is_earlier_install &&
639
- ( ! is_object( $current_fs_user ) || $current_fs_user->id == $install->user_id )
640
- ) {
641
- // Update to the earliest install info if there's no install found so far that is owned by the current WP user; OR only if the found install is owned by the current WP user.
642
- $update_network_user_info = true;
643
- }
644
- }
645
-
646
- if ( $update_network_user_info ) {
647
- $network_user_info = array(
648
- 'user_id' => $install->user_id,
649
- 'blog_id' => $blog_id
650
- );
651
- }
652
-
653
- $site_prev_is_premium = $this->_storage->get( 'prev_is_premium', null, $blog_id );
654
-
655
- if ( $is_first_non_ignored_blog ) {
656
- $prev_is_premium = $site_prev_is_premium;
657
-
658
- if ( is_null( $network_install_timestamp ) ) {
659
- $install_timestamp = $blog_install_timestamp;
660
- }
661
-
662
- $is_first_non_ignored_blog = false;
663
-
664
- continue;
665
- }
666
-
667
- if ( ! is_null( $prev_is_premium ) && $prev_is_premium !== $site_prev_is_premium ) {
668
- // If a different `$site_prev_is_premium` value is found, do not include the option in the collection of options to update.
669
- $prev_is_premium = null;
670
- }
671
-
672
- if ( $is_earlier_install ) {
673
- // If an earlier install timestamp is found.
674
- $install_timestamp = $blog_install_timestamp;
675
- }
676
- }
677
-
678
- $installs_count = count( $blog_id_2_install_map );
679
-
680
- if ( $sites_count === ( $installs_count + $skips_count ) ) {
681
- if ( ! empty( $network_user_info ) ) {
682
- $options_to_update['network_user_id'] = $network_user_info['user_id'];
683
- $options_to_update['network_install_blog_id'] = $network_user_info['blog_id'];
684
-
685
- foreach ( $blog_id_2_install_map as $blog_id => $install ) {
686
- if ( $install->user_id == $network_user_info['user_id'] ) {
687
- continue;
688
- }
689
-
690
- $this->_storage->store( 'is_delegated_connection', true, $blog_id );
691
- }
692
- }
693
-
694
- if ( $sites_count === $skips_count ) {
695
- /**
696
- * Assume network-level skipping as the intended action if all actions identified were only
697
- * skipping of the connection (i.e., no opt-ins and delegated connections so far).
698
- */
699
- $options_to_update['is_anonymous_ms'] = true;
700
- } else if ( $sites_count === $installs_count ) {
701
- /**
702
- * Assume network-level opt-in as the intended action if all actions identified were only opt-ins
703
- * (i.e., no delegation and skipping of the connections so far).
704
- */
705
- $options_to_update['is_network_connected'] = true;
706
- }
707
- }
708
- }
709
-
710
- if ( ! is_null( $install_timestamp ) ) {
711
- $options_to_update['install_timestamp'] = $install_timestamp;
712
- }
713
-
714
- if ( ! is_null( $prev_is_premium ) ) {
715
- $options_to_update['prev_is_premium'] = $prev_is_premium;
716
- }
717
-
718
- if ( ! empty( $options_to_update ) ) {
719
- $this->adjust_storage( $options_to_update, $is_network_admin );
720
- }
721
- }
722
-
723
- /**
724
- * @author Leo Fajardo (@leorw)
725
- * @since 2.3.0
726
- *
727
- * @param array $options
728
- * @param bool $is_network_admin
729
- */
730
- private function adjust_storage( $options, $is_network_admin ) {
731
- foreach ( $options as $name => $value ) {
732
- $this->_storage->store( $name, $value, $is_network_admin ? true : null );
733
- }
734
- }
735
-
736
- /**
737
- * Checks whether this module has a settings menu.
738
- *
739
- * @author Leo Fajardo (@leorw)
740
- * @since 1.2.2
741
- *
742
- * @return bool
743
- */
744
- function has_settings_menu() {
745
- return ( $this->_is_network_active && fs_is_network_admin() ) ?
746
- $this->_menu->has_network_menu() :
747
- $this->_menu->has_menu();
748
- }
749
-
750
- /**
751
- * If `true` the opt-in should be shown as a modal dialog box on the themes.php page. WordPress.org themes guidelines prohibit from redirecting the user from the themes.php page after activating a theme.
752
- *
753
- * @author Vova Feldman (@svovaf)
754
- * @since 2.4.5
755
- *
756
- * @return bool
757
- */
758
- function show_opt_in_on_themes_page() {
759
- if ( ! $this->is_free_wp_org_theme() ) {
760
- return false;
761
- }
762
-
763
- if ( ! $this->has_settings_menu() ) {
764
- return true;
765
- }
766
-
767
- return $this->show_settings_with_tabs();
768
- }
769
-
770
- /**
771
- * If `true` the opt-in should be shown on the product's main setting page.
772
- *
773
- * @author Vova Feldman (@svovaf)
774
- * @since 2.4.5
775
- *
776
- * @return bool
777
- *
778
- * @uses show_opt_in_on_themes_page();
779
- */
780
- function show_opt_in_on_setting_page() {
781
- return ! $this->show_opt_in_on_themes_page();
782
- }
783
-
784
- /**
785
- * If `true` the settings should be shown using tabs.
786
- *
787
- * @author Vova Feldman (@svovaf)
788
- * @since 2.4.5
789
- *
790
- * @return bool
791
- */
792
- function show_settings_with_tabs() {
793
- return ( self::NAVIGATION_TABS === $this->_navigation );
794
- }
795
-
796
- /**
797
- * Check if the context module is free wp.org theme.
798
- *
799
- * This method is helpful because:
800
- * 1. wp.org themes are limited to a single submenu item,
801
- * and sub-submenu items are most likely not allowed (never verified).
802
- * 2. wp.org themes are not allowed to redirect the user
803
- * after the theme activation, therefore, the agreed UX
804
- * is showing the opt-in as a modal dialog box after
805
- * activation (approved by @otto42, @emiluzelac, @greenshady, @grapplerulrich).
806
- *
807
- * @author Vova Feldman (@svovaf)
808
- * @since 1.2.2.7
809
- *
810
- * @return bool
811
- */
812
- function is_free_wp_org_theme() {
813
- return (
814
- $this->is_theme() &&
815
- $this->is_org_repo_compliant() &&
816
- ! $this->is_premium()
817
- );
818
- }
819
-
820
- /**
821
- * Checks whether this a submenu item is visible.
822
- *
823
- * @author Vova Feldman (@svovaf)
824
- * @since 1.2.2.6
825
- * @since 1.2.2.7 Even if the menu item was specified to be hidden, when it is the context page, then show the submenu item so the user will have the right context page.
826
- *
827
- * @param string $slug
828
- * @param bool $is_tabs_visibility_check This is used to decide if the associated tab should be shown or hidden.
829
- *
830
- * @return bool
831
- */
832
- function is_submenu_item_visible( $slug, $is_tabs_visibility_check = false ) {
833
- if ( $this->is_admin_page( $slug ) ) {
834
- /**
835
- * It is the current context page, so show the submenu item
836
- * so the user will have the right context page, even if it
837
- * was set to hidden.
838
- */
839
- return true;
840
- }
841
-
842
- if ( ! $this->has_settings_menu() ) {
843
- // No menu settings at all.
844
- return false;
845
- }
846
-
847
- if (
848
- ! $is_tabs_visibility_check &&
849
- $this->is_org_repo_compliant() &&
850
- $this->show_settings_with_tabs()
851
- ) {
852
- /**
853
- * wp.org themes are limited to a single submenu item, and
854
- * sub-submenu items are most likely not allowed (never verified).
855
- */
856
- return false;
857
- }
858
-
859
- return $this->_menu->is_submenu_item_visible( $slug );
860
- }
861
-
862
- /**
863
- * Check if a Freemius page should be accessible via the UI.
864
- *
865
- * @author Vova Feldman (@svovaf)
866
- * @since 1.2.2.7
867
- *
868
- * @param string $slug
869
- *
870
- * @return bool
871
- */
872
- function is_page_visible( $slug ) {
873
- if ( $this->is_admin_page( $slug ) ) {
874
- return true;
875
- }
876
-
877
- return $this->_menu->is_submenu_item_visible( $slug, true, true );
878
- }
879
-
880
- /**
881
- * @author Vova Feldman (@svovaf)
882
- * @since 1.0.9
883
- */
884
- private function _version_updates_handler() {
885
- if ( ! isset( $this->_storage->sdk_version ) || $this->_storage->sdk_version != $this->version ) {
886
- // Freemius version upgrade mode.
887
- $this->_storage->sdk_last_version = $this->_storage->sdk_version;
888
- $this->_storage->sdk_version = $this->version;
889
-
890
- if ( empty( $this->_storage->sdk_last_version ) ||
891
- version_compare( $this->_storage->sdk_last_version, $this->version, '<' )
892
- ) {
893
- $this->_storage->sdk_upgrade_mode = true;
894
- $this->_storage->sdk_downgrade_mode = false;
895
- } else {
896
- $this->_storage->sdk_downgrade_mode = true;
897
- $this->_storage->sdk_upgrade_mode = false;
898
-
899
- }
900
-
901
- $this->do_action( 'sdk_version_update', $this->_storage->sdk_last_version, $this->version );
902
- }
903
-
904
- $plugin_version = $this->get_plugin_version();
905
- if ( ! isset( $this->_storage->plugin_version ) || $this->_storage->plugin_version != $plugin_version ) {
906
- // Plugin version upgrade mode.
907
- $this->_storage->plugin_last_version = $this->_storage->plugin_version;
908
- $this->_storage->plugin_version = $plugin_version;
909
-
910
- if ( empty( $this->_storage->plugin_last_version ) ||
911
- version_compare( $this->_storage->plugin_last_version, $plugin_version, '<' )
912
- ) {
913
- $this->_storage->plugin_upgrade_mode = true;
914
- $this->_storage->plugin_downgrade_mode = false;
915
- } else {
916
- $this->_storage->plugin_downgrade_mode = true;
917
- $this->_storage->plugin_upgrade_mode = false;
918
- }
919
-
920
- if ( ! empty( $this->_storage->plugin_last_version ) ) {
921
- // Different version of the plugin was installed before, therefore it's an update.
922
- $this->_storage->is_plugin_new_install = false;
923
- }
924
-
925
- $this->do_action( 'plugin_version_update', $this->_storage->plugin_last_version, $plugin_version );
926
- }
927
- }
928
-
929
- #--------------------------------------------------------------------------------
930
- #region Data Migration on SDK Update
931
- #--------------------------------------------------------------------------------
932
-
933
- /**
934
- * @author Vova Feldman (@svovaf)
935
- * @since 1.1.5
936
- *
937
- * @param string $sdk_prev_version
938
- * @param string $sdk_version
939
- */
940
- function _sdk_version_update( $sdk_prev_version, $sdk_version ) {
941
- /**
942
- * @since 1.1.7.3 Fixed unwanted connectivity test cleanup.
943
- */
944
- if ( empty( $sdk_prev_version ) ) {
945
- return;
946
- }
947
-
948
- if ( version_compare( $sdk_prev_version, '2.1.0', '<' ) &&
949
- version_compare( $sdk_version, '2.1.0', '>=' )
950
- ) {
951
- $this->_storage->handle_gdpr_admin_notice = true;
952
- }
953
-
954
- if ( version_compare( $sdk_prev_version, '2.0.0', '<' ) &&
955
- version_compare( $sdk_version, '2.0.0', '>=' )
956
- ) {
957
- $this->migrate_to_subscriptions_collection();
958
-
959
- $this->consolidate_licenses();
960
-
961
- // Clear trial_plan since it's now loaded from the plans collection when needed.
962
- $this->_storage->remove( 'trial_plan', true, false );
963
- }
964
-
965
- if ( version_compare( $sdk_prev_version, '1.2.3', '<' ) &&
966
- version_compare( $sdk_version, '1.2.3', '>=' )
967
- ) {
968
- /**
969
- * Starting from version 1.2.3, paths are stored as relative instead of absolute and some of them can be
970
- * invalid.
971
- *
972
- * @author Leo Fajardo (@leorw)
973
- */
974
- $this->remove_invalid_paths();
975
- }
976
-
977
- if ( version_compare( $sdk_prev_version, '1.1.5', '<' ) &&
978
- version_compare( $sdk_version, '1.1.5', '>=' )
979
- ) {
980
- // On version 1.1.5 merged connectivity and is_on data.
981
- if ( isset( $this->_storage->connectivity_test ) ) {
982
- if ( ! isset( $this->_storage->is_on ) ) {
983
- unset( $this->_storage->connectivity_test );
984
- } else {
985
- $connectivity_data = $this->_storage->connectivity_test;
986
- $connectivity_data['is_active'] = $this->_storage->is_on['is_active'];
987
- $connectivity_data['timestamp'] = $this->_storage->is_on['timestamp'];
988
-
989
- // Override.
990
- $this->_storage->connectivity_test = $connectivity_data;
991
-
992
- // Remove previous structure.
993
- unset( $this->_storage->is_on );
994
- }
995
-
996
- }
997
- }
998
-
999
- if (
1000
- version_compare( $sdk_prev_version, '2.2.1', '<' ) &&
1001
- version_compare( $sdk_version, '2.2.1', '>=' )
1002
- ) {
1003
- /**
1004
- * Clear the file cache without storing the previous path since it could be a wrong path. For example,
1005
- * in the versions of the SDK lower than 2.2.1, it's possible for the path of an add-on to be the same
1006
- * as the parent plugin's when the add-on was auto-installed since the relevant method names were not
1007
- * skipped in the logic that determines the right path in the `get_caller_main_file_and_type` method
1008
- * (e.g. `try_activate_plugin`). Since it was an auto-installation, the caller was the parent plugin
1009
- * and so its path was used. In case the stored path is wrong, clearing the cache will resolve issues
1010
- * related to data mix-up between plugins (e.g. titles and versions of an add-on and its parent plugin).
1011
- *
1012
- * @author Leo Fajardo (@leorw)
1013
- * @since 2.2.1
1014
- */
1015
- $this->clear_module_main_file_cache( false );
1016
- }
1017
- }
1018
-
1019
- /**
1020
- * @author Leo Fajardo (@leorw)
1021
- * @since 2.0.0
1022
- *
1023
- * @param \FS_Storage $storage
1024
- * @param bool|int|null $blog_id
1025
- */
1026
- private static function migrate_install_plan_to_plan_id( FS_Storage $storage, $blog_id = null ) {
1027
- if ( empty( $storage->sdk_version ) ) {
1028
- // New installation of the plugin, no need to upgrade.
1029
- return;
1030
- }
1031
-
1032
- if ( ! version_compare( $storage->sdk_version, '2.0.0', '<' ) ) {
1033
- // Previous version is >= 2.0.0, so no need to migrate.
1034
- return;
1035
- }
1036
-
1037
- // Alias.
1038
- $module_type = $storage->get_module_type();
1039
- $module_slug = $storage->get_module_slug();
1040
-
1041
- $installs = self::get_all_sites( $module_type, $blog_id );
1042
- $install = isset( $installs[ $module_slug ] ) ? $installs[ $module_slug ] : null;
1043
-
1044
- if ( ! is_object( $install ) ) {
1045
- return;
1046
- }
1047
-
1048
- if ( isset( $install->plan ) && is_object( $install->plan ) ) {
1049
- if ( isset( $install->plan->id ) && ! empty( $install->plan->id ) ) {
1050
- $install->plan_id = self::_decrypt( $install->plan->id );
1051
- }
1052
-
1053
- unset( $install->plan );
1054
-
1055
- $installs[ $module_slug ] = clone $install;
1056
-
1057
- self::set_account_option_by_module(
1058
- $module_type,
1059
- 'sites',
1060
- $installs,
1061
- true,
1062
- $blog_id
1063
- );
1064
- }
1065
- }
1066
-
1067
- /**
1068
- * @author Leo Fajardo (@leorw)
1069
- * @since 2.0.0
1070
- */
1071
- private function migrate_to_subscriptions_collection() {
1072
- if ( ! is_object( $this->_site ) ) {
1073
- return;
1074
- }
1075
-
1076
- if ( isset( $this->_storage->subscription ) && is_object( $this->_storage->subscription ) ) {
1077
- $this->_storage->subscriptions = array( fs_get_entity( $this->_storage->subscription, FS_Subscription::get_class_name() ) );
1078
- }
1079
- }
1080
-
1081
- /**
1082
- * @author Leo Fajardo (@leorw)
1083
- * @since 2.0.0
1084
- */
1085
- private function consolidate_licenses() {
1086
- $plugin_licenses = self::get_account_option( 'licenses', WP_FS__MODULE_TYPE_PLUGIN );
1087
- if ( isset( $plugin_licenses[ $this->_slug ] ) ) {
1088
- $plugin_licenses = $plugin_licenses[ $this->_slug ];
1089
- } else {
1090
- $plugin_licenses = array();
1091
- }
1092
-
1093
- $theme_licenses = self::get_account_option( 'licenses', WP_FS__MODULE_TYPE_THEME );
1094
- if ( isset( $theme_licenses[ $this->_slug ] ) ) {
1095
- $theme_licenses = $theme_licenses[ $this->_slug ];
1096
- } else {
1097
- $theme_licenses = array();
1098
- }
1099
-
1100
- if ( empty( $plugin_licenses ) && empty( $theme_licenses ) ) {
1101
- return;
1102
- }
1103
-
1104
- $all_licenses = array();
1105
- $user_id_license_ids_map = array();
1106
-
1107
- foreach ( $plugin_licenses as $user_id => $user_licenses ) {
1108
- if ( is_array( $user_licenses ) ) {
1109
- if ( ! isset( $user_license_ids[ $user_id ] ) ) {
1110
- $user_id_license_ids_map[ $user_id ] = array();
1111
- }
1112
-
1113
- foreach ( $user_licenses as $user_license ) {
1114
- $all_licenses[] = $user_license;
1115
- $user_id_license_ids_map[ $user_id ][] = $user_license->id;
1116
- }
1117
- }
1118
- }
1119
-
1120
- foreach ( $theme_licenses as $user_id => $user_licenses ) {
1121
- if ( is_array( $user_licenses ) ) {
1122
- if ( ! isset( $user_license_ids[ $user_id ] ) ) {
1123
- $user_id_license_ids_map[ $user_id ] = array();
1124
- }
1125
-
1126
- foreach ( $user_licenses as $user_license ) {
1127
- $all_licenses[] = $user_license;
1128
- $user_id_license_ids_map[ $user_id ][] = $user_license->id;
1129
- }
1130
- }
1131
- }
1132
-
1133
- self::store_user_id_license_ids_map(
1134
- $user_id_license_ids_map,
1135
- $this->_module_id
1136
- );
1137
-
1138
- $this->_store_licenses( true, $this->_module_id, $all_licenses );
1139
- }
1140
-
1141
- /**
1142
- * Remove invalid paths.
1143
- *
1144
- * @author Leo Fajardo (@leorw)
1145
- * @since 1.2.3
1146
- */
1147
- private function remove_invalid_paths() {
1148
- // Remove invalid path that is still associated with the current slug if there's any.
1149
- $file_slug_map = self::$_accounts->get_option( 'file_slug_map', array() );
1150
- foreach ( $file_slug_map as $plugin_basename => $slug ) {
1151
- if ( $slug === $this->_slug &&
1152
- $plugin_basename !== $this->_plugin_basename &&
1153
- ! file_exists( $this->get_absolute_path( $plugin_basename ) )
1154
- ) {
1155
- unset( $file_slug_map[ $plugin_basename ] );
1156
- self::$_accounts->set_option( 'file_slug_map', $file_slug_map, true );
1157
-
1158
- break;
1159
- }
1160
- }
1161
- }
1162
-
1163
- /**
1164
- * @author Vova Feldman (@svovaf)
1165
- * @since 1.2.2.7
1166
- *
1167
- * @param string $plugin_prev_version
1168
- * @param string $plugin_version
1169
- */
1170
- function _after_version_update( $plugin_prev_version, $plugin_version ) {
1171
- if ( $this->is_theme() ) {
1172
- // Expire the cache of the previous tabs since the theme may
1173
- // have setting updates.
1174
- $this->_cache->expire( 'tabs' );
1175
- $this->_cache->expire( 'tabs_stylesheets' );
1176
- }
1177
- }
1178
-
1179
- /**
1180
- * A special migration logic for the $_accounts, executed for all the plugins in the system:
1181
- * - Moves some data to the network level storage.
1182
- * - If the plugin's connection was skipped for all sites, set the plugin as if it was network skipped.
1183
- * - If the plugin's connection was ignored for all sites, don't do anything in terms of the network connection.
1184
- * - If the plugin was connected to all sites by the same super-admin, set the plugin as if was network opted-in for all sites.
1185
- * - If there's at least one site that was connected by a super-admin, find the "main super-admin" (the one that installed the majority of the plugin installs) and set the plugin as if was network activated with the main super-admin, set all the sites that were skipped or opted-in with a different user to delegated mode. Then, prompt the currently logged super-admin to choose what to do with the ignored sites.
1186
- * - If there are any sites in the network which the connection decision was not yet taken for, set this plugin into network activation mode so a super-admin can choose what to do with the rest of the sites.
1187
- *
1188
- * @author Vova Feldman (@svovaf)
1189
- * @since 2.0.0
1190
- */
1191
- private static function migrate_accounts_to_network() {
1192
- $sites = self::get_sites();
1193
- $sites_count = count( $sites );
1194
- $connection_status = array();
1195
- $plugin_slugs = array();
1196
- foreach ( $sites as $site ) {
1197
- $blog_id = self::get_site_blog_id( $site );
1198
-
1199
- self::$_accounts->migrate_to_network( $blog_id );
1200
-
1201
- /**
1202
- * Build a list of all Freemius powered plugins slugs.
1203
- */
1204
- $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array(), $blog_id );
1205
- foreach ( $id_slug_type_path_map as $module_id => $data ) {
1206
- if ( WP_FS__MODULE_TYPE_PLUGIN === $data['type'] ) {
1207
- $plugin_slugs[ $data['slug'] ] = true;
1208
- }
1209
- }
1210
-
1211
- $installs = self::get_account_option( 'sites', WP_FS__MODULE_TYPE_PLUGIN, $blog_id );
1212
-
1213
- if ( is_array( $installs ) ) {
1214
- foreach ( $installs as $slug => $install ) {
1215
- if ( ! isset( $connection_status[ $slug ] ) ) {
1216
- $connection_status[ $slug ] = array();
1217
- }
1218
-
1219
- if ( is_object( $install ) &&
1220
- FS_Site::is_valid_id( $install->id ) &&
1221
- FS_User::is_valid_id( $install->user_id )
1222
- ) {
1223
- $connection_status[ $slug ][ $blog_id ] = $install->user_id;
1224
- }
1225
- }
1226
- }
1227
- }
1228
-
1229
- foreach ( $plugin_slugs as $slug => $true ) {
1230
- if ( ! isset( $connection_status[ $slug ] ) ) {
1231
- $connection_status[ $slug ] = array();
1232
- }
1233
-
1234
- foreach ( $sites as $site ) {
1235
- $blog_id = self::get_site_blog_id( $site );
1236
-
1237
- if ( isset( $connection_status[ $slug ][ $blog_id ] ) ) {
1238
- continue;
1239
- }
1240
-
1241
- $storage = FS_Storage::instance( WP_FS__MODULE_TYPE_PLUGIN, $slug );
1242
-
1243
- $is_anonymous = $storage->get( 'is_anonymous', null, $blog_id );
1244
-
1245
- if ( ! is_null( $is_anonymous ) ) {
1246
- // Since 1.1.3 is_anonymous is an array.
1247
- if ( is_array( $is_anonymous ) && isset( $is_anonymous['is'] ) ) {
1248
- $is_anonymous = $is_anonymous['is'];
1249
- }
1250
-
1251
- if ( is_bool( $is_anonymous ) && true === $is_anonymous ) {
1252
- $connection_status[ $slug ][ $blog_id ] = 'skipped';
1253
- }
1254
- }
1255
-
1256
- if ( ! isset( $connection_status[ $slug ][ $blog_id ] ) ) {
1257
- $connection_status[ $slug ][ $blog_id ] = 'ignored';
1258
- }
1259
- }
1260
- }
1261
-
1262
- $super_admins = array();
1263
-
1264
- foreach ( $connection_status as $slug => $blogs_status ) {
1265
- $skips = 0;
1266
- $ignores = 0;
1267
- $connections = 0;
1268
- $opted_in_users = array();
1269
- $opted_in_super_admins = array();
1270
-
1271
- $storage = FS_Storage::instance( WP_FS__MODULE_TYPE_PLUGIN, $slug );
1272
-
1273
- foreach ( $blogs_status as $blog_id => $status_or_user_id ) {
1274
- if ( 'skipped' === $status_or_user_id ) {
1275
- $skips ++;
1276
- } else if ( 'ignored' === $status_or_user_id ) {
1277
- $ignores ++;
1278
- } else if ( FS_User::is_valid_id( $status_or_user_id ) ) {
1279
- $connections ++;
1280
-
1281
- if ( ! isset( $opted_in_users[ $status_or_user_id ] ) ) {
1282
- $opted_in_users[ $status_or_user_id ] = array();
1283
- }
1284
-
1285
- $opted_in_users[ $status_or_user_id ][] = $blog_id;
1286
-
1287
- if ( isset( $super_admins[ $status_or_user_id ] ) ||
1288
- self::is_super_admin( $status_or_user_id )
1289
- ) {
1290
- // Cache super-admin data.
1291
- $super_admins[ $status_or_user_id ] = true;
1292
-
1293
- // Remember opted-in super-admins for the plugin.
1294
- $opted_in_super_admins[ $status_or_user_id ] = true;
1295
- }
1296
- }
1297
- }
1298
-
1299
- $main_super_admin_user_id = null;
1300
- $all_migrated = false;
1301
- if ( $sites_count == $skips ) {
1302
- // All sites were skipped -> network skip by copying the anonymous mode from any of the sites.
1303
- $storage->is_anonymous_ms = $storage->is_anonymous;
1304
-
1305
- $all_migrated = true;
1306
- } else if ( $sites_count == $ignores ) {
1307
- // Don't do anything, still in activation mode.
1308
-
1309
- $all_migrated = true;
1310
- } else if ( 0 < count( $opted_in_super_admins ) ) {
1311
- // Find the super-admin with the majority of installs.
1312
- $max_installs_by_super_admin = 0;
1313
- foreach ( $opted_in_super_admins as $user_id => $true ) {
1314
- $installs_count = count( $opted_in_users[ $user_id ] );
1315
-
1316
- if ( $installs_count > $max_installs_by_super_admin ) {
1317
- $max_installs_by_super_admin = $installs_count;
1318
- $main_super_admin_user_id = $user_id;
1319
- }
1320
- }
1321
-
1322
- if ( $sites_count == $connections && 1 == count( $opted_in_super_admins ) ) {
1323
- // Super-admin opted-in for all sites in the network.
1324
- $storage->is_network_connected = true;
1325
-
1326
- $all_migrated = true;
1327
- }
1328
-
1329
- // Store network user.
1330
- $storage->network_user_id = $main_super_admin_user_id;
1331
-
1332
- $storage->network_install_blog_id = ( $sites_count == $connections ) ?
1333
- // Since all sites are opted-in, associating with the main site.
1334
- get_current_blog_id() :
1335
- // Associating with the 1st found opted-in site.
1336
- $opted_in_users[ $main_super_admin_user_id ][0];
1337
-
1338
- /**
1339
- * Make sure we migrate the plan ID of the network install, otherwise, if after the migration
1340
- * the 1st page that will be loaded is the network level WP Admin and $storage->network_install_blog_id
1341
- * is different than the main site of the network, the $this->_site will not be set since the plan_id
1342
- * will be empty.
1343
- */
1344
- $storage->migrate_to_network();
1345
- self::migrate_install_plan_to_plan_id( $storage, $storage->network_install_blog_id );
1346
- } else {
1347
- // At least one opt-in. All the opt-in were created by a non-super-admin.
1348
- if ( 0 == $ignores ) {
1349
- // All sites were opted-in or skipped, all by non-super-admin. So delegate all.
1350
- $storage->store( 'is_delegated_connection', true, true );
1351
-
1352
- $all_migrated = true;
1353
- }
1354
- }
1355
-
1356
- if ( ! $all_migrated ) {
1357
- /**
1358
- * Delegate all sites that were:
1359
- * 1) Opted-in by a user that is NOT the main-super-admin.
1360
- * 2) Skipped and non of the sites was opted-in by a super-admin. If any site was opted-in by a super-admin, there will be a main-super-admin, and we consider the skip as if it was done by that user.
1361
- */
1362
- foreach ( $blogs_status as $blog_id => $status_or_user_id ) {
1363
- if ( $status_or_user_id == $main_super_admin_user_id ) {
1364
- continue;
1365
- }
1366
-
1367
- if ( FS_User::is_valid_id( $status_or_user_id ) ||
1368
- ( 'skipped' === $status_or_user_id && is_null( $main_super_admin_user_id ) )
1369
- ) {
1370
- $storage->store( 'is_delegated_connection', true, $blog_id );
1371
- }
1372
- }
1373
- }
1374
-
1375
-
1376
- if ( ( $connections + $skips > 0 ) ) {
1377
- if ( $ignores > 0 ) {
1378
- /**
1379
- * If admin already opted-in or skipped in any of the network sites, and also
1380
- * have sites which the connection decision was not yet taken, set this plugin
1381
- * into network activation mode so the super-admin can choose what to do with
1382
- * the rest of the sites.
1383
- */
1384
- self::set_network_upgrade_mode( $storage );
1385
- }
1386
- }
1387
- }
1388
- }
1389
-
1390
- /**
1391
- * Set a module into network upgrade mode.
1392
- *
1393
- * @author Vova Feldman (@svovaf)
1394
- * @since 2.0.0
1395
- *
1396
- * @param \FS_Storage $storage
1397
- *
1398
- * @return bool
1399
- */
1400
- private static function set_network_upgrade_mode( FS_Storage $storage ) {
1401
- return $storage->is_network_activation = true;
1402
- }
1403
-
1404
- /**
1405
- * Will return true after upgrading to the SDK with the network level integration,
1406
- * when the super-admin involvement is required regarding the rest of the sites.
1407
- *
1408
- * @author Vova Feldman (@svovaf)
1409
- * @since 2.0.0
1410
- *
1411
- * @return bool
1412
- */
1413
- function is_network_upgrade_mode() {
1414
- return $this->_storage->get( 'is_network_activation' );
1415
- }
1416
-
1417
- /**
1418
- * Clear flag after the upgrade mode completion.
1419
- *
1420
- * @author Vova Feldman (@svovaf)
1421
- * @since 2.0.0
1422
- *
1423
- * @return bool True if network activation was on and now completed.
1424
- */
1425
- private function network_upgrade_mode_completed() {
1426
- if ( fs_is_network_admin() && $this->is_network_upgrade_mode() ) {
1427
- $this->_storage->remove( 'is_network_activation' );
1428
-
1429
- return true;
1430
- }
1431
-
1432
- return false;
1433
- }
1434
-
1435
- #endregion
1436
-
1437
- /**
1438
- * This action is connected to the 'plugins_loaded' hook and helps to determine
1439
- * if this is a new plugin installation or a plugin update.
1440
- *
1441
- * There are 3 different use-cases:
1442
- * 1) New plugin installation right with Freemius:
1443
- * 1.1 _activate_plugin_event_hook() will be executed first
1444
- * 1.2 Since $this->_storage->is_plugin_new_install is not set,
1445
- * and $this->_storage->plugin_last_version is not set,
1446
- * $this->_storage->is_plugin_new_install will be set to TRUE.
1447
- * 1.3 When _plugins_loaded() will be executed, $this->_storage->is_plugin_new_install will
1448
- * be already set to TRUE.
1449
- *
1450
- * 2) Plugin update, didn't have Freemius before, and now have the SDK:
1451
- * 2.1 _activate_plugin_event_hook() will not be executed, because
1452
- * the activation hook do NOT fires on updates since WP 3.1.
1453
- * 2.2 When _plugins_loaded() will be executed, $this->_storage->is_plugin_new_install will
1454
- * be empty, therefore, it will be set to FALSE.
1455
- *
1456
- * 3) Plugin update, had Freemius in prev version as well:
1457
- * 3.1 _version_updates_handler() will be executed 1st, since FS was installed
1458
- * before, $this->_storage->plugin_last_version will NOT be empty,
1459
- * therefore, $this->_storage->is_plugin_new_install will be set to FALSE.
1460
- * 3.2 When _plugins_loaded() will be executed, $this->_storage->is_plugin_new_install is
1461
- * already set, therefore, it will not be modified.
1462
- *
1463
- * Use-case #3 is backward compatible, #3.1 will be executed since 1.0.9.
1464
- *
1465
- * NOTE:
1466
- * The only fallback of this mechanism is if an admin updates a plugin based on use-case #2,
1467
- * and then, the next immediate PageView is the plugin's main settings page, it will not
1468
- * show the opt-in right away. The reason it will happen is because Freemius execution
1469
- * will be turned off till the plugin is fully loaded at least once
1470
- * (till $this->_storage->was_plugin_loaded is TRUE).
1471
- *
1472
- * @author Vova Feldman (@svovaf)
1473
- * @since 1.1.9
1474
- *
1475
- */
1476
- function _plugins_loaded() {
1477
- // Update flag that plugin was loaded with Freemius at least once.
1478
- $this->_storage->was_plugin_loaded = true;
1479
-
1480
- /**
1481
- * Bug fix - only set to false when it's a plugin, due to the
1482
- * execution sequence of the theme hooks and our methods, if
1483
- * this will be set for themes, Freemius will always assume
1484
- * it's a theme update.
1485
- *
1486
- * @author Vova Feldman (@svovaf)
1487
- * @since 1.2.2.2
1488
- */
1489
- if ( $this->is_plugin() &&
1490
- ! isset( $this->_storage->is_plugin_new_install )
1491
- ) {
1492
- $this->_storage->is_plugin_new_install = (
1493
- ! is_plugin_active( $this->_plugin_basename ) &&
1494
- empty( $this->_storage->plugin_last_version )
1495
- );
1496
- }
1497
- }
1498
-
1499
- /**
1500
- * Add special parameter to WP admin AJAX calls so when we
1501
- * process AJAX calls we can identify its source properly.
1502
- *
1503
- * @author Leo Fajardo (@leorw)
1504
- * @since 2.0.0
1505
- */
1506
- static function _enrich_ajax_url() {
1507
- $admin_param = is_network_admin() ?
1508
- '_fs_network_admin' :
1509
- '_fs_blog_admin';
1510
- ?>
1511
- <script type="text/javascript">
1512
- (function ($) {
1513
- $(document).ajaxSend(function (event, jqxhr, settings) {
1514
- if (settings.url &&
1515
- -1 < settings.url.indexOf('admin-ajax.php') &&
1516
- ! ( settings.url.indexOf( '<?php echo $admin_param ?>' ) > 0 )
1517
- ) {
1518
- if (
1519
- 'string' === typeof settings.data &&
1520
- settings.data.indexOf( 'action=heartbeat' ) > 0
1521
- ) {
1522
- return;
1523
- }
1524
-
1525
- if (settings.url.indexOf('?') > 0) {
1526
- settings.url += '&';
1527
- } else {
1528
- settings.url += '?';
1529
- }
1530
-
1531
- settings.url += '<?php echo $admin_param ?>=true';
1532
- }
1533
- });
1534
- })(jQuery);
1535
- </script>
1536
- <?php
1537
- }
1538
-
1539
- /**
1540
- * Opens the support forum subemenu item in a new browser page.
1541
- *
1542
- * @author Vova Feldman (@svovaf)
1543
- * @since 2.1.4
1544
- */
1545
- static function _open_support_forum_in_new_page() {
1546
- ?>
1547
- <script type="text/javascript">
1548
- (function ($) {
1549
- $('.fs-submenu-item.wp-support-forum').parent().attr( { target: '_blank', rel: 'noopener noreferrer' } );
1550
- })(jQuery);
1551
- </script>
1552
- <?php
1553
- }
1554
-
1555
- /**
1556
- * @author Vova Feldman (@svovaf)
1557
- * @since 1.0.9
1558
- */
1559
- private function register_constructor_hooks() {
1560
- $this->_logger->entrance();
1561
-
1562
- if ( is_admin() ) {
1563
- add_action( 'admin_init', array( &$this, '_hook_action_links_and_register_account_hooks' ) );
1564
-
1565
- if ( $this->is_plugin() ) {
1566
- if ( self::is_plugin_install_page() && true !== fs_request_get_bool( 'fs_allow_updater_and_dialog' ) ) {
1567
- /**
1568
- * Unless the `fs_allow_updater_and_dialog` URL param exists and its value is `true`, make
1569
- * Freemius-related updates unavailable on the "Add Plugins" admin page (/plugin-install.php)
1570
- * so that they won't interfere with the .org plugins' functionalities on that page (e.g.
1571
- * updating of a .org plugin).
1572
- */
1573
- add_filter( 'site_transient_update_plugins', array( 'Freemius', '_remove_fs_updates_from_plugin_install_page' ), 10, 2 );
1574
- } else if ( self::is_plugins_page() || self::is_updates_page() ) {
1575
- /**
1576
- * On the "Plugins" and "Updates" admin pages, if there are premium or non–org-compliant plugins, modify their details dialog URLs (add a Freemius-specific param) so that the SDK can determine if the plugin information dialog should show information from Freemius.
1577
- *
1578
- * @author Leo Fajardo (@leorw)
1579
- * @since 2.2.3
1580
- */
1581
- add_action( 'admin_footer', array( 'Freemius', '_prepend_fs_allow_updater_and_dialog_flag_url_param' ) );
1582
- }
1583
-
1584
- $plugin_dir = dirname( $this->_plugin_dir_path ) . '/';
1585
-
1586
- /**
1587
- * @since 1.2.2
1588
- *
1589
- * Hook to both free and premium version activations to support
1590
- * auto deactivation on the other version activation.
1591
- */
1592
- register_activation_hook(
1593
- $plugin_dir . $this->_free_plugin_basename,
1594
- array( &$this, '_activate_plugin_event_hook' )
1595
- );
1596
-
1597
- register_activation_hook(
1598
- $plugin_dir . $this->premium_plugin_basename(),
1599
- array( &$this, '_activate_plugin_event_hook' )
1600
- );
1601
- } else {
1602
- add_action( 'after_switch_theme', array( &$this, '_activate_theme_event_hook' ), 10, 2 );
1603
-
1604
- add_action( 'admin_footer', array( &$this, '_style_premium_theme' ) );
1605
- }
1606
-
1607
- /**
1608
- * Part of the mechanism to identify new plugin install vs. plugin update.
1609
- *
1610
- * @author Vova Feldman (@svovaf)
1611
- * @since 1.1.9
1612
- */
1613
- if ( empty( $this->_storage->was_plugin_loaded ) ) {
1614
- /**
1615
- * During the plugin activation (not theme), 'plugins_loaded' will be already executed
1616
- * when the logic gets here since the activation logic first add the activate plugins,
1617
- * then triggers 'plugins_loaded', and only then include the code of the plugin that
1618
- * is activated. Which means that _plugins_loaded() will NOT be executed during the
1619
- * plugin activation, and that IS intentional.
1620
- *
1621
- * @author Vova Feldman (@svovaf)
1622
- */
1623
- if ( $this->is_plugin() &&
1624
- $this->is_activation_mode( false ) &&
1625
- 0 == did_action( 'plugins_loaded' )
1626
- ) {
1627
- add_action( 'plugins_loaded', array( &$this, '_plugins_loaded' ) );
1628
- } else {
1629
- // If was activated before, then it was already loaded before.
1630
- $this->_plugins_loaded();
1631
- }
1632
- }
1633
-
1634
- if ( ! self::is_ajax() ) {
1635
- if ( ! $this->is_addon() ) {
1636
- add_action( 'init', array( &$this, '_add_default_submenu_items' ), WP_FS__LOWEST_PRIORITY );
1637
- }
1638
- }
1639
-
1640
- if ( $this->_storage->handle_gdpr_admin_notice ) {
1641
- add_action( 'init', array( &$this, '_maybe_show_gdpr_admin_notice' ) );
1642
- }
1643
-
1644
- add_action( 'init', array( &$this, '_maybe_add_gdpr_optin_ajax_handler') );
1645
- add_action( 'init', array( &$this, '_maybe_add_pricing_ajax_handler' ) );
1646
- }
1647
-
1648
- if ( $this->is_plugin() ) {
1649
- if ( version_compare( $GLOBALS['wp_version'], '5.1', '<' ) ) {
1650
- add_action( 'wpmu_new_blog', array( $this, '_after_new_blog_callback' ), 10, 6 );
1651
- } else {
1652
- add_action( 'wp_initialize_site', array( $this, '_after_wp_initialize_site_callback' ), 11, 2 );
1653
- }
1654
-
1655
- register_deactivation_hook( $this->_plugin_main_file_path, array( &$this, '_deactivate_plugin_hook' ) );
1656
- }
1657
-
1658
- if ( is_multisite() ) {
1659
- add_action( 'deactivate_blog', array( &$this, '_after_site_deactivated_callback' ) );
1660
- add_action( 'archive_blog', array( &$this, '_after_site_deactivated_callback' ) );
1661
- add_action( 'make_spam_blog', array( &$this, '_after_site_deactivated_callback' ) );
1662
-
1663
- if ( version_compare( $GLOBALS['wp_version'], '5.1', '<' ) ) {
1664
- add_action( 'deleted_blog', array( $this, '_after_site_deleted_callback' ), 10, 2 );
1665
- } else {
1666
- add_action( 'wp_delete_site', array( $this, '_after_wpsite_deleted_callback' ) );
1667
- }
1668
-
1669
- add_action( 'activate_blog', array( &$this, '_after_site_reactivated_callback' ) );
1670
- add_action( 'unarchive_blog', array( &$this, '_after_site_reactivated_callback' ) );
1671
- add_action( 'make_ham_blog', array( &$this, '_after_site_reactivated_callback' ) );
1672
- }
1673
-
1674
- if ( $this->is_theme() &&
1675
- self::is_customizer() &&
1676
- $this->apply_filters( 'show_customizer_upsell', true )
1677
- ) {
1678
- // Register customizer upsell.
1679
- add_action( 'customize_register', array( &$this, '_customizer_register' ) );
1680
- }
1681
-
1682
- add_action( 'admin_init', array( &$this, '_redirect_on_clicked_menu_link' ), WP_FS__LOWEST_PRIORITY );
1683
-
1684
- if ( $this->is_theme() && ! $this->is_migration() ) {
1685
- add_action( 'admin_init', array( &$this, '_add_tracking_links' ) );
1686
- }
1687
-
1688
- add_action( 'admin_init', array( &$this, '_add_license_activation' ) );
1689
- add_action( 'admin_init', array( &$this, '_add_premium_version_upgrade_selection' ) );
1690
- add_action( 'admin_init', array( &$this, '_add_beta_mode_update_handler' ) );
1691
- add_action( 'admin_init', array( &$this, '_add_user_change_option' ) );
1692
- add_action( 'admin_init', array( &$this, '_add_email_address_update_option' ) );
1693
-
1694
- $this->add_ajax_action( 'update_billing', array( &$this, '_update_billing_ajax_action' ) );
1695
- $this->add_ajax_action( 'start_trial', array( &$this, '_start_trial_ajax_action' ) );
1696
- $this->add_ajax_action( 'set_data_debug_mode', array( &$this, '_set_data_debug_mode' ) );
1697
- $this->add_ajax_action( 'toggle_whitelabel_mode', array( &$this, '_toggle_whitelabel_mode_ajax_handler' ) );
1698
-
1699
- if ( $this->_is_network_active && fs_is_network_admin() ) {
1700
- $this->add_ajax_action( 'network_activate', array( &$this, '_network_activate_ajax_action' ) );
1701
- }
1702
-
1703
- $this->add_ajax_action( 'install_premium_version', array(
1704
- &$this,
1705
- '_install_premium_version_ajax_action'
1706
- ) );
1707
-
1708
- $this->add_ajax_action( 'submit_affiliate_application', array( &$this, '_submit_affiliate_application' ) );
1709
-
1710
- $this->add_action( 'after_plans_sync', array( &$this, '_check_for_trial_plans' ) );
1711
-
1712
- $this->add_action( 'sdk_version_update', array( &$this, '_sdk_version_update' ), WP_FS__DEFAULT_PRIORITY, 2 );
1713
-
1714
- $this->add_action(
1715
- 'plugin_version_update',
1716
- array( &$this, '_after_version_update' ),
1717
- WP_FS__DEFAULT_PRIORITY,
1718
- 2
1719
- );
1720
- $this->add_filter( 'after_code_type_change', array( &$this, '_after_code_type_change' ) );
1721
-
1722
- add_action( 'admin_init', array( &$this, '_add_trial_notice' ) );
1723
- add_action( 'admin_init', array( &$this, '_add_affiliate_program_notice' ) );
1724
- add_action( 'admin_enqueue_scripts', array( &$this, '_enqueue_common_css' ) );
1725
-
1726
- /**
1727
- * Handle request to reset anonymous mode for `get_reconnect_url()`.
1728
- *
1729
- * @author Vova Feldman (@svovaf)
1730
- * @since 1.2.1.5
1731
- */
1732
- if ( fs_request_is_action( 'reset_anonymous_mode' ) &&
1733
- $this->get_unique_affix() === fs_request_get( 'fs_unique_affix' )
1734
- ) {
1735
- add_action( 'admin_init', array( &$this, 'connect_again' ) );
1736
- }
1737
- }
1738
-
1739
- /**
1740
- * Register the required hooks right after the settings parse is completed.
1741
- *
1742
- * @author Vova Feldman (@svovaf)
1743
- * @since 2.3.1
1744
- */
1745
- private function register_after_settings_parse_hooks() {
1746
- if ( is_admin() &&
1747
- $this->is_theme() &&
1748
- $this->is_premium() &&
1749
- ! $this->has_active_valid_license()
1750
- ) {
1751
- $this->add_ajax_action(
1752
- 'delete_theme_update_data',
1753
- array( &$this, '_delete_theme_update_data_action' )
1754
- );
1755
- }
1756
-
1757
- if ( $this->show_settings_with_tabs() ) {
1758
- /**
1759
- * Include the required hooks to capture the theme settings' page tabs
1760
- * and cache them.
1761
- *
1762
- * @author Vova Feldman (@svovaf)
1763
- * @since 1.2.2.7
1764
- */
1765
- if ( ! $this->_cache->has_valid( 'tabs' ) ) {
1766
- add_action( 'admin_footer', array( &$this, '_tabs_capture' ) );
1767
- // Add license activation AJAX callback.
1768
- $this->add_ajax_action( 'store_tabs', array( &$this, '_store_tabs_ajax_action' ) );
1769
-
1770
- add_action( 'admin_enqueue_scripts', array( &$this, '_store_tabs_styles' ), 9999999 );
1771
- }
1772
-
1773
- add_action(
1774
- 'admin_footer',
1775
- array( &$this, '_add_freemius_tabs' ),
1776
- /**
1777
- * The tabs JS code must be executed after the tabs capture logic (_tabs_capture()).
1778
- * That's why the priority is 11 while the tabs capture logic is added
1779
- * with priority 10.
1780
- *
1781
- * @author Vova Feldman (@svovaf)
1782
- */
1783
- 11
1784
- );
1785
- }
1786
-
1787
- if ( ! self::is_ajax() ) {
1788
- if ( ! $this->is_addon() || $this->is_only_premium() ) {
1789
- add_action(
1790
- ( $this->_is_network_active && fs_is_network_admin() ? 'network_' : '' ) . 'admin_menu',
1791
- array( &$this, '_prepare_admin_menu' ),
1792
- WP_FS__LOWEST_PRIORITY
1793
- );
1794
- }
1795
- }
1796
- }
1797
-
1798
- /**
1799
- * Makes Freemius-related updates unavailable on the "Add Plugins" admin page (/plugin-install.php) so that
1800
- * they won't interfere with the .org plugins' functionalities on that page (e.g. updating of a .org plugin).
1801
- *
1802
- * @author Leo Fajardo (@leorw)
1803
- * @since 2.2.3
1804
- *
1805
- * @param object $updates
1806
- * @param string|null $transient
1807
- *
1808
- * @return object
1809
- */
1810
- static function _remove_fs_updates_from_plugin_install_page( $updates, $transient = null ) {
1811
- if ( is_object( $updates ) && isset( $updates->response ) ) {
1812
- foreach ( $updates->response as $file => $plugin ) {
1813
- if ( isset( $plugin->package ) && false !== strpos( $plugin->package, 'api.freemius' ) ) {
1814
- unset( $updates->response[ $file ] );
1815
- }
1816
- }
1817
- }
1818
-
1819
- return $updates;
1820
- }
1821
-
1822
- /**
1823
- * Prepends the `fs_allow_updater_and_dialog` param to the plugin information URLs to tell the SDK to handle
1824
- * the information that is shown on the plugin details dialog that is shown when the relevant link is clicked.
1825
- *
1826
- * @author Leo Fajardo (@leorw)
1827
- * @since 2.2.3
1828
- *
1829
- * @return string
1830
- */
1831
- static function _prepend_fs_allow_updater_and_dialog_flag_url_param() {
1832
- $slug_basename_map = array();
1833
- foreach ( self::$_instances as $instance ) {
1834
- if ( ! $instance->is_plugin() ) {
1835
- continue;
1836
- }
1837
-
1838
- $slug_basename_map[ $instance->get_slug() ] = $instance->premium_plugin_basename();
1839
- }
1840
- ?>
1841
- <script type="text/javascript">
1842
- (function( $ ) {
1843
- var slugBasenameMap = <?php echo json_encode( $slug_basename_map ) ?>;
1844
- for ( var slug in slugBasenameMap ) {
1845
- var basename = slugBasenameMap[ slug ];
1846
-
1847
- // Try to get the plugin rows if on the "Plugins" page.
1848
- var $pluginRows = $( '.wp-list-table.plugins tr[data-plugin="' + basename + '"]');
1849
-
1850
- if ( 0 === $pluginRows.length ) {
1851
- // Try to get the plugin rows if on the "Updates" page.
1852
- var $pluginCheckbox = $( '#update-plugins-table input[type="checkbox"][value="' + basename + '"]' );
1853
- if ( 0 !== $pluginCheckbox.length ) {
1854
- $pluginRows = $pluginCheckbox.parents( 'tr:first' );
1855
- }
1856
- }
1857
-
1858
- if ( 0 === $pluginRows.length ) {
1859
- // No plugin rows found.
1860
- continue;
1861
- }
1862
-
1863
- // Find the "View details" links and add the `fs_allow_updater_and_dialog` param to the URL.
1864
- $pluginRows.find( 'a[href*="plugin-install.php?tab=plugin-information"]' ).each(function() {
1865
- var $this = $( this ),
1866
- href = $this.attr( 'href' ).replace( '?tab=', '?fs_allow_updater_and_dialog=true&tab=');
1867
-
1868
- $this.attr( 'href', href );
1869
- });
1870
- }
1871
- })( jQuery );
1872
- </script>
1873
- <?php
1874
- }
1875
-
1876
- /**
1877
- * @author Leo Fajardo (@leorw)
1878
- * @since 2.3.0
1879
- */
1880
- static function _maybe_add_beta_label_styles() {
1881
- $has_any_beta_version = false;
1882
-
1883
- foreach ( self::$_instances as $instance ) {
1884
- if ( $instance->is_beta() ) {
1885
- $has_any_beta_version = true;
1886
- break;
1887
- }
1888
- }
1889
-
1890
- if ( $has_any_beta_version ) {
1891
- fs_enqueue_local_style( 'fs_plugins', '/admin/plugins.css' );
1892
- }
1893
- }
1894
-
1895
- /**
1896
- * @author Leo Fajardo (@leorw)
1897
- * @since 2.3.0
1898
- */
1899
- static function _maybe_add_beta_label_to_plugins_and_handle_confirmation() {
1900
- $beta_data = array();
1901
-
1902
- foreach ( self::$_instances as $instance ) {
1903
- if ( ! $instance->is_premium() ) {
1904
- continue;
1905
- }
1906
-
1907
- /**
1908
- * If there's an available beta version update, a confirmation message will be shown when the
1909
- * "Update now" link on the "Plugins" or "Themes" page is clicked.
1910
- */
1911
- $has_beta_update = $instance->has_beta_update();
1912
-
1913
- $is_beta = (
1914
- // The "Beta" label is added separately for themes.
1915
- $instance->is_plugin() &&
1916
- $instance->is_beta()
1917
- );
1918
-
1919
- if ( ! $is_beta && ! $has_beta_update ) {
1920
- continue;
1921
- }
1922
-
1923
- $beta_data[ $instance->get_plugin_basename() ] = array( 'is_installed_version_beta' => $is_beta );
1924
-
1925
- if ( ! $has_beta_update ) {
1926
- continue;
1927
- }
1928
-
1929
- $beta_data[ $instance->get_plugin_basename() ]['beta_version_update_confirmation_message'] = sprintf(
1930
- '%s %s',
1931
- sprintf(
1932
- fs_esc_attr_inline(
1933
- 'An update to a Beta version will replace your installed version of %s with the latest Beta release - use with caution, and not on production sites. You have been warned.',
1934
- 'beta-version-update-caution',
1935
- $instance->get_slug()
1936
- ),
1937
- $instance->get_plugin_title()
1938
- ),
1939
- fs_esc_attr_inline( 'Would you like to proceed with the update?', 'update-confirmation', $instance->get_slug() )
1940
- );
1941
- }
1942
-
1943
- if ( empty( $beta_data ) ) {
1944
- return;
1945
- }
1946
- ?>
1947
- <script type="text/javascript">
1948
- ( function( $ ) {
1949
- var betaData = <?php echo json_encode( $beta_data ) ?>;
1950
-
1951
- for ( var pluginBasename in betaData ) {
1952
- if ( ! betaData.hasOwnProperty( pluginBasename ) ) {
1953
- continue;
1954
- }
1955
-
1956
- if ( ! betaData[ pluginBasename ].is_installed_version_beta ) {
1957
- continue;
1958
- }
1959
-
1960
- var $parentContainer = $( '.wp-list-table.plugins tr[data-plugin="' + pluginBasename + '"]' );
1961
- if ( 0 === $parentContainer.length ) {
1962
- continue;
1963
- }
1964
-
1965
- $parentContainer.find( '.plugin-title > strong:first-child').append(
1966
- '<span class="fs-tag fs-info"><?php fs_esc_js_echo_inline( 'Beta', 'beta' ) ?></span>'
1967
- );
1968
- }
1969
-
1970
- setTimeout( function() {
1971
- // Wait a little bit before adding the event handler, otherwise, it will be overridden by the core WP logic.
1972
- $( '.plugins .update-message .update-link, .themes .theme .update-message' ).on( 'click', function() {
1973
- var $parentContainer = $( this ).parents( 'tr:first' );
1974
- pluginBasename = ( 0 !== $parentContainer.length ) ?
1975
- $parentContainer.data( 'plugin' ) :
1976
- $( this ).parents( '.theme:first' ).data( 'slug' );
1977
-
1978
- if (
1979
- betaData[ pluginBasename ] &&
1980
- betaData[ pluginBasename ].beta_version_update_confirmation_message &&
1981
- ! confirm( betaData[ pluginBasename ].beta_version_update_confirmation_message )
1982
- ) {
1983
- return false;
1984
- }
1985
- } );
1986
- }, 20 );
1987
- } )( jQuery );
1988
- </script>
1989
- <?php
1990
- }
1991
-
1992
- /**
1993
- * Keeping the uninstall hook registered for free or premium plugin version may result to a fatal error that
1994
- * could happen when a user tries to uninstall either version while one of them is still active. Uninstalling a
1995
- * plugin will trigger inclusion of the free or premium version and if one of them is active during the
1996
- * uninstallation, a fatal error may occur in case the plugin's class or functions are already defined.
1997
- *
1998
- * @author Leo Fajardo (@leorw)
1999
- *
2000
- * @since 1.2.0
2001
- */
2002
- private function unregister_uninstall_hook() {
2003
- $uninstallable_plugins = (array) get_option( 'uninstall_plugins' );
2004
- unset( $uninstallable_plugins[ $this->_free_plugin_basename ] );
2005
- unset( $uninstallable_plugins[ $this->premium_plugin_basename() ] );
2006
-
2007
- update_option( 'uninstall_plugins', $uninstallable_plugins );
2008
- }
2009
-
2010
- /**
2011
- * @since 1.2.0 Invalidate module's main file cache, otherwise, FS_Plugin_Updater will not fetch updates.
2012
- *
2013
- * @param bool $store_prev_path
2014
- */
2015
- private function clear_module_main_file_cache( $store_prev_path = true ) {
2016
- if ( ! isset( $this->_storage->plugin_main_file ) ||
2017
- empty( $this->_storage->plugin_main_file->path )
2018
- ) {
2019
- return;
2020
- }
2021
-
2022
- if ( ! $store_prev_path ) {
2023
- /**
2024
- * Storing the previous path is not needed when clearing the cache after an SDK version update since
2025
- * the main purpose of the cache clearing in that event is to correct a wrong plugin main file path
2026
- * which causes data mix-up between plugins (e.g. titles and versions of an add-on and its parent plugin).
2027
- *
2028
- * @author Leo Fajardo (@leorw)
2029
- * @since 2.2.1
2030
- */
2031
- unset( $this->_storage->plugin_main_file->path );
2032
- } else {
2033
- $plugin_main_file = clone $this->_storage->plugin_main_file;
2034
-
2035
- // Store cached path (2nd layer cache).
2036
- $plugin_main_file->prev_path = $plugin_main_file->path;
2037
-
2038
- // Clear cached path.
2039
- unset( $plugin_main_file->path );
2040
-
2041
- $this->_storage->plugin_main_file = $plugin_main_file;
2042
- }
2043
-
2044
- /**
2045
- * Clear global cached path.
2046
- *
2047
- * @author Leo Fajardo (@leorw)
2048
- * @since 1.2.2
2049
- */
2050
- $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map' );
2051
- unset( $id_slug_type_path_map[ $this->_module_id ]['path'] );
2052
- self::$_accounts->set_option( 'id_slug_type_path_map', $id_slug_type_path_map, true );
2053
- }
2054
-
2055
- /**
2056
- * @author Leo Fajardo (@leorw)
2057
- * @since 2.0.0
2058
- */
2059
- function _hook_action_links_and_register_account_hooks() {
2060
- if ( $this->is_migration() ) {
2061
- return;
2062
- }
2063
-
2064
- $this->_add_tracking_links();
2065
-
2066
- if ( self::is_plugins_page() && $this->is_plugin() ) {
2067
- $this->hook_plugin_action_links();
2068
- }
2069
-
2070
- $this->_register_account_hooks();
2071
- }
2072
-
2073
- /**
2074
- * @author Vova Feldman (@svovaf)
2075
- * @since 1.0.9
2076
- */
2077
- private function _register_account_hooks() {
2078
- if ( ! is_admin() ) {
2079
- return;
2080
- }
2081
-
2082
- /**
2083
- * Always show the deactivation feedback form since we added
2084
- * automatic free version deactivation upon premium code activation.
2085
- *
2086
- * @since 1.2.1.6
2087
- */
2088
- $this->add_ajax_action(
2089
- 'submit_uninstall_reason',
2090
- array( &$this, '_submit_uninstall_reason_action' )
2091
- );
2092
-
2093
- $this->add_ajax_action(
2094
- 'cancel_subscription_or_trial',
2095
- array( &$this, 'cancel_subscription_or_trial_ajax_action' )
2096
- );
2097
-
2098
- if ( ! $this->is_addon() || $this->is_parent_plugin_installed() ) {
2099
- if ( ( $this->is_plugin() && self::is_plugins_page() ) ||
2100
- ( $this->is_theme() && self::is_themes_page() )
2101
- ) {
2102
- add_action( 'admin_footer', array( &$this, '_add_deactivation_feedback_dialog_box' ) );
2103
- }
2104
- }
2105
- }
2106
-
2107
- /**
2108
- * Leverage backtrace to find caller plugin file path.
2109
- *
2110
- * @param bool $is_init Is initiation sequence.
2111
- * @param string $main_file Since 2.5.0 expects the module's main file path to potentially purge the cached path.
2112
- *
2113
- * @return string
2114
- * @since 1.0.6
2115
- *
2116
- * @author Vova Feldman (@svovaf)
2117
- */
2118
- private function _find_caller_plugin_file( $is_init = false, $main_file = '' ) {
2119
- // Try to load the cached value of the file path.
2120
- if ( isset( $this->_storage->plugin_main_file ) ) {
2121
- $plugin_main_file = $this->_storage->plugin_main_file;
2122
- if ( ! empty( $plugin_main_file->path ) ) {
2123
- $absolute_path = $this->get_absolute_path( $plugin_main_file->path );
2124
- if ( file_exists( $absolute_path ) ) {
2125
- if ( $is_init && $absolute_path !== $this->get_absolute_path( $main_file ) ) {
2126
- // Update cached path if not matching the actual path.
2127
- $plugin_main_file->path = $main_file;
2128
- $this->_storage->plugin_main_file = $plugin_main_file;
2129
- }
2130
-
2131
- return $absolute_path;
2132
- }
2133
- }
2134
- }
2135
-
2136
- /**
2137
- * @since 1.2.1
2138
- *
2139
- * `clear_module_main_file_cache()` is clearing the plugin's cached path on
2140
- * deactivation. Therefore, if any plugin/theme was initiating `Freemius`
2141
- * with that plugin's slug, it was overriding the empty plugin path with a wrong path.
2142
- *
2143
- * So, we've added a special mechanism with a 2nd layer of cache that uses `prev_path`
2144
- * when the class instantiator isn't the module.
2145
- */
2146
- if ( ! $is_init ) {
2147
- // Fetch prev path cache.
2148
- if ( isset( $this->_storage->plugin_main_file ) &&
2149
- ! empty( $this->_storage->plugin_main_file->prev_path )
2150
- ) {
2151
- $absolute_path = $this->get_absolute_path( $this->_storage->plugin_main_file->prev_path );
2152
- if ( file_exists( $absolute_path ) ) {
2153
- return $absolute_path;
2154
- }
2155
- }
2156
-
2157
- wp_die(
2158
- $this->get_text_inline( 'Freemius SDK couldn\'t find the plugin\'s main file. Please contact sdk@freemius.com with the current error.', 'failed-finding-main-path' ) .
2159
- " Module: {$this->_slug}; SDK: " . WP_FS__SDK_VERSION . ";",
2160
- $this->get_text_inline( 'Error', 'error' ),
2161
- array( 'back_link' => true )
2162
- );
2163
- }
2164
-
2165
- /**
2166
- * @since 1.2.1
2167
- *
2168
- * Only the original instantiator that calls dynamic_init can modify the module's path.
2169
- */
2170
- // Find caller module.
2171
- $this->_storage->plugin_main_file = (object) array(
2172
- 'path' => $main_file,
2173
- );
2174
-
2175
- return $this->get_absolute_path( $main_file );
2176
- }
2177
-
2178
- /**
2179
- * @author Leo Fajardo (@leorw)
2180
- * @since 1.2.3
2181
- *
2182
- * @param string $path
2183
- *
2184
- * @return string
2185
- */
2186
- private function get_relative_path( $path ) {
2187
- $module_root_dir = $this->get_module_root_dir_path();
2188
- if ( 0 === strpos( $path, $module_root_dir ) ) {
2189
- $path = substr( $path, strlen( $module_root_dir ) );
2190
- }
2191
-
2192
- return $path;
2193
- }
2194
-
2195
- /**
2196
- * @author Leo Fajardo (@leorw)
2197
- * @since 1.2.3
2198
- *
2199
- * @param string $path
2200
- * @param string|bool $module_type
2201
- *
2202
- * @return string
2203
- */
2204
- private function get_absolute_path( $path, $module_type = false ) {
2205
- $module_root_dir = $this->get_module_root_dir_path( $module_type );
2206
- if ( 0 !== strpos( $path, $module_root_dir ) ) {
2207
- $path = fs_normalize_path( $module_root_dir . $path );
2208
- }
2209
-
2210
- return $path;
2211
- }
2212
-
2213
- /**
2214
- * @author Leo Fajardo (@leorw)
2215
- * @since 1.2.3
2216
- *
2217
- * @param string|bool $module_type
2218
- *
2219
- * @return string
2220
- */
2221
- private function get_module_root_dir_path( $module_type = false ) {
2222
- $is_plugin = empty( $module_type ) ?
2223
- $this->is_plugin() :
2224
- ( WP_FS__MODULE_TYPE_PLUGIN === $module_type );
2225
-
2226
- return fs_normalize_path( trailingslashit( $is_plugin ?
2227
- WP_PLUGIN_DIR :
2228
- get_theme_root( get_stylesheet() ) ) );
2229
- }
2230
-
2231
- /**
2232
- * @author Leo Fajardo (@leorw)
2233
- *
2234
- * @param number $module_id
2235
- * @param string $slug
2236
- *
2237
- * @return string Since 2.5.0 return the module's main file path.
2238
- *
2239
- * @since 1.2.2
2240
- */
2241
- private function store_id_slug_type_path_map( $module_id, $slug ) {
2242
- $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array() );
2243
-
2244
- $store_option = false;
2245
-
2246
- if ( ! isset( $id_slug_type_path_map[ $module_id ] ) ) {
2247
- $id_slug_type_path_map[ $module_id ] = array(
2248
- 'slug' => $slug
2249
- );
2250
-
2251
- $store_option = true;
2252
- } else if (
2253
- isset( $id_slug_type_path_map[ $module_id ]['slug'] ) &&
2254
- $slug !== $id_slug_type_path_map[ $module_id ]['slug']
2255
- ) {
2256
- $id_slug_type_path_map[ $module_id ]['slug'] = $slug;
2257
- $store_option = true;
2258
- }
2259
-
2260
- $find_caller = empty( $id_slug_type_path_map[ $module_id ]['path'] );
2261
-
2262
- if ( ! $find_caller ) {
2263
- /**
2264
- * This verification is for cases when suddenly the same module
2265
- * is installed but with a different folder name.
2266
- *
2267
- * @author Vova Feldman (@svovaf)
2268
- * @since 1.2.3
2269
- */
2270
- $find_caller = ! file_exists( $this->get_absolute_path(
2271
- $id_slug_type_path_map[ $module_id ]['path'],
2272
- $id_slug_type_path_map[ $module_id ]['type']
2273
- ) );
2274
- }
2275
-
2276
- foreach ( $id_slug_type_path_map as $id => $data ) {
2277
- if ( empty( $id ) ) {
2278
- // Remove maps with empty module ID.
2279
- unset( $id_slug_type_path_map[ $id ] );
2280
- $store_option = true;
2281
- continue;
2282
- }
2283
-
2284
- /**
2285
- * If the module's main file path is identical to the main file path of another module then it means that the cached path of the current module or the other one with the same path is wrong, and therefore, we need to recalculate those paths.
2286
- *
2287
- * @author Vova Feldman (@svovaf)
2288
- * @since 2.5.0
2289
- */
2290
- if ( ! $find_caller ) {
2291
- if ( $id == $module_id ) {
2292
- continue;
2293
- }
2294
-
2295
- if (
2296
- isset( $data['path'] ) &&
2297
- $data['path'] === $id_slug_type_path_map[ $module_id ]['path']
2298
- ) {
2299
- $find_caller = true;
2300
- }
2301
- }
2302
- }
2303
-
2304
- if ( $find_caller ) {
2305
- $caller_main_file_and_type = $this->get_caller_main_file_and_type( $module_id );
2306
-
2307
- $id_slug_type_path_map[ $module_id ]['type'] = $caller_main_file_and_type->module_type;
2308
- $id_slug_type_path_map[ $module_id ]['path'] = $caller_main_file_and_type->path;
2309
-
2310
- $store_option = true;
2311
- }
2312
-
2313
- if ( $store_option ) {
2314
- self::$_accounts->set_option( 'id_slug_type_path_map', $id_slug_type_path_map, true );
2315
- }
2316
-
2317
- return $id_slug_type_path_map[ $module_id ]['path'];
2318
- }
2319
-
2320
- /**
2321
- * Identifies the caller type: plugin or theme.
2322
- *
2323
- * @author Leo Fajardo (@leorw)
2324
- * @since 1.2.2
2325
- *
2326
- * @author Vova Feldman (@svovaf)
2327
- * @since 1.2.2.3 Find the earliest module in the call stack that calls to the SDK. This fix is for cases when
2328
- * add-ons are relying on loading the SDK from the parent module, and also allows themes including the
2329
- * SDK an internal file instead of directly from functions.php.
2330
- * @since 1.2.1.7 Knows how to handle cases when an add-on includes the parent module logic.
2331
- *
2332
- * @param number $module_id @since 2.5.0
2333
- */
2334
- private function get_caller_main_file_and_type( $module_id ) {
2335
- self::require_plugin_essentials();
2336
-
2337
- $all_plugins = fs_get_plugins( true );
2338
- $all_plugins_paths = array();
2339
-
2340
- // Get active plugin's main files real full names (might be symlinks).
2341
- foreach ( $all_plugins as $relative_path => $data ) {
2342
- if ( false === strpos( fs_normalize_path( $relative_path ), '/' ) ) {
2343
- /**
2344
- * Ignore plugins that don't have a folder (e.g. Hello Dolly) since they
2345
- * can't really include the SDK.
2346
- *
2347
- * @author Vova Feldman
2348
- * @since 1.2.1.7
2349
- */
2350
- continue;
2351
- }
2352
-
2353
- $all_plugins_paths[] = fs_normalize_path( realpath( WP_PLUGIN_DIR . '/' . $relative_path ) );
2354
- }
2355
-
2356
- $caller_file_candidate = false;
2357
- $caller_map = array();
2358
- $module_type = WP_FS__MODULE_TYPE_PLUGIN;
2359
- $themes_dir = fs_normalize_path( get_theme_root( get_stylesheet() ) );
2360
- $plugin_dir_to_skip = false;
2361
-
2362
- for ( $i = 1, $bt = debug_backtrace(), $len = count( $bt ); $i < $len; $i ++ ) {
2363
- if ( empty( $bt[ $i ]['file'] ) ) {
2364
- continue;
2365
- }
2366
-
2367
- if ( $i > 1 && ! empty( $bt[ $i - 1 ]['file'] ) && $bt[ $i ]['file'] === $bt[ $i - 1 ]['file'] ) {
2368
- // If file same as the prev file in the stack, skip it.
2369
- continue;
2370
- }
2371
-
2372
- if ( ! empty( $bt[ $i ]['function'] ) && in_array( $bt[ $i ]['function'], array(
2373
- 'do_action',
2374
- 'apply_filter',
2375
- // The string split is stupid, but otherwise, theme check
2376
- // throws info notices.
2377
- 'requir' . 'e_once',
2378
- 'requir' . 'e',
2379
- 'includ' . 'e_once',
2380
- 'includ' . 'e',
2381
- 'install_and_activate_plugin',
2382
- 'try_activate_plugin',
2383
- 'activate_plugin'
2384
- ) )
2385
- ) {
2386
- if ( 'activate_plugin' === $bt[ $i ]['function'] ) {
2387
- /**
2388
- * Store the directory of the activator plugin so that any other file that starts with it
2389
- * cannot be mistakenly chosen as a candidate caller file.
2390
- *
2391
- * @author Leo Fajardo
2392
- *
2393
- * @since 2.3.0
2394
- */
2395
- $caller_file_path = fs_normalize_path( $bt[ $i ]['file'] );
2396
-
2397
- foreach ( $all_plugins_paths as $plugin_path ) {
2398
- $plugin_dir = fs_normalize_path( dirname( $plugin_path ) . '/' );
2399
- if ( false !== strpos( $caller_file_path, $plugin_dir ) ) {
2400
- $plugin_dir_to_skip = $plugin_dir;
2401
-
2402
- break;
2403
- }
2404
- }
2405
- }
2406
-
2407
- // Ignore call stack hooks and files inclusion.
2408
- continue;
2409
- }
2410
-
2411
- $caller_file_path = fs_normalize_path( $bt[ $i ]['file'] );
2412
-
2413
- if ( ! empty( $plugin_dir_to_skip ) ) {
2414
- /**
2415
- * Skip if it's an activator plugin file to avoid mistakenly choosing it as a candidate caller file.
2416
- *
2417
- * @author Leo Fajardo
2418
- *
2419
- * @since 2.3.0
2420
- */
2421
- if ( 0 === strpos( $caller_file_path, $plugin_dir_to_skip ) ) {
2422
- continue;
2423
- }
2424
- }
2425
-
2426
- if ( 'functions.php' === basename( $caller_file_path ) ) {
2427
- /**
2428
- * 1. Assumes that theme's starting execution file is functions.php.
2429
- * 2. This complex logic fixes symlink issues (e.g. with Vargant).
2430
- *
2431
- * @author Vova Feldman (@svovaf)
2432
- * @since 1.2.2.5
2433
- */
2434
-
2435
- if ( $caller_file_path == fs_normalize_path( realpath( trailingslashit( $themes_dir ) . basename( dirname( $caller_file_path ) ) . '/' . basename( $caller_file_path ) ) ) ) {
2436
- $module_type = WP_FS__MODULE_TYPE_THEME;
2437
-
2438
- /**
2439
- * Relative path of the theme, e.g.:
2440
- * `my-theme/functions.php`
2441
- *
2442
- * @author Leo Fajardo (@leorw)
2443
- */
2444
- $caller_file_candidate = basename( dirname( $caller_file_path ) ) .
2445
- '/' .
2446
- basename( $caller_file_path );
2447
-
2448
- continue;
2449
- }
2450
- }
2451
-
2452
- $caller_file_hash = md5( $caller_file_path );
2453
-
2454
- if ( ! isset( $caller_map[ $caller_file_hash ] ) ) {
2455
- foreach ( $all_plugins_paths as $plugin_path ) {
2456
- if ( empty( $plugin_path ) ) {
2457
- continue;
2458
- }
2459
-
2460
- if ( false !== strpos( $caller_file_path, fs_normalize_path( dirname( $plugin_path ) . '/' ) ) ) {
2461
- $caller_map[ $caller_file_hash ] = fs_normalize_path( $plugin_path );
2462
- break;
2463
- }
2464
- }
2465
- }
2466
-
2467
- if ( isset( $caller_map[ $caller_file_hash ] ) ) {
2468
- $module_type = WP_FS__MODULE_TYPE_PLUGIN;
2469
- $caller_file_candidate = plugin_basename( $caller_map[ $caller_file_hash ] );
2470
- }
2471
- }
2472
-
2473
- $caller_main_file_and_type = (object) array(
2474
- 'module_type' => $module_type,
2475
- 'path' => $caller_file_candidate
2476
- );
2477
-
2478
- return apply_filters( "fs_{$module_id}_caller_main_file_and_type", $caller_main_file_and_type );
2479
- }
2480
-
2481
- #----------------------------------------------------------------------------------
2482
- #region Deactivation Feedback Form
2483
- #----------------------------------------------------------------------------------
2484
-
2485
- /**
2486
- * Displays a confirmation and feedback dialog box when the user clicks on the "Deactivate" link on the plugins
2487
- * page.
2488
- *
2489
- * @author Vova Feldman (@svovaf)
2490
- * @author Leo Fajardo (@leorw)
2491
- *
2492
- * @since 1.1.2
2493
- */
2494
- function _add_deactivation_feedback_dialog_box() {
2495
- if (
2496
- $this->is_clone() ||
2497
- ( is_object( $this->_site ) && ! $this->is_registered() )
2498
- ) {
2499
- return;
2500
- }
2501
-
2502
- $subscription_cancellation_dialog_box_template_params = $this->apply_filters( 'show_deactivation_subscription_cancellation', true ) ?
2503
- $this->_get_subscription_cancellation_dialog_box_template_params() :
2504
- array();
2505
-
2506
- /**
2507
- * @since 2.3.0 Developers can optionally hide the deactivation feedback form using the 'show_deactivation_feedback_form' filter.
2508
- */
2509
- $show_deactivation_feedback_form = ! self::is_deactivation_snoozed();
2510
- if ( $this->has_filter( 'show_deactivation_feedback_form' ) ) {
2511
- $show_deactivation_feedback_form = $this->apply_filters( 'show_deactivation_feedback_form', true );
2512
- } else if ( $this->is_addon() ) {
2513
- /**
2514
- * If the add-on's 'show_deactivation_feedback_form' is not set, try to inherit the value from the parent.
2515
- */
2516
- $show_deactivation_feedback_form = $this->get_parent_instance()->apply_filters( 'show_deactivation_feedback_form', true );
2517
- }
2518
-
2519
- $uninstall_confirmation_message = $this->apply_filters( 'uninstall_confirmation_message', '' );
2520
-
2521
- if (
2522
- empty( $subscription_cancellation_dialog_box_template_params ) &&
2523
- ! $show_deactivation_feedback_form &&
2524
- empty( $uninstall_confirmation_message )
2525
- ) {
2526
- return;
2527
- }
2528
-
2529
- $vars = array( 'id' => $this->_module_id );
2530
-
2531
- if ( $show_deactivation_feedback_form ) {
2532
- /* Check the type of user:
2533
- * 1. Long-term (long-term)
2534
- * 2. Non-registered and non-anonymous short-term (non-registered-and-non-anonymous-short-term).
2535
- * 3. Short-term (short-term)
2536
- */
2537
- $is_long_term_user = true;
2538
-
2539
- // Check if the site is at least 2 days old.
2540
- $time_installed = $this->_storage->install_timestamp;
2541
-
2542
- // Difference in seconds.
2543
- $date_diff = time() - $time_installed;
2544
-
2545
- // Convert seconds to days.
2546
- $date_diff_days = floor( $date_diff / ( 60 * 60 * 24 ) );
2547
-
2548
- if ( $date_diff_days < 2 ) {
2549
- $is_long_term_user = false;
2550
- }
2551
-
2552
- $is_long_term_user = $this->apply_filters( 'is_long_term_user', $is_long_term_user );
2553
-
2554
- if ( $is_long_term_user ) {
2555
- $user_type = 'long-term';
2556
- } else {
2557
- if ( ! $this->is_registered() && ! $this->is_anonymous() ) {
2558
- $user_type = 'non-registered-and-non-anonymous-short-term';
2559
- } else {
2560
- $user_type = 'short-term';
2561
- }
2562
- }
2563
-
2564
- $uninstall_reasons = $this->_get_uninstall_reasons( $user_type );
2565
-
2566
- $vars['reasons'] = $uninstall_reasons;
2567
- }
2568
-
2569
- $vars['subscription_cancellation_dialog_box_template_params'] = &$subscription_cancellation_dialog_box_template_params;
2570
- $vars['show_deactivation_feedback_form'] = $show_deactivation_feedback_form;
2571
- $vars['uninstall_confirmation_message'] = $uninstall_confirmation_message;
2572
-
2573
- /**
2574
- * Load the HTML template for the deactivation feedback dialog box.
2575
- *
2576
- * @todo Deactivation form core functions should be loaded only once! Otherwise, when there are multiple Freemius powered plugins the same code is loaded multiple times. The only thing that should be loaded differently is the various deactivation reasons object based on the state of the plugin.
2577
- */
2578
- fs_require_template( 'forms/deactivation/form.php', $vars );
2579
- }
2580
-
2581
- /**
2582
- * @author Leo Fajardo (@leorw)
2583
- * @since 1.1.2
2584
- *
2585
- * @param string $user_type
2586
- *
2587
- * @return array The uninstall reasons for the specified user type.
2588
- */
2589
- function _get_uninstall_reasons( $user_type = 'long-term' ) {
2590
- $module_type = $this->_module_type;
2591
-
2592
- $internal_message_template_var = array(
2593
- 'id' => $this->_module_id
2594
- );
2595
-
2596
- $plan = $this->get_plan();
2597
-
2598
- if ( $this->is_registered() && is_object( $plan ) && $plan->has_technical_support() ) {
2599
- $contact_support_template = fs_get_template( 'forms/deactivation/contact.php', $internal_message_template_var );
2600
- } else {
2601
- $contact_support_template = '';
2602
- }
2603
-
2604
- $reason_found_better_plugin = array(
2605
- 'id' => self::REASON_FOUND_A_BETTER_PLUGIN,
2606
- 'text' => sprintf( $this->get_text_inline( 'I found a better %s', 'reason-found-a-better-plugin' ), $module_type ),
2607
- 'input_type' => 'textfield',
2608
- 'input_placeholder' => sprintf( $this->get_text_inline( "What's the %s's name?", 'placeholder-plugin-name' ), $module_type ),
2609
- );
2610
-
2611
- $reason_temporary_deactivation = array(
2612
- 'id' => self::REASON_TEMPORARY_DEACTIVATION,
2613
- 'text' => sprintf(
2614
- $this->get_text_inline( "It's a temporary %s - I'm troubleshooting an issue", 'reason-temporary-x' ),
2615
- strtolower( $this->is_plugin() ?
2616
- $this->get_text_inline( 'Deactivation', 'deactivation' ) :
2617
- $this->get_text_inline( 'Theme Switch', 'theme-switch' )
2618
- )
2619
- ),
2620
- 'input_type' => '',
2621
- 'input_placeholder' => ''
2622
- );
2623
-
2624
- $reason_other = array(
2625
- 'id' => self::REASON_OTHER,
2626
- 'text' => $this->get_text_inline( 'Other', 'reason-other' ),
2627
- 'input_type' => 'textfield',
2628
- 'input_placeholder' => ''
2629
- );
2630
-
2631
- $long_term_user_reasons = array(
2632
- array(
2633
- 'id' => self::REASON_NO_LONGER_NEEDED,
2634
- 'text' => sprintf( $this->get_text_inline( 'I no longer need the %s', 'reason-no-longer-needed' ), $module_type ),
2635
- 'input_type' => '',
2636
- 'input_placeholder' => ''
2637
- ),
2638
- $reason_found_better_plugin,
2639
- array(
2640
- 'id' => self::REASON_NEEDED_FOR_A_SHORT_PERIOD,
2641
- 'text' => sprintf( $this->get_text_inline( 'I only needed the %s for a short period', 'reason-needed-for-a-short-period' ), $module_type ),
2642
- 'input_type' => '',
2643
- 'input_placeholder' => ''
2644
- ),
2645
- array(
2646
- 'id' => self::REASON_BROKE_MY_SITE,
2647
- 'text' => sprintf( $this->get_text_inline( 'The %s broke my site', 'reason-broke-my-site' ), $module_type ),
2648
- 'input_type' => '',
2649
- 'input_placeholder' => '',
2650
- 'internal_message' => $contact_support_template
2651
- ),
2652
- array(
2653
- 'id' => self::REASON_SUDDENLY_STOPPED_WORKING,
2654
- 'text' => sprintf( $this->get_text_inline( 'The %s suddenly stopped working', 'reason-suddenly-stopped-working' ), $module_type ),
2655
- 'input_type' => '',
2656
- 'input_placeholder' => '',
2657
- 'internal_message' => $contact_support_template
2658
- )
2659
- );
2660
-
2661
- if ( $this->is_paying() ) {
2662
- $long_term_user_reasons[] = array(
2663
- 'id' => self::REASON_CANT_PAY_ANYMORE,
2664
- 'text' => $this->get_text_inline( "I can't pay for it anymore", 'reason-cant-pay-anymore' ),
2665
- 'input_type' => 'textfield',
2666
- 'input_placeholder' => $this->get_text_inline( 'What price would you feel comfortable paying?', 'placeholder-comfortable-price' )
2667
- );
2668
- }
2669
-
2670
- $reason_dont_share_info = array(
2671
- 'id' => self::REASON_DONT_LIKE_TO_SHARE_MY_INFORMATION,
2672
- 'text' => $this->get_text_inline( "I don't like to share my information with you", 'reason-dont-like-to-share-my-information' ),
2673
- 'input_type' => '',
2674
- 'input_placeholder' => ''
2675
- );
2676
-
2677
- /**
2678
- * If the current user has selected the "don't share data" reason in the deactivation feedback modal, inform the
2679
- * user by showing additional message that he doesn't have to share data and can just choose to skip the opt-in
2680
- * (the Skip button is included in the message to show). This message will only be shown if anonymous mode is
2681
- * enabled and the user's account is currently not in pending activation state (similar to the way the Skip
2682
- * button in the opt-in form is shown/hidden).
2683
- */
2684
- if ( $this->is_enable_anonymous() && ! $this->is_pending_activation() ) {
2685
- $reason_dont_share_info['internal_message'] = fs_get_template( 'forms/deactivation/retry-skip.php', $internal_message_template_var );
2686
- }
2687
-
2688
- $uninstall_reasons = array(
2689
- 'long-term' => $long_term_user_reasons,
2690
- 'non-registered-and-non-anonymous-short-term' => array(
2691
- array(
2692
- 'id' => self::REASON_DIDNT_WORK,
2693
- 'text' => sprintf( $this->get_text_inline( "The %s didn't work", 'reason-didnt-work' ), $module_type ),
2694
- 'input_type' => '',
2695
- 'input_placeholder' => ''
2696
- ),
2697
- $reason_dont_share_info,
2698
- $reason_found_better_plugin
2699
- ),
2700
- 'short-term' => array(
2701
- array(
2702
- 'id' => self::REASON_COULDNT_MAKE_IT_WORK,
2703
- 'text' => $this->get_text_inline( "I couldn't understand how to make it work", 'reason-couldnt-make-it-work' ),
2704
- 'input_type' => '',
2705
- 'input_placeholder' => '',
2706
- 'internal_message' => $contact_support_template
2707
- ),
2708
- $reason_found_better_plugin,
2709
- array(
2710
- 'id' => self::REASON_GREAT_BUT_NEED_SPECIFIC_FEATURE,
2711
- 'text' => sprintf( $this->get_text_inline( "The %s is great, but I need specific feature that you don't support", 'reason-great-but-need-specific-feature' ), $module_type ),
2712
- 'input_type' => 'textarea',
2713
- 'input_placeholder' => $this->get_text_inline( 'What feature?', 'placeholder-feature' )
2714
- ),
2715
- array(
2716
- 'id' => self::REASON_NOT_WORKING,
2717
- 'text' => sprintf( $this->get_text_inline( 'The %s is not working', 'reason-not-working' ), $module_type ),
2718
- 'input_type' => 'textarea',
2719
- 'input_placeholder' => $this->get_text_inline( "Kindly share what didn't work so we can fix it for future users...", 'placeholder-share-what-didnt-work' )
2720
- ),
2721
- array(
2722
- 'id' => self::REASON_NOT_WHAT_I_WAS_LOOKING_FOR,
2723
- 'text' => $this->get_text_inline( "It's not what I was looking for", 'reason-not-what-i-was-looking-for' ),
2724
- 'input_type' => 'textarea',
2725
- 'input_placeholder' => $this->get_text_inline( "What you've been looking for?", 'placeholder-what-youve-been-looking-for' )
2726
- ),
2727
- array(
2728
- 'id' => self::REASON_DIDNT_WORK_AS_EXPECTED,
2729
- 'text' => sprintf( $this->get_text_inline( "The %s didn't work as expected", 'reason-didnt-work-as-expected' ), $module_type ),
2730
- 'input_type' => 'textarea',
2731
- 'input_placeholder' => $this->get_text_inline( 'What did you expect?', 'placeholder-what-did-you-expect' )
2732
- )
2733
- )
2734
- );
2735
-
2736
- // Randomize the reasons for the current user type.
2737
- shuffle( $uninstall_reasons[ $user_type ] );
2738
-
2739
- // Keep the following reasons as the last items in the list.
2740
- $uninstall_reasons[ $user_type ][] = $reason_temporary_deactivation;
2741
- $uninstall_reasons[ $user_type ][] = $reason_other;
2742
-
2743
- $uninstall_reasons = $this->apply_filters( 'uninstall_reasons', $uninstall_reasons );
2744
-
2745
- return $uninstall_reasons[ $user_type ];
2746
- }
2747
-
2748
- /**
2749
- * Called after the user has submitted his reason for deactivating the plugin.
2750
- *
2751
- * @author Leo Fajardo (@leorw)
2752
- * @since 1.1.2
2753
- */
2754
- function _submit_uninstall_reason_action() {
2755
- $this->_logger->entrance();
2756
-
2757
- $this->check_ajax_referer( 'submit_uninstall_reason' );
2758
-
2759
- $reason_id = fs_request_get( 'reason_id' );
2760
-
2761
- // Check if the given reason ID is an unsigned integer.
2762
- if ( ! ctype_digit( $reason_id ) ) {
2763
- exit;
2764
- }
2765
-
2766
- $reason_info = trim( fs_request_get( 'reason_info', '' ) );
2767
- if ( ! empty( $reason_info ) ) {
2768
- $reason_info = substr( $reason_info, 0, 128 );
2769
- }
2770
-
2771
- $reason = (object) array(
2772
- 'id' => $reason_id,
2773
- 'info' => $reason_info,
2774
- 'is_anonymous' => fs_request_get_bool( 'is_anonymous' )
2775
- );
2776
-
2777
- $this->_storage->store( 'uninstall_reason', $reason );
2778
-
2779
- if ( self::REASON_TEMPORARY_DEACTIVATION == $reason->id ) {
2780
- $snooze_period = fs_request_get( 'snooze_period' );
2781
-
2782
- if ( is_numeric( $snooze_period ) && 0 < $snooze_period ) {
2783
- self::snooze_deactivation_form( (int) $snooze_period );
2784
- }
2785
- }
2786
-
2787
- /**
2788
- * If the module type is "theme", trigger the uninstall event here (on theme deactivation) since themes do
2789
- * not support uninstall hook.
2790
- *
2791
- * @author Leo Fajardo (@leorw)
2792
- * @since 1.2.2
2793
- */
2794
- if ( $this->is_theme() ) {
2795
- if ( $this->is_premium() && ! $this->has_active_valid_license() ) {
2796
- FS_Plugin_Updater::instance( $this )->delete_update_data();
2797
- }
2798
-
2799
- $this->_uninstall_plugin_event( false );
2800
- $this->remove_sdk_reference();
2801
- }
2802
-
2803
- // Print '1' for successful operation.
2804
- echo 1;
2805
- exit;
2806
- }
2807
-
2808
- #--------------------------------------------------------------------------------
2809
- #region Deactivation Feedback Snoozing
2810
- #--------------------------------------------------------------------------------
2811
-
2812
- /**
2813
- * @author Vova Feldman (@svovaf)
2814
- * @since 2.4.3
2815
- *
2816
- * @param int $period
2817
- *
2818
- * @return bool True if the value was set, false otherwise.
2819
- */
2820
- private static function snooze_deactivation_form( $period ) {
2821
- return ( 0 < $period && self::reset_deactivation_snoozing( $period ) );
2822
- }
2823
-
2824
- /**
2825
- * Check if deactivation feedback form is snoozed.
2826
- *
2827
- * @author Vova Feldman (@svovaf)
2828
- * @since 2.4.3
2829
- *
2830
- * @return bool
2831
- */
2832
- static function is_deactivation_snoozed() {
2833
- $is_snoozed = ( ! is_multisite() || fs_is_network_admin() ) ?
2834
- get_transient( 'fs_snooze_period' ) :
2835
- get_site_transient( 'fs_snooze_period' );
2836
-
2837
-
2838
- return ( 'true' === $is_snoozed );
2839
- }
2840
-
2841
- /**
2842
- * Reset deactivation snoozing. When `$period` is `0` will stop deactivation snoozing by deleting the transients. Otherwise, will set the transients for the selected period.
2843
- *
2844
- * @param int $period Period in seconds.
2845
- *
2846
- * @author Vova Feldman (@svovaf)
2847
- * @since 2.4.3
2848
- */
2849
- private static function reset_deactivation_snoozing( $period = 0 ) {
2850
- $value = ( 0 === $period ) ? null : 'true';
2851
-
2852
- if ( ! is_multisite() || fs_is_network_admin() ) {
2853
- return set_transient( 'fs_snooze_period', $value, $period );
2854
- } else {
2855
- return set_site_transient( 'fs_snooze_period', $value, $period );
2856
- }
2857
- }
2858
-
2859
- /**
2860
- * The deactivation snooze expiration UNIX timestamp (in sec).
2861
- *
2862
- * @author Vova Feldman (@svovaf)
2863
- * @since 2.4.3
2864
- *
2865
- * @return int
2866
- */
2867
- static function deactivation_snooze_expires_at() {
2868
- return ( ! is_multisite() || fs_is_network_admin() ) ?
2869
- (int) get_option( '_transient_timeout_fs_snooze_period' ) :
2870
- (int) get_site_option( '_site_transient_timeout_fs_snooze_period' );
2871
- }
2872
-
2873
- #endregion
2874
-
2875
- /**
2876
- * @author Leo Fajardo (@leorw)
2877
- * @since 2.1.4
2878
- */
2879
- function cancel_subscription_or_trial_ajax_action() {
2880
- $this->_logger->entrance();
2881
-
2882
- $this->check_ajax_referer( 'cancel_subscription_or_trial' );
2883
-
2884
- $result = $this->cancel_subscription_or_trial( fs_request_get( 'plugin_id', $this->get_id() ), false );
2885
-
2886
- if ( $this->is_api_error( $result ) ) {
2887
- $this->shoot_ajax_failure( $result->error->message );
2888
- }
2889
-
2890
- $this->shoot_ajax_success();
2891
- }
2892
-
2893
- /**
2894
- * @author Leo Fajardo (@leorw)
2895
- * @since 2.1.4
2896
- *
2897
- * @param number $plugin_id
2898
- *
2899
- * @return object
2900
- */
2901
- private function cancel_subscription_or_trial( $plugin_id ) {
2902
- $fs = null;
2903
- if ( $plugin_id == $this->get_id() ) {
2904
- $fs = $this;
2905
- } else if ( $this->is_addon_activated( $plugin_id ) ) {
2906
- $fs = self::get_instance_by_id( $plugin_id );
2907
- }
2908
-
2909
- $result = null;
2910
-
2911
- if ( ! is_null( $fs ) ) {
2912
- $result = $fs->is_paid_trial() ?
2913
- $fs->_cancel_trial() :
2914
- $fs->_downgrade_site();
2915
- }
2916
-
2917
- return $result;
2918
- }
2919
-
2920
- /**
2921
- * @author Leo Fajardo (@leorw)
2922
- * @since 2.0.2
2923
- */
2924
- function _delete_theme_update_data_action() {
2925
- FS_Plugin_Updater::instance( $this )->delete_update_data();
2926
- }
2927
-
2928
- #endregion
2929
-
2930
- #----------------------------------------------------------------------------------
2931
- #region Instance
2932
- #----------------------------------------------------------------------------------
2933
-
2934
- /**
2935
- * Main singleton instance.
2936
- *
2937
- * @author Vova Feldman (@svovaf)
2938
- * @since 1.0.0
2939
- *
2940
- * @param number $module_id
2941
- * @param string|bool $slug
2942
- * @param bool $is_init Is initiation sequence.
2943
- *
2944
- * @return Freemius|false
2945
- */
2946
- static function instance( $module_id, $slug = false, $is_init = false ) {
2947
- if ( empty( $module_id ) ) {
2948
- return false;
2949
- }
2950
-
2951
- /**
2952
- * 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.
2953
- */
2954
- self::_load_required_static();
2955
-
2956
- if ( ! is_numeric( $module_id ) ) {
2957
- if ( ! $is_init && true === $slug ) {
2958
- $is_init = true;
2959
- }
2960
-
2961
- $slug = $module_id;
2962
-
2963
- $module = FS_Plugin_Manager::instance( $slug )->get();
2964
-
2965
- if ( is_object( $module ) ) {
2966
- $module_id = $module->id;
2967
- }
2968
- }
2969
-
2970
- $key = 'm_' . $module_id;
2971
-
2972
- if ( ! isset( self::$_instances[ $key ] ) ) {
2973
- self::$_instances[ $key ] = new Freemius( $module_id, $slug, $is_init );
2974
- }
2975
-
2976
- return self::$_instances[ $key ];
2977
- }
2978
-
2979
- /**
2980
- * @author Vova Feldman (@svovaf)
2981
- * @since 1.0.6
2982
- *
2983
- * @param number $addon_id
2984
- *
2985
- * @return bool
2986
- */
2987
- private static function has_instance( $addon_id ) {
2988
- return isset( self::$_instances[ 'm_' . $addon_id ] );
2989
- }
2990
-
2991
- /**
2992
- * @author Leo Fajardo (@leorw)
2993
- * @since 1.2.2
2994
- *
2995
- * @param string|number $id_or_slug
2996
- * @param string $module_type
2997
- *
2998
- * @return number|false
2999
- */
3000
- private static function get_module_id( $id_or_slug, $module_type = WP_FS__MODULE_TYPE_PLUGIN ) {
3001
- if ( is_numeric( $id_or_slug ) ) {
3002
- return $id_or_slug;
3003
- }
3004
-
3005
- foreach ( self::$_instances as $instance ) {
3006
- // Also check the module type since there can be a plugin and a theme with the same slug.
3007
- if ( ( $module_type === $instance->get_module_type() ) && ( $id_or_slug === $instance->get_slug() ) ) {
3008
- return $instance->get_id();
3009
- }
3010
- }
3011
-
3012
- return false;
3013
- }
3014
-
3015
- /**
3016
- * @author Vova Feldman (@svovaf)
3017
- * @since 1.0.6
3018
- *
3019
- * @param number $id
3020
- *
3021
- * @return false|Freemius
3022
- */
3023
- static function get_instance_by_id( $id ) {
3024
- return isset ( self::$_instances[ 'm_' . $id ] ) ?
3025
- self::$_instances[ 'm_' . $id ] :
3026
- false;
3027
- }
3028
-
3029
- /**
3030
- *
3031
- * @author Vova Feldman (@svovaf)
3032
- * @since 1.0.1
3033
- *
3034
- * @param string $plugin_file
3035
- * @param string $module_type
3036
- *
3037
- * @return false|Freemius
3038
- */
3039
- static function get_instance_by_file( $plugin_file, $module_type = WP_FS__MODULE_TYPE_PLUGIN ) {
3040
- $slug = self::find_slug_by_basename( $plugin_file );
3041
-
3042
- return ( false !== $slug ) ?
3043
- self::instance( self::get_module_id( $slug, $module_type ) ) :
3044
- false;
3045
- }
3046
-
3047
- /**
3048
- * @author Vova Feldman (@svovaf)
3049
- * @since 1.0.6
3050
- *
3051
- * @return false|Freemius
3052
- */
3053
- function get_parent_instance() {
3054
- return self::get_instance_by_id( $this->_plugin->parent_plugin_id );
3055
- }
3056
-
3057
- /**
3058
- * @author Vova Feldman (@svovaf)
3059
- * @since 1.0.6
3060
- *
3061
- * @param string|number $id_or_slug
3062
- *
3063
- * @return false|Freemius
3064
- */
3065
- function get_addon_instance( $id_or_slug ) {
3066
- $addon_id = self::get_module_id( $id_or_slug );
3067
-
3068
- return self::instance( $addon_id );
3069
- }
3070
-
3071
- /**
3072
- * @return Freemius[]
3073
- */
3074
- static function _get_all_instances() {
3075
- return self::$_instances;
3076
- }
3077
-
3078
- #endregion ------------------------------------------------------------------
3079
-
3080
- /**
3081
- * @author Vova Feldman (@svovaf)
3082
- * @since 1.0.6
3083
- *
3084
- * @return bool
3085
- */
3086
- function is_parent_plugin_installed() {
3087
- $is_active = self::has_instance( $this->_plugin->parent_plugin_id );
3088
-
3089
- if ( $is_active ) {
3090
- return true;
3091
- }
3092
-
3093
- /**
3094
- * Parent module might be a theme. If that's the case, the add-on's FS
3095
- * instance will be loaded prior to the theme's FS instance, therefore,
3096
- * we need to check if it's active with a "look ahead".
3097
- *
3098
- * @author Vova Feldman
3099
- * @since 1.2.2.3
3100
- */
3101
- global $fs_active_plugins;
3102
- if ( is_object( $fs_active_plugins ) && is_array( $fs_active_plugins->plugins ) ) {
3103
- $active_theme = wp_get_theme();
3104
-
3105
- foreach ( $fs_active_plugins->plugins as $sdk => $module ) {
3106
- if ( WP_FS__MODULE_TYPE_THEME === $module->type ) {
3107
- if ( $module->plugin_path == $active_theme->get_stylesheet() ) {
3108
- // Parent module is a theme and it's currently active.
3109
- return true;
3110
- }
3111
- }
3112
- }
3113
- }
3114
-
3115
- return false;
3116
- }
3117
-
3118
- /**
3119
- * Check if add-on parent plugin in activation mode.
3120
- *
3121
- * @author Vova Feldman (@svovaf)
3122
- * @since 1.0.7
3123
- *
3124
- * @return bool
3125
- */
3126
- function is_parent_in_activation() {
3127
- $parent_fs = $this->get_parent_instance();
3128
- if ( ! is_object( $parent_fs ) ) {
3129
- return false;
3130
- }
3131
-
3132
- return ( $parent_fs->is_activation_mode() );
3133
- }
3134
-
3135
- /**
3136
- * Is plugin in activation mode.
3137
- *
3138
- * @author Vova Feldman (@svovaf)
3139
- * @since 1.0.7
3140
- *
3141
- * @param bool $and_on
3142
- *
3143
- * @return bool
3144
- */
3145
- function is_activation_mode( $and_on = true ) {
3146
- return fs_is_network_admin() ?
3147
- $this->is_network_activation_mode( $and_on ) :
3148
- $this->is_site_activation_mode( $and_on );
3149
- }
3150
-
3151
- /**
3152
- * Is plugin in activation mode.
3153
- *
3154
- * @author Vova Feldman (@svovaf)
3155
- * @since 1.0.7
3156
- *
3157
- * @param bool $and_on
3158
- *
3159
- * @return bool
3160
- */
3161
- function is_site_activation_mode( $and_on = true ) {
3162
- return (
3163
- ( $this->is_on() || ! $and_on ) &&
3164
- (
3165
- ( $this->is_premium() && true === $this->_storage->require_license_activation ) ||
3166
- (
3167
- ( ! $this->is_registered() ||
3168
- ( $this->is_only_premium() && ! $this->has_features_enabled_license() ) ) &&
3169
- ( ! $this->is_enable_anonymous() ||
3170
- ( ! $this->is_anonymous() && ! $this->is_pending_activation() ) )
3171
- )
3172
- )
3173
- );
3174
- }
3175
-
3176
- /**
3177
- * Checks if the SDK in network activation mode.
3178
- *
3179
- * @author Leo Fajardo (@leorw)
3180
- * @since 2.0.0
3181
- *
3182
- * @param bool $and_on
3183
- *
3184
- * @return bool
3185
- */
3186
- private function is_network_activation_mode( $and_on = true ) {
3187
- if ( ! $this->_is_network_active ) {
3188
- // Not network activated.
3189
- return false;
3190
- }
3191
-
3192
- if ( $this->is_network_upgrade_mode() ) {
3193
- // Special flag to enforce network activation mode to decide what to do with the sites that are not yet opted-in nor skipped.
3194
- return true;
3195
- }
3196
-
3197
- if ( ! $this->is_site_activation_mode( $and_on ) ) {
3198
- // Whether the context is single site or the network, if the plugin is no longer in activation mode then it is not in network activation mode as well.
3199
- return false;
3200
- }
3201
-
3202
- if ( $this->is_network_delegated_connection() ) {
3203
- // Super-admin delegated the connection to the site admins -> not activation mode.
3204
- return false;
3205
- }
3206
-
3207
- if ( $this->is_network_anonymous() && true !== $this->_storage->require_license_activation ) {
3208
- // Super-admin skipped the connection network wide -> not activation mode.
3209
- return false;
3210
- }
3211
-
3212
- if ( $this->is_network_registered() ) {
3213
- // Super-admin connected at least one site -> not activation mode.
3214
- return false;
3215
- }
3216
-
3217
- return true;
3218
- }
3219
-
3220
- /**
3221
- * Check if current page is the opt-in/pending-activation page.
3222
- *
3223
- * @author Vova Feldman (@svovaf)
3224
- * @since 1.2.1.7
3225
- *
3226
- * @return bool
3227
- */
3228
- function is_activation_page() {
3229
- if ( $this->_menu->is_activation_page( $this->show_opt_in_on_themes_page() ) ) {
3230
- return true;
3231
- }
3232
-
3233
- if ( ! $this->is_activation_mode() ) {
3234
- return false;
3235
- }
3236
-
3237
- // Check if current page is matching the activation page.
3238
- return $this->is_matching_url( $this->get_activation_url() );
3239
- }
3240
-
3241
- /**
3242
- * Check if URL path's are matching and that all querystring
3243
- * arguments of the $sub_url exist in the $url with the same values.
3244
- *
3245
- * WARNING:
3246
- * 1. This method doesn't check if the sub/domain are matching.
3247
- * 2. Ignore case sensitivity.
3248
- *
3249
- * @author Vova Feldman (@svovaf)
3250
- * @since 1.2.1.7
3251
- *
3252
- * @param string $sub_url
3253
- * @param string $url If argument is not set, check if the sub_url matching the current's page URL.
3254
- *
3255
- * @return bool
3256
- */
3257
- private function is_matching_url( $sub_url, $url = '' ) {
3258
- if ( empty( $url ) ) {
3259
- $url = $_SERVER['REQUEST_URI'];
3260
- }
3261
-
3262
- $url = strtolower( $url );
3263
- $sub_url = strtolower( $sub_url );
3264
-
3265
- if ( parse_url( $sub_url, PHP_URL_PATH ) !== parse_url( $url, PHP_URL_PATH ) ) {
3266
- // Different path - DO NOT OVERRIDE PAGE.
3267
- return false;
3268
- }
3269
-
3270
- $url_params = array();
3271
- parse_str( parse_url( $url, PHP_URL_QUERY ), $url_params );
3272
-
3273
- $sub_url_params = array();
3274
- parse_str( parse_url( $sub_url, PHP_URL_QUERY ), $sub_url_params );
3275
-
3276
- foreach ( $sub_url_params as $key => $val ) {
3277
- if ( ! isset( $url_params[ $key ] ) || $val != $url_params[ $key ] ) {
3278
- // Not matching query string - DO NOT OVERRIDE PAGE.
3279
- return false;
3280
- }
3281
- }
3282
-
3283
- return true;
3284
- }
3285
-
3286
- /**
3287
- * Get the basenames of all active plugins for specific blog. Including network activated plugins.
3288
- *
3289
- * @author Vova Feldman (@svovaf)
3290
- * @since 2.0.0
3291
- *
3292
- * @param int $blog_id
3293
- *
3294
- * @return string[]
3295
- */
3296
- private static function get_active_plugins_basenames( $blog_id = 0 ) {
3297
- if ( is_multisite() && $blog_id > 0 ) {
3298
- $active_basenames = get_blog_option( $blog_id, 'active_plugins' );
3299
- } else {
3300
- $active_basenames = get_option( 'active_plugins' );
3301
- }
3302
-
3303
- if ( ! is_array( $active_basenames ) ) {
3304
- $active_basenames = array();
3305
- }
3306
-
3307
- if ( is_multisite() ) {
3308
- $network_active_basenames = get_site_option( 'active_sitewide_plugins' );
3309
-
3310
- if ( is_array( $network_active_basenames ) && ! empty( $network_active_basenames ) ) {
3311
- $active_basenames = array_merge( $active_basenames, array_keys( $network_active_basenames ) );
3312
- }
3313
- }
3314
-
3315
- return $active_basenames;
3316
- }
3317
-
3318
- /**
3319
- * @author Leo Fajardo (@leorw)
3320
- * @since 2.3.0
3321
- *
3322
- * @param int $blog_id
3323
- *
3324
- * @return array
3325
- */
3326
- static function get_active_plugins_directories_map( $blog_id = 0 ) {
3327
- $active_basenames = self::get_active_plugins_basenames( $blog_id );
3328
-
3329
- $map = array();
3330
-
3331
- foreach ( $active_basenames as $active_basename ) {
3332
- $active_basename = fs_normalize_path( $active_basename );
3333
-
3334
- if ( false === strpos( $active_basename, '/' ) ) {
3335
- continue;
3336
- }
3337
-
3338
- $map[ dirname( $active_basename ) ] = true;
3339
- }
3340
-
3341
- return $map;
3342
- }
3343
-
3344
- /**
3345
- * Get collection of all active plugins. Including network activated plugins.
3346
- *
3347
- * @author Vova Feldman (@svovaf)
3348
- * @since 1.0.9
3349
- *
3350
- * @param int $blog_id Since 2.0.0
3351
- *
3352
- * @return array[string]array
3353
- */
3354
- private static function get_active_plugins( $blog_id = 0 ) {
3355
- self::require_plugin_essentials();
3356
-
3357
- $active_plugin = array();
3358
- $all_plugins = fs_get_plugins();
3359
- $active_plugins_basenames = self::get_active_plugins_basenames( $blog_id );
3360
-
3361
- foreach ( $active_plugins_basenames as $plugin_basename ) {
3362
- $active_plugin[ $plugin_basename ] = $all_plugins[ $plugin_basename ];
3363
- }
3364
-
3365
- return $active_plugin;
3366
- }
3367
-
3368
- /**
3369
- * Get collection of all site active plugins for a specified blog.
3370
- *
3371
- * @author Vova Feldman (@svovaf)
3372
- * @since 2.0.0
3373
- *
3374
- * @param int $blog_id
3375
- *
3376
- * @return array[string]array
3377
- */
3378
- private static function get_site_active_plugins( $blog_id = 0 ) {
3379
- $active_basenames = ( is_multisite() && $blog_id > 0 ) ?
3380
- get_blog_option( $blog_id, 'active_plugins' ) :
3381
- get_option( 'active_plugins' );
3382
-
3383
- $active = array();
3384
-
3385
- if ( ! is_array( $active_basenames ) ) {
3386
- return $active;
3387
- }
3388
-
3389
- foreach ( $active_basenames as $basename ) {
3390
- $active[ $basename ] = array(
3391
- 'is_active' => true,
3392
- 'Version' => '1.0', // Dummy version.
3393
- 'slug' => self::get_plugin_slug( $basename ),
3394
- );
3395
- }
3396
-
3397
- return $active;
3398
- }
3399
-
3400
- /**
3401
- * Get collection of all plugins with their activation status for a specified blog.
3402
- *
3403
- * @author Vova Feldman (@svovaf)
3404
- * @since 1.1.8
3405
- *
3406
- * @param int $blog_id Since 2.0.0
3407
- *
3408
- * @return array Key is the plugin file path and the value is an array of the plugin data.
3409
- */
3410
- private static function get_all_plugins( $blog_id = 0 ) {
3411
- self::require_plugin_essentials();
3412
-
3413
- $all_plugins = fs_get_plugins();
3414
-
3415
- $active_plugins_basenames = self::get_active_plugins_basenames( $blog_id );
3416
-
3417
- foreach ( $all_plugins as $basename => &$data ) {
3418
- // By default set to inactive (next foreach update the active plugins).
3419
- $data['is_active'] = false;
3420
- // Enrich with plugin slug.
3421
- $data['slug'] = self::get_plugin_slug( $basename );
3422
- }
3423
-
3424
- // Flag active plugins.
3425
- foreach ( $active_plugins_basenames as $basename ) {
3426
- if ( isset( $all_plugins[ $basename ] ) ) {
3427
- $all_plugins[ $basename ]['is_active'] = true;
3428
- }
3429
- }
3430
-
3431
- return $all_plugins;
3432
- }
3433
-
3434
- /**
3435
- * Get collection of all plugins and if they are network level activated.
3436
- *
3437
- * @author Vova Feldman (@svovaf)
3438
- * @since 2.0.0
3439
- *
3440
- * @return array Key is the plugin basename and the value is an array of the plugin data.
3441
- */
3442
- private static function get_network_plugins() {
3443
- self::require_plugin_essentials();
3444
-
3445
- $all_plugins = fs_get_plugins();
3446
-
3447
- $network_active_basenames = is_multisite() ?
3448
- get_site_option( 'active_sitewide_plugins' ) :
3449
- array();
3450
-
3451
- foreach ( $all_plugins as $basename => &$data ) {
3452
- // By default set to inactive (next foreach update the active plugins).
3453
- $data['is_active'] = false;
3454
- // Enrich with plugin slug.
3455
- $data['slug'] = self::get_plugin_slug( $basename );
3456
- }
3457
-
3458
- // Flag active plugins.
3459
- foreach ( $network_active_basenames as $basename ) {
3460
- if ( isset( $all_plugins[ $basename ] ) ) {
3461
- $all_plugins[ $basename ]['is_active'] = true;
3462
- }
3463
- }
3464
-
3465
- return $all_plugins;
3466
- }
3467
-
3468
- /**
3469
- * Cached result of get_site_transient( 'update_plugins' )
3470
- *
3471
- * @author Vova Feldman (@svovaf)
3472
- * @since 1.1.8
3473
- *
3474
- * @var object
3475
- */
3476
- private static $_plugins_info;
3477
-
3478
- /**
3479
- * Helper function to get specified plugin's slug.
3480
- *
3481
- * @author Vova Feldman (@svovaf)
3482
- * @since 1.1.8
3483
- *
3484
- * @param $basename
3485
- *
3486
- * @return string
3487
- */
3488
- private static function get_plugin_slug( $basename ) {
3489
- if ( ! isset( self::$_plugins_info ) ) {
3490
- self::$_plugins_info = get_site_transient( 'update_plugins' );
3491
- }
3492
-
3493
- $slug = '';
3494
-
3495
- if ( is_object( self::$_plugins_info ) ) {
3496
- if ( isset( self::$_plugins_info->no_update ) &&
3497
- isset( self::$_plugins_info->no_update[ $basename ] ) &&
3498
- ! empty( self::$_plugins_info->no_update[ $basename ]->slug )
3499
- ) {
3500
- $slug = self::$_plugins_info->no_update[ $basename ]->slug;
3501
- } else if ( isset( self::$_plugins_info->response ) &&
3502
- isset( self::$_plugins_info->response[ $basename ] ) &&
3503
- ! empty( self::$_plugins_info->response[ $basename ]->slug )
3504
- ) {
3505
- $slug = self::$_plugins_info->response[ $basename ]->slug;
3506
- }
3507
- }
3508
-
3509
- if ( empty( $slug ) ) {
3510
- // Try to find slug from FS data.
3511
- $slug = self::find_slug_by_basename( $basename );
3512
- }
3513
-
3514
- if ( empty( $slug ) ) {
3515
- // Fallback to plugin's folder name.
3516
- $slug = dirname( $basename );
3517
- }
3518
-
3519
- return $slug;
3520
- }
3521
-
3522
- private static $_statics_loaded = false;
3523
-
3524
- /**
3525
- * Load static resources.
3526
- *
3527
- * @author Vova Feldman (@svovaf)
3528
- * @since 1.0.1
3529
- */
3530
- private static function _load_required_static() {
3531
- if ( self::$_statics_loaded ) {
3532
- return;
3533
- }
3534
-
3535
- self::$_static_logger = FS_Logger::get_logger( WP_FS__SLUG, WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
3536
-
3537
- self::$_static_logger->entrance();
3538
-
3539
- self::$_accounts = FS_Options::instance( WP_FS__ACCOUNTS_OPTION_NAME, true );
3540
-
3541
- if ( is_multisite() ) {
3542
- $has_skipped_migration = (
3543
- // 'id_slug_type_path_map' - was never stored on older versions, therefore, not exists on the site level.
3544
- null === self::$_accounts->get_option( 'id_slug_type_path_map', null, false ) &&
3545
- // 'file_slug_map' stored on the site level, so it was running an SDK version before it was integrated with MS-network.
3546
- null !== self::$_accounts->get_option( 'file_slug_map', null, false )
3547
- );
3548
-
3549
- /**
3550
- * If the file_slug_map exists on the site level but doesn't exist on the
3551
- * network level storage, it means that we need to process the storage with migration.
3552
- *
3553
- * 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, file_slug_map will be already set in the network level storage.
3554
- *
3555
- * @author Vova Feldman (@svovaf)
3556
- * @since 2.0.0
3557
- */
3558
- if (
3559
- ( $has_skipped_migration && true !== self::$_accounts->get_option( 'ms_migration_complete', false, true ) ) ||
3560
- ( null === self::$_accounts->get_option( 'file_slug_map', null, true ) &&
3561
- null !== self::$_accounts->get_option( 'file_slug_map', null, false ) )
3562
- ) {
3563
- self::migrate_options_to_network();
3564
- }
3565
- }
3566
-
3567
- self::$_global_admin_notices = FS_Admin_Notices::instance( 'global' );
3568
-
3569
- if ( ! WP_FS__DEMO_MODE ) {
3570
- add_action( ( fs_is_network_admin() ? 'network_' : '' ) . 'admin_menu', array(
3571
- 'Freemius',
3572
- '_add_debug_section'
3573
- ) );
3574
- }
3575
-
3576
- add_action( "wp_ajax_fs_toggle_debug_mode", array( 'Freemius', '_toggle_debug_mode' ) );
3577
-
3578
- self::add_ajax_action_static( 'get_debug_log', array( 'Freemius', '_get_debug_log' ) );
3579
-
3580
- self::add_ajax_action_static( 'get_db_option', array( 'Freemius', '_get_db_option' ) );
3581
-
3582
- self::add_ajax_action_static( 'set_db_option', array( 'Freemius', '_set_db_option' ) );
3583
-
3584
- if ( 0 == did_action( 'plugins_loaded' ) ) {
3585
- add_action( 'plugins_loaded', array( 'Freemius', '_load_textdomain' ), 1 );
3586
- }
3587
-
3588
- $clone_manager = FS_Clone_Manager::instance();
3589
- add_action( 'init', array( $clone_manager, '_init' ) );
3590
-
3591
- add_action( 'admin_footer', array( 'Freemius', '_enrich_ajax_url' ) );
3592
- add_action( 'admin_footer', array( 'Freemius', '_open_support_forum_in_new_page' ) );
3593
-
3594
- if ( self::is_plugins_page() || self::is_themes_page() ) {
3595
- add_action( 'admin_print_footer_scripts', array( 'Freemius', '_maybe_add_beta_label_styles' ), 9 );
3596
-
3597
- /**
3598
- * Specifically use this hook so that the JS event handlers will work properly on the "Themes"
3599
- * page.
3600
- *
3601
- * @author Leo Fajardo (@leorw)
3602
- * @since 2.3.0
3603
- */
3604
- add_action( 'admin_footer-' . self::get_current_page(), array( 'Freemius', '_maybe_add_beta_label_to_plugins_and_handle_confirmation') );
3605
- }
3606
-
3607
- self::$_statics_loaded = true;
3608
- }
3609
-
3610
- #--------------------------------------------------------------------------------
3611
- #region Clone
3612
- #--------------------------------------------------------------------------------
3613
-
3614
- /**
3615
- * @author Leo Fajardo (@leorw)
3616
- * @since 2.5.0
3617
- *
3618
- * @return bool
3619
- */
3620
- private function is_unresolved_clone() {
3621
- if ( ! $this->is_clone() ) {
3622
- return false;
3623
- }
3624
-
3625
- return FS_Clone_Manager::instance()->has_temporary_duplicate_mode_expired();
3626
- }
3627
-
3628
- /**
3629
- * @author Leo Fajardo (@leorw)
3630
- * @since 2.5.0
3631
- */
3632
- function is_clone() {
3633
- if ( ! is_object( $this->_site ) ) {
3634
- return false;
3635
- }
3636
-
3637
- return (
3638
- fs_strip_url_protocol( trailingslashit( $this->_site->url ) ) !== fs_strip_url_protocol( trailingslashit( self::get_site_url() ) )
3639
- );
3640
- }
3641
-
3642
- /**
3643
- * @author Leo Fajardo (@leorw)
3644
- * @since 2.5.0
3645
- *
3646
- * @param int|null $blog_id
3647
- *
3648
- * @return string
3649
- */
3650
- static function get_site_url( $blog_id = null ) {
3651
- global $wp_filter;
3652
-
3653
- $site_url_filters = array(
3654
- 'site_url' => null,
3655
- 'pre_option_siteurl' => null,
3656
- 'default_option_siteurl' => null,
3657
- 'option_siteurl' => null,
3658
- );
3659
-
3660
- foreach ( $site_url_filters as $hook_name => $site_url_filter ) {
3661
- if ( ! empty( $wp_filter[ $hook_name ] ) ) {
3662
- $site_url_filters[ $hook_name ] = $wp_filter[ $hook_name ];
3663
- unset( $wp_filter[ $hook_name ] );
3664
- }
3665
- }
3666
-
3667
- $url = get_site_url( $blog_id );
3668
-
3669
- foreach ( $site_url_filters as $hook_name => $site_url_filter ) {
3670
- if ( ! empty( $site_url_filter ) ) {
3671
- $wp_filter[ $hook_name ] = $site_url_filter;
3672
- }
3673
- }
3674
-
3675
- return $url;
3676
- }
3677
-
3678
- /**
3679
- * @author Leo Fajardo (@leorw)
3680
- * @since 2.5.0
3681
- *
3682
- * @param number $site_id
3683
- */
3684
- function fetch_install_by_id( $site_id ) {
3685
- return $this->get_current_or_network_user_api_scope()->get( "/installs/{$site_id}.json" );
3686
- }
3687
-
3688
- /**
3689
- * @author Leo Fajardo (@leorw)
3690
- * @since 2.5.0
3691
- *
3692
- * @return string|object|bool
3693
- */
3694
- function _handle_long_term_duplicate() {
3695
- $this->_logger->entrance();
3696
-
3697
- $this->delete_current_install( false );
3698
-
3699
- $license_key = false;
3700
-
3701
- if (
3702
- is_object( $this->_license ) &&
3703
- ! $this->_license->is_utilized(
3704
- ( WP_FS__IS_LOCALHOST_FOR_SERVER || FS_Site::is_localhost_by_address( self::get_site_url() ) )
3705
- )
3706
- ) {
3707
- $license_key = $this->_license->secret_key;
3708
- }
3709
-
3710
- return $this->opt_in(
3711
- false,
3712
- false,
3713
- false,
3714
- $license_key,
3715
- false,
3716
- false,
3717
- false,
3718
- null,
3719
- array(),
3720
- false
3721
- );
3722
- }
3723
-
3724
- #endregion
3725
-
3726
- /**
3727
- * @author Leo Fajardo (@leorw)
3728
- *
3729
- * @since 2.1.3
3730
- */
3731
- private static function migrate_options_to_network() {
3732
- self::migrate_accounts_to_network();
3733
-
3734
- // Migrate API options from site level to network level.
3735
- $api_network_options = FS_Option_Manager::get_manager( WP_FS__OPTIONS_OPTION_NAME, true, true );
3736
- $api_network_options->migrate_to_network();
3737
-
3738
- // Migrate API cache to network level storage.
3739
- FS_Cache_Manager::get_manager( WP_FS__API_CACHE_OPTION_NAME )->migrate_to_network();
3740
-
3741
- self::$_accounts->set_option( 'ms_migration_complete', true, true );
3742
- }
3743
-
3744
- #----------------------------------------------------------------------------------
3745
- #region Localization
3746
- #----------------------------------------------------------------------------------
3747
-
3748
- /**
3749
- * Load framework's text domain.
3750
- *
3751
- * @author Vova Feldman (@svovaf)
3752
- * @since 1.2.1
3753
- */
3754
- static function _load_textdomain() {
3755
- if ( ! is_admin() ) {
3756
- return;
3757
- }
3758
-
3759
- global $fs_active_plugins;
3760
-
3761
- // Works both for plugins and themes.
3762
- load_plugin_textdomain(
3763
- 'freemius',
3764
- false,
3765
- $fs_active_plugins->newest->sdk_path . '/languages/'
3766
- );
3767
- }
3768
-
3769
- #endregion
3770
-
3771
- #----------------------------------------------------------------------------------
3772
- #region Debugging
3773
- #----------------------------------------------------------------------------------
3774
-
3775
- /**
3776
- * @author Vova Feldman (@svovaf)
3777
- * @since 1.0.8
3778
- */
3779
- static function _add_debug_section() {
3780
- if ( ! is_super_admin() ) {
3781
- // Add debug page only for super-admins.
3782
- return;
3783
- }
3784
-
3785
- self::$_static_logger->entrance();
3786
-
3787
- $title = sprintf( '%s [v.%s]', fs_text_inline( 'Freemius Debug' ), WP_FS__SDK_VERSION );
3788
-
3789
- if ( WP_FS__DEV_MODE ) {
3790
- // Add top-level debug menu item.
3791
- $hook = FS_Admin_Menu_Manager::add_page(
3792
- $title,
3793
- $title,
3794
- 'manage_options',
3795
- 'freemius',
3796
- array( 'Freemius', '_debug_page_render' )
3797
- );
3798
- } else {
3799
- // Add hidden debug page.
3800
- $hook = FS_Admin_Menu_Manager::add_subpage(
3801
- null,
3802
- $title,
3803
- $title,
3804
- 'manage_options',
3805
- 'freemius',
3806
- array( 'Freemius', '_debug_page_render' )
3807
- );
3808
- }
3809
-
3810
- if ( ! empty( $hook ) ) {
3811
- add_action( "load-$hook", array( 'Freemius', '_debug_page_actions' ) );
3812
- }
3813
- }
3814
-
3815
- /**
3816
- * @author Vova Feldman (@svovaf)
3817
- * @since 1.1.7.3
3818
- */
3819
- static function _toggle_debug_mode() {
3820
- check_admin_referer( 'fs_toggle_debug_mode' );
3821
-
3822
- if ( ! is_super_admin() ) {
3823
- return;
3824
- }
3825
-
3826
- $is_on = fs_request_get( 'is_on', false, 'post' );
3827
-
3828
- if ( fs_request_is_post() && in_array( $is_on, array( 0, 1 ) ) ) {
3829
- update_option( 'fs_debug_mode', $is_on );
3830
-
3831
- // Turn on/off storage logging.
3832
- FS_Logger::_set_storage_logging( ( 1 == $is_on ) );
3833
- }
3834
-
3835
- exit;
3836
- }
3837
-
3838
- /**
3839
- * @author Vova Feldman (@svovaf)
3840
- * @since 1.2.1.6
3841
- */
3842
- static function _get_debug_log() {
3843
- check_admin_referer( 'fs_get_debug_log' );
3844
-
3845
- if ( ! is_super_admin() ) {
3846
- return;
3847
- }
3848
-
3849
- $limit = min( ! empty( $_POST['limit'] ) ? absint( $_POST['limit'] ) : 200, 200 );
3850
- $offset = min( ! empty( $_POST['offset'] ) ? absint( $_POST['offset'] ) : 200, 200 );
3851
-
3852
- $logs = FS_Logger::load_db_logs(
3853
- fs_request_get( 'filters', false, 'post' ),
3854
- $limit,
3855
- $offset
3856
- );
3857
-
3858
- self::shoot_ajax_success( $logs );
3859
- }
3860
-
3861
- /**
3862
- * @author Vova Feldman (@svovaf)
3863
- * @since 1.2.1.7
3864
- */
3865
- static function _get_db_option() {
3866
- check_admin_referer( 'fs_get_db_option' );
3867
-
3868
- $option_name = fs_request_get( 'option_name' );
3869
-
3870
- if ( ! is_super_admin() ||
3871
- ! fs_starts_with( $option_name, 'fs_' )
3872
- ) {
3873
- self::shoot_ajax_failure();
3874
- }
3875
-
3876
- $value = get_option( $option_name );
3877
-
3878
- $result = array(
3879
- 'name' => $option_name,
3880
- );
3881
-
3882
- if ( false !== $value ) {
3883
- if ( ! is_string( $value ) ) {
3884
- $value = json_encode( $value );
3885
- }
3886
-
3887
- $result['value'] = $value;
3888
- }
3889
-
3890
- self::shoot_ajax_success( $result );
3891
- }
3892
-
3893
- /**
3894
- * @author Vova Feldman (@svovaf)
3895
- * @since 1.2.1.7
3896
- */
3897
- static function _set_db_option() {
3898
- check_admin_referer( 'fs_set_db_option' );
3899
-
3900
- $option_name = fs_request_get( 'option_name' );
3901
-
3902
- if ( ! is_super_admin() ||
3903
- ! fs_starts_with( $option_name, 'fs_' )
3904
- ) {
3905
- self::shoot_ajax_failure();
3906
- }
3907
-
3908
- $option_value = fs_request_get( 'option_value' );
3909
-
3910
- if ( ! empty( $option_value ) ) {
3911
- update_option( $option_name, $option_value );
3912
- }
3913
-
3914
- self::shoot_ajax_success();
3915
- }
3916
-
3917
- /**
3918
- * @author Vova Feldman (@svovaf)
3919
- * @since 1.0.8
3920
- */
3921
- static function _debug_page_actions() {
3922
- self::_clean_admin_content_section();
3923
-
3924
- if ( fs_request_is_action( 'restart_freemius' ) ) {
3925
- check_admin_referer( 'restart_freemius' );
3926
-
3927
- if ( ! is_multisite() ) {
3928
- // Clear accounts data.
3929
- self::$_accounts->clear( null, true );
3930
- } else {
3931
- $sites = self::get_sites();
3932
- foreach ( $sites as $site ) {
3933
- $blog_id = self::get_site_blog_id( $site );
3934
- self::$_accounts->clear( $blog_id, true );
3935
- }
3936
-
3937
- // Clear network level storage.
3938
- self::$_accounts->clear( true, true );
3939
- }
3940
-
3941
- // Clear SDK reference cache.
3942
- delete_option( 'fs_active_plugins' );
3943
- } else if ( fs_request_is_action( 'clear_updates_data' ) ) {
3944
- check_admin_referer( 'clear_updates_data' );
3945
-
3946
- if ( ! is_multisite() ) {
3947
- set_site_transient( 'update_plugins', null );
3948
- set_site_transient( 'update_themes', null );
3949
- } else {
3950
- $current_blog_id = get_current_blog_id();
3951
-
3952
- $sites = self::get_sites();
3953
- foreach ( $sites as $site ) {
3954
- switch_to_blog( self::get_site_blog_id( $site ) );
3955
-
3956
- set_site_transient( 'update_plugins', null );
3957
- set_site_transient( 'update_themes', null );
3958
- }
3959
-
3960
- switch_to_blog( $current_blog_id );
3961
- }
3962
- } else if ( fs_request_is_action( 'reset_deactivation_snoozing' ) ) {
3963
- check_admin_referer( 'reset_deactivation_snoozing' );
3964
-
3965
- self::reset_deactivation_snoozing();
3966
- } else if ( fs_request_is_action( 'simulate_trial' ) ) {
3967
- check_admin_referer( 'simulate_trial' );
3968
-
3969
- $fs = freemius( fs_request_get( 'module_id' ) );
3970
-
3971
- // Update SDK install to at least 24 hours before.
3972
- $fs->_storage->install_timestamp = ( time() - WP_FS__TIME_24_HOURS_IN_SEC );
3973
- // Unset the trial shown timestamp.
3974
- unset( $fs->_storage->trial_promotion_shown );
3975
- } else if ( fs_request_is_action( 'simulate_network_upgrade' ) ) {
3976
- check_admin_referer( 'simulate_network_upgrade' );
3977
-
3978
- $fs = freemius( fs_request_get( 'module_id' ) );
3979
-
3980
- self::set_network_upgrade_mode( $fs->_storage );
3981
- } else if ( fs_request_is_action( 'delete_install' ) ) {
3982
- check_admin_referer( 'delete_install' );
3983
-
3984
- self::_delete_site_by_slug(
3985
- fs_request_get( 'slug' ),
3986
- fs_request_get( 'module_type' ),
3987
- true,
3988
- fs_request_get( 'blog_id', null )
3989
- );
3990
- } else if ( fs_request_is_action( 'delete_user' ) ) {
3991
- check_admin_referer( 'delete_user' );
3992
-
3993
- self::delete_user( fs_request_get( 'user_id' ) );
3994
- } else if ( fs_request_is_action( 'download_logs' ) ) {
3995
- check_admin_referer( 'download_logs' );
3996
-
3997
- $download_url = FS_Logger::download_db_logs(
3998
- fs_request_get( 'filters', false, 'post' )
3999
- );
4000
-
4001
- if ( false === $download_url ) {
4002
- wp_die( 'Oops... there was an error while generating the logs download file. Please try again and if it doesn\'t work contact support@freemius.com.' );
4003
- }
4004
-
4005
- fs_redirect( $download_url );
4006
- } else if ( fs_request_is_action( 'migrate_options_to_network' ) ) {
4007
- check_admin_referer( 'migrate_options_to_network' );
4008
-
4009
- self::migrate_options_to_network();
4010
- }
4011
- }
4012
-
4013
- /**
4014
- * @author Leo Fajardo (@leorw)
4015
- * @since 2.5.0
4016
- *
4017
- * @return array
4018
- */
4019
- static function get_all_modules_sites() {
4020
- self::$_static_logger->entrance();
4021
-
4022
- $sites_by_type = array(
4023
- WP_FS__MODULE_TYPE_PLUGIN => array(),
4024
- WP_FS__MODULE_TYPE_THEME => array(),
4025
- );
4026
-
4027
- $module_types = array_keys( $sites_by_type );
4028
-
4029
- if ( ! is_multisite() ) {
4030
- foreach ( $module_types as $type ) {
4031
- $sites_by_type[ $type ] = self::get_all_sites( $type );
4032
-
4033
- foreach ( $sites_by_type[ $type ] as $slug => $install ) {
4034
- $sites_by_type[ $type ][ $slug ] = array( $install );
4035
- }
4036
- }
4037
- } else {
4038
- $sites = self::get_sites();
4039
-
4040
- foreach ( $sites as $site ) {
4041
- $blog_id = self::get_site_blog_id( $site );
4042
-
4043
- foreach ( $module_types as $type ) {
4044
- $installs = self::get_all_sites( $type, $blog_id );
4045
-
4046
- foreach ( $installs as $slug => $install ) {
4047
- if ( ! isset( $sites_by_type[ $type ][ $slug ] ) ) {
4048
- $sites_by_type[ $type ][ $slug ] = array();
4049
- }
4050
-
4051
- $install->blog_id = $blog_id;
4052
-
4053
- $sites_by_type[ $type ][ $slug ][] = $install;
4054
- }
4055
-
4056
- }
4057
- }
4058
- }
4059
-
4060
- return $sites_by_type;
4061
- }
4062
-
4063
- /**
4064
- * @author Vova Feldman (@svovaf)
4065
- * @since 1.0.8
4066
- */
4067
- static function _debug_page_render() {
4068
- self::$_static_logger->entrance();
4069
-
4070
- $all_modules_sites = self::get_all_modules_sites();
4071
-
4072
- $licenses_by_module_type = self::get_all_licenses_by_module_type();
4073
-
4074
- $vars = array(
4075
- 'plugin_sites' => $all_modules_sites[ WP_FS__MODULE_TYPE_PLUGIN ],
4076
- 'theme_sites' => $all_modules_sites[ WP_FS__MODULE_TYPE_THEME ],
4077
- 'users' => self::get_all_users(),
4078
- 'addons' => self::get_all_addons(),
4079
- 'account_addons' => self::get_all_account_addons(),
4080
- 'plugin_licenses' => $licenses_by_module_type[ WP_FS__MODULE_TYPE_PLUGIN ],
4081
- 'theme_licenses' => $licenses_by_module_type[ WP_FS__MODULE_TYPE_THEME ]
4082
- );
4083
-
4084
- fs_enqueue_local_style( 'fs_debug', '/admin/debug.css' );
4085
- fs_require_once_template( 'debug.php', $vars );
4086
- }
4087
-
4088
- #endregion
4089
-
4090
- #----------------------------------------------------------------------------------
4091
- #region Connectivity Issues
4092
- #----------------------------------------------------------------------------------
4093
-
4094
- /**
4095
- * Check if Freemius should be turned on for the current plugin install.
4096
- *
4097
- * Note:
4098
- * $this->_is_on is updated in has_api_connectivity()
4099
- *
4100
- * @author Vova Feldman (@svovaf)
4101
- * @since 1.0.9
4102
- *
4103
- * @return bool
4104
- */
4105
- function is_on() {
4106
- self::$_static_logger->entrance();
4107
-
4108
- if ( is_object( $this->_site ) && ! $this->is_registered() ) {
4109
- return false;
4110
- }
4111
-
4112
- if ( isset( $this->_is_on ) ) {
4113
- return $this->_is_on;
4114
- }
4115
-
4116
- // If already installed or pending then sure it's on :)
4117
- if ( $this->is_registered() || $this->is_pending_activation() ) {
4118
- $this->_is_on = true;
4119
-
4120
- return true;
4121
- }
4122
-
4123
- return false;
4124
- }
4125
-
4126
- /**
4127
- * @author Vova Feldman (@svovaf)
4128
- * @since 1.1.7.3
4129
- *
4130
- * @param bool $flush_if_no_connectivity
4131
- *
4132
- * @return bool
4133
- */
4134
- private function should_run_connectivity_test( $flush_if_no_connectivity = false ) {
4135
- if ( ! isset( $this->_storage->connectivity_test ) ) {
4136
- // Connectivity test was never executed, or cache was cleared.
4137
- return true;
4138
- }
4139
-
4140
- if ( WP_FS__PING_API_ON_IP_OR_HOST_CHANGES ) {
4141
- if ( WP_FS__IS_HTTP_REQUEST ) {
4142
- if ( $_SERVER['HTTP_HOST'] != $this->_storage->connectivity_test['host'] ) {
4143
- // Domain changed.
4144
- return true;
4145
- }
4146
-
4147
- if ( WP_FS__REMOTE_ADDR != $this->_storage->connectivity_test['server_ip'] ) {
4148
- // Server IP changed.
4149
- return true;
4150
- }
4151
- }
4152
- }
4153
-
4154
- if ( $this->_storage->connectivity_test['is_connected'] &&
4155
- $this->_storage->connectivity_test['is_active']
4156
- ) {
4157
- // API connected and Freemius is active - no need to run connectivity check.
4158
- return false;
4159
- }
4160
-
4161
- if ( $flush_if_no_connectivity ) {
4162
- /**
4163
- * If explicitly asked to flush when no connectivity - do it only
4164
- * if at least 10 sec passed from the last API connectivity test.
4165
- */
4166
- return ( isset( $this->_storage->connectivity_test['timestamp'] ) &&
4167
- ( WP_FS__SCRIPT_START_TIME - $this->_storage->connectivity_test['timestamp'] ) > 10 );
4168
- }
4169
-
4170
- /**
4171
- * @since 1.1.7 Don't check for connectivity on plugin downgrade.
4172
- */
4173
- $version = $this->get_plugin_version();
4174
- if ( version_compare( $version, $this->_storage->connectivity_test['version'], '>' ) ) {
4175
- // If it's a plugin version upgrade and Freemius is off or no connectivity, run connectivity test.
4176
- return true;
4177
- }
4178
-
4179
- return false;
4180
- }
4181
-
4182
- /**
4183
- * @author Vova Feldman (@svovaf)
4184
- * @since 1.1.7.4
4185
- *
4186
- * @param int|null $blog_id Since 2.0.0.
4187
- * @param bool $is_gdpr_test Since 2.0.2. Perform only the GDPR test.
4188
- *
4189
- * @return object|false
4190
- */
4191
- private function ping( $blog_id = null, $is_gdpr_test = false ) {
4192
- if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY ) {
4193
- return false;
4194
- }
4195
-
4196
- $version = $this->get_plugin_version();
4197
-
4198
- $is_update = $this->apply_filters( 'is_plugin_update', $this->is_plugin_update() );
4199
-
4200
- $params = array(
4201
- 'is_update' => json_encode( $is_update ),
4202
- 'version' => $version,
4203
- 'sdk' => $this->version,
4204
- 'is_admin' => json_encode( is_admin() ),
4205
- 'is_ajax' => json_encode( self::is_ajax() ),
4206
- 'is_cron' => json_encode( self::is_cron() ),
4207
- 'is_gdpr_test' => $is_gdpr_test,
4208
- 'is_http' => json_encode( WP_FS__IS_HTTP_REQUEST ),
4209
- );
4210
-
4211
- if ( is_multisite() && function_exists( 'get_network' ) ) {
4212
- $params['network_uid'] = $this->get_anonymous_network_id();
4213
- }
4214
-
4215
- return $this->get_api_plugin_scope()->ping(
4216
- $this->get_anonymous_id( $blog_id ),
4217
- $params
4218
- );
4219
- }
4220
-
4221
- /**
4222
- * Check if there's any connectivity issue to Freemius API.
4223
- *
4224
- * @author Vova Feldman (@svovaf)
4225
- * @since 1.0.9
4226
- *
4227
- * @param bool $flush_if_no_connectivity
4228
- *
4229
- * @return bool
4230
- */
4231
- function has_api_connectivity( $flush_if_no_connectivity = false ) {
4232
- $this->_logger->entrance();
4233
-
4234
- if ( isset( $this->_has_api_connection ) && ( $this->_has_api_connection || ! $flush_if_no_connectivity ) ) {
4235
- return $this->_has_api_connection;
4236
- }
4237
-
4238
- if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY &&
4239
- isset( $this->_storage->connectivity_test ) &&
4240
- true === $this->_storage->connectivity_test['is_connected']
4241
- ) {
4242
- unset( $this->_storage->connectivity_test );
4243
- }
4244
-
4245
- if ( ! $this->should_run_connectivity_test( $flush_if_no_connectivity ) ) {
4246
- $this->_has_api_connection = $this->_storage->connectivity_test['is_connected'];
4247
- /**
4248
- * @since 1.1.6 During dev mode, if there's connectivity - turn Freemius on regardless the configuration.
4249
- *
4250
- * @since 1.2.1.5 If the user running the premium version then ignore the 'is_active' flag and turn Freemius on to enable license key activation.
4251
- */
4252
- $this->_is_on = $this->_storage->connectivity_test['is_active'] ||
4253
- $this->is_premium() ||
4254
- ( WP_FS__DEV_MODE && $this->_has_api_connection && ! WP_FS__SIMULATE_FREEMIUS_OFF );
4255
-
4256
- return $this->_has_api_connection;
4257
- }
4258
-
4259
- $pong = $this->ping();
4260
- $is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
4261
-
4262
- if ( ! $is_connected ) {
4263
- // API failure.
4264
- $this->_add_connectivity_issue_message( $pong );
4265
- }
4266
-
4267
- if ( $is_connected ) {
4268
- FS_GDPR_Manager::instance()->store_is_required( $pong->is_gdpr_required );
4269
- }
4270
-
4271
- $this->store_connectivity_info( $pong, $is_connected );
4272
-
4273
- return $this->_has_api_connection;
4274
- }
4275
-
4276
- /**
4277
- * @author Vova Feldman (@svovaf)
4278
- * @since 1.1.7.4
4279
- *
4280
- * @param object $pong
4281
- * @param bool $is_connected
4282
- */
4283
- private function store_connectivity_info( $pong, $is_connected ) {
4284
- $this->_logger->entrance();
4285
-
4286
- $version = $this->get_plugin_version();
4287
-
4288
- if ( ! $is_connected || WP_FS__SIMULATE_FREEMIUS_OFF ) {
4289
- $is_active = false;
4290
- } else {
4291
- $is_active = ( isset( $pong->is_active ) && true == $pong->is_active );
4292
- }
4293
-
4294
- $is_active = $this->apply_filters(
4295
- 'is_on',
4296
- $is_active,
4297
- $this->is_plugin_update(),
4298
- $version
4299
- );
4300
-
4301
- $this->_storage->connectivity_test = array(
4302
- 'is_connected' => $is_connected,
4303
- 'host' => $_SERVER['HTTP_HOST'],
4304
- 'server_ip' => WP_FS__REMOTE_ADDR,
4305
- 'is_active' => $is_active,
4306
- 'timestamp' => WP_FS__SCRIPT_START_TIME,
4307
- // Last version with connectivity attempt.
4308
- 'version' => $version,
4309
- );
4310
-
4311
- $this->_has_api_connection = $is_connected;
4312
- $this->_is_on = $is_active || ( WP_FS__DEV_MODE && $is_connected && ! WP_FS__SIMULATE_FREEMIUS_OFF );
4313
- }
4314
-
4315
- /**
4316
- * Force turning Freemius on.
4317
- *
4318
- * @author Vova Feldman (@svovaf)
4319
- * @since 1.1.8.1
4320
- *
4321
- * @return bool TRUE if successfully turned on.
4322
- */
4323
- private function turn_on() {
4324
- $this->_logger->entrance();
4325
-
4326
- if ( $this->is_on() || ! isset( $this->_storage->connectivity_test['is_active'] ) ) {
4327
- return false;
4328
- }
4329
-
4330
- $updated_connectivity = $this->_storage->connectivity_test;
4331
- $updated_connectivity['is_active'] = true;
4332
- $updated_connectivity['timestamp'] = WP_FS__SCRIPT_START_TIME;
4333
- $this->_storage->connectivity_test = $updated_connectivity;
4334
-
4335
- $this->_is_on = true;
4336
-
4337
- return true;
4338
- }
4339
-
4340
- /**
4341
- * Anonymous and unique site identifier (Hash).
4342
- *
4343
- * @author Vova Feldman (@svovaf)
4344
- * @since 1.1.0
4345
- *
4346
- * @param null|int $blog_id Since 2.0.0
4347
- *
4348
- * @return string
4349
- */
4350
- function get_anonymous_id( $blog_id = null ) {
4351
- $unique_id = self::$_accounts->get_option( 'unique_id', null, $blog_id );
4352
-
4353
- if ( empty( $unique_id ) || ! is_string( $unique_id ) ) {
4354
- $key = fs_strip_url_protocol( self::get_site_url( $blog_id ) );
4355
-
4356
- $secure_auth = defined( 'SECURE_AUTH_KEY' ) ? SECURE_AUTH_KEY : '';
4357
- if ( empty( $secure_auth ) ||
4358
- false !== strpos( $secure_auth, ' ' ) ||
4359
- 'put your unique phrase here' === $secure_auth
4360
- ) {
4361
- // Protect against default auth key.
4362
- $secure_auth = md5( microtime() );
4363
- }
4364
-
4365
- /**
4366
- * Base the unique identifier on the WP secure authentication key. Which
4367
- * turns the key into a secret anonymous identifier. This will help us
4368
- * to avoid duplicate installs generation on the backend upon opt-in.
4369
- *
4370
- * @author Vova Feldman (@svovaf)
4371
- * @since 1.2.3
4372
- */
4373
- $unique_id = md5( $key . $secure_auth );
4374
-
4375
- self::$_accounts->set_option( 'unique_id', $unique_id, true, $blog_id );
4376
- }
4377
-
4378
- $this->_logger->departure( $unique_id );
4379
-
4380
- return $unique_id;
4381
- }
4382
-
4383
- /**
4384
- * Returns anonymous network ID.
4385
- *
4386
- * @since 2.4.3
4387
- *
4388
- * @return string
4389
- */
4390
- function get_anonymous_network_id() {
4391
- return $this->get_anonymous_id( get_network()->site_id );
4392
- }
4393
-
4394
- /**
4395
- * @author Vova Feldman (@svovaf)
4396
- * @since 1.1.7.4
4397
- *
4398
- * @return \WP_User
4399
- */
4400
- static function _get_current_wp_user() {
4401
- self::require_pluggable_essentials();
4402
- self::wp_cookie_constants();
4403
-
4404
- return wp_get_current_user();
4405
- }
4406
-
4407
- /**
4408
- * Define cookie constants which are required by Freemius::_get_current_wp_user() since
4409
- * it uses wp_get_current_user() which needs the cookie constants set. When a plugin
4410
- * is network activated the cookie constants are only configured after the network
4411
- * plugins activation, therefore, if we don't define those constants WP will throw
4412
- * PHP warnings/notices.
4413
- *
4414
- * @author Vova Feldman (@svovaf)
4415
- * @since 2.1.1
4416
- */
4417
- private static function wp_cookie_constants() {
4418
- if ( defined( 'LOGGED_IN_COOKIE' ) &&
4419
- ( defined( 'AUTH_COOKIE' ) || defined( 'SECURE_AUTH_COOKIE' ) )
4420
- ) {
4421
- return;
4422
- }
4423
-
4424
- /**
4425
- * Used to guarantee unique hash cookies
4426
- *
4427
- * @since 1.5.0
4428
- */
4429
- if ( ! defined( 'COOKIEHASH' ) ) {
4430
- $siteurl = get_site_option( 'siteurl' );
4431
- if ( $siteurl ) {
4432
- define( 'COOKIEHASH', md5( $siteurl ) );
4433
- } else {
4434
- define( 'COOKIEHASH', '' );
4435
- }
4436
- }
4437
-
4438
- if ( ! defined( 'LOGGED_IN_COOKIE' ) ) {
4439
- define( 'LOGGED_IN_COOKIE', 'wordpress_logged_in_' . COOKIEHASH );
4440
- }
4441
-
4442
- /**
4443
- * @since 2.5.0
4444
- */
4445
- if ( ! defined( 'AUTH_COOKIE' ) ) {
4446
- define( 'AUTH_COOKIE', 'wordpress_' . COOKIEHASH );
4447
- }
4448
-
4449
- /**
4450
- * @since 2.6.0
4451
- */
4452
- if ( ! defined( 'SECURE_AUTH_COOKIE' ) ) {
4453
- define( 'SECURE_AUTH_COOKIE', 'wordpress_sec_' . COOKIEHASH );
4454
- }
4455
- }
4456
-
4457
- /**
4458
- * @author Vova Feldman (@svovaf)
4459
- * @since 2.1.0
4460
- *
4461
- * @return int
4462
- */
4463
- static function get_current_wp_user_id() {
4464
- $wp_user = self::_get_current_wp_user();
4465
-
4466
- return $wp_user->ID;
4467
- }
4468
-
4469
- /**
4470
- * @author Vova Feldman (@svovaf)
4471
- * @since 1.2.1.7
4472
- *
4473
- * @param string $email
4474
- *
4475
- * @return bool
4476
- */
4477
- static function is_valid_email( $email ) {
4478
- if ( false === filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
4479
- return false;
4480
- }
4481
-
4482
- $parts = explode( '@', $email );
4483
-
4484
- if ( 2 !== count( $parts ) || empty( $parts[1] ) ) {
4485
- return false;
4486
- }
4487
-
4488
- $blacklist = array(
4489
- 'admin.',
4490
- 'webmaster.',
4491
- 'localhost.',
4492
- 'dev.',
4493
- 'development.',
4494
- 'test.',
4495
- 'stage.',
4496
- 'staging.',
4497
- );
4498
-
4499
- // Make sure domain is not one of the blacklisted.
4500
- foreach ( $blacklist as $invalid ) {
4501
- if ( 0 === strpos( $parts[1], $invalid ) ) {
4502
- return false;
4503
- }
4504
- }
4505
-
4506
- // Get the UTF encoded domain name.
4507
- $domain = idn_to_ascii( $parts[1] ) . '.';
4508
-
4509
- return ( checkdnsrr( $domain, 'MX' ) || checkdnsrr( $domain, 'A' ) );
4510
- }
4511
-
4512
- /**
4513
- * Generate API connectivity issue message.
4514
- *
4515
- * @author Vova Feldman (@svovaf)
4516
- * @since 1.0.9
4517
- *
4518
- * @param mixed $api_result
4519
- * @param bool $is_first_failure
4520
- */
4521
- function _add_connectivity_issue_message( $api_result, $is_first_failure = true ) {
4522
- if ( ! $this->is_premium() && $this->_enable_anonymous ) {
4523
- // Don't add message if it's the free version and can run anonymously.
4524
- return;
4525
- }
4526
-
4527
- if ( ! function_exists( 'wp_nonce_url' ) ) {
4528
- require_once ABSPATH . 'wp-includes/functions.php';
4529
- }
4530
-
4531
- $current_user = self::_get_current_wp_user();
4532
- // $admin_email = get_option( 'admin_email' );
4533
- $admin_email = $current_user->user_email;
4534
-
4535
- // Aliases.
4536
- $deactivate_plugin_title = $this->esc_html_inline( 'That\'s exhausting, please deactivate', 'deactivate-plugin-title' );
4537
- $deactivate_plugin_desc = $this->esc_html_inline( 'We feel your frustration and sincerely apologize for the inconvenience. Hope to see you again in the future.', 'deactivate-plugin-desc' );
4538
- $install_previous_title = $this->esc_html_inline( 'Let\'s try your previous version', 'install-previous-title' );
4539
- $install_previous_desc = $this->esc_html_inline( 'Uninstall this version and install the previous one.', 'install-previous-desc' );
4540
- $fix_issue_title = $this->esc_html_inline( 'Yes - I\'m giving you a chance to fix it', 'fix-issue-title' );
4541
- $fix_issue_desc = $this->esc_html_inline( 'We will do our best to whitelist your server and resolve this issue ASAP. You will get a follow-up email to %s once we have an update.', 'fix-issue-desc' );
4542
- /* translators: %s: product title (e.g. "Awesome Plugin" requires an access to...) */
4543
- $x_requires_access_to_api = $this->esc_html_inline( '%s requires an access to our API.', 'x-requires-access-to-api' );
4544
- $sysadmin_title = $this->esc_html_inline( 'I\'m a system administrator', 'sysadmin-title' );
4545
- $happy_to_resolve_issue_asap = $this->esc_html_inline( 'We are sure it\'s an issue on our side and more than happy to resolve it for you ASAP if you give us a chance.', 'happy-to-resolve-issue-asap' );
4546
-
4547
- $message = false;
4548
- if ( is_object( $api_result ) &&
4549
- isset( $api_result->error ) &&
4550
- isset( $api_result->error->code )
4551
- ) {
4552
- switch ( $api_result->error->code ) {
4553
- case 'curl_missing':
4554
- $missing_methods = '';
4555
- if ( is_array( $api_result->missing_methods ) &&
4556
- ! empty( $api_result->missing_methods )
4557
- ) {
4558
- foreach ( $api_result->missing_methods as $m ) {
4559
- if ( 'curl_version' === $m ) {
4560
- continue;
4561
- }
4562
-
4563
- if ( ! empty( $missing_methods ) ) {
4564
- $missing_methods .= ', ';
4565
- }
4566
-
4567
- $missing_methods .= sprintf( '<code>%s</code>', $m );
4568
- }
4569
-
4570
- if ( ! empty( $missing_methods ) ) {
4571
- $missing_methods = sprintf(
4572
- '<br><br><b>%s</b> %s',
4573
- $this->esc_html_inline( 'Disabled method(s):', 'curl-disabled-methods' ),
4574
- $missing_methods
4575
- );
4576
- }
4577
- }
4578
-
4579
- $message = sprintf(
4580
- $x_requires_access_to_api . ' ' .
4581
- $this->esc_html_inline( 'We use PHP cURL library for the API calls, which is a very common library and usually installed and activated out of the box. Unfortunately, cURL is not activated (or disabled) on your server.', 'curl-missing-message' ) . ' ' .
4582
- $missing_methods .
4583
- ' %s',
4584
- '<b>' . $this->get_plugin_name() . '</b>',
4585
- sprintf(
4586
- '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
4587
- sprintf(
4588
- '<a class="fs-resolve" data-type="curl" href="#"><b>%s</b></a>%s',
4589
- $this->get_text_inline( 'I don\'t know what is cURL or how to install it, help me!', 'curl-missing-no-clue-title' ),
4590
- ' - ' . sprintf(
4591
- $this->get_text_inline( 'We\'ll make sure to contact your hosting company and resolve the issue. You will get a follow-up email to %s once we have an update.', 'curl-missing-no-clue-desc' ),
4592
- '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
4593
- )
4594
- ),
4595
- sprintf(
4596
- '<b>%s</b> - %s',
4597
- $sysadmin_title,
4598
- esc_html( sprintf( $this->get_text_inline( 'Great, please install cURL and enable it in your php.ini file. In addition, search for the \'disable_functions\' directive in your php.ini file and remove any disabled methods starting with \'curl_\'. To make sure it was successfully activated, use \'phpinfo()\'. Once activated, deactivate the %s and reactivate it back again.', 'curl-missing-sysadmin-desc' ), $this->get_module_label( true ) ) )
4599
- ),
4600
- sprintf(
4601
- '<a href="%s"><b>%s</b></a> - %s',
4602
- wp_nonce_url( 'plugins.php?action=deactivate&amp;plugin=' . $this->_plugin_basename . '&amp;plugin_status=all&amp;paged=1&amp;s=', 'deactivate-plugin_' . $this->_plugin_basename ),
4603
- $deactivate_plugin_title,
4604
- $deactivate_plugin_desc
4605
- )
4606
- )
4607
- );
4608
- break;
4609
- case 'cloudflare_ddos_protection':
4610
- $message = sprintf(
4611
- $x_requires_access_to_api . ' ' .
4612
- $this->esc_html_inline( 'From unknown reason, CloudFlare, the firewall we use, blocks the connection.', 'cloudflare-blocks-connection-message' ) . ' ' .
4613
- $happy_to_resolve_issue_asap .
4614
- ' %s',
4615
- '<b>' . $this->get_plugin_name() . '</b>',
4616
- sprintf(
4617
- '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
4618
- sprintf(
4619
- '<a class="fs-resolve" data-type="cloudflare" href="#"><b>%s</b></a>%s',
4620
- $fix_issue_title,
4621
- ' - ' . sprintf(
4622
- $fix_issue_desc,
4623
- '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
4624
- )
4625
- ),
4626
- sprintf(
4627
- '<a href="%s" target="_blank" rel="noopener noreferrer"><b>%s</b></a> - %s',
4628
- sprintf( 'https://wordpress.org/plugins/%s/download/', $this->_slug ),
4629
- $install_previous_title,
4630
- $install_previous_desc
4631
- ),
4632
- sprintf(
4633
- '<a href="%s"><b>%s</b></a> - %s',
4634
- wp_nonce_url( 'plugins.php?action=deactivate&amp;plugin=' . $this->_plugin_basename . '&amp;plugin_status=all&amp;paged=1&amp;s=' . '', 'deactivate-plugin_' . $this->_plugin_basename ),
4635
- $deactivate_plugin_title,
4636
- $deactivate_plugin_desc
4637
- )
4638
- )
4639
- );
4640
- break;
4641
- case 'squid_cache_block':
4642
- $message = sprintf(
4643
- $x_requires_access_to_api . ' ' .
4644
- $this->esc_html_inline( 'It looks like your server is using Squid ACL (access control lists), which blocks the connection.', 'squid-blocks-connection-message' ) .
4645
- ' %s',
4646
- '<b>' . $this->get_plugin_name() . '</b>',
4647
- sprintf(
4648
- '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
4649
- sprintf(
4650
- '<a class="fs-resolve" data-type="squid" href="#"><b>%s</b></a> - %s',
4651
- $this->esc_html_inline( 'I don\'t know what is Squid or ACL, help me!', 'squid-no-clue-title' ),
4652
- sprintf(
4653
- $this->esc_html_inline( 'We\'ll make sure to contact your hosting company and resolve the issue. You will get a follow-up email to %s once we have an update.', 'squid-no-clue-desc' ),
4654
- '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
4655
- )
4656
- ),
4657
- sprintf(
4658
- '<b>%s</b> - %s',
4659
- $sysadmin_title,
4660
- sprintf(
4661
- $this->esc_html_inline( 'Great, please whitelist the following domains: %s. Once you are done, deactivate the %s and activate it again.', 'squid-sysadmin-desc' ),
4662
- // We use a filter since the plugin might require additional API connectivity.
4663
- '<b>' . implode( ', ', $this->apply_filters( 'api_domains', array(
4664
- 'api.freemius.com',
4665
- 'wp.freemius.com'
4666
- ) ) ) . '</b>',
4667
- $this->_module_type
4668
- )
4669
- ),
4670
- sprintf(
4671
- '<a href="%s"><b>%s</b></a> - %s',
4672
- wp_nonce_url( 'plugins.php?action=deactivate&amp;plugin=' . $this->_plugin_basename . '&amp;plugin_status=all&amp;paged=1&amp;s=', 'deactivate-plugin_' . $this->_plugin_basename ),
4673
- $deactivate_plugin_title,
4674
- $deactivate_plugin_desc
4675
- )
4676
- )
4677
- );
4678
- break;
4679
- // default:
4680
- // $message = $this->get_text_inline( 'connectivity-test-fails-message' );
4681
- // break;
4682
- }
4683
- }
4684
-
4685
- $message_id = 'failed_connect_api';
4686
- $type = 'error';
4687
-
4688
- $connectivity_test_fails_message = $this->esc_html_inline( 'From unknown reason, the API connectivity test failed.', 'connectivity-test-fails-message' );
4689
-
4690
- if ( false === $message ) {
4691
- if ( $is_first_failure ) {
4692
- // First attempt failed.
4693
- $message = sprintf(
4694
- $x_requires_access_to_api . ' ' .
4695
- $connectivity_test_fails_message . ' ' .
4696
- $this->esc_html_inline( 'It\'s probably a temporary issue on our end. Just to be sure, with your permission, would it be o.k to run another connectivity test?', 'connectivity-test-maybe-temporary' ) . '<br><br>' .
4697
- '%s',
4698
- '<b>' . $this->get_plugin_name() . '</b>',
4699
- sprintf(
4700
- '<div id="fs_firewall_issue_options">%s %s</div>',
4701
- sprintf(
4702
- '<a class="button button-primary fs-resolve" data-type="retry_ping" href="#">%s</a>',
4703
- $this->get_text_inline( 'Yes - do your thing', 'yes-do-your-thing' )
4704
- ),
4705
- sprintf(
4706
- '<a href="%s" class="button">%s</a>',
4707
- wp_nonce_url( 'plugins.php?action=deactivate&amp;plugin=' . $this->_plugin_basename . '&amp;plugin_status=all&amp;paged=1&amp;s=', 'deactivate-plugin_' . $this->_plugin_basename ),
4708
- $this->get_text_inline( 'No - just deactivate', 'no-deactivate' )
4709
- )
4710
- )
4711
- );
4712
-
4713
- $message_id = 'failed_connect_api_first';
4714
- $type = 'promotion';
4715
- } else {
4716
- // Second connectivity attempt failed.
4717
- $message = sprintf(
4718
- $x_requires_access_to_api . ' ' .
4719
- $connectivity_test_fails_message . ' ' .
4720
- $happy_to_resolve_issue_asap .
4721
- ' %s',
4722
- '<b>' . $this->get_plugin_name() . '</b>',
4723
- sprintf(
4724
- '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
4725
- sprintf(
4726
- '<a class="fs-resolve" data-type="general" href="#"><b>%s</b></a>%s',
4727
- $fix_issue_title,
4728
- ' - ' . sprintf(
4729
- $fix_issue_desc,
4730
- '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
4731
- )
4732
- ),
4733
- sprintf(
4734
- '<a href="%s" target="_blank" rel="noopener noreferrer"><b>%s</b></a> - %s',
4735
- sprintf( 'https://wordpress.org/plugins/%s/download/', $this->_slug ),
4736
- $install_previous_title,
4737
- $install_previous_desc
4738
- ),
4739
- sprintf(
4740
- '<a href="%s"><b>%s</b></a> - %s',
4741
- wp_nonce_url( 'plugins.php?action=deactivate&amp;plugin=' . $this->_plugin_basename . '&amp;plugin_status=all&amp;paged=1&amp;s=', 'deactivate-plugin_' . $this->_plugin_basename ),
4742
- $deactivate_plugin_title,
4743
- $deactivate_plugin_desc
4744
- )
4745
- )
4746
- );
4747
- }
4748
- }
4749
-
4750
- $this->_admin_notices->add_sticky(
4751
- $message,
4752
- $message_id,
4753
- $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
4754
- $type
4755
- );
4756
- }
4757
-
4758
- /**
4759
- * Handle user request to resolve connectivity issue.
4760
- * This method will send an email to Freemius API technical staff for resolution.
4761
- * The email will contain server's info and installed plugins (might be caching issue).
4762
- *
4763
- * @author Vova Feldman (@svovaf)
4764
- * @since 1.0.9
4765
- */
4766
- function _email_about_firewall_issue() {
4767
- check_admin_referer( 'fs_resolve_firewall_issues' );
4768
-
4769
- if ( ! current_user_can( is_multisite() ? 'manage_options' : 'activate_plugins' ) ) {
4770
- return;
4771
- }
4772
-
4773
- $this->_admin_notices->remove_sticky( 'failed_connect_api' );
4774
-
4775
- $pong = $this->ping();
4776
-
4777
- $is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
4778
-
4779
- if ( $is_connected ) {
4780
- FS_GDPR_Manager::instance()->store_is_required( $pong->is_gdpr_required );
4781
-
4782
- $this->store_connectivity_info( $pong, $is_connected );
4783
-
4784
- echo $this->get_after_plugin_activation_redirect_url();
4785
- exit;
4786
- }
4787
-
4788
- $current_user = self::_get_current_wp_user();
4789
- $admin_email = $current_user->user_email;
4790
-
4791
- $error_type = fs_request_get( 'error_type', 'general' );
4792
-
4793
- switch ( $error_type ) {
4794
- case 'squid':
4795
- $title = 'Squid ACL Blocking Issue';
4796
- break;
4797
- case 'cloudflare':
4798
- $title = 'CloudFlare Blocking Issue';
4799
- break;
4800
- default:
4801
- $title = 'API Connectivity Issue';
4802
- break;
4803
- }
4804
-
4805
- $custom_email_sections = array();
4806
-
4807
- // Add 'API Error' custom email section.
4808
- $custom_email_sections['api_error'] = array(
4809
- 'title' => 'API Error',
4810
- 'rows' => array(
4811
- 'ping' => array(
4812
- 'API Error',
4813
- is_string( $pong ) ? htmlentities( $pong ) : json_encode( $pong )
4814
- ),
4815
- )
4816
- );
4817
-
4818
- // Send email with technical details to resolve API connectivity issues.
4819
- $this->send_email(
4820
- 'api@freemius.com', // recipient
4821
- $title . ' [' . $this->get_plugin_name() . ']', // subject
4822
- $custom_email_sections,
4823
- array( "Reply-To: $admin_email <$admin_email>" ) // headers
4824
- );
4825
-
4826
- $this->_admin_notices->add_sticky(
4827
- sprintf(
4828
- $this->get_text_inline( 'Thank for giving us the chance to fix it! A message was just sent to our technical staff. We will get back to you as soon as we have an update to %s. Appreciate your patience.', 'fix-request-sent-message' ),
4829
- '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
4830
- ),
4831
- 'server_details_sent'
4832
- );
4833
-
4834
- // Action was taken, tell that API connectivity troubleshooting should be off now.
4835
-
4836
- echo "1";
4837
- exit;
4838
- }
4839
-
4840
- /**
4841
- * Handle connectivity test retry approved by the user.
4842
- *
4843
- * @author Vova Feldman (@svovaf)
4844
- * @since 1.1.7.4
4845
- */
4846
- function _retry_connectivity_test() {
4847
- check_admin_referer( 'fs_retry_connectivity_test' );
4848
-
4849
- if ( ! current_user_can( is_multisite() ? 'manage_options' : 'activate_plugins' ) ) {
4850
- return;
4851
- }
4852
-
4853
- $this->_admin_notices->remove_sticky( 'failed_connect_api_first' );
4854
-
4855
- $pong = $this->ping();
4856
-
4857
- $is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
4858
-
4859
- if ( $is_connected ) {
4860
- FS_GDPR_Manager::instance()->store_is_required( $pong->is_gdpr_required );
4861
-
4862
- $this->store_connectivity_info( $pong, $is_connected );
4863
-
4864
- echo $this->get_after_plugin_activation_redirect_url();
4865
- } else {
4866
- // Add connectivity issue message after 2nd failed attempt.
4867
- $this->_add_connectivity_issue_message( $pong, false );
4868
-
4869
- echo "1";
4870
- }
4871
-
4872
- exit;
4873
- }
4874
-
4875
- static function _add_firewall_issues_javascript() {
4876
- $params = array();
4877
- fs_require_once_template( 'firewall-issues-js.php', $params );
4878
- }
4879
-
4880
- #endregion
4881
-
4882
- #----------------------------------------------------------------------------------
4883
- #region Email
4884
- #----------------------------------------------------------------------------------
4885
-
4886
- /**
4887
- * Generates and sends an HTML email with customizable sections.
4888
- *
4889
- * @author Leo Fajardo (@leorw)
4890
- * @since 1.1.2
4891
- *
4892
- * @param string $to_address
4893
- * @param string $subject
4894
- * @param array $sections
4895
- * @param array $headers
4896
- *
4897
- * @return bool Whether the email contents were sent successfully.
4898
- */
4899
- private function send_email(
4900
- $to_address,
4901
- $subject,
4902
- $sections = array(),
4903
- $headers = array()
4904
- ) {
4905
- $default_sections = $this->get_email_sections();
4906
-
4907
- // Insert new sections or replace the default email sections.
4908
- if ( is_array( $sections ) && ! empty( $sections ) ) {
4909
- foreach ( $sections as $section_id => $custom_section ) {
4910
- if ( ! isset( $default_sections[ $section_id ] ) ) {
4911
- // If the section does not exist, add it.
4912
- $default_sections[ $section_id ] = $custom_section;
4913
- } else {
4914
- // If the section already exists, override it.
4915
- $current_section = $default_sections[ $section_id ];
4916
-
4917
- // Replace the current section's title if a custom section title exists.
4918
- if ( isset( $custom_section['title'] ) ) {
4919
- $current_section['title'] = $custom_section['title'];
4920
- }
4921
-
4922
- // Insert new rows under the current section or replace the default rows.
4923
- if ( isset( $custom_section['rows'] ) && is_array( $custom_section['rows'] ) && ! empty( $custom_section['rows'] ) ) {
4924
- foreach ( $custom_section['rows'] as $row_id => $row ) {
4925
- $current_section['rows'][ $row_id ] = $row;
4926
- }
4927
- }
4928
-
4929
- $default_sections[ $section_id ] = $current_section;
4930
- }
4931
- }
4932
- }
4933
-
4934
- $vars = array( 'sections' => $default_sections );
4935
- $message = fs_get_template( 'email.php', $vars );
4936
-
4937
- // Set the type of email to HTML.
4938
- $headers[] = 'Content-type: text/html; charset=UTF-8';
4939
-
4940
- $header_string = implode( "\r\n", $headers );
4941
-
4942
- return wp_mail(
4943
- $to_address,
4944
- $subject,
4945
- $message,
4946
- $header_string
4947
- );
4948
- }
4949
-
4950
- /**
4951
- * Generates the data for the sections of the email content.
4952
- *
4953
- * @author Leo Fajardo (@leorw)
4954
- * @since 1.1.2
4955
- *
4956
- * @return array
4957
- */
4958
- private function get_email_sections() {
4959
- // Retrieve the current user's information so that we can get the user's email, first name, and last name below.
4960
- $current_user = self::_get_current_wp_user();
4961
-
4962
- // Retrieve the cURL version information so that we can get the version number below.
4963
- $curl_version_information = curl_version();
4964
-
4965
- $active_plugin = self::get_active_plugins();
4966
-
4967
- // Generate the list of active plugins separated by new line.
4968
- $active_plugin_string = '';
4969
- foreach ( $active_plugin as $plugin ) {
4970
- $active_plugin_string .= sprintf(
4971
- '<a href="%s">%s</a> [v%s]<br>',
4972
- $plugin['PluginURI'],
4973
- $plugin['Name'],
4974
- $plugin['Version']
4975
- );
4976
- }
4977
-
4978
- $server_ip = WP_FS__REMOTE_ADDR;
4979
-
4980
- // Add PHP info for deeper investigation.
4981
- ob_start();
4982
- phpinfo();
4983
- $php_info = ob_get_clean();
4984
-
4985
- $api_domain = substr( FS_API__ADDRESS, strpos( FS_API__ADDRESS, ':' ) + 3 );
4986
-
4987
- // Generate the default email sections.
4988
- $sections = array(
4989
- 'sdk' => array(
4990
- 'title' => 'SDK',
4991
- 'rows' => array(
4992
- 'fs_version' => array( 'FS Version', $this->version ),
4993
- 'curl_version' => array( 'cURL Version', $curl_version_information['version'] )
4994
- )
4995
- ),
4996
- 'plugin' => array(
4997
- 'title' => ucfirst( $this->get_module_type() ),
4998
- 'rows' => array(
4999
- 'name' => array( 'Name', $this->get_plugin_name() ),
5000
- 'version' => array( 'Version', $this->get_plugin_version() )
5001
- )
5002
- ),
5003
- 'api' => array(
5004
- 'title' => 'API Subdomain',
5005
- 'rows' => array(
5006
- 'dns' => array(
5007
- 'DNS_CNAME',
5008
- function_exists( 'dns_get_record' ) ?
5009
- var_export( dns_get_record( $api_domain, DNS_CNAME ), true ) :
5010
- 'dns_get_record() disabled/blocked'
5011
- ),
5012
- 'ip' => array(
5013
- 'IP',
5014
- function_exists( 'gethostbyname' ) ?
5015
- gethostbyname( $api_domain ) :
5016
- 'gethostbyname() disabled/blocked'
5017
- ),
5018
- ),
5019
- ),
5020
- 'site' => array(
5021
- 'title' => 'Site',
5022
- 'rows' => array(
5023
- 'unique_id' => array( 'Unique ID', $this->get_anonymous_id() ),
5024
- 'address' => array( 'Address', site_url() ),
5025
- 'host' => array(
5026
- 'HTTP_HOST',
5027
- ( ! empty( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : '' )
5028
- ),
5029
- 'hosting' => array(
5030
- 'Hosting Company' => fs_request_has( 'hosting_company' ) ?
5031
- fs_request_get( 'hosting_company' ) :
5032
- 'Unknown',
5033
- ),
5034
- 'server_addr' => array(
5035
- 'SERVER_ADDR',
5036
- '<a href="http://www.projecthoneypot.org/ip_' . $server_ip . '">' . $server_ip . '</a>'
5037
- )
5038
- )
5039
- ),
5040
- 'user' => array(
5041
- 'title' => 'User',
5042
- 'rows' => array(
5043
- 'email' => array( 'Email', $current_user->user_email ),
5044
- 'first' => array( 'First', $current_user->user_firstname ),
5045
- 'last' => array( 'Last', $current_user->user_lastname )
5046
- )
5047
- ),
5048
- 'plugins' => array(
5049
- 'title' => 'Plugins',
5050
- 'rows' => array(
5051
- 'active_plugins' => array( 'Active Plugins', $active_plugin_string )
5052
- )
5053
- ),
5054
- 'php_info' => array(
5055
- 'title' => 'PHP Info',
5056
- 'rows' => array(
5057
- 'info' => array( $php_info )
5058
- ),
5059
- )
5060
- );
5061
-
5062
- // Allow the sections to be modified by other code.
5063
- $sections = $this->apply_filters( 'email_template_sections', $sections );
5064
-
5065
- return $sections;
5066
- }
5067
-
5068
- #endregion
5069
-
5070
- #----------------------------------------------------------------------------------
5071
- #region Initialization
5072
- #----------------------------------------------------------------------------------
5073
-
5074
- /**
5075
- * Init plugin's Freemius instance.
5076
- *
5077
- * @author Vova Feldman (@svovaf)
5078
- * @since 1.0.1
5079
- *
5080
- * @param number $id
5081
- * @param string $public_key
5082
- * @param bool $is_live
5083
- * @param bool $is_premium
5084
- */
5085
- function init( $id, $public_key, $is_live = true, $is_premium = true ) {
5086
- $this->_logger->entrance();
5087
-
5088
- $this->dynamic_init( array(
5089
- 'id' => $id,
5090
- 'public_key' => $public_key,
5091
- 'is_live' => $is_live,
5092
- 'is_premium' => $is_premium,
5093
- ) );
5094
- }
5095
-
5096
- /**
5097
- * Dynamic initiator, originally created to support initiation
5098
- * with parent_id for add-ons.
5099
- *
5100
- * @author Vova Feldman (@svovaf)
5101
- * @since 1.0.6
5102
- *
5103
- * @param array $plugin_info
5104
- *
5105
- * @throws Freemius_Exception
5106
- */
5107
- function dynamic_init( array $plugin_info ) {
5108
- $this->_logger->entrance();
5109
-
5110
- $this->parse_settings( $plugin_info );
5111
-
5112
- $this->register_after_settings_parse_hooks();
5113
-
5114
- if ( $this->should_stop_execution() ) {
5115
- return;
5116
- }
5117
-
5118
- if ( ! $this->is_registered() ) {
5119
- if ( $this->is_anonymous() ) {
5120
- // If user skipped, no need to test connectivity.
5121
- $this->_has_api_connection = true;
5122
- $this->_is_on = true;
5123
- } else {
5124
- if ( ! $this->has_api_connectivity() ) {
5125
- if ( $this->_admin_notices->has_sticky( 'failed_connect_api_first' ) ||
5126
- $this->_admin_notices->has_sticky( 'failed_connect_api' )
5127
- ) {
5128
- if ( ! $this->_enable_anonymous || $this->is_premium() ) {
5129
- // If anonymous mode is disabled, add firewall admin-notice message.
5130
- add_action( 'admin_footer', array( 'Freemius', '_add_firewall_issues_javascript' ) );
5131
-
5132
- $ajax_action_suffix = $this->_slug . ( $this->is_theme() ? ':theme' : '' );
5133
- add_action( "wp_ajax_fs_resolve_firewall_issues_{$ajax_action_suffix}", array(
5134
- &$this,
5135
- '_email_about_firewall_issue'
5136
- ) );
5137
-
5138
- add_action( "wp_ajax_fs_retry_connectivity_test_{$ajax_action_suffix}", array(
5139
- &$this,
5140
- '_retry_connectivity_test'
5141
- ) );
5142
-
5143
- /**
5144
- * Currently the admin notice manager relies on the module's type and slug. The new AJAX actions manager uses module IDs, hence, consider to replace the if block above with the commented code below after adjusting the admin notices manager to work with module IDs.
5145
- *
5146
- * @author Vova Feldman (@svovaf)
5147
- * @since 2.0.0
5148
- */
5149
- /*$this->add_ajax_action( 'resolve_firewall_issues', array(
5150
- &$this,
5151
- '_email_about_firewall_issue'
5152
- ) );
5153
-
5154
- $this->add_ajax_action( 'retry_connectivity_test', array(
5155
- &$this,
5156
- '_retry_connectivity_test'
5157
- ) );*/
5158
- }
5159
- }
5160
-
5161
- return;
5162
- } else {
5163
- $this->_admin_notices->remove_sticky( array(
5164
- 'failed_connect_api_first',
5165
- 'failed_connect_api',
5166
- ) );
5167
-
5168
- if ( $this->_anonymous_mode ) {
5169
- // Simulate anonymous mode.
5170
- $this->_is_anonymous = true;
5171
- }
5172
- }
5173
- }
5174
- }
5175
-
5176
- /**
5177
- * This should be executed even if Freemius is off for the core module,
5178
- * otherwise, the add-ons dialogbox won't work properly. This is esepcially
5179
- * relevant when the developer decided to turn FS off for existing users.
5180
- *
5181
- * @author Vova Feldman (@svovaf)
5182
- */
5183
- if ( $this->is_user_in_admin() &&
5184
- 'plugin-information' === fs_request_get( 'tab', false ) &&
5185
- $this->should_use_freemius_updater_and_dialog() &&
5186
- (
5187
- ( $this->is_addon() && $this->get_slug() == fs_request_get( 'plugin', false ) ) ||
5188
- ( $this->has_addons() && $this->get_id() == fs_request_get( 'parent_plugin_id', false ) )
5189
- )
5190
- ) {
5191
- require_once WP_FS__DIR_INCLUDES . '/fs-plugin-info-dialog.php';
5192
-
5193
- new FS_Plugin_Info_Dialog( $this->is_addon() ? $this->get_parent_instance() : $this );
5194
- }
5195
-
5196
- // Check if Freemius is on for the current plugin.
5197
- // This MUST be executed after all the plugin variables has been loaded.
5198
- if ( ! $this->is_registered() && ! $this->is_on() ) {
5199
- return;
5200
- }
5201
-
5202
- if ( $this->has_api_connectivity() ) {
5203
- if ( self::is_cron() ) {
5204
- $this->hook_callback_to_sync_cron();
5205
- } else if ( $this->is_user_in_admin() ) {
5206
- /**
5207
- * Schedule daily data sync cron if:
5208
- *
5209
- * 1. User opted-in (for tracking).
5210
- * 2. If skipped, but later upgraded (opted-in via upgrade).
5211
- *
5212
- * @author Vova Feldman (@svovaf)
5213
- * @since 1.1.7.3
5214
- *
5215
- */
5216
- if ( $this->is_registered() && $this->is_tracking_allowed() ) {
5217
- $this->maybe_schedule_sync_cron();
5218
- }
5219
-
5220
- /**
5221
- * Check if requested for manual blocking background sync.
5222
- */
5223
- if ( fs_request_has( 'background_sync' ) ) {
5224
- $this->run_manual_sync();
5225
- }
5226
- }
5227
- }
5228
-
5229
- if ( $this->is_registered() ) {
5230
- FS_Clone_Manager::instance()->maybe_resolve_new_subsite_install_automatically( $this );
5231
-
5232
- $this->hook_callback_to_install_sync();
5233
- }
5234
-
5235
- if ( $this->is_addon() ) {
5236
- if ( $this->is_parent_plugin_installed() ) {
5237
- // Link to parent FS.
5238
- $this->_parent = self::get_instance_by_id( $this->_plugin->parent_plugin_id );
5239
-
5240
- // Get parent plugin reference.
5241
- $this->_parent_plugin = $this->_parent->get_plugin();
5242
- }
5243
- }
5244
-
5245
- if ( $this->is_user_in_admin() ) {
5246
- if ( $this->is_registered() && fs_request_has( 'purchase_completed' ) ) {
5247
- $this->_admin_notices->add_sticky(
5248
- sprintf(
5249
- /* translators: %s: License type (e.g. you have a professional license) */
5250
- $this->get_text_inline( 'You have purchased a %s license.', 'you-have-x-license' ),
5251
- fs_request_get( 'purchased_plan' )
5252
- ) .
5253
- sprintf(
5254
- $this->get_text_inline(" The %s's %sdownload link%s, license key, and installation instructions have been sent to %s. If you can't find the email after 5 min, please check your spam box.", 'post-purchase-email-sent-message' ),
5255
- $this->get_module_label( true ),
5256
- ( FS_Plugin::is_valid_id( $this->get_bundle_id() ) ? "products' " : '' ),
5257
- ( FS_Plugin::is_valid_id( $this->get_bundle_id() ) ? 's' : '' ),
5258
- sprintf(
5259
- '<strong>%s</strong>',
5260
- fs_request_get( 'purchase_email' )
5261
- )
5262
- ),
5263
- 'plan_purchased',
5264
- $this->get_text_x_inline( 'Yee-haw', 'interjection expressing joy or exuberance', 'yee-haw' ) . '!'
5265
- );
5266
- }
5267
-
5268
- if ( $this->is_addon() ) {
5269
- if ( ! $this->is_parent_plugin_installed() ) {
5270
- $parent_name = $this->get_option( $plugin_info, 'parent_name', null );
5271
-
5272
- if ( isset( $plugin_info['parent'] ) ) {
5273
- $parent_name = $this->get_option( $plugin_info['parent'], 'name', null );
5274
- }
5275
-
5276
- $this->_admin_notices->add(
5277
- ( ! empty( $parent_name ) ?
5278
- sprintf( $this->get_text_x_inline( '%s cannot run without %s.', 'addonX cannot run without pluginY', 'addon-x-cannot-run-without-y' ), $this->get_plugin_name(), $parent_name ) :
5279
- sprintf( $this->get_text_x_inline( '%s cannot run without the plugin.', 'addonX cannot run...', 'addon-x-cannot-run-without-parent' ), $this->get_plugin_name() )
5280
- ),
5281
- $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
5282
- 'error'
5283
- );
5284
-
5285
- return;
5286
- } else {
5287
- $is_network_admin = fs_is_network_admin();
5288
-
5289
- if ( ! $this->_parent->is_registered() && $this->is_registered() ) {
5290
- // If add-on activated and parent not, automatically install parent for the user.
5291
- $this->activate_parent_account( $this->_parent );
5292
- } else if (
5293
- $this->_parent->is_registered() &&
5294
- ! $this->is_registered() &&
5295
- /**
5296
- * If not registered for add-on and the following conditions for the add-on are met, activate add-on account.
5297
- * * Network active and in network admin - network activate add-on account.
5298
- * * Network active and not in network admin - activate add-on account for the current blog.
5299
- * * Not network active and not in network admin - activate add-on account for the current blog.
5300
- *
5301
- * If not registered for add-on, not network active, and in network admin, do not handle the add-on activation.
5302
- *
5303
- * @author Leo Fajardo (@leorw)
5304
- * @since 2.3.0
5305
- */
5306
- ( $this->is_network_active() || ! $is_network_admin )
5307
- ) {
5308
- $premium_license = null;
5309
-
5310
- if (
5311
- ! $this->has_free_plan() &&
5312
- $this->is_bundle_license_auto_activation_enabled() &&
5313
- $this->_parent->is_activated_with_bundle_license()
5314
- ) {
5315
- /**
5316
- * If the add-on has no free plan, try to activate the account only when there's a bundle license.
5317
- *
5318
- * @author Leo Fajardo (@leorw)
5319
- * @since 2.4.0
5320
- */
5321
- $bundle_license = $this->get_active_parent_license( $this->_parent->_get_license()->secret_key, false );
5322
-
5323
- if (
5324
- is_object( $bundle_license ) &&
5325
- ! empty( $bundle_license->products ) &&
5326
- in_array( $this->get_id(), $bundle_license->products )
5327
- ) {
5328
- $premium_license = $bundle_license;
5329
- }
5330
- }
5331
-
5332
- if ( $this->has_free_plan() || is_object( $premium_license) ) {
5333
- // If parent plugin activated, automatically install add-on for the user.
5334
- $this->_activate_addon_account(
5335
- $this->_parent,
5336
- ( $this->is_network_active() && $is_network_admin ) ?
5337
- true :
5338
- get_current_blog_id(),
5339
- $premium_license
5340
- );
5341
- }
5342
- }
5343
-
5344
- // @todo This should be only executed on activation. It should be migrated to register_activation_hook() together with other activation related logic.
5345
- if ( $this->is_premium() ) {
5346
- // Remove add-on download admin-notice.
5347
- $this->_parent->_admin_notices->remove_sticky( array(
5348
- 'addon_plan_upgraded_' . $this->_slug,
5349
- 'no_addon_license_' . $this->_slug,
5350
- ) );
5351
- }
5352
-
5353
- // $this->deactivate_premium_only_addon_without_license();
5354
- }
5355
- }
5356
-
5357
- add_action( 'admin_init', array( &$this, '_admin_init_action' ) );
5358
-
5359
- // if ( $this->is_registered() ||
5360
- // $this->is_anonymous() ||
5361
- // $this->is_pending_activation()
5362
- // ) {
5363
- // $this->_init_admin();
5364
- // }
5365
- }
5366
-
5367
- /**
5368
- * Should be called outside `$this->is_user_in_admin()` scope
5369
- * because the updater has some logic that needs to be executed
5370
- * during AJAX calls.
5371
- *
5372
- * Currently we need to hook to the `http_request_host_is_external` filter.
5373
- * In the future, there might be additional logic added.
5374
- *
5375
- * @author Vova Feldman
5376
- * @since 1.2.1.6
5377
- */
5378
- if (
5379
- $this->should_use_freemius_updater_and_dialog() &&
5380
- (
5381
- $this->is_premium() ||
5382
- /**
5383
- * If not premium but the premium version is installed, also instantiate the updater so that the
5384
- * plugin information dialog of the premium version will have the information from the server.
5385
- *
5386
- * @author Leo Fajardo (@leorw)
5387
- * @since 2.2.3
5388
- */
5389
- ( file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $this->premium_plugin_basename() ) ) )
5390
- ) &&
5391
- $this->has_release_on_freemius() &&
5392
- ( ! $this->is_unresolved_clone() )
5393
- ) {
5394
- FS_Plugin_Updater::instance( $this );
5395
- }
5396
-
5397
- $this->do_action( 'initiated' );
5398
-
5399
- if ( $this->_storage->prev_is_premium !== $this->_plugin->is_premium ) {
5400
- if ( isset( $this->_storage->prev_is_premium ) ) {
5401
- $this->apply_filters(
5402
- 'after_code_type_change',
5403
- // New code type.
5404
- $this->_plugin->is_premium
5405
- );
5406
- } else {
5407
- // Set for code type for the first time.
5408
- $this->_storage->prev_is_premium = $this->_plugin->is_premium;
5409
- }
5410
- }
5411
-
5412
- if ( ! $this->is_addon() ) {
5413
- if ( $this->is_registered() ) {
5414
- // Fix for upgrade from versions < 1.0.9.
5415
- if ( ! isset( $this->_storage->activation_timestamp ) ) {
5416
- $this->_storage->activation_timestamp = WP_FS__SCRIPT_START_TIME;
5417
- }
5418
-
5419
- $this->do_action( 'after_init_plugin_registered' );
5420
- } else if ( $this->is_anonymous() ) {
5421
- $this->do_action( 'after_init_plugin_anonymous' );
5422
- } else if ( $this->is_pending_activation() ) {
5423
- $this->do_action( 'after_init_plugin_pending_activations' );
5424
- }
5425
- } else {
5426
- if ( $this->is_registered() ) {
5427
- $this->do_action( 'after_init_addon_registered' );
5428
- } else if ( $this->is_anonymous() ) {
5429
- $this->do_action( 'after_init_addon_anonymous' );
5430
- } else if ( $this->is_pending_activation() ) {
5431
- $this->do_action( 'after_init_addon_pending_activations' );
5432
- }
5433
- }
5434
- }
5435
-
5436
- /**
5437
- * @author Leo Fajardo (@leorw)
5438
- * @since 2.2.3
5439
- *
5440
- * @return bool
5441
- */
5442
- private function should_use_freemius_updater_and_dialog() {
5443
- return (
5444
- /**
5445
- * Allow updater and dialog when the `fs_allow_updater_and_dialog` URL query param exists and has `true`
5446
- * value, or when the current page is not the "Add Plugins" page (/plugin-install.php) and the `action`
5447
- * URL query param doesn't exist or its value is not `install-plugin` so that there will be no conflicts
5448
- * with the .org plugins' functionalities (e.g. installation from the "Add Plugins" page and viewing
5449
- * plugin details from .org).
5450
- */
5451
- ( true === fs_request_get_bool( 'fs_allow_updater_and_dialog' ) ) ||
5452
- (
5453
- ! self::is_plugin_install_page() &&
5454
- // Disallow updater and dialog when installing a plugin, otherwise .org "add-on" plugins will be affected.
5455
- ( 'install-plugin' !== fs_request_get( 'action' ) )
5456
- )
5457
- );
5458
- }
5459
-
5460
- /**
5461
- * @author Leo Fajardo (@leorw)
5462
- *
5463
- * @since 1.2.1.5
5464
- */
5465
- function _stop_tracking_callback() {
5466
- $this->_logger->entrance();
5467
-
5468
- $this->check_ajax_referer( 'stop_tracking' );
5469
-
5470
- $result = $this->stop_tracking( fs_is_network_admin() );
5471
-
5472
- if ( true === $result ) {
5473
- self::shoot_ajax_success();
5474
- }
5475
-
5476
- $this->_logger->api_error( $result );
5477
-
5478
- self::shoot_ajax_failure(
5479
- sprintf( $this->get_text_inline( 'Unexpected API error. Please contact the %s\'s author with the following error.', 'unexpected-api-error' ), $this->_module_type ) .
5480
- ( $this->is_api_error( $result ) && isset( $result->error ) ?
5481
- $result->error->message :
5482
- var_export( $result, true ) )
5483
- );
5484
- }
5485
-
5486
- /**
5487
- * @author Leo Fajardo (@leorw)
5488
- * @since 1.2.1.5
5489
- */
5490
- function _allow_tracking_callback() {
5491
- $this->_logger->entrance();
5492
-
5493
- $this->check_ajax_referer( 'allow_tracking' );
5494
-
5495
- $result = $this->allow_tracking( fs_is_network_admin() );
5496
-
5497
- if ( true === $result ) {
5498
- self::shoot_ajax_success();
5499
- }
5500
-
5501
- $this->_logger->api_error( $result );
5502
-
5503
- self::shoot_ajax_failure(
5504
- sprintf( $this->get_text_inline( 'Unexpected API error. Please contact the %s\'s author with the following error.', 'unexpected-api-error' ), $this->_module_type ) .
5505
- ( $this->is_api_error( $result ) && isset( $result->error ) ?
5506
- $result->error->message :
5507
- var_export( $result, true ) )
5508
- );
5509
- }
5510
-
5511
- /**
5512
- * Opt-out from usage tracking.
5513
- *
5514
- * Note: This will not delete the account information but will stop all tracking.
5515
- *
5516
- * Returns:
5517
- * 1. FALSE - If the user never opted-in.
5518
- * 2. TRUE - If successfully opted-out.
5519
- * 3. object - API result on failure.
5520
- *
5521
- * @author Leo Fajardo (@leorw)
5522
- * @since 1.2.1.5
5523
- *
5524
- * @return bool|object
5525
- */
5526
- function stop_site_tracking() {
5527
- $this->_logger->entrance();
5528
-
5529
- if ( ! $this->is_registered() ) {
5530
- // User never opted-in.
5531
- return false;
5532
- }
5533
-
5534
- if ( $this->is_tracking_prohibited() ) {
5535
- // Already disconnected.
5536
- return true;
5537
- }
5538
-
5539
- // Send update to FS.
5540
- $result = $this->api_site_call( '/?fields=is_disconnected', 'put', array(
5541
- 'is_disconnected' => true
5542
- ) );
5543
-
5544
- if ( ! $this->is_api_result_entity( $result ) ||
5545
- ! isset( $result->is_disconnected ) ||
5546
- ! $result->is_disconnected
5547
- ) {
5548
- $this->_logger->api_error( $result );
5549
-
5550
- return $result;
5551
- }
5552
-
5553
- $this->_site->is_disconnected = $result->is_disconnected;
5554
- $this->_store_site();
5555
-
5556
- $this->clear_sync_cron();
5557
-
5558
- // Successfully disconnected.
5559
- return true;
5560
- }
5561
-
5562
- /**
5563
- * Opt-out network from usage tracking.
5564
- *
5565
- * Note: This will not delete the account information but will stop all tracking.
5566
- *
5567
- * Returns:
5568
- * 1. FALSE - If the user never opted-in.
5569
- * 2. TRUE - If successfully opted-out.
5570
- * 3. object - API result on failure.
5571
- *
5572
- * @author Leo Fajardo (@leorw)
5573
- * @since 1.2.1.5
5574
- *
5575
- * @return bool|object
5576
- */
5577
- function stop_network_tracking() {
5578
- $this->_logger->entrance();
5579
-
5580
- if ( ! $this->is_registered() ) {
5581
- // User never opted-in.
5582
- return false;
5583
- }
5584
-
5585
- $install_id_2_blog_id = array();
5586
- $installs_map = $this->get_blog_install_map();
5587
-
5588
- $opt_out_all = true;
5589
-
5590
- $params = array();
5591
- foreach ( $installs_map as $blog_id => $install ) {
5592
- if ( $install->is_tracking_prohibited() ) {
5593
- // Already opted-out.
5594
- continue;
5595
- }
5596
-
5597
- if ( $this->is_site_delegated_connection( $blog_id ) ) {
5598
- // Opt-out only from non-delegated installs.
5599
- $opt_out_all = false;
5600
- continue;
5601
- }
5602
-
5603
- $params[] = array( 'id' => $install->id );
5604
-
5605
- $install_id_2_blog_id[ $install->id ] = $blog_id;
5606
- }
5607
-
5608
- if ( empty( $install_id_2_blog_id ) ) {
5609
- return true;
5610
- }
5611
-
5612
- $params[] = array( 'is_disconnected' => true );
5613
-
5614
- // Send update to FS.
5615
- $result = $this->get_current_or_network_user_api_scope()->call( "/plugins/{$this->_module_id}/installs.json", 'put', $params );
5616
-
5617
- if ( ! $this->is_api_result_object( $result, 'installs' ) ) {
5618
- $this->_logger->api_error( $result );
5619
-
5620
- return $result;
5621
- }
5622
-
5623
- foreach ( $result->installs as $r_install ) {
5624
- $blog_id = $install_id_2_blog_id[ $r_install->id ];
5625
- $install = $installs_map[ $blog_id ];
5626
- $install->is_disconnected = $r_install->is_disconnected;
5627
- $this->_store_site( true, $blog_id, $install );
5628
- }
5629
-
5630
- $this->clear_sync_cron( $opt_out_all );
5631
-
5632
- // Successfully disconnected.
5633
- return true;
5634
- }
5635
-
5636
- /**
5637
- * Opt-out from usage tracking.
5638
- *
5639
- * Note: This will not delete the account information but will stop all tracking.
5640
- *
5641
- * Returns:
5642
- * 1. FALSE - If the user never opted-in.
5643
- * 2. TRUE - If successfully opted-out.
5644
- * 3. object - API result on failure.
5645
- *
5646
- * @author Leo Fajardo (@leorw)
5647
- * @since 1.2.1.5
5648
- *
5649
- * @param bool $is_network_action
5650
- *
5651
- * @return bool|object
5652
- */
5653
- function stop_tracking( $is_network_action = false ) {
5654
- $this->_logger->entrance();
5655
-
5656
- return $is_network_action ?
5657
- $this->stop_network_tracking() :
5658
- $this->stop_site_tracking();
5659
- }
5660
-
5661
- /**
5662
- * Opt-in back into usage tracking.
5663
- *
5664
- * Note: This will only work if the user opted-in previously.
5665
- *
5666
- * Returns:
5667
- * 1. FALSE - If the user never opted-in.
5668
- * 2. TRUE - If successfully opted-in back to usage tracking.
5669
- * 3. object - API result on failure.
5670
- *
5671
- * @author Leo Fajardo (@leorw)
5672
- * @since 1.2.1.5
5673
- *
5674
- * @return bool|object
5675
- */
5676
- function allow_site_tracking() {
5677
- $this->_logger->entrance();
5678
-
5679
- if ( ! $this->is_registered() ) {
5680
- // User never opted-in.
5681
- return false;
5682
- }
5683
-
5684
- if ( $this->is_tracking_allowed() ) {
5685
- // Tracking already allowed.
5686
- return true;
5687
- }
5688
-
5689
- $result = $this->api_site_call( '/?is_disconnected', 'put', array(
5690
- 'is_disconnected' => false
5691
- ) );
5692
-
5693
- if ( ! $this->is_api_result_entity( $result ) ||
5694
- ! isset( $result->is_disconnected ) ||
5695
- $result->is_disconnected
5696
- ) {
5697
- $this->_logger->api_error( $result );
5698
-
5699
- return $result;
5700
- }
5701
-
5702
- $this->_site->is_disconnected = $result->is_disconnected;
5703
- $this->_store_site();
5704
-
5705
- $this->schedule_sync_cron();
5706
-
5707
- // Successfully reconnected.
5708
- return true;
5709
- }
5710
-
5711
- /**
5712
- * Opt-in network back into usage tracking.
5713
- *
5714
- * Note: This will only work if the user opted-in previously.
5715
- *
5716
- * Returns:
5717
- * 1. FALSE - If the user never opted-in.
5718
- * 2. TRUE - If successfully opted-in back to usage tracking.
5719
- * 3. object - API result on failure.
5720
- *
5721
- * @author Leo Fajardo (@leorw)
5722
- * @since 1.2.1.5
5723
- *
5724
- * @return bool|object
5725
- */
5726
- function allow_network_tracking() {
5727
- $this->_logger->entrance();
5728
-
5729
- if ( ! $this->is_registered() ) {
5730
- // User never opted-in.
5731
- return false;
5732
- }
5733
-
5734
- $install_id_2_blog_id = array();
5735
- $installs_map = $this->get_blog_install_map();
5736
-
5737
- $params = array();
5738
- foreach ( $installs_map as $blog_id => $install ) {
5739
- if ( $install->is_tracking_allowed() ) {
5740
- continue;
5741
- }
5742
-
5743
- $params[] = array( 'id' => $install->id );
5744
-
5745
- $install_id_2_blog_id[ $install->id ] = $blog_id;
5746
- }
5747
-
5748
- if ( empty( $install_id_2_blog_id ) ) {
5749
- return true;
5750
- }
5751
-
5752
- $params[] = array( 'is_disconnected' => false );
5753
-
5754
- // Send update to FS.
5755
- $result = $this->get_current_or_network_user_api_scope()->call( "/plugins/{$this->_module_id}/installs.json", 'put', $params );
5756
-
5757
-
5758
- if ( ! $this->is_api_result_object( $result, 'installs' ) ) {
5759
- $this->_logger->api_error( $result );
5760
-
5761
- return $result;
5762
- }
5763
-
5764
- foreach ( $result->installs as $r_install ) {
5765
- $blog_id = $install_id_2_blog_id[ $r_install->id ];
5766
- $install = $installs_map[ $blog_id ];
5767
- $install->is_disconnected = $r_install->is_disconnected;
5768
- $this->_store_site( true, $blog_id, $install );
5769
- }
5770
-
5771
- $this->schedule_sync_cron();
5772
-
5773
- // Successfully reconnected.
5774
- return true;
5775
- }
5776
-
5777
- /**
5778
- * Opt-in back into usage tracking.
5779
- *
5780
- * Note: This will only work if the user opted-in previously.
5781
- *
5782
- * Returns:
5783
- * 1. FALSE - If the user never opted-in.
5784
- * 2. TRUE - If successfully opted-in back to usage tracking.
5785
- * 3. object - API result on failure.
5786
- *
5787
- * @author Leo Fajardo (@leorw)
5788
- * @since 1.2.1.5
5789
- *
5790
- * @param bool $is_network_action
5791
- *
5792
- * @return bool|object
5793
- */
5794
- function allow_tracking( $is_network_action = false ) {
5795
- $this->_logger->entrance();
5796
-
5797
- return $is_network_action ?
5798
- $this->allow_network_tracking() :
5799
- $this->allow_site_tracking();
5800
- }
5801
-
5802
- /**
5803
- * If user opted-in and later disabled usage-tracking,
5804
- * re-allow tracking for licensing and updates.
5805
- *
5806
- * @author Leo Fajardo (@leorw)
5807
- * @since 1.2.1.5
5808
- *
5809
- * @param bool $is_context_single_site
5810
- */
5811
- private function reconnect_locally( $is_context_single_site = false ) {
5812
- $this->_logger->entrance();
5813
-
5814
- if ( ! $this->is_registered() ) {
5815
- return;
5816
- }
5817
-
5818
- if ( ! fs_is_network_admin() || $is_context_single_site ) {
5819
- if ( $this->is_tracking_prohibited() ) {
5820
- $this->_site->is_disconnected = false;
5821
- $this->_store_site();
5822
- }
5823
- } else {
5824
- $installs_map = $this->get_blog_install_map();
5825
- foreach ( $installs_map as $blog_id => $install ) {
5826
- /**
5827
- * @var FS_Site $install
5828
- */
5829
- if ( $install->is_tracking_prohibited() ) {
5830
- $install->is_disconnected = false;
5831
- $this->_store_site( true, $blog_id, $install );
5832
- }
5833
- }
5834
- }
5835
- }
5836
-
5837
- /**
5838
- * @author Vova Feldman (@svovaf)
5839
- * @since 2.3.2
5840
- *
5841
- * @return bool
5842
- */
5843
- function is_extensions_tracking_allowed() {
5844
- return ( true === $this->apply_filters(
5845
- 'is_extensions_tracking_allowed',
5846
- $this->_storage->get( 'is_extensions_tracking_allowed', null )
5847
- ) );
5848
- }
5849
-
5850
- /**
5851
- * @author Vova Feldman (@svovaf)
5852
- * @since 2.3.2
5853
- */
5854
- function _update_tracking_permission_callback() {
5855
- $this->_logger->entrance();
5856
-
5857
- $this->check_ajax_referer( 'update_tracking_permission' );
5858
-
5859
- $is_enabled = fs_request_get_bool( 'is_enabled', null );
5860
-
5861
- if ( ! is_bool( $is_enabled ) ) {
5862
- self::shoot_ajax_failure();
5863
- }
5864
-
5865
- $permission = fs_request_get( 'permission' );
5866
-
5867
- switch ( $permission ) {
5868
- case 'extensions':
5869
- $this->update_extensions_tracking_flag( $is_enabled );
5870
- break;
5871
- default:
5872
- $permission = 'no_match';
5873
- }
5874
-
5875
- if ( 'no_match' === $permission ) {
5876
- self::shoot_ajax_failure();
5877
- }
5878
-
5879
- self::shoot_ajax_success( array(
5880
- 'permissions' => array(
5881
- $permission => $is_enabled,
5882
- )
5883
- ) );
5884
- }
5885
-
5886
- /**
5887
- * @author Leo Fajardo (@leorw)
5888
- * @since 2.3.2
5889
- *
5890
- * @param bool|null $is_enabled
5891
- */
5892
- function update_extensions_tracking_flag( $is_enabled ) {
5893
- if ( is_bool( $is_enabled ) ) {
5894
- $this->_storage->store( 'is_extensions_tracking_allowed', $is_enabled );
5895
- }
5896
- }
5897
-
5898
- /**
5899
- * Parse plugin's settings (as defined by the plugin dev).
5900
- *
5901
- * @author Vova Feldman (@svovaf)
5902
- * @since 1.1.7.3
5903
- *
5904
- * @param array $plugin_info
5905
- *
5906
- * @throws \Freemius_Exception
5907
- */
5908
- private function parse_settings( &$plugin_info ) {
5909
- $this->_logger->entrance();
5910
-
5911
- $id = $this->get_numeric_option( $plugin_info, 'id', false );
5912
- $public_key = $this->get_option( $plugin_info, 'public_key', false );
5913
- $secret_key = $this->get_option( $plugin_info, 'secret_key', null );
5914
- $parent_id = $this->get_numeric_option( $plugin_info, 'parent_id', null );
5915
- $parent_name = $this->get_option( $plugin_info, 'parent_name', null );
5916
-
5917
- /**
5918
- * @author Vova Feldman (@svovaf)
5919
- * @since 1.1.9 Try to pull secret key from external config.
5920
- */
5921
- if ( is_null( $secret_key ) && defined( "WP_FS__{$this->_slug}_SECRET_KEY" ) ) {
5922
- $secret_key = constant( "WP_FS__{$this->_slug}_SECRET_KEY" );
5923
- }
5924
-
5925
- if ( isset( $plugin_info['parent'] ) ) {
5926
- $parent_id = $this->get_numeric_option( $plugin_info['parent'], 'id', null );
5927
- // $parent_slug = $this->get_option( $plugin_info['parent'], 'slug', null );
5928
- // $parent_public_key = $this->get_option( $plugin_info['parent'], 'public_key', null );
5929
- // $parent_name = $this->get_option( $plugin_info['parent'], 'name', null );
5930
- }
5931
-
5932
- if ( false === $id ) {
5933
- throw new Freemius_Exception( array(
5934
- 'error' => array(
5935
- 'type' => 'ParameterNotSet',
5936
- 'message' => 'Plugin id parameter is not set.',
5937
- 'code' => 'plugin_id_not_set',
5938
- 'http' => 500,
5939
- )
5940
- ) );
5941
- }
5942
- if ( false === $public_key ) {
5943
- throw new Freemius_Exception( array(
5944
- 'error' => array(
5945
- 'type' => 'ParameterNotSet',
5946
- 'message' => 'Plugin public_key parameter is not set.',
5947
- 'code' => 'plugin_public_key_not_set',
5948
- 'http' => 500,
5949
- )
5950
- ) );
5951
- }
5952
-
5953
- $plugin = ( $this->_plugin instanceof FS_Plugin ) ?
5954
- $this->_plugin :
5955
- new FS_Plugin();
5956
-
5957
- $premium_suffix = $this->get_option( $plugin_info, 'premium_suffix', '(Premium)' );
5958
-
5959
- $plugin->update( array(
5960
- 'id' => $id,
5961
- 'type' => $this->get_option( $plugin_info, 'type', $this->_module_type ),
5962
- 'public_key' => $public_key,
5963
- 'slug' => $this->_slug,
5964
- 'premium_slug' => $this->get_option( $plugin_info, 'premium_slug', "{$this->_slug}-premium" ),
5965
- 'parent_plugin_id' => $parent_id,
5966
- 'version' => $this->get_plugin_version(),
5967
- 'title' => $this->get_plugin_name( $premium_suffix ),
5968
- 'file' => $this->_plugin_basename,
5969
- 'is_premium' => $this->get_bool_option( $plugin_info, 'is_premium', true ),
5970
- 'premium_suffix' => $premium_suffix,
5971
- 'is_live' => $this->get_bool_option( $plugin_info, 'is_live', true ),
5972
- 'affiliate_moderation' => $this->get_option( $plugin_info, 'has_affiliation' ),
5973
- 'bundle_id' => $this->get_option( $plugin_info, 'bundle_id', null ),
5974
- 'bundle_public_key' => $this->get_option( $plugin_info, 'bundle_public_key', null ),
5975
- ) );
5976
-
5977
- if ( $plugin->is_updated() ) {
5978
- // Update plugin details.
5979
- $this->_plugin = FS_Plugin_Manager::instance( $this->_module_id )->store( $plugin );
5980
- }
5981
- // Set the secret key after storing the plugin, we don't want to store the key in the storage.
5982
- $this->_plugin->secret_key = $secret_key;
5983
-
5984
- /**
5985
- * If the product is network integrated and activated and the current view is in the network level Admin dashboard, if the product's network-level menu located differently from the sub-site level, then use the network menu details (when set).
5986
- *
5987
- * @author Vova Feldman
5988
- * @since 2.4.5
5989
- */
5990
- if ( $this->is_network_active() && fs_is_network_admin() ) {
5991
- if ( isset( $plugin_info['menu_network'] ) &&
5992
- is_array( $plugin_info['menu_network'] ) &&
5993
- ! empty( $plugin_info['menu_network'] )
5994
- ) {
5995
- $plugin_info['menu'] = $plugin_info['menu_network'];
5996
- }
5997
- }
5998
-
5999
- if ( ! isset( $plugin_info['menu'] ) ) {
6000
- $plugin_info['menu'] = array();
6001
-
6002
- if ( ! empty( $this->_storage->sdk_last_version ) &&
6003
- version_compare( $this->_storage->sdk_last_version, '1.1.2', '<=' )
6004
- ) {
6005
- // Backward compatibility to 1.1.2
6006
- $plugin_info['menu']['slug'] = isset( $plugin_info['menu_slug'] ) ?
6007
- $plugin_info['menu_slug'] :
6008
- $this->_slug;
6009
- }
6010
- }
6011
-
6012
- $this->_menu = FS_Admin_Menu_Manager::instance(
6013
- $this->_module_id,
6014
- $this->_module_type,
6015
- $this->get_unique_affix()
6016
- );
6017
-
6018
- $this->_menu->init( $plugin_info['menu'], $this->is_addon() );
6019
-
6020
- $this->_has_addons = $this->get_bool_option( $plugin_info, 'has_addons', false );
6021
- $this->_has_paid_plans = $this->get_bool_option( $plugin_info, 'has_paid_plans', true );
6022
- $this->_has_premium_version = $this->get_bool_option( $plugin_info, 'has_premium_version', $this->_has_paid_plans );
6023
- $this->_ignore_pending_mode = $this->get_bool_option( $plugin_info, 'ignore_pending_mode', false );
6024
- $this->_is_org_compliant = $this->get_bool_option( $plugin_info, 'is_org_compliant', true );
6025
- $this->_is_premium_only = $this->get_bool_option( $plugin_info, 'is_premium_only', false );
6026
- if ( $this->_is_premium_only ) {
6027
- // If premium only plugin, disable anonymous mode.
6028
- $this->_enable_anonymous = false;
6029
- $this->_anonymous_mode = false;
6030
- } else {
6031
- $this->_enable_anonymous = $this->get_bool_option( $plugin_info, 'enable_anonymous', true );
6032
- $this->_anonymous_mode = $this->get_bool_option( $plugin_info, 'anonymous_mode', false );
6033
- }
6034
- $this->_permissions = $this->get_option( $plugin_info, 'permissions', array() );
6035
- $this->_is_bundle_license_auto_activation_enabled = $this->get_option( $plugin_info, 'bundle_license_auto_activation', false );
6036
-
6037
- if ( ! empty( $plugin_info['trial'] ) ) {
6038
- $this->_trial_days = $this->get_numeric_option(
6039
- $plugin_info['trial'],
6040
- 'days',
6041
- // Default to 0 - trial without days specification.
6042
- 0
6043
- );
6044
-
6045
- $this->_is_trial_require_payment = $this->get_bool_option( $plugin_info['trial'], 'is_require_payment', false );
6046
- }
6047
-
6048
- $this->_navigation = $this->get_option(
6049
- $plugin_info,
6050
- 'navigation',
6051
- $this->is_free_wp_org_theme() ?
6052
- self::NAVIGATION_TABS :
6053
- self::NAVIGATION_MENU
6054
- );
6055
- }
6056
-
6057
- /**
6058
- * @param string[] $options
6059
- * @param string $key
6060
- * @param mixed $default
6061
- *
6062
- * @return bool
6063
- */
6064
- private function get_option( &$options, $key, $default = false ) {
6065
- return ! empty( $options[ $key ] ) ? $options[ $key ] : $default;
6066
- }
6067
-
6068
- private function get_bool_option( &$options, $key, $default = false ) {
6069
- return isset( $options[ $key ] ) && is_bool( $options[ $key ] ) ? $options[ $key ] : $default;
6070
- }
6071
-
6072
- private function get_numeric_option( &$options, $key, $default = false ) {
6073
- return isset( $options[ $key ] ) && is_numeric( $options[ $key ] ) ? $options[ $key ] : $default;
6074
- }
6075
-
6076
- /**
6077
- * Gate keeper.
6078
- *
6079
- * @author Vova Feldman (@svovaf)
6080
- * @since 1.1.7.3
6081
- *
6082
- * @return bool
6083
- */
6084
- private function should_stop_execution() {
6085
- if ( empty( $this->_storage->was_plugin_loaded ) ) {
6086
- /**
6087
- * Don't execute Freemius until plugin was fully loaded at least once,
6088
- * to give the opportunity for the activation hook to run before pinging
6089
- * the API for connectivity test. This logic is relevant for the
6090
- * identification of new plugin install vs. plugin update.
6091
- *
6092
- * @author Vova Feldman (@svovaf)
6093
- * @since 1.1.9
6094
- */
6095
- return true;
6096
- }
6097
-
6098
- if ( $this->is_activation_mode() ) {
6099
- if ( ! is_admin() ) {
6100
- /**
6101
- * If in activation mode, don't execute Freemius outside of the
6102
- * admin dashboard.
6103
- *
6104
- * @author Vova Feldman (@svovaf)
6105
- * @since 1.1.7.3
6106
- */
6107
- return true;
6108
- }
6109
-
6110
- if ( ! WP_FS__IS_HTTP_REQUEST ) {
6111
- /**
6112
- * If in activation and executed without HTTP context (e.g. CLI, Cronjob),
6113
- * then don't start Freemius.
6114
- *
6115
- * @author Vova Feldman (@svovaf)
6116
- * @since 1.1.6.3
6117
- *
6118
- * @link https://wordpress.org/support/topic/errors-in-the-freemius-class-when-running-in-wordpress-in-cli
6119
- */
6120
- return true;
6121
- }
6122
-
6123
- if ( self::is_cron() ) {
6124
- /**
6125
- * If in activation mode, don't execute Freemius during wp crons
6126
- * (wp crons have HTTP context - called as HTTP request).
6127
- *
6128
- * @author Vova Feldman (@svovaf)
6129
- * @since 1.1.7.3
6130
- */
6131
- return true;
6132
- }
6133
-
6134
- if ( self::is_ajax() &&
6135
- ! $this->_admin_notices->has_sticky( 'failed_connect_api_first' ) &&
6136
- ! $this->_admin_notices->has_sticky( 'failed_connect_api' )
6137
- ) {
6138
- /**
6139
- * During activation, if running in AJAX mode, unless there's a sticky
6140
- * connectivity issue notice, don't run Freemius.
6141
- *
6142
- * @author Vova Feldman (@svovaf)
6143
- * @since 1.1.7.3
6144
- */
6145
- return true;
6146
- }
6147
- }
6148
-
6149
- return false;
6150
- }
6151
-
6152
- /**
6153
- * Triggered after code type has changed.
6154
- *
6155
- * @author Vova Feldman (@svovaf)
6156
- * @since 1.1.9.1
6157
- */
6158
- function _after_code_type_change() {
6159
- $this->_logger->entrance();
6160
-
6161
- if ( $this->is_theme() ) {
6162
- // Expire the cache of the previous tabs since the theme may
6163
- // have setting updates after code type has changed.
6164
- $this->_cache->expire( 'tabs' );
6165
- $this->_cache->expire( 'tabs_stylesheets' );
6166
- }
6167
-
6168
- if ( $this->is_registered() ) {
6169
- if ( ! $this->is_addon() ) {
6170
- add_action(
6171
- is_admin() ? 'admin_init' : 'init',
6172
- array( &$this, '_plugin_code_type_changed' )
6173
- );
6174
- }
6175
-
6176
- if ( $this->is_premium() ) {
6177
- // Purge cached payments after switching to the premium version.
6178
- // @todo This logic doesn't handle purging the cache for serviceware module upgrade.
6179
- $this->get_api_user_scope()->purge_cache( "/plugins/{$this->_module_id}/payments.json?include_addons=true" );
6180
- }
6181
- }
6182
- }
6183
-
6184
- /**
6185
- * Handles plugin's code type change (free <--> premium).
6186
- *
6187
- * @author Vova Feldman (@svovaf)
6188
- * @since 1.0.9
6189
- */
6190
- function _plugin_code_type_changed() {
6191
- $this->_logger->entrance();
6192
-
6193
- if ( $this->is_premium() ) {
6194
- $this->reconnect_locally();
6195
-
6196
- // Activated premium code.
6197
- $this->do_action( 'after_premium_version_activation' );
6198
-
6199
- // Remove all sticky messages related to download of the premium version.
6200
- $this->_admin_notices->remove_sticky( array(
6201
- 'trial_started',
6202
- 'plan_upgraded',
6203
- 'plan_changed',
6204
- 'license_activated',
6205
- ) );
6206
-
6207
- $notice = '';
6208
- if ( ! $this->is_only_premium() ) {
6209
- $notice = sprintf( $this->get_text_inline( 'Premium %s version was successfully activated.', 'premium-activated-message' ), $this->_module_type );
6210
- }
6211
-
6212
- $license_notice = $this->get_license_network_activation_notice();
6213
- if ( ! empty( $license_notice ) ) {
6214
- $notice .= ' ' . $license_notice;
6215
- }
6216
-
6217
- if ( ! empty( $notice ) ) {
6218
- $this->_admin_notices->add_sticky(
6219
- trim( $notice ),
6220
- 'premium_activated',
6221
- $this->get_text_x_inline( 'W00t',
6222
- 'Used to express elation, enthusiasm, or triumph (especially in electronic communication).', 'woot' ) . '!'
6223
- );
6224
- }
6225
- } else {
6226
- // Remove sticky message related to premium code activation.
6227
- $this->_admin_notices->remove_sticky( 'premium_activated' );
6228
-
6229
- // Activated free code (after had the premium before).
6230
- $this->do_action( 'after_free_version_reactivation' );
6231
-
6232
- if ( $this->is_paying() && ! $this->is_premium() ) {
6233
- $this->_admin_notices->add_sticky(
6234
- sprintf(
6235
- /* translators: %s: License type (e.g. you have a professional license) */
6236
- $this->get_text_inline( 'You have a %s license.', 'you-have-x-license' ),
6237
- $this->get_plan_title()
6238
- ) . $this->get_complete_upgrade_instructions(),
6239
- 'plan_upgraded',
6240
- $this->get_text_x_inline( 'Yee-haw', 'interjection expressing joy or exuberance', 'yee-haw' ) . '!'
6241
- );
6242
- }
6243
- }
6244
-
6245
- // Schedule code type changes event.
6246
- $this->schedule_install_sync();
6247
-
6248
- /**
6249
- * Unregister the uninstall hook for the other version of the plugin (with different code type) to avoid
6250
- * triggering a fatal error when uninstalling that plugin. For example, after deactivating the "free" version
6251
- * of a specific plugin, its uninstall hook should be unregistered after the "premium" version has been
6252
- * activated. If we don't do that, a fatal error will occur when we try to uninstall the "free" version since
6253
- * the main file of the "free" version will be loaded first before calling the hooked callback. Since the
6254
- * free and premium versions are almost identical (same class or have same functions), a fatal error like
6255
- * "Cannot redeclare class MyClass" or "Cannot redeclare my_function()" will occur.
6256
- */
6257
- $this->unregister_uninstall_hook();
6258
-
6259
- $this->clear_module_main_file_cache();
6260
-
6261
- // Update is_premium of latest version.
6262
- $this->_storage->prev_is_premium = $this->_plugin->is_premium;
6263
- }
6264
-
6265
- #endregion
6266
-
6267
- #----------------------------------------------------------------------------------
6268
- #region Add-ons
6269
- #----------------------------------------------------------------------------------
6270
-
6271
- /**
6272
- * Check if add-on installed and activated on site.
6273
- *
6274
- * @author Vova Feldman (@svovaf)
6275
- * @since 1.0.6
6276
- *
6277
- * @param string|number $id_or_slug
6278
- * @param bool|null $is_premium Since 1.2.1.7 can check for specified add-on version.
6279
- *
6280
- * @return bool
6281
- */
6282
- function is_addon_activated( $id_or_slug, $is_premium = null ) {
6283
- $this->_logger->entrance();
6284
-
6285
- $addon_id = self::get_module_id( $id_or_slug );
6286
- $is_activated = self::has_instance( $addon_id );
6287
-
6288
- if ( ! $is_activated ) {
6289
- return false;
6290
- }
6291
-
6292
- if ( is_bool( $is_premium ) ) {
6293
- // Check if the specified code version is activate.
6294
- $addon = $this->get_addon_instance( $addon_id );
6295
- $is_activated = ( $is_premium === $addon->is_premium() );
6296
- }
6297
-
6298
- return $is_activated;
6299
- }
6300
-
6301
- /**
6302
- * Check if add-on was connected to install
6303
- *
6304
- * @author Vova Feldman (@svovaf)
6305
- * @since 1.1.7
6306
- *
6307
- * @param string|number $id_or_slug
6308
- *
6309
- * @return bool
6310
- */
6311
- function is_addon_connected( $id_or_slug ) {
6312
- $this->_logger->entrance();
6313
-
6314
- $sites = self::get_all_sites( WP_FS__MODULE_TYPE_PLUGIN );
6315
-
6316
- $addon_id = self::get_module_id( $id_or_slug );
6317
- $addon = $this->get_addon( $addon_id );
6318
- $slug = $addon->slug;
6319
- if ( ! isset( $sites[ $slug ] ) ) {
6320
- return false;
6321
- }
6322
-
6323
- $site = $sites[ $slug ];
6324
-
6325
- $plugin = FS_Plugin_Manager::instance( $addon_id )->get();
6326
-
6327
- if ( $plugin->parent_plugin_id != $this->_plugin->id ) {
6328
- // The given slug do NOT belong to any of the plugin's add-ons.
6329
- return false;
6330
- }
6331
-
6332
- return ( is_object( $site ) &&
6333
- is_numeric( $site->id ) &&
6334
- is_numeric( $site->user_id ) &&
6335
- FS_Plugin_Plan::is_valid_id( $site->plan_id )
6336
- );
6337
- }
6338
-
6339
- /**
6340
- * Determines if add-on installed.
6341
- *
6342
- * NOTE: This is a heuristic and only works if the folder/file named as the slug.
6343
- *
6344
- * @author Vova Feldman (@svovaf)
6345
- * @since 1.0.6
6346
- *
6347
- * @param string|number $id_or_slug
6348
- *
6349
- * @return bool
6350
- */
6351
- function is_addon_installed( $id_or_slug ) {
6352
- $this->_logger->entrance();
6353
-
6354
- $addon_id = self::get_module_id( $id_or_slug );
6355
-
6356
- return file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $this->get_addon_basename( $addon_id ) ) );
6357
- }
6358
-
6359
- /**
6360
- * Get add-on basename.
6361
- *
6362
- * @author Vova Feldman (@svovaf)
6363
- * @since 1.0.6
6364
- *
6365
- * @param string|number $id_or_slug
6366
- *
6367
- * @return string
6368
- */
6369
- function get_addon_basename( $id_or_slug ) {
6370
- $addon_id = self::get_module_id( $id_or_slug );
6371
-
6372
- if ( $this->is_addon_activated( $addon_id ) ) {
6373
- return self::instance( $addon_id )->get_plugin_basename();
6374
- }
6375
-
6376
- $addon = $this->get_addon( $addon_id );
6377
- $premium_basename = "{$addon->premium_slug}/{$addon->slug}.php";
6378
-
6379
- if ( file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $premium_basename ) ) ) {
6380
- return $premium_basename;
6381
- }
6382
-
6383
- $all_plugins = $this->get_all_plugins();
6384
-
6385
- foreach ( $all_plugins as $basename => $data ) {
6386
- if ( $addon->slug === $data['slug'] ||
6387
- $addon->premium_slug === $data['slug']
6388
- ) {
6389
- return $basename;
6390
- }
6391
- }
6392
-
6393
- $free_basename = "{$addon->slug}/{$addon->slug}.php";
6394
-
6395
- return $free_basename;
6396
- }
6397
-
6398
- /**
6399
- * Get installed add-ons instances.
6400
- *
6401
- * @author Vova Feldman (@svovaf)
6402
- * @since 1.0.6
6403
- *
6404
- * @return Freemius[]
6405
- */
6406
- function get_installed_addons() {
6407
- if ( $this->is_addon() ) {
6408
- // Add-on cannot have add-ons.
6409
- return array();
6410
- }
6411
-
6412
- $installed_addons = array();
6413
-
6414
- foreach ( self::$_instances as $instance ) {
6415
- if ( $instance->is_addon_of( $this->_plugin->id ) ) {
6416
- $installed_addons[] = $instance;
6417
- }
6418
- }
6419
-
6420
- return $installed_addons;
6421
- }
6422
-
6423
- /**
6424
- * Check if any add-ons of the plugin are installed.
6425
- *
6426
- * @author Leo Fajardo (@leorw)
6427
- * @since 1.1.1
6428
- *
6429
- * @return bool
6430
- */
6431
- function has_installed_addons() {
6432
- if ( ! $this->has_addons() ) {
6433
- return false;
6434
- }
6435
-
6436
- foreach ( self::$_instances as $instance ) {
6437
- if ( $instance->is_addon() && is_object( $instance->_parent_plugin ) ) {
6438
- if ( $this->_plugin->id == $instance->_parent_plugin->id ) {
6439
- return true;
6440
- }
6441
- }
6442
- }
6443
-
6444
- return false;
6445
- }
6446
-
6447
- /**
6448
- * Tell Freemius that the current plugin is an add-on.
6449
- *
6450
- * @author Vova Feldman (@svovaf)
6451
- * @since 1.0.6
6452
- *
6453
- * @param number $parent_plugin_id The parent plugin ID
6454
- */
6455
- function init_addon( $parent_plugin_id ) {
6456
- $this->_plugin->parent_plugin_id = $parent_plugin_id;
6457
- }
6458
-
6459
- /**
6460
- * @author Vova Feldman (@svovaf)
6461
- * @since 1.0.6
6462
- *
6463
- * @return bool
6464
- */
6465
- function is_addon() {
6466
- return (
6467
- isset( $this->_plugin->parent_plugin_id ) &&
6468
- is_numeric( $this->_plugin->parent_plugin_id )
6469
- );
6470
- }
6471
-
6472
- /**
6473
- * @author Vova Feldman (@svovaf)
6474
- * @since 2.3.2
6475
- *
6476
- * @param number $parent_product_id
6477
- *
6478
- * @return bool
6479
- */
6480
- function is_addon_of( $parent_product_id ) {
6481
- return (
6482
- $this->is_addon() &&
6483
- $parent_product_id == $this->_plugin->parent_plugin_id
6484
- );
6485
- }
6486
-
6487
- /**
6488
- * Deactivate add-on if it's premium only and the user does't have a valid license.
6489
- *
6490
- * @param bool $is_after_trial_cancel
6491
- *
6492
- * @return bool If add-on was deactivated.
6493
- */
6494
- private function deactivate_premium_only_addon_without_license( $is_after_trial_cancel = false ) {
6495
- if ( ! $this->has_free_plan() &&
6496
- ! $this->has_features_enabled_license() &&
6497
- ! $this->_has_premium_license()
6498
- ) {
6499
- if ( $this->is_registered() ) {
6500
- // IF wrapper is turned off because activation_timestamp is currently only stored for plugins (not addons).
6501
- // if (empty($this->_storage->activation_timestamp) ||
6502
- // (WP_FS__SCRIPT_START_TIME - $this->_storage->activation_timestamp) > 30
6503
- // ) {
6504
- /**
6505
- * @todo When it's first fail, there's no reason to try and re-sync because the licenses were just synced after initial activation.
6506
- *
6507
- * Retry syncing the user add-on licenses.
6508
- */
6509
- // Sync licenses.
6510
- $this->_sync_licenses();
6511
- // }
6512
-
6513
- // Try to activate premium license.
6514
- $this->_activate_license( true );
6515
- }
6516
-
6517
- if ( ! $this->has_free_plan() &&
6518
- ! $this->has_features_enabled_license() &&
6519
- ! $this->_has_premium_license()
6520
- ) {
6521
- // @todo Check if deactivate plugins also call the deactivation hook.
6522
-
6523
- $this->_parent->_admin_notices->add_sticky(
6524
- sprintf(
6525
- ( $is_after_trial_cancel ?
6526
- $this->_parent->get_text_inline(
6527
- '%s free trial was successfully cancelled. Since the add-on is premium only it was automatically deactivated. If you like to use it in the future, you\'ll have to purchase a license.',
6528
- 'addon-trial-cancelled-message'
6529
- ) :
6530
- $this->_parent->get_text_inline(
6531
- '%s is a premium only add-on. You have to purchase a license first before activating the plugin.',
6532
- 'addon-no-license-message'
6533
- )
6534
- ),
6535
- '<b>' . $this->_plugin->title . '</b>'
6536
- ) . ' ' . sprintf(
6537
- '<a href="%s" aria-label="%s" class="button button-primary" style="margin-left: 10px; vertical-align: middle;">%s &nbsp;&#10140;</a>',
6538
- $this->_parent->addon_url( $this->_slug ),
6539
- esc_attr( sprintf( $this->_parent->get_text_inline( 'More information about %s', 'more-information-about-x' ), $this->_plugin->title ) ),
6540
- $this->_parent->get_text_inline( 'Purchase License', 'purchase-license' )
6541
- ),
6542
- 'no_addon_license_' . $this->_slug,
6543
- ( $is_after_trial_cancel ? '' : $this->_parent->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...' ),
6544
- ( $is_after_trial_cancel ? 'success' : 'error' )
6545
- );
6546
-
6547
- deactivate_plugins( array( $this->_plugin_basename ), true );
6548
-
6549
- return true;
6550
- }
6551
- }
6552
-
6553
- return false;
6554
- }
6555
-
6556
- #endregion
6557
-
6558
- #----------------------------------------------------------------------------------
6559
- #region Sandbox
6560
- #----------------------------------------------------------------------------------
6561
-
6562
- /**
6563
- * Set Freemius into sandbox mode for debugging.
6564
- *
6565
- * @author Vova Feldman (@svovaf)
6566
- * @since 1.0.4
6567
- *
6568
- * @param string $secret_key
6569
- */
6570
- function init_sandbox( $secret_key ) {
6571
- $this->_plugin->secret_key = $secret_key;
6572
-
6573
- // Update plugin details.
6574
- FS_Plugin_Manager::instance( $this->_module_id )->update( $this->_plugin, true );
6575
- }
6576
-
6577
- /**
6578
- * Check if running payments in sandbox mode.
6579
- *
6580
- * @author Vova Feldman (@svovaf)
6581
- * @since 1.0.4
6582
- *
6583
- * @return bool
6584
- */
6585
- function is_payments_sandbox() {
6586
- return ( ! $this->is_live() ) || isset( $this->_plugin->secret_key );
6587
- }
6588
-
6589
- #endregion
6590
-
6591
- /**
6592
- * Check if running test vs. live plugin.
6593
- *
6594
- * @author Vova Feldman (@svovaf)
6595
- * @since 1.0.5
6596
- *
6597
- * @return bool
6598
- */
6599
- function is_live() {
6600
- return $this->_plugin->is_live;
6601
- }
6602
-
6603
- /**
6604
- * Check if super-admin skipped connection for all sites in the network.
6605
- *
6606
- * @author Vova Feldman (@svovaf)
6607
- * @since 2.0.0
6608
- */
6609
- function is_network_anonymous() {
6610
- if ( ! $this->_is_network_active ) {
6611
- return false;
6612
- }
6613
-
6614
- $is_anonymous_ms = $this->_storage->get( 'is_anonymous_ms' );
6615
-
6616
- if ( empty( $is_anonymous_ms ) ) {
6617
- return false;
6618
- }
6619
-
6620
- return $is_anonymous_ms['is'];
6621
- }
6622
-
6623
- /**
6624
- * Check if super-admin opted-in for all sites in the network.
6625
- *
6626
- * @author Vova Feldman (@svovaf)
6627
- * @since 2.0.0
6628
- */
6629
- function is_network_connected() {
6630
- if ( ! $this->_is_network_active ) {
6631
- return false;
6632
- }
6633
-
6634
- return $this->_storage->get( 'is_network_connected' );
6635
- }
6636
-
6637
- /**
6638
- * Check if the user skipped connecting the account with Freemius.
6639
- *
6640
- * @author Vova Feldman (@svovaf)
6641
- * @since 1.0.7
6642
- *
6643
- * @return bool
6644
- */
6645
- function is_anonymous() {
6646
- if ( ! isset( $this->_is_anonymous ) ) {
6647
- if ( $this->is_network_anonymous() ) {
6648
- $this->_is_anonymous = true;
6649
- } else if ( ! fs_is_network_admin() ) {
6650
- if ( ! isset( $this->_storage->is_anonymous ) ) {
6651
- // Not skipped.
6652
- $this->_is_anonymous = false;
6653
- } else if ( is_bool( $this->_storage->is_anonymous ) ) {
6654
- // For back compatibility, since the variable was boolean before.
6655
- $this->_is_anonymous = $this->_storage->is_anonymous;
6656
-
6657
- // Upgrade stored data format to 1.1.3 format.
6658
- $this->set_anonymous_mode( $this->_storage->is_anonymous );
6659
- } else {
6660
- // Version 1.1.3 and later.
6661
- $this->_is_anonymous = $this->_storage->is_anonymous['is'];
6662
- }
6663
- }
6664
- }
6665
-
6666
- return $this->_is_anonymous;
6667
- }
6668
-
6669
- /**
6670
- * Check if the user skipped the connection of a specified site.
6671
- *
6672
- * @author Vova Feldman (@svovaf)
6673
- * @since 2.0.0
6674
- *
6675
- * @param int $blog_id
6676
- *
6677
- * @return bool
6678
- */
6679
- function is_anonymous_site( $blog_id = 0 ) {
6680
- if ( $this->is_network_anonymous() ) {
6681
- return true;
6682
- }
6683
-
6684
- $is_anonymous = $this->_storage->get( 'is_anonymous', false, $blog_id );
6685
-
6686
- if ( empty( $is_anonymous ) ) {
6687
- return false;
6688
- }
6689
-
6690
- return $is_anonymous['is'];
6691
- }
6692
-
6693
- /**
6694
- * Check if user connected his account and install pending email activation.
6695
- *
6696
- * @author Vova Feldman (@svovaf)
6697
- * @since 1.0.7
6698
- *
6699
- * @return bool
6700
- */
6701
- function is_pending_activation() {
6702
- return $this->_storage->get( 'is_pending_activation', false );
6703
- }
6704
-
6705
- /**
6706
- * Check if plugin must be WordPress.org compliant.
6707
- *
6708
- * @since 1.0.7
6709
- *
6710
- * @return bool
6711
- */
6712
- function is_org_repo_compliant() {
6713
- return $this->_is_org_compliant;
6714
- }
6715
-
6716
- #--------------------------------------------------------------------------------
6717
- #region WP Cron Common
6718
- #--------------------------------------------------------------------------------
6719
-
6720
- /**
6721
- * @author Vova Feldman (@svovaf)
6722
- * @since 2.0.0
6723
- *
6724
- * @param string $name Cron name.
6725
- *
6726
- * @return object
6727
- */
6728
- private function get_cron_data( $name ) {
6729
- $this->_logger->entrance( $name );
6730
-
6731
- /**
6732
- * @var object $cron_data
6733
- */
6734
- return $this->_storage->get( "{$name}_cron", null );
6735
- }
6736
-
6737
- /**
6738
- * @author Vova Feldman (@svovaf)
6739
- * @since 2.0.0
6740
- *
6741
- * @param string $name Cron name.
6742
- */
6743
- private function clear_cron_data( $name ) {
6744
- $this->_logger->entrance( $name );
6745
-
6746
- $this->_storage->remove( "{$name}_cron" );
6747
- }
6748
-
6749
- /**
6750
- * @author Vova Feldman (@svovaf)
6751
- * @since 2.0.0
6752
- *
6753
- * @param string $name Cron name.
6754
- * @param int $cron_blog_id The cron executing blog ID.
6755
- */
6756
- private function set_cron_data( $name, $cron_blog_id = 0 ) {
6757
- $this->_logger->entrance( $name );
6758
-
6759
- $this->_storage->store( "{$name}_cron", (object) array(
6760
- 'version' => $this->get_plugin_version(),
6761
- 'blog_id' => $cron_blog_id,
6762
- 'sdk_version' => $this->version,
6763
- 'timestamp' => WP_FS__SCRIPT_START_TIME,
6764
- 'on' => true,
6765
- ) );
6766
- }
6767
-
6768
- /**
6769
- * Get the cron's executing blog ID.
6770
- *
6771
- * @author Vova Feldman (@svovaf)
6772
- * @since 2.0.0
6773
- *
6774
- * @param string $name Cron name.
6775
- *
6776
- * @return int
6777
- */
6778
- private function get_cron_blog_id( $name ) {
6779
- $this->_logger->entrance( $name );
6780
-
6781
- /**
6782
- * @var object $cron_data
6783
- */
6784
- $cron_data = $this->get_cron_data( $name );
6785
-
6786
- return ( is_object( $cron_data ) && is_numeric( $cron_data->blog_id ) ) ?
6787
- $cron_data->blog_id :
6788
- 0;
6789
- }
6790
-
6791
- /**
6792
- * @author Vova Feldman (@svovaf)
6793
- * @since 2.0.0
6794
- *
6795
- * @param string $name Cron name.
6796
- *
6797
- * @return bool
6798
- */
6799
- private function is_cron_on( $name ) {
6800
- $this->_logger->entrance( $name );
6801
-
6802
- /**
6803
- * @var object $cron_data
6804
- */
6805
- $cron_data = $this->get_cron_data( $name );
6806
-
6807
- return ( ! is_null( $cron_data ) && true === $cron_data->on );
6808
- }
6809
-
6810
- /**
6811
- * Unix timestamp for previous cron execution or false if never executed.
6812
- *
6813
- * @author Vova Feldman (@svovaf)
6814
- * @since 2.0.0
6815
- *
6816
- * @param string $name Cron name.
6817
- *
6818
- * @return int|false
6819
- */
6820
- private function cron_last_execution( $name ) {
6821
- $this->_logger->entrance( $name );
6822
-
6823
- return $this->_storage->get( "{$name}_timestamp" );
6824
- }
6825
-
6826
- /**
6827
- * Set cron execution time to now.
6828
- *
6829
- * @author Vova Feldman (@svovaf)
6830
- * @since 2.0.0
6831
- *
6832
- * @param string $name Cron name.
6833
- */
6834
- private function set_cron_execution_timestamp( $name ) {
6835
- $this->_logger->entrance( $name );
6836
-
6837
- $this->_storage->store( "{$name}_timestamp", time() );
6838
- }
6839
-
6840
- /**
6841
- * Sets the keepalive time to now.
6842
- *
6843
- * @author Leo Fajardo (@leorw)
6844
- * @since 2.2.3
6845
- *
6846
- * @param bool|null $use_network_level_storage
6847
- */
6848
- private function set_keepalive_timestamp( $use_network_level_storage = null ) {
6849
- $this->_logger->entrance();
6850
-
6851
- $this->_storage->store( 'keepalive_timestamp', time(), $use_network_level_storage );
6852
- }
6853
-
6854
- /**
6855
- * Check if cron was executed in the last $period of seconds.
6856
- *
6857
- * @author Vova Feldman (@svovaf)
6858
- * @since 2.0.0
6859
- *
6860
- * @param string $name Cron name.
6861
- * @param int $period In seconds
6862
- *
6863
- * @return bool
6864
- */
6865
- private function is_cron_executed( $name, $period = WP_FS__TIME_24_HOURS_IN_SEC ) {
6866
- $this->_logger->entrance( $name );
6867
-
6868
- $last_execution = $this->cron_last_execution( $name );
6869
-
6870
- if ( ! is_numeric( $last_execution ) ) {
6871
- return false;
6872
- }
6873
-
6874
- return ( $last_execution > ( WP_FS__SCRIPT_START_TIME - $period ) );
6875
- }
6876
-
6877
- /**
6878
- * WP Cron is executed on a site level. When running in a multisite network environment
6879
- * with the network integration activated, for optimization reasons, we are consolidating
6880
- * the installs data sync cron to be executed only from a single site.
6881
- *
6882
- * @author Vova Feldman (@svovaf)
6883
- * @since 2.0.0
6884
- *
6885
- * @param int $except_blog_id Target any except the excluded blog ID.
6886
- *
6887
- * @return int
6888
- */
6889
- private function get_cron_target_blog_id( $except_blog_id = 0 ) {
6890
- if ( ! is_multisite() ) {
6891
- return 0;
6892
- }
6893
-
6894
- if ( $this->_is_network_active &&
6895
- is_numeric( $this->_storage->network_install_blog_id ) &&
6896
- $except_blog_id != $this->_storage->network_install_blog_id &&
6897
- self::is_site_active( $this->_storage->network_install_blog_id )
6898
- ) {
6899
- // Try to run cron from the main network blog.
6900
- $install = $this->get_install_by_blog_id( $this->_storage->network_install_blog_id );
6901
-
6902
- if ( is_object( $install ) &&
6903
- ( $this->is_premium() || $install->is_tracking_allowed() )
6904
- ) {
6905
- return $this->_storage->network_install_blog_id;
6906
- }
6907
- }
6908
-
6909
- // Get first opted-in blog ID with active tracking.
6910
- $installs = $this->get_blog_install_map();
6911
- foreach ( $installs as $blog_id => $install ) {
6912
- if ( $except_blog_id != $blog_id &&
6913
- self::is_site_active( $blog_id ) &&
6914
- ( $this->is_premium() || $install->is_tracking_allowed() )
6915
- ) {
6916
- return $blog_id;
6917
- }
6918
- }
6919
-
6920
- return 0;
6921
- }
6922
-
6923
- /**
6924
- * @author Vova Feldman (@svovaf)
6925
- * @since 2.0.0
6926
- *
6927
- * @param string $name Cron name.
6928
- * @param string $action_tag Callback action tag.
6929
- * @param bool $is_network_clear If set to TRUE, clear sync cron even if there are installs that are still connected.
6930
- */
6931
- private function clear_cron( $name, $action_tag = '', $is_network_clear = false ) {
6932
- $this->_logger->entrance( $name );
6933
-
6934
- if ( ! $this->is_cron_on( $name ) ) {
6935
- return;
6936
- }
6937
-
6938
- $clear_cron = true;
6939
- if ( ! $is_network_clear && $this->_is_network_active ) {
6940
- $installs = $this->get_blog_install_map();
6941
-
6942
- foreach ( $installs as $blog_id => $install ) {
6943
- /**
6944
- * @var FS_Site $install
6945
- */
6946
- if ( $install->is_tracking_allowed() ) {
6947
- $clear_cron = false;
6948
- break;
6949
- }
6950
- }
6951
- }
6952
-
6953
- if ( ! $clear_cron ) {
6954
- return;
6955
- }
6956
-
6957
- /**
6958
- * @var object $cron_data
6959
- */
6960
- $cron_data = $this->get_cron_data( $name );
6961
-
6962
- $cron_blog_id = is_object( $cron_data ) && isset( $cron_data->blog_id ) ?
6963
- $cron_data->blog_id :
6964
- 0;
6965
-
6966
- $this->clear_cron_data( $name );
6967
-
6968
- if ( 0 < $cron_blog_id ) {
6969
- switch_to_blog( $cron_blog_id );
6970
- }
6971
-
6972
- if ( empty( $action_tag ) ) {
6973
- $action_tag = $name;
6974
- }
6975
-
6976
- wp_clear_scheduled_hook( $this->get_action_tag( $action_tag ) );
6977
-
6978
- if ( 0 < $cron_blog_id ) {
6979
- restore_current_blog();
6980
- }
6981
- }
6982
-
6983
- /**
6984
- * Unix timestamp for next cron execution or false if not scheduled.
6985
- *
6986
- * @author Vova Feldman (@svovaf)
6987
- * @since 2.0.0
6988
- *
6989
- * @param string $name Cron name.
6990
- * @param string $action_tag Callback action tag.
6991
- *
6992
- * @return int|false
6993
- */
6994
- private function get_next_scheduled_cron( $name, $action_tag = '' ) {
6995
- $this->_logger->entrance( $name );
6996
-
6997
- if ( ! $this->is_cron_on( $name ) ) {
6998
- return false;
6999
- }
7000
-
7001
- /**
7002
- * @var object $cron_data
7003
- */
7004
- $cron_data = $this->get_cron_data( $name );
7005
-
7006
- $cron_blog_id = is_object( $cron_data ) && isset( $cron_data->blog_id ) ?
7007
- $cron_data->blog_id :
7008
- 0;
7009
-
7010
- if ( 0 < $cron_blog_id ) {
7011
- switch_to_blog( $cron_blog_id );
7012
- }
7013
-
7014
- if ( empty( $action_tag ) ) {
7015
- $action_tag = $name;
7016
- }
7017
-
7018
- $next_scheduled = wp_next_scheduled( $this->get_action_tag( $action_tag ) );
7019
-
7020
- if ( 0 < $cron_blog_id ) {
7021
- restore_current_blog();
7022
- }
7023
-
7024
- return $next_scheduled;
7025
- }
7026
-
7027
- /**
7028
- * @author Vova Feldman (@svovaf)
7029
- * @since 2.0.0
7030
- *
7031
- * @param string $name Cron name.
7032
- * @param string $action_tag Callback action tag.
7033
- * @param string $recurrence 'single' or 'daily'.
7034
- * @param int $start_at Defaults to now.
7035
- * @param bool $randomize_start If true, schedule first job randomly during the next 12 hours. Otherwise, schedule job to start right away.
7036
- * @param int $except_blog_id Target any except the excluded blog ID.
7037
- */
7038
- private function schedule_cron(
7039
- $name,
7040
- $action_tag = '',
7041
- $recurrence = 'single',
7042
- $start_at = WP_FS__SCRIPT_START_TIME,
7043
- $randomize_start = true,
7044
- $except_blog_id = 0
7045
- ) {
7046
- $this->_logger->entrance( $name );
7047
-
7048
- $this->clear_cron( $name, $action_tag, true );
7049
-
7050
- $cron_blog_id = $this->get_cron_target_blog_id( $except_blog_id );
7051
-
7052
- if ( is_multisite() && 0 == $cron_blog_id ) {
7053
- // Don't schedule cron since couldn't find a target blog.
7054
- return;
7055
- }
7056
-
7057
- if ( 0 < $cron_blog_id ) {
7058
- switch_to_blog( $cron_blog_id );
7059
- }
7060
-
7061
- if ( 'daily' === $recurrence ) {
7062
- if ( $randomize_start ) {
7063
- // Schedule first sync with a random 12 hour time range from now.
7064
- $start_at += rand( 0, ( WP_FS__TIME_24_HOURS_IN_SEC / 2 ) );
7065
- }
7066
-
7067
- // Schedule daily WP cron.
7068
- wp_schedule_event(
7069
- $start_at,
7070
- 'daily',
7071
- $this->get_action_tag( $action_tag )
7072
- );
7073
- } else if ( 'single' === $recurrence ) {
7074
- // Schedule single cron.
7075
- wp_schedule_single_event(
7076
- $start_at,
7077
- $this->get_action_tag( $action_tag )
7078
- );
7079
- }
7080
-
7081
- $this->set_cron_data( $name, $cron_blog_id );
7082
-
7083
- if ( 0 < $cron_blog_id ) {
7084
- restore_current_blog();
7085
- }
7086
- }
7087
-
7088
- /**
7089
- * Consolidated cron execution for performance optimization. The max number of API requests is based on the number of unique opted-in users.
7090
- * that doesn't halt page loading.
7091
- *
7092
- * @author Vova Feldman (@svovaf)
7093
- * @since 2.0.0
7094
- *
7095
- * @param string $name Cron name.
7096
- * @param callable $callable The function that should be executed.
7097
- */
7098
- private function execute_cron( $name, $callable ) {
7099
- $this->_logger->entrance( $name );
7100
-
7101
- // Store the last time data sync was executed.
7102
- $this->set_cron_execution_timestamp( $name );
7103
-
7104
- // Check if API is temporary down.
7105
- if ( FS_Api::is_temporary_down() ) {
7106
- return;
7107
- }
7108
-
7109
- // @todo Add logic that identifies API latency, and reschedule the next background sync randomly between 8-16 hours.
7110
-
7111
- $users_2_blog_ids = array();
7112
-
7113
- if ( ! is_multisite() ) {
7114
- // Add dummy blog.
7115
- $users_2_blog_ids[0] = array( 0 );
7116
- } else {
7117
- $installs = $this->get_blog_install_map();
7118
- foreach ( $installs as $blog_id => $install ) {
7119
- if ( $this->is_premium() || $install->is_tracking_allowed() ) {
7120
- if ( ! isset( $users_2_blog_ids[ $install->user_id ] ) ) {
7121
- $users_2_blog_ids[ $install->user_id ] = array();
7122
- }
7123
-
7124
- $users_2_blog_ids[ $install->user_id ][] = $blog_id;
7125
- }
7126
- }
7127
- }
7128
-
7129
- $current_blog_id = get_current_blog_id();
7130
-
7131
- foreach ( $users_2_blog_ids as $user_id => $blog_ids ) {
7132
- if ( 0 < $blog_ids[0] ) {
7133
- $this->switch_to_blog( $blog_ids[0] );
7134
- }
7135
-
7136
- call_user_func_array( $callable, array( $blog_ids, ( is_multisite() ? $current_blog_id : null ) ) );
7137
-
7138
- foreach ( $blog_ids as $blog_id ) {
7139
- $this->do_action( "after_{$name}_cron", $blog_id );
7140
- }
7141
- }
7142
-
7143
- if ( is_multisite() ) {
7144
- $this->switch_to_blog( $current_blog_id, fs_is_network_admin() ? $this->get_network_install() : null );
7145
-
7146
- $this->do_action( "after_{$name}_cron_multisite" );
7147
- }
7148
- }
7149
-
7150
- #endregion
7151
-
7152
- #----------------------------------------------------------------------------------
7153
- #region Daily Sync Cron
7154
- #----------------------------------------------------------------------------------
7155
-
7156
-
7157
- /**
7158
- * @author Vova Feldman (@svovaf)
7159
- * @since 2.0.0
7160
- *
7161
- * @return bool
7162
- */
7163
- private function is_sync_cron_scheduled() {
7164
- return $this->is_cron_on( 'sync' );
7165
- }
7166
-
7167
- /**
7168
- * Get the sync cron's executing blog ID.
7169
- *
7170
- * @author Vova Feldman (@svovaf)
7171
- * @since 2.0.0
7172
- *
7173
- * @return int
7174
- */
7175
- private function get_sync_cron_blog_id() {
7176
- return $this->get_cron_blog_id( 'sync' );
7177
- }
7178
-
7179
- /**
7180
- * @author Vova Feldman (@svovaf)
7181
- * @since 1.1.7.3
7182
- */
7183
- private function run_manual_sync() {
7184
- self::require_pluggable_essentials();
7185
-
7186
- if ( ! $this->is_user_admin() ) {
7187
- return;
7188
- }
7189
-
7190
- // Run manual sync.
7191
- $this->_sync_cron();
7192
-
7193
- // Reschedule next cron to run 24 hours from now (performance optimization).
7194
- $this->schedule_sync_cron( time() + WP_FS__TIME_24_HOURS_IN_SEC, false );
7195
- }
7196
-
7197
- /**
7198
- * Data sync cron job. Replaces the background sync non blocking HTTP request
7199
- * that doesn't halt page loading.
7200
- *
7201
- * @author Vova Feldman (@svovaf)
7202
- * @since 1.1.7.3
7203
- * @since 2.0.0 Consolidate all the data sync into the same cron for performance optimization. The max number of API requests is based on the number of unique opted-in users.
7204
- */
7205
- function _sync_cron() {
7206
- $this->_logger->entrance();
7207
-
7208
- $this->execute_cron( 'sync', array( &$this, '_sync_cron_method' ) );
7209
- }
7210
-
7211
- /**
7212
- * The actual data sync cron logic.
7213
- *
7214
- * @author Vova Feldman (@svovaf)
7215
- * @since 2.0.0
7216
- *
7217
- * @param int[] $blog_ids
7218
- * @param int|null $current_blog_id @since 2.2.3. This is passed from the `execute_cron` method and used by the
7219
- * `_sync_plugin_license` method in order to switch to the previous blog when sending
7220
- * updates for a single site in case `execute_cron` has switched to a different blog.
7221
- */
7222
- function _sync_cron_method( array $blog_ids, $current_blog_id = null ) {
7223
- if ( $this->is_registered() ) {
7224
- if ( $this->has_paid_plan() ) {
7225
- // Initiate background plan sync.
7226
- $this->_sync_license( true, false, $current_blog_id );
7227
-
7228
- if ( $this->is_paying() ) {
7229
- // Check for premium plugin updates.
7230
- $this->check_updates( true );
7231
- }
7232
- } else {
7233
- // Sync install(s) (only if something changed locally).
7234
- if ( 1 < count( $blog_ids ) ) {
7235
- $this->sync_installs();
7236
- } else {
7237
- $this->sync_install();
7238
- }
7239
-
7240
- $this->maybe_sync_install_user();
7241
- }
7242
- }
7243
- }
7244
-
7245
- /**
7246
- * Check if sync was executed in the last $period of seconds.
7247
- *
7248
- * @author Vova Feldman (@svovaf)
7249
- * @since 1.1.7.3
7250
- *
7251
- * @param int $period In seconds
7252
- *
7253
- * @return bool
7254
- */
7255
- private function is_sync_executed( $period = WP_FS__TIME_24_HOURS_IN_SEC ) {
7256
- return $this->is_cron_executed( 'sync', $period );
7257
- }
7258
-
7259
- /**
7260
- * @author Vova Feldman (@svovaf)
7261
- * @since 1.1.7.3
7262
- *
7263
- * @return bool
7264
- */
7265
- private function is_sync_cron_on() {
7266
- return $this->is_cron_on( 'sync' );
7267
- }
7268
-
7269
- /**
7270
- * @author Leo Fajardo (@leorw)
7271
- * @since 2.5.0
7272
- */
7273
- private function maybe_schedule_sync_cron() {
7274
- $next_schedule = $this->next_sync_cron();
7275
-
7276
- // The event is properly scheduled, so no need to reschedule it.
7277
- if (
7278
- is_numeric( $next_schedule ) &&
7279
- $next_schedule > time()
7280
- ) {
7281
- return;
7282
- }
7283
-
7284
- $this->schedule_sync_cron();
7285
- }
7286
-
7287
- /**
7288
- * @author Vova Feldman (@svovaf)
7289
- * @since 1.1.7.3
7290
- *
7291
- * @param int $start_at Defaults to now.
7292
- * @param bool $randomize_start If true, schedule first job randomly during the next 12 hours. Otherwise, schedule job to start right away.
7293
- * @param int $except_blog_id Since 2.0.0 when running in a multisite network environment, the cron execution is consolidated. This param allows excluding excluded specified blog ID from being the cron executor.
7294
- */
7295
- private function schedule_sync_cron(
7296
- $start_at = WP_FS__SCRIPT_START_TIME,
7297
- $randomize_start = true,
7298
- $except_blog_id = 0
7299
- ) {
7300
- $this->schedule_cron(
7301
- 'sync',
7302
- 'data_sync',
7303
- 'daily',
7304
- $start_at,
7305
- $randomize_start,
7306
- $except_blog_id
7307
- );
7308
- }
7309
-
7310
- /**
7311
- * Add the actual sync function to the cron job hook.
7312
- *
7313
- * @author Vova Feldman (@svovaf)
7314
- * @since 1.1.7.3
7315
- */
7316
- private function hook_callback_to_sync_cron() {
7317
- $this->add_action( 'data_sync', array( &$this, '_sync_cron' ) );
7318
- }
7319
-
7320
- /**
7321
- * @author Vova Feldman (@svovaf)
7322
- * @since 1.1.7.3
7323
- *
7324
- * @param bool $is_network_clear Since 2.0.0 If set to TRUE, clear sync cron even if there are installs that are still connected.
7325
- */
7326
- private function clear_sync_cron( $is_network_clear = false ) {
7327
- $this->_logger->entrance();
7328
-
7329
- $this->clear_cron( 'sync', 'data_sync', $is_network_clear );
7330
- }
7331
-
7332
- /**
7333
- * Unix timestamp for next sync cron execution or false if not scheduled.
7334
- *
7335
- * @author Vova Feldman (@svovaf)
7336
- * @since 1.1.7.3
7337
- *
7338
- * @return int|false
7339
- */
7340
- function next_sync_cron() {
7341
- return $this->get_next_scheduled_cron( 'sync', 'data_sync' );
7342
- }
7343
-
7344
- /**
7345
- * Unix timestamp for previous sync cron execution or false if never executed.
7346
- *
7347
- * @author Vova Feldman (@svovaf)
7348
- * @since 1.1.7.3
7349
- *
7350
- * @return int|false
7351
- */
7352
- function last_sync_cron() {
7353
- return $this->cron_last_execution( 'sync' );
7354
- }
7355
-
7356
- #endregion Daily Sync Cron ------------------------------------------------------------------
7357
-
7358
- #----------------------------------------------------------------------------------
7359
- #region Async Install Sync
7360
- #----------------------------------------------------------------------------------
7361
-
7362
- /**
7363
- * @author Vova Feldman (@svovaf)
7364
- * @since 1.1.7.3
7365
- *
7366
- * @return bool
7367
- */
7368
- private function is_install_sync_scheduled() {
7369
- return $this->is_cron_on( 'install_sync' );
7370
- }
7371
-
7372
- /**
7373
- * Get the sync cron's executing blog ID.
7374
- *
7375
- * @author Vova Feldman (@svovaf)
7376
- * @since 2.0.0
7377
- *
7378
- * @return int
7379
- */
7380
- private function get_install_sync_cron_blog_id() {
7381
- return $this->get_cron_blog_id( 'install_sync' );
7382
- }
7383
-
7384
- /**
7385
- * Instead of running blocking install sync event, execute non blocking scheduled wp-cron.
7386
- *
7387
- * @author Vova Feldman (@svovaf)
7388
- * @since 1.1.7.3
7389
- *
7390
- * @param int $except_blog_id Since 2.0.0 when running in a multisite network environment, the cron execution is consolidated. This param allows excluding excluded specified blog ID from being the cron executor.
7391
- */
7392
- private function schedule_install_sync( $except_blog_id = 0 ) {
7393
- $this->schedule_cron( 'install_sync', 'install_sync', 'single', WP_FS__SCRIPT_START_TIME, false, $except_blog_id );
7394
- }
7395
-
7396
- /**
7397
- * Unix timestamp for previous install sync cron execution or false if never executed.
7398
- *
7399
- * @todo There's some very strange bug that $this->_storage->install_sync_timestamp value is not being updated. But for sure the sync event is working.
7400
- *
7401
- * @author Vova Feldman (@svovaf)
7402
- * @since 1.1.7.3
7403
- *
7404
- * @return int|false
7405
- */
7406
- function last_install_sync() {
7407
- return $this->cron_last_execution( 'install_sync' );
7408
- }
7409
-
7410
- /**
7411
- * Unix timestamp for next install sync cron execution or false if not scheduled.
7412
- *
7413
- * @author Vova Feldman (@svovaf)
7414
- * @since 1.1.7.3
7415
- *
7416
- * @return int|false
7417
- */
7418
- function next_install_sync() {
7419
- return $this->get_next_scheduled_cron( 'install_sync', 'install_sync' );
7420
- }
7421
-
7422
- /**
7423
- * Add the actual install sync function to the cron job hook.
7424
- *
7425
- * @author Vova Feldman (@svovaf)
7426
- * @since 1.1.7.3
7427
- */
7428
- private function hook_callback_to_install_sync() {
7429
- $this->add_action( 'install_sync', array( &$this, '_run_sync_install' ) );
7430
- }
7431
-
7432
- /**
7433
- * @author Vova Feldman (@svovaf)
7434
- * @since 1.1.7.3
7435
- *
7436
- * @param bool $is_network_clear Since 2.0.0 If set to TRUE, clear sync cron even if there are installs that are still connected.
7437
- */
7438
- private function clear_install_sync_cron( $is_network_clear = false ) {
7439
- $this->_logger->entrance();
7440
-
7441
- $this->clear_cron( 'install_sync', 'install_sync', $is_network_clear );
7442
- }
7443
-
7444
- /**
7445
- * @author Vova Feldman (@svovaf)
7446
- * @since 1.1.7.3
7447
- * @since 2.0.0 Consolidate all the data sync into the same cron for performance optimization. The max number of API requests is based on the number of unique opted-in users.
7448
- */
7449
- public function _run_sync_install() {
7450
- $this->_logger->entrance();
7451
-
7452
- $this->execute_cron( 'sync', array( &$this, '_sync_install_cron_method' ) );
7453
- }
7454
-
7455
- /**
7456
- * The actual install(s) sync cron logic.
7457
- *
7458
- * @author Vova Feldman (@svovaf)
7459
- * @since 2.0.0
7460
- *
7461
- * @param int[] $blog_ids
7462
- * @param int|null $current_blog_id
7463
- */
7464
- function _sync_install_cron_method( array $blog_ids, $current_blog_id = null ) {
7465
- if ( $this->is_clone() ) {
7466
- return;
7467
- }
7468
-
7469
- if ( $this->is_registered() ) {
7470
- if ( 1 < count( $blog_ids ) ) {
7471
- $this->sync_installs( array(), true );
7472
- } else {
7473
- $this->sync_install( array(), true );
7474
- }
7475
-
7476
- $this->maybe_sync_install_user();
7477
- }
7478
- }
7479
-
7480
- #endregion Async Install Sync ------------------------------------------------------------------
7481
-
7482
- /**
7483
- * Show a notice that activation is currently pending.
7484
- *
7485
- * @todo Add some sort of mechanism to allow users to update the email address they would like to opt-in with when $is_suspicious_email is true.
7486
- *
7487
- * @author Vova Feldman (@svovaf)
7488
- * @since 1.0.7
7489
- *
7490
- * @param bool|string $email
7491
- * @param bool $is_pending_trial Since 1.2.1.5
7492
- * @param bool $is_suspicious_email Since 2.5.0 Set to true when there's an indication that email address the user opted in with is fake/dummy/placeholder.
7493
- */
7494
- function _add_pending_activation_notice(
7495
- $email = false,
7496
- $is_pending_trial = false,
7497
- $is_suspicious_email = false
7498
- ) {
7499
- if ( ! is_string( $email ) ) {
7500
- $current_user = self::_get_current_wp_user();
7501
- $email = $current_user->user_email;
7502
- }
7503
-
7504
- $this->_admin_notices->add_sticky(
7505
- sprintf(
7506
- $this->get_text_inline( 'You should receive an activation email for %s to your mailbox at %s. Please make sure you click the activation button in that email to %s.', 'pending-activation-message' ),
7507
- '<b>' . $this->get_plugin_name() . '</b>',
7508
- '<b>' . $email . '</b>',
7509
- ( $is_pending_trial ?
7510
- $this->get_text_inline( 'start the trial', 'start-the-trial' ) :
7511
- $this->get_text_inline( 'complete the install', 'complete-the-install' ) )
7512
- ),
7513
- 'activation_pending',
7514
- 'Thanks!'
7515
- );
7516
- }
7517
-
7518
- /**
7519
- * Check if currently in plugin activation.
7520
- *
7521
- * @author Vova Feldman (@svovaf)
7522
- * @since 1.1.4
7523
- *
7524
- * @return bool
7525
- */
7526
- function is_plugin_activation() {
7527
- $result = get_transient( "fs_{$this->_module_type}_{$this->_slug}_activated" );
7528
-
7529
- return !empty($result);
7530
- }
7531
-
7532
- /**
7533
- *
7534
- * NOTE: admin_menu action executed before admin_init.
7535
- *
7536
- * @author Vova Feldman (@svovaf)
7537
- * @since 1.0.7
7538
- */
7539
- function _admin_init_action() {
7540
- $is_migration = $this->is_migration();
7541
-
7542
- /**
7543
- * Automatically redirect to connect/activation page after plugin activation.
7544
- *
7545
- * @since 1.1.7 Do NOT redirect to opt-in when running in network admin mode.
7546
- */
7547
- if ( $this->is_plugin_activation() ) {
7548
- delete_transient( "fs_{$this->_module_type}_{$this->_slug}_activated" );
7549
-
7550
- if ( isset( $_GET['activate-multi'] ) ) {
7551
- /**
7552
- * Don't redirect if activating multiple plugins at once (bulk activation).
7553
- */
7554
- } else if (
7555
- self::is_deactivation_snoozed() &&
7556
- (
7557
- // Either running the free code base.
7558
- ! $this->is_premium() ||
7559
- // Or if has a free version.
7560
- ! $this->is_only_premium() ||
7561
- // If premium only, don't redirect if license is activated.
7562
- ( $this->is_registered() && ! $this->can_use_premium_code() )
7563
- )
7564
- ) {
7565
- /**
7566
- * Don't redirect if activating during the deactivation snooze period (aka troubleshooting), unless activating a paid product version that the admin didn't enter its license key yet.
7567
- */
7568
- } else if ( ! $is_migration ) {
7569
- $this->_redirect_on_activation_hook();
7570
- return;
7571
- }
7572
- }
7573
-
7574
- if ( $is_migration ) {
7575
- return;
7576
- }
7577
-
7578
- if ( fs_request_is_action( $this->get_unique_affix() . '_skip_activation' ) ) {
7579
- check_admin_referer( $this->get_unique_affix() . '_skip_activation' );
7580
-
7581
- $this->skip_connection( null, fs_is_network_admin() );
7582
-
7583
- fs_redirect( $this->get_after_activation_url( 'after_skip_url' ) );
7584
- }
7585
-
7586
- if ( $this->is_network_activation_mode() &&
7587
- fs_request_is_action( $this->get_unique_affix() . '_delegate_activation' )
7588
- ) {
7589
- check_admin_referer( $this->get_unique_affix() . '_delegate_activation' );
7590
-
7591
- $this->delegate_connection();
7592
-
7593
- fs_redirect( $this->get_after_activation_url( 'after_delegation_url' ) );
7594
- }
7595
-
7596
- $this->_add_upgrade_action_link();
7597
-
7598
- if ( ! ( ! $this->_is_network_active && fs_is_network_admin() ) &&
7599
- (
7600
- ( true === $this->_storage->require_license_activation ) ||
7601
- // Not registered nor anonymous.
7602
- ( ! $this->is_registered() && ! $this->is_anonymous() ) ||
7603
- // OR, network level and in network upgrade mode.
7604
- ( fs_is_network_admin() && $this->_is_network_active && $this->is_network_upgrade_mode() )
7605
- )
7606
- ) {
7607
- if ( ! $this->is_pending_activation() ) {
7608
- if ( ! $this->is_activation_page() ) {
7609
- /**
7610
- * If a user visits any other admin page before activating the premium-only theme with a valid
7611
- * license, reactivate the previous theme.
7612
- *
7613
- * @author Leo Fajardo (@leorw)
7614
- * @since 1.2.2
7615
- */
7616
- if ( $this->is_theme() &&
7617
- ! $this->has_settings_menu() &&
7618
- ! isset( $_REQUEST['fs_action'] ) &&
7619
- $this->can_activate_previous_theme()
7620
- ) {
7621
- if ( $this->is_only_premium() ) {
7622
- $this->activate_previous_theme();
7623
- return;
7624
- }
7625
-
7626
- if ( true === $this->_storage->require_license_activation ) {
7627
- $this->_storage->require_license_activation = false;
7628
- }
7629
- }
7630
-
7631
- if ( ! fs_is_network_admin() &&
7632
- $this->is_network_activation_mode() &&
7633
- ! $this->is_delegated_connection()
7634
- ) {
7635
- return;
7636
- }
7637
-
7638
- if ( $this->is_plugin_new_install() || $this->is_only_premium() ) {
7639
- if ( ! $this->_anonymous_mode &&
7640
- ( ! $this->is_addon() || ! $this->_parent->is_anonymous() ) ) {
7641
- // Show notice for new plugin installations.
7642
- $this->_admin_notices->add(
7643
- sprintf(
7644
- $this->get_text_inline( 'You are just one step away - %s', 'you-are-step-away' ),
7645
- sprintf( '<b><a href="%s">%s</a></b>',
7646
- $this->get_activation_url( array(), ! $this->is_delegated_connection() ),
7647
- sprintf( $this->get_text_x_inline( 'Complete "%s" Activation Now',
7648
- '%s - plugin name. As complete "PluginX" activation now', 'activate-x-now' ), $this->get_plugin_name() )
7649
- )
7650
- ),
7651
- '',
7652
- 'update-nag'
7653
- );
7654
- }
7655
- } else {
7656
- if ( $this->should_add_sticky_optin_notice() ) {
7657
- $this->add_sticky_optin_admin_notice();
7658
- }
7659
-
7660
- if ( $this->has_filter( 'optin_pointer_element' ) ) {
7661
- // Don't show admin nag if plugin update.
7662
- wp_enqueue_script( 'wp-pointer' );
7663
- wp_enqueue_style( 'wp-pointer' );
7664
-
7665
- $this->_enqueue_connect_essentials();
7666
-
7667
- add_action( 'admin_print_footer_scripts', array(
7668
- $this,
7669
- '_add_connect_pointer_script'
7670
- ) );
7671
- }
7672
- }
7673
- }
7674
- }
7675
-
7676
- if ( $this->show_opt_in_on_themes_page() &&
7677
- $this->is_activation_page()
7678
- ) {
7679
- $this->_show_theme_activation_optin_dialog();
7680
- }
7681
- }
7682
- }
7683
-
7684
- /**
7685
- * @author Vova Feldman (@svovaf)
7686
- * @since 2.0.0
7687
- *
7688
- * @return bool
7689
- */
7690
- private function should_add_sticky_optin_notice() {
7691
- if ( $this->is_addon() && $this->_parent->is_anonymous() ) {
7692
- return false;
7693
- }
7694
-
7695
- if ( fs_is_network_admin() ) {
7696
- if ( ! $this->_is_network_active ) {
7697
- return false;
7698
- }
7699
-
7700
- if ( ! $this->is_network_activation_mode() ) {
7701
- return false;
7702
- }
7703
-
7704
- return ! isset( $this->_storage->sticky_optin_added_ms );
7705
- }
7706
-
7707
- if ( ! $this->is_activation_mode() ) {
7708
- return false;
7709
- }
7710
-
7711
- // If running from a blog admin and delegated the connection.
7712
- return ! isset( $this->_storage->sticky_optin_added );
7713
- }
7714
-
7715
- /**
7716
- * @author Leo Fajardo (@leorw)
7717
- * @since 2.0.0
7718
- */
7719
- private function add_sticky_optin_admin_notice() {
7720
- if ( ! $this->_is_network_active || ! fs_is_network_admin() ) {
7721
- $this->_storage->sticky_optin_added = true;
7722
- } else {
7723
- $this->_storage->sticky_optin_added_ms = true;
7724
- }
7725
-
7726
- // Show notice for new plugin installations.
7727
- $this->_admin_notices->add_sticky(
7728
- sprintf(
7729
- $this->get_text_inline( 'We made a few tweaks to the %s, %s', 'few-plugin-tweaks' ),
7730
- $this->_module_type,
7731
- sprintf( '<b><a href="%s">%s</a></b>',
7732
- $this->get_activation_url(),
7733
- sprintf( $this->get_text_inline( 'Opt in to make "%s" better!', 'optin-x-now' ), $this->get_plugin_name() )
7734
- )
7735
- ),
7736
- 'connect_account',
7737
- '',
7738
- 'update-nag'
7739
- );
7740
- }
7741
-
7742
- /**
7743
- * Enqueue connect requires scripts and styles.
7744
- *
7745
- * @author Vova Feldman (@svovaf)
7746
- * @since 1.1.4
7747
- */
7748
- function _enqueue_connect_essentials() {
7749
- wp_enqueue_script( 'jquery' );
7750
- wp_enqueue_script( 'json2' );
7751
-
7752
- fs_enqueue_local_script( 'postmessage', 'nojquery.ba-postmessage.min.js' );
7753
- fs_enqueue_local_script( 'fs-postmessage', 'postmessage.js' );
7754
- }
7755
-
7756
- /**
7757
- * Add connect / opt-in pointer.
7758
- *
7759
- * @author Vova Feldman (@svovaf)
7760
- * @since 1.1.4
7761
- */
7762
- function _add_connect_pointer_script() {
7763
- $vars = array( 'id' => $this->_module_id );
7764
- $pointer_content = fs_get_template( 'connect.php', $vars );
7765
- ?>
7766
- <script type="text/javascript">// <![CDATA[
7767
- jQuery(document).ready(function ($) {
7768
- if ('undefined' !== typeof(jQuery().pointer)) {
7769
-
7770
- var element = <?php echo $this->apply_filters( 'optin_pointer_element', '$("#non_existing_element");' ) ?>;
7771
-
7772
- if (element.length > 0) {
7773
- var optin = $(element).pointer($.extend(true, {}, {
7774
- content : <?php echo json_encode( $pointer_content ) ?>,
7775
- position : {
7776
- edge : 'left',
7777
- align: 'center'
7778
- },
7779
- buttons : function () {
7780
- // Don't show pointer buttons.
7781
- return '';
7782
- },
7783
- pointerWidth: 482
7784
- }, <?php echo $this->apply_filters( 'optin_pointer_options_json', '{}' ) ?>));
7785
-
7786
- <?php
7787
- echo $this->apply_filters( 'optin_pointer_execute', "
7788
-
7789
- optin.pointer('open');
7790
-
7791
- // Tag the opt-in pointer with custom class.
7792
- $('.wp-pointer #fs_connect')
7793
- .parents('.wp-pointer.wp-pointer-top')
7794
- .addClass('fs-opt-in-pointer');
7795
-
7796
- ", 'element', 'optin' ) ?>
7797
- }
7798
- }
7799
- });
7800
- // ]]></script>
7801
- <?php
7802
- }
7803
-
7804
- /**
7805
- * Return current page's URL.
7806
- *
7807
- * @author Vova Feldman (@svovaf)
7808
- * @since 1.0.7
7809
- *
7810
- * @return string
7811
- */
7812
- function current_page_url() {
7813
- $url = 'http';
7814
-
7815
- if ( isset( $_SERVER["HTTPS"] ) ) {
7816
- if ( $_SERVER["HTTPS"] == "on" ) {
7817
- $url .= "s";
7818
- }
7819
- }
7820
- $url .= "://";
7821
- if ( $_SERVER["SERVER_PORT"] != "80" ) {
7822
- $url .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
7823
- } else {
7824
- $url .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
7825
- }
7826
-
7827
- return esc_url( $url );
7828
- }
7829
-
7830
- /**
7831
- * Check if the current page is the plugin's main admin settings page.
7832
- *
7833
- * @author Vova Feldman (@svovaf)
7834
- * @since 1.0.7
7835
- *
7836
- * @return bool
7837
- */
7838
- function _is_plugin_page() {
7839
- return fs_is_plugin_page( $this->_menu->get_raw_slug() ) ||
7840
- fs_is_plugin_page( $this->_slug );
7841
- }
7842
-
7843
- /* Events
7844
- ------------------------------------------------------------------------------------------------------------------*/
7845
- /**
7846
- * Delete site install from Database.
7847
- *
7848
- * @author Vova Feldman (@svovaf)
7849
- * @since 1.0.1
7850
- *
7851
- * @param bool $store
7852
- * @param int|null $blog_id Since 2.0.0
7853
- *
7854
- * @return false|int The install ID if deleted. Otherwise, FALSE (when install not exist).
7855
- */
7856
- function _delete_site( $store = true, $blog_id = null ) {
7857
- return self::_delete_site_by_slug( $this->_slug, $this->_module_type, $store, $blog_id );
7858
- }
7859
-
7860
- /**
7861
- * Delete site install from Database.
7862
- *
7863
- * @author Vova Feldman (@svovaf)
7864
- * @since 1.2.2.7
7865
- *
7866
- * @param string $slug
7867
- * @param string $module_type
7868
- * @param bool $store
7869
- * @param int|null $blog_id Since 2.0.0
7870
- *
7871
- * @return false|int The install ID if deleted. Otherwise, FALSE (when install not exist).
7872
- */
7873
- static function _delete_site_by_slug( $slug, $module_type, $store = true, $blog_id = null ) {
7874
- $sites = self::get_all_sites( $module_type, $blog_id );
7875
-
7876
- $install_id = false;
7877
-
7878
- if ( isset( $sites[ $slug ] ) ) {
7879
- if ( is_object( $sites[ $slug ] ) ) {
7880
- $install_id = $sites[ $slug ]->id;
7881
- }
7882
-
7883
- unset( $sites[ $slug ] );
7884
-
7885
- self::set_account_option_by_module( $module_type, 'sites', $sites, $store, $blog_id );
7886
- }
7887
-
7888
- return $install_id;
7889
- }
7890
-
7891
- /**
7892
- * Delete user.
7893
- *
7894
- * @author Vova Feldman (@svovaf)
7895
- * @since 2.0.0
7896
- *
7897
- * @param number $user_id
7898
- * @param bool $store
7899
- *
7900
- * @return false|int The user ID if deleted. Otherwise, FALSE (when install not exist).
7901
- */
7902
- private static function delete_user( $user_id, $store = true ) {
7903
- $users = self::get_all_users();
7904
-
7905
- if ( ! is_array( $users ) || ! isset( $users[ $user_id ] ) ) {
7906
- return false;
7907
- }
7908
-
7909
- unset( $users[ $user_id ] );
7910
-
7911
- self::$_accounts->set_option( 'users', $users, $store );
7912
-
7913
- return $user_id;
7914
- }
7915
-
7916
- /**
7917
- * Delete plugin's plans information.
7918
- *
7919
- * @param bool $store Flush to Database if true.
7920
- * @param bool $keep_associated_plans If set to false, delete all plans, even if a plan is associated with an install.
7921
- *
7922
- * @author Vova Feldman (@svovaf)
7923
- * @since 1.0.9
7924
- */
7925
- private function _delete_plans( $store = true, $keep_associated_plans = true ) {
7926
- $this->_logger->entrance();
7927
-
7928
- $plans = self::get_all_plans( $this->_module_type );
7929
-
7930
- $plans_to_keep = array();
7931
-
7932
- if ( $keep_associated_plans ) {
7933
- $plans_ids_to_keep = $this->get_plans_ids_associated_with_installs();
7934
- foreach ( $plans_ids_to_keep as $plan_id ) {
7935
- $plan = self::_get_plan_by_id( $plan_id );
7936
- if ( is_object( $plan ) ) {
7937
- $plans_to_keep[] = self::_encrypt_entity( $plan );
7938
- }
7939
- }
7940
- }
7941
-
7942
- if ( ! empty( $plans_to_keep ) ) {
7943
- $plans[ $this->_slug ] = $plans_to_keep;
7944
- } else {
7945
- unset( $plans[ $this->_slug ] );
7946
- }
7947
-
7948
- $this->set_account_option( 'plans', $plans, $store );
7949
- }
7950
-
7951
- /**
7952
- * Delete all plugin licenses.
7953
- *
7954
- * @author Vova Feldman (@svovaf)
7955
- * @since 1.0.9
7956
- *
7957
- * @param bool $store
7958
- */
7959
- private function _delete_licenses( $store = true ) {
7960
- $this->_logger->entrance();
7961
-
7962
- $all_licenses = self::get_all_licenses();
7963
-
7964
- unset( $all_licenses[ $this->_module_id ] );
7965
-
7966
- self::$_accounts->set_option( 'all_licenses', $all_licenses, $store );
7967
- }
7968
-
7969
- /**
7970
- * Check if Freemius was added on new plugin installation.
7971
- *
7972
- * @author Vova Feldman (@svovaf)
7973
- * @since 1.1.5
7974
- *
7975
- * @return bool
7976
- */
7977
- function is_plugin_new_install() {
7978
- return isset( $this->_storage->is_plugin_new_install ) &&
7979
- $this->_storage->is_plugin_new_install;
7980
- }
7981
-
7982
- /**
7983
- * Check if it's the first plugin release that is running Freemius.
7984
- *
7985
- * @author Vova Feldman (@svovaf)
7986
- * @since 1.2.1.5
7987
- *
7988
- * @return bool
7989
- */
7990
- function is_first_freemius_powered_version() {
7991
- return empty( $this->_storage->plugin_last_version );
7992
- }
7993
-
7994
- /**
7995
- * @author Leo Fajardo (@leorw)
7996
- * @since 1.2.2
7997
- *
7998
- * @return bool|string
7999
- */
8000
- private function get_previous_theme_slug() {
8001
- return isset( $this->_storage->previous_theme ) ?
8002
- $this->_storage->previous_theme :
8003
- false;
8004
- }
8005
-
8006
- /**
8007
- * @author Leo Fajardo (@leorw)
8008
- * @since 1.2.2
8009
- *
8010
- * @return string
8011
- */
8012
- private function can_activate_previous_theme() {
8013
- $slug = $this->get_previous_theme_slug();
8014
- if ( false !== $slug && current_user_can( 'switch_themes' ) ) {
8015
- $theme_instance = wp_get_theme( $slug );
8016
-
8017
- return $theme_instance->exists();
8018
- }
8019
-
8020
- return false;
8021
- }
8022
-
8023
- /**
8024
- * @author Leo Fajardo (@leorw)
8025
- * @since 1.2.2
8026
- */
8027
- private function activate_previous_theme() {
8028
- switch_theme( $this->get_previous_theme_slug() );
8029
- unset( $this->_storage->previous_theme );
8030
-
8031
- global $pagenow;
8032
- if ( 'themes.php' === $pagenow ) {
8033
- /**
8034
- * Refresh the active theme information.
8035
- *
8036
- * @author Leo Fajardo (@leorw)
8037
- * @since 1.2.2
8038
- */
8039
- fs_redirect( $this->admin_url( $pagenow ) );
8040
- }
8041
- }
8042
-
8043
- /**
8044
- * @author Leo Fajardo (@leorw)
8045
- * @since 1.2.2
8046
- *
8047
- * @return string
8048
- */
8049
- function get_previous_theme_activation_url() {
8050
- if ( ! $this->can_activate_previous_theme() ) {
8051
- return '';
8052
- }
8053
-
8054
- /**
8055
- * Activation URL
8056
- *
8057
- * @author Leo Fajardo (@leorw)
8058
- * @since 1.2.2
8059
- */
8060
- return wp_nonce_url(
8061
- $this->admin_url( 'themes.php?action=activate&stylesheet=' . urlencode( $this->get_previous_theme_slug() ) ),
8062
- 'switch-theme_' . $this->get_previous_theme_slug()
8063
- );
8064
- }
8065
-
8066
- /**
8067
- * Saves the slug of the previous theme if it still exists so that it can be used by the logic in the opt-in
8068
- * form that decides whether to add a close button to the opt-in dialog or not. So after a premium-only theme is
8069
- * activated, the close button will appear and will reactivate the previous theme if clicked. If the previous
8070
- * theme doesn't exist, then there will be no close button.
8071
- *
8072
- * @author Leo Fajardo (@leorw)
8073
- * @since 1.2.2
8074
- *
8075
- * @param string $slug_or_name Old theme's slug or name.
8076
- * @param bool|WP_Theme $old_theme WP_Theme instance of the old theme if it still exists.
8077
- */
8078
- function _activate_theme_event_hook( $slug_or_name, $old_theme = false ) {
8079
- $this->_storage->previous_theme = ( false !== $old_theme ) ?
8080
- $old_theme->get_stylesheet() :
8081
- $slug_or_name;
8082
-
8083
- $this->_activate_plugin_event_hook();
8084
- }
8085
-
8086
- /**
8087
- * Plugin activated hook.
8088
- *
8089
- * @author Vova Feldman (@svovaf)
8090
- * @since 1.0.1
8091
- *
8092
- * @uses FS_Api
8093
- */
8094
- function _activate_plugin_event_hook() {
8095
- $this->_logger->entrance( 'slug = ' . $this->_slug );
8096
-
8097
- if ( ! $this->is_user_admin() ) {
8098
- return;
8099
- }
8100
-
8101
- $this->unregister_uninstall_hook();
8102
-
8103
- // Clear API cache on activation.
8104
- FS_Api::clear_cache();
8105
-
8106
- $is_premium_version_activation = $this->is_plugin() ?
8107
- ( current_filter() !== ( 'activate_' . $this->_free_plugin_basename ) ) :
8108
- $this->is_premium();
8109
-
8110
- $this->_logger->info( 'Activating ' . ( $is_premium_version_activation ? 'premium' : 'free' ) . ' plugin version.' );
8111
-
8112
- if ( $this->is_plugin() ) {
8113
- // This logic is relevant only to plugins since both the free and premium versions of a plugin can be active at the same time.
8114
- // 1. If running in the activation of the FREE module, get the basename of the PREMIUM.
8115
- // 2. If running in the activation of the PREMIUM module, get the basename of the FREE.
8116
- $other_version_basename = $is_premium_version_activation ?
8117
- $this->_free_plugin_basename :
8118
- $this->premium_plugin_basename();
8119
-
8120
- if ( ! $this->_is_network_active ) {
8121
- /**
8122
- * Themes are always network activated, but the ACTUAL activation is per site.
8123
- *
8124
- * During the activation, the plugin isn't yet active, therefore,
8125
- * _is_network_active will be set to false even if it's a network level
8126
- * activation. So we need to fix that by looking at the is_network_admin() value.
8127
- *
8128
- * @author Vova Feldman
8129
- */
8130
- $this->_is_network_active = (
8131
- $this->_is_multisite_integrated &&
8132
- fs_is_network_admin()
8133
- );
8134
- }
8135
-
8136
- /**
8137
- * If the other module version is active, deactivate it.
8138
- *
8139
- * is_plugin_active() checks if the plugin is active on the site or the network level and
8140
- * deactivate_plugins() deactivates the plugin whether it's activated on the site or network level.
8141
- *
8142
- * @author Leo Fajardo (@leorw)
8143
- * @since 1.2.2
8144
- */
8145
- if (
8146
- is_plugin_active( $other_version_basename ) &&
8147
- $this->apply_filters( 'deactivate_on_activation', true )
8148
- ) {
8149
- deactivate_plugins( $other_version_basename );
8150
- }
8151
- }
8152
-
8153
- if ( $this->is_registered() ) {
8154
- if ( $is_premium_version_activation ) {
8155
- $this->reconnect_locally();
8156
- }
8157
-
8158
-
8159
- // Schedule re-activation event and sync.
8160
- // $this->sync_install( array(), true );
8161
- $this->schedule_install_sync();
8162
-
8163
- // If activating the premium module version, add an admin notice to congratulate for an upgrade completion.
8164
- if ( $is_premium_version_activation ) {
8165
- $this->_admin_notices->add(
8166
- sprintf( $this->get_text_inline( 'The upgrade of %s was successfully completed.', 'successful-version-upgrade-message' ), sprintf( '<b>%s</b>', $this->_plugin->title ) ),
8167
- $this->get_text_x_inline( 'W00t',
8168
- 'Used to express elation, enthusiasm, or triumph (especially in electronic communication).', 'woot' ) . '!'
8169
- );
8170
- }
8171
- } else if ( $this->is_anonymous() ) {
8172
- if ( isset( $this->_storage->is_anonymous_ms ) && $this->_storage->is_anonymous_ms['is'] ) {
8173
- $plugin_version = $this->_storage->is_anonymous_ms['version'];
8174
- $network = true;
8175
- } else {
8176
- $plugin_version = isset( $this->_storage->is_anonymous ) ?
8177
- $this->_storage->is_anonymous['version'] :
8178
- null;
8179
- $network = false;
8180
- }
8181
-
8182
- /**
8183
- * Reset "skipped" click cache on the following:
8184
- * 1. Freemius DEV mode.
8185
- * 2. WordPress DEBUG mode.
8186
- * 3. If a plugin and the user skipped the exact same version before.
8187
- *
8188
- * @since 1.2.2.7 Ulrich Pogson (@grapplerulrich) asked to not reset the SKIPPED flag if the exact same THEME version was activated before unless the developer is running with WP_DEBUG on, or Freemius debug mode on (WP_FS__DEV_MODE).
8189
- *
8190
- * @todo 4. If explicitly asked to retry after every activation.
8191
- */
8192
- if ( WP_FS__DEV_MODE ||
8193
- (
8194
- ( $this->is_plugin() || ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ) &&
8195
- $this->get_plugin_version() == $plugin_version
8196
- )
8197
- ) {
8198
- $this->reset_anonymous_mode( $network );
8199
- }
8200
- }
8201
-
8202
- $is_trial_or_has_features_enabled_license = ( $this->is_trial() || $this->has_features_enabled_license() );
8203
-
8204
- if ( $this->is_addon() && ! $is_trial_or_has_features_enabled_license ) {
8205
- /**
8206
- * When activating an add-on, try to also activate a license.
8207
- *
8208
- * @author Leo Fajardo (@leorw)
8209
- * @since 2.3.0
8210
- */
8211
- if ( ! $this->_is_network_active ) {
8212
- $this->maybe_activate_addon_license();
8213
- } else {
8214
- $this->maybe_network_activate_addon_license();
8215
- }
8216
-
8217
- /**
8218
- * Avoid redirecting to the license activation screen after automatically activating an add-on license.
8219
- *
8220
- * @author Leo Fajardo (@leorw)
8221
- * @since 2.3.0
8222
- */
8223
- $is_trial_or_has_features_enabled_license = ( $this->is_trial() || $this->has_features_enabled_license() );
8224
-
8225
- if ( $is_trial_or_has_features_enabled_license && true === $this->_storage->require_license_activation ) {
8226
- $this->_storage->require_license_activation = false;
8227
- }
8228
- }
8229
-
8230
- if (
8231
- $is_premium_version_activation &&
8232
- (
8233
- ( ! $this->is_registered() && $this->is_anonymous() ) ||
8234
- (
8235
- $this->is_registered() &&
8236
- ! $is_trial_or_has_features_enabled_license
8237
- )
8238
- )
8239
- ) {
8240
- $this->_storage->require_license_activation = true;
8241
- }
8242
-
8243
- if ( ! isset( $this->_storage->is_plugin_new_install ) ) {
8244
- /**
8245
- * If no previous version of plugin's version exist, it means that it's either
8246
- * the first time that the plugin installed on the site, or the plugin was installed
8247
- * before but didn't have Freemius integrated.
8248
- *
8249
- * Since register_activation_hook() do NOT fires on updates since 3.1, and only fires
8250
- * on manual activation via the dashboard, is_plugin_activation() is TRUE
8251
- * only after immediate activation.
8252
- *
8253
- * @since 1.1.4
8254
- * @link https://make.wordpress.org/core/2010/10/27/plugin-activation-hooks-no-longer-fire-for-updates/
8255
- */
8256
- $this->_storage->is_plugin_new_install = empty( $this->_storage->plugin_last_version );
8257
- }
8258
-
8259
- /**
8260
- * Also flush when activating the premium version so that even if Freemius was off before, the API
8261
- * connectivity test can be run again.
8262
- *
8263
- * @author Leo Fajardo (@leorw)
8264
- * @since 2.2.3.1
8265
- */
8266
- $has_api_connectivity = $this->has_api_connectivity( WP_FS__DEV_MODE || $is_premium_version_activation );
8267
-
8268
- if ( ! $this->_anonymous_mode &&
8269
- $has_api_connectivity &&
8270
- ! $this->_isAutoInstall
8271
- ) {
8272
- // Store hint that the plugin was just activated to enable auto-redirection to settings.
8273
- set_transient( "fs_{$this->_module_type}_{$this->_slug}_activated", true, 60 );
8274
- }
8275
-
8276
- /**
8277
- * Activation hook is executed after the plugin's main file is loaded, therefore,
8278
- * after the plugin was loaded. The logic is located at activate_plugin()
8279
- * ./wp-admin/includes/plugin.php.
8280
- *
8281
- * @author Vova Feldman (@svovaf)
8282
- * @since 1.1.9
8283
- */
8284
- $this->_storage->was_plugin_loaded = true;
8285
- }
8286
-
8287
- /**
8288
- * @author Leo Fajardo (@leorw)
8289
- * @since 2.3.0
8290
- */
8291
- private function maybe_activate_addon_license() {
8292
- $parent_fs = $this->get_parent_instance();
8293
-
8294
- if (
8295
- ! is_object( $parent_fs ) ||
8296
- ( ! $parent_fs->is_registered() && ! $parent_fs->is_network_registered() )
8297
- ) {
8298
- // Try to activate a license only if the parent plugin is active and has a valid `install`.
8299
- return;
8300
- }
8301
-
8302
- $license = $this->get_active_parent_license();
8303
- if ( ! is_object( $license ) ) {
8304
- return;
8305
- }
8306
-
8307
- if (
8308
- $this->is_bundle_license_auto_activation_enabled() &&
8309
- ! empty( $license->products )
8310
- ) {
8311
- $this->activate_bundle_license( $license );
8312
-
8313
- return;
8314
- }
8315
-
8316
- if ( ! $this->is_registered() ) {
8317
- // Opt in with a license key.
8318
- $this->opt_in(
8319
- $parent_fs->get_current_or_network_user()->email,
8320
- false,
8321
- false,
8322
- $license->secret_key
8323
- );
8324
- } else {
8325
- // Activate the license.
8326
- $install = $this->api_site_call(
8327
- '/',
8328
- 'put',
8329
- array( 'license_key' => $this->apply_filters( 'license_key', $license->secret_key ) )
8330
- );
8331
-
8332
- if ( ! FS_Api::is_api_error( $install ) ) {
8333
- $this->_sync_addon_license( $this->get_id(), true );
8334
- }
8335
- }
8336
- }
8337
-
8338
- /**
8339
- * @author Leo Fajardo (@leorw)
8340
- * @since 2.3.0
8341
- *
8342
- * @param FS_Plugin_License $license
8343
- */
8344
- private function maybe_network_activate_addon_license( $license = null ) {
8345
- $parent_fs = $this->get_parent_instance();
8346
- if ( ! is_object( $parent_fs ) || ( ! $parent_fs->is_registered() && ! $parent_fs->is_network_registered() ) ) {
8347
- // Try to activate a license only if the parent plugin is active and has a valid `install`.
8348
- return;
8349
- }
8350
-
8351
- $license = ( ! is_null( $license ) ) ?
8352
- $license :
8353
- $this->get_active_parent_license();
8354
-
8355
- if ( ! is_object( $license ) ) {
8356
- return;
8357
- }
8358
-
8359
- if (
8360
- $this->is_bundle_license_auto_activation_enabled() &&
8361
- ! empty( $license->products )
8362
- ) {
8363
- $this->activate_bundle_license( $license );
8364
-
8365
- return;
8366
- }
8367
-
8368
- if ( ! $this->is_network_registered() ) {
8369
- $sites = $this->get_sites_for_network_level_optin();
8370
-
8371
- if ( count( $sites ) > $license->left() ) {
8372
- // If the add-on is network active, try to activate the license only if it can be activated on all sites.
8373
- return;
8374
- }
8375
-
8376
- // Opt in with a license key.
8377
- $this->opt_in(
8378
- $parent_fs->get_user()->email,
8379
- false,
8380
- false,
8381
- $license->secret_key,
8382
- false,
8383
- false,
8384
- false,
8385
- null,
8386
- $sites
8387
- );
8388
- } else {
8389
- $blog_2_install_map = array();
8390
- $site_ids = array();
8391
-
8392
- $all_sites = Freemius::get_sites();
8393
-
8394
- foreach ( $all_sites as $site ) {
8395
- $blog_id = Freemius::get_site_blog_id( $site );
8396
- $install = $this->get_install_by_blog_id( $blog_id );
8397
-
8398
- if ( is_object( $install ) && FS_Plugin_License::is_valid_id( $install->license_id ) ) {
8399
- // Skip license activation for installs that are already associated with a license.
8400
- continue;
8401
- }
8402
-
8403
- if ( is_object( $install ) ) {
8404
- $blog_2_install_map[ $blog_id ] = $install;
8405
- } else {
8406
- $site_ids[] = $blog_id;
8407
- }
8408
- }
8409
-
8410
- if ( ( count( $blog_2_install_map ) + count( $site_ids ) ) > $license->left() ) {
8411
- return;
8412
- }
8413
-
8414
- $user = $this->get_current_or_network_user();
8415
-
8416
- if ( ! empty( $blog_2_install_map ) ) {
8417
- $result = $this->activate_license_on_many_installs( $user, $license->secret_key, $blog_2_install_map );
8418
-
8419
- if ( true !== $result ) {
8420
- return;
8421
- }
8422
- }
8423
-
8424
- if ( ! empty( $site_ids ) ) {
8425
- $this->activate_license_on_many_sites( $user, $license->secret_key, $site_ids );
8426
- }
8427
- }
8428
- }
8429
-
8430
- /**
8431
- * Tries to activate a bundle license for all supported products if the current product is activated with a bundle license. This is called after activating an available license (not via the license activation dialog but by clicking on a license activation button) for a product via its "Account" page.
8432
- *
8433
- * @author Leo Fajardo (@leorw)
8434
- * @since 2.4.0
8435
- *
8436
- * @param FS_Plugin_License $license
8437
- * @param array $sites
8438
- * @param int $blog_id
8439
- */
8440
- private function maybe_activate_bundle_license( FS_Plugin_License $license = null, $sites = array(), $blog_id = 0 ) {
8441
- if ( ! is_object( $license ) && $this->has_active_valid_license() ) {
8442
- $license = $this->_license;
8443
- }
8444
-
8445
- if ( ! is_object( $license ) ) {
8446
- return;
8447
- }
8448
-
8449
- $parent_license = ( ! empty( $license->products ) ) ?
8450
- $license :
8451
- $this->get_active_parent_license( $license->secret_key );
8452
-
8453
- if ( is_object( $parent_license ) ) {
8454
- $this->activate_bundle_license( $parent_license, $sites, $blog_id );
8455
- }
8456
- }
8457
-
8458
- /**
8459
- * Try to activate a bundle license for all the bundle products installed on the site.
8460
- * (1) If a child product install already has a license, the bundle license won't be activated.
8461
- * (2) On multi-site networks, if the attempt to activate the bundle license is triggered from the network admin, the bundle license activation will only work for non-delegated sites and only if none of them is associated with a license. Even if one of the sites has the product installed with a license key, skip the bundle license activation for the product.
8462
- * (3) On multi-site networks, if the attempt to activate the bundle license is triggered from a site-level admin, only activate the license if the product is site-level activated or delegated, and the product installation is not yet associated with a license.
8463
- *
8464
- * @author Leo Fajardo (@leorw)
8465
- * @since 2.4.0
8466
- *
8467
- * @param FS_Plugin_License $license
8468
- * @param array $sites
8469
- * @param int $current_blog_id
8470
- */
8471
- private function activate_bundle_license( $license, $sites = array(), $current_blog_id = 0 ) {
8472
- $is_network_admin = fs_is_network_admin();
8473
-
8474
- $installs_by_blog_map = array();
8475
- $site_info_by_blog_map = array();
8476
-
8477
- /**
8478
- * Try to activate the license for all supported products.
8479
- *
8480
- * @author Leo Fajardo
8481
- */
8482
- foreach ( $license->products as $product_id ) {
8483
- $fs = self::get_instance_by_id( $product_id );
8484
-
8485
- if ( ! is_object( $fs ) ) {
8486
- continue;
8487
- }
8488
-
8489
- if ( ! $fs->has_paid_plan() ) {
8490
- continue;
8491
- }
8492
-
8493
- if (
8494
- ! $fs->is_addon() &&
8495
- ! FS_Plan_Manager::instance()->has_paid_plan( $fs->_plans )
8496
- ) {
8497
- /**
8498
- * The parent product can be free-only but can have its `has_paid_plan` flag set to `true` when
8499
- * there is a context bundle.
8500
- */
8501
- continue;
8502
- }
8503
-
8504
- if ( $current_blog_id > 0 ) {
8505
- $fs->switch_to_blog( $current_blog_id );
8506
- }
8507
-
8508
- if ( $fs->has_active_valid_license() ) {
8509
- continue;
8510
- }
8511
-
8512
- if ( ! $is_network_admin || $current_blog_id > 0 ) {
8513
- if ( $fs->is_network_active() && ! $fs->is_delegated_connection( $current_blog_id ) ) {
8514
- // Do not try to activate the license in the site level if the product is network active and the connection was not delegated.
8515
- continue;
8516
- }
8517
- } else {
8518
- if ( ! $fs->is_network_active() ) {
8519
- // Do not try to activate the license in the network level if the product is not network active.
8520
- continue;
8521
- }
8522
-
8523
- if ( $fs->is_network_delegated_connection() ) {
8524
- // Do not try to activate the license in the network level if the activation has been delegated to site admins.
8525
- continue;
8526
- }
8527
-
8528
- $has_install_with_license = false;
8529
-
8530
- // Collection of sites that have an install entity that is not activated with a license or non-delegated sites that have no install entity, or both types of site.
8531
- $filtered_sites = array();
8532
-
8533
- if ( empty( $sites ) ) {
8534
- $all_sites = self::get_sites();
8535
-
8536
- foreach ( $all_sites as $site ) {
8537
- $sites[] = array( 'blog_id' => self::get_site_blog_id( $site ) );
8538
- }
8539
- } else {
8540
- // Populate the map here to avoid calling `$fs->get_site_info( $site );` in the other `for` loop below.
8541
- foreach ( $sites as $site ) {
8542
- if ( ! isset( $site['blog_id'] ) || ! is_numeric( $site['blog_id'] ) ) {
8543
- continue;
8544
- }
8545
-
8546
- $site_info_by_blog_map[ $site['blog_id'] ] = $site;
8547
- }
8548
- }
8549
-
8550
- foreach ( $sites as $site ) {
8551
- if ( ! isset( $site['blog_id'] ) || ! is_numeric( $site['blog_id'] ) ) {
8552
- continue;
8553
- }
8554
-
8555
- $blog_id = $site['blog_id'];
8556
-
8557
- if ( ! isset( $installs_by_blog_map[ $blog_id ] ) ) {
8558
- $installs_by_blog_map[ $blog_id ] = self::get_all_sites( $fs->get_module_type(), $blog_id );
8559
- }
8560
-
8561
- $installs = $installs_by_blog_map[ $blog_id ];
8562
- $install = null;
8563
-
8564
- if ( isset( $installs[ $fs->get_slug() ] ) ) {
8565
- $install = $installs[ $fs->get_slug() ];
8566
-
8567
- if (
8568
- is_object( $install ) &&
8569
- (
8570
- ! FS_Site::is_valid_id( $install->id ) ||
8571
- ! FS_User::is_valid_id( $install->user_id ) ||
8572
- ! FS_Plugin_Plan::is_valid_id( $install->plan_id )
8573
- )
8574
- ) {
8575
- $install = null;
8576
- }
8577
- }
8578
-
8579
- if (
8580
- is_object( $install ) &&
8581
- FS_Plugin_License::is_valid_id( $install->license_id )
8582
- ) {
8583
- $has_install_with_license = true;
8584
- break;
8585
- }
8586
-
8587
- if ( $fs->is_site_delegated_connection( $blog_id ) ) {
8588
- // Site activation delegated, don't activate bundle license on the site in the network admin.
8589
- continue;
8590
- }
8591
-
8592
- if ( ! isset( $site_info_by_blog_map[ $blog_id ] ) ) {
8593
- $site_info_by_blog_map[ $blog_id ] = $fs->get_site_info( $site );
8594
- }
8595
-
8596
- $filtered_sites[] = $site_info_by_blog_map[ $blog_id ];
8597
- }
8598
-
8599
- if ( $has_install_with_license || empty( $filtered_sites ) ) {
8600
- // Do not try to activate the license at the network level if there's any install with a license or there's no site to activate the license on.
8601
- continue;
8602
- }
8603
-
8604
- $sites = $filtered_sites;
8605
- }
8606
-
8607
- $fs->activate_migrated_license(
8608
- $license->secret_key,
8609
- null,
8610
- null,
8611
- $sites,
8612
- ( $current_blog_id > 0 ? $current_blog_id : null )
8613
- );
8614
- }
8615
- }
8616
-
8617
- /**
8618
- * Returns a parent license that can be activated for the context product.
8619
- *
8620
- * @author Leo Fajardo (@leorw)
8621
- * @since 2.3.0
8622
- *
8623
- * @param string|null $license_key
8624
- * @param bool $flush
8625
- *
8626
- * @return FS_Plugin_License
8627
- */
8628
- function get_active_parent_license( $license_key = null, $flush = true ) {
8629
- $parent_licenses_endpoint = "/plugins/{$this->get_id()}/parent_licenses.json?filter=activatable";
8630
-
8631
- $fs = $this;
8632
-
8633
- if ( $this->is_addon() ) {
8634
- $parent_instance = $this->get_parent_instance();
8635
-
8636
- if ( is_object( $parent_instance ) && $parent_instance->is_registered() ) {
8637
- $fs = $parent_instance;
8638
- }
8639
- }
8640
-
8641
- $foreign_licenses = $fs->get_foreign_licenses_info(
8642
- self::get_all_licenses( $this->get_parent_id() )
8643
- );
8644
-
8645
- if ( ! empty ( $foreign_licenses ) ) {
8646
- $foreign_licenses = array(
8647
- // Prefix with `+` to tell the server to include foreign licenses in the licenses collection.
8648
- 'ids' => ( urlencode( '+' ) . implode( ',', $foreign_licenses['ids'] ) ),
8649
- 'license_keys' => implode( ',', array_map( 'urlencode', $foreign_licenses['license_keys'] ) )
8650
- );
8651
-
8652
- $parent_licenses_endpoint = add_query_arg( $foreign_licenses, $parent_licenses_endpoint );
8653
- }
8654
-
8655
- $result = $fs->get_current_or_network_user_api_scope()->get( $parent_licenses_endpoint, $flush );
8656
-
8657
- if (
8658
- ! $this->is_api_result_object( $result, 'licenses' ) ||
8659
- ! is_array( $result->licenses ) ||
8660
- empty( $result->licenses )
8661
- ) {
8662
- return null;
8663
- }
8664
-
8665
- $parent_license = null;
8666
-
8667
- if ( empty( $license_key ) ) {
8668
- $parent_license = $result->licenses[0];
8669
- } else {
8670
- foreach ( $result->licenses as $license ) {
8671
- if ( $license_key === $license->secret_key ) {
8672
- $parent_license = $license;
8673
- break;
8674
- }
8675
- }
8676
- }
8677
-
8678
- if ( ! is_null( $parent_license ) ) {
8679
- $parent_license = new FS_Plugin_License( $parent_license );
8680
- }
8681
-
8682
- return $parent_license;
8683
- }
8684
-
8685
- /**
8686
- * @author Leo Fajardo (@leorw)
8687
- * @since 2.3.0
8688
- *
8689
- * @return array
8690
- */
8691
- function get_sites_for_network_level_optin() {
8692
- $sites = array();
8693
- $all_sites = self::get_sites();
8694
-
8695
- foreach ( $all_sites as $site ) {
8696
- $blog_id = self::get_site_blog_id( $site );
8697
-
8698
- if ( ! $this->is_site_delegated_connection( $blog_id ) &&
8699
- ! $this->is_installed_on_site( $blog_id )
8700
- ) {
8701
- $sites[] = $this->get_site_info( $site );
8702
- }
8703
- }
8704
-
8705
- return $sites;
8706
- }
8707
-
8708
- /**
8709
- * Delete account.
8710
- *
8711
- * @author Vova Feldman (@svovaf)
8712
- * @since 1.0.3
8713
- *
8714
- * @param bool $check_user Enforce checking if user have plugins activation privileges.
8715
- */
8716
- function delete_account_event( $check_user = true ) {
8717
- $this->_logger->entrance( 'slug = ' . $this->_slug );
8718
-
8719
- if ( $check_user && ! $this->is_user_admin() ) {
8720
- return;
8721
- }
8722
-
8723
- $this->do_action( 'before_account_delete' );
8724
-
8725
- // Clear all admin notices.
8726
- $this->_admin_notices->clear_all_sticky( false );
8727
-
8728
- $this->_delete_site( false );
8729
-
8730
- $delete_network_common_data = true;
8731
-
8732
- if ( $this->_is_network_active ) {
8733
- $installs = $this->get_blog_install_map();
8734
-
8735
- // Don't delete common network data unless no other installs left.
8736
- $delete_network_common_data = empty( $installs );
8737
- }
8738
-
8739
- if ( $delete_network_common_data ) {
8740
- $this->_delete_plans( false );
8741
-
8742
- $this->_delete_licenses( false );
8743
-
8744
- // Delete add-ons related to plugin's account.
8745
- $this->_delete_account_addons( false );
8746
- }
8747
-
8748
- // @todo Delete plans and licenses of add-ons.
8749
-
8750
- self::$_accounts->store();
8751
-
8752
- /**
8753
- * IMPORTANT:
8754
- * Clear crons must be executed before clearing all storage.
8755
- * Otherwise, the cron will not be cleared.
8756
- */
8757
- if ( $delete_network_common_data ) {
8758
- $this->clear_sync_cron();
8759
- }
8760
-
8761
- $this->clear_install_sync_cron();
8762
-
8763
- // Clear all storage data.
8764
- $this->_storage->clear_all( true, array(
8765
- 'is_delegated_connection',
8766
- 'connectivity_test',
8767
- 'is_on',
8768
- ), false );
8769
-
8770
- // Send delete event.
8771
- $this->get_api_site_scope()->call( '/', 'delete' );
8772
-
8773
- $this->do_action( 'after_account_delete' );
8774
- }
8775
-
8776
- /**
8777
- * Delete network level account.
8778
- *
8779
- * @author Vova Feldman (@svovaf)
8780
- * @since 2.0.0
8781
- *
8782
- * @param bool $check_user Enforce checking if user have plugins activation privileges.
8783
- */
8784
- function delete_network_account_event( $check_user = true ) {
8785
- $this->_logger->entrance( 'slug = ' . $this->_slug );
8786
-
8787
- if ( $check_user && ! $this->is_user_admin() ) {
8788
- return;
8789
- }
8790
-
8791
- $this->do_action( 'before_network_account_delete' );
8792
-
8793
- // Clear all admin notices.
8794
- $this->_admin_notices->clear_all_sticky();
8795
-
8796
- $this->_delete_plans( false, false );
8797
-
8798
- $this->_delete_licenses( false );
8799
-
8800
- // Delete add-ons related to plugin's account.
8801
- $this->_delete_account_addons( false );
8802
-
8803
- // @todo Delete plans and licenses of add-ons.
8804
-
8805
- self::$_accounts->store( true );
8806
-
8807
- /**
8808
- * IMPORTANT:
8809
- * Clear crons must be executed before clearing all storage.
8810
- * Otherwise, the cron will not be cleared.
8811
- */
8812
- $this->clear_sync_cron( true );
8813
- $this->clear_install_sync_cron( true );
8814
-
8815
- $sites = self::get_sites();
8816
-
8817
- $install_ids = array();
8818
- foreach ( $sites as $site ) {
8819
- $blog_id = self::get_site_blog_id( $site );
8820
-
8821
- if ( $this->is_site_delegated_connection( $blog_id ) ) {
8822
- continue;
8823
- }
8824
-
8825
- $install_id = $this->_delete_site( true, $blog_id );
8826
-
8827
- // Clear all storage data.
8828
- $this->_storage->clear_all( true, array( 'connectivity_test' ), $blog_id );
8829
-
8830
- if ( FS_Site::is_valid_id( $install_id ) ) {
8831
- $install_ids[] = $install_id;
8832
- }
8833
-
8834
- switch_to_blog( $blog_id );
8835
-
8836
- $this->do_action( 'after_account_delete' );
8837
-
8838
- restore_current_blog();
8839
- }
8840
-
8841
- $this->_storage->clear_all( true, array(
8842
- 'connectivity_test',
8843
- 'is_on',
8844
- ), true );
8845
-
8846
- // Send delete event.
8847
- if ( ! empty( $install_ids ) ) {
8848
- $result = $this->get_current_or_network_user_api_scope()->call( "/plugins/{$this->_module_id}/installs.json?ids=" . implode( ',', $install_ids ), 'delete' );
8849
- }
8850
-
8851
- $this->do_action( 'after_network_account_delete' );
8852
- }
8853
-
8854
- /**
8855
- * Plugin deactivation hook.
8856
- *
8857
- * @author Vova Feldman (@svovaf)
8858
- * @since 1.0.1
8859
- */
8860
- function _deactivate_plugin_hook() {
8861
- $this->_logger->entrance( 'slug = ' . $this->_slug );
8862
-
8863
- if ( ! $this->is_user_admin() ) {
8864
- return;
8865
- }
8866
-
8867
- $is_network_deactivation = fs_is_network_admin();
8868
- $storage_keys_for_removal = array();
8869
-
8870
- $this->_admin_notices->clear_all_sticky();
8871
-
8872
- $storage_keys_for_removal[] = 'sticky_optin_added';
8873
- if ( isset( $this->_storage->sticky_optin_added ) ) {
8874
- unset( $this->_storage->sticky_optin_added );
8875
- }
8876
-
8877
- if ( ! isset( $this->_storage->is_plugin_new_install ) ) {
8878
- // Remember that plugin was already installed.
8879
- $this->_storage->is_plugin_new_install = false;
8880
- }
8881
-
8882
- // Hook to plugin uninstall.
8883
- register_uninstall_hook( $this->_plugin_main_file_path, array( 'Freemius', '_uninstall_plugin_hook' ) );
8884
-
8885
- $this->clear_module_main_file_cache();
8886
- $this->clear_sync_cron( $this->_is_network_active );
8887
- $this->clear_install_sync_cron();
8888
-
8889
- if ( $this->is_registered() ) {
8890
- if ( $this->is_premium() && ! $this->has_active_valid_license() ) {
8891
- FS_Plugin_Updater::instance( $this )->delete_update_data();
8892
- }
8893
-
8894
- if ( $is_network_deactivation ) {
8895
- // Send deactivation event.
8896
- $this->sync_installs( array(
8897
- 'is_active' => false,
8898
- ) );
8899
- } else {
8900
- // Send deactivation event.
8901
- $this->sync_install( array(
8902
- 'is_active' => false,
8903
- ) );
8904
- }
8905
- } else {
8906
- if ( ! $this->has_api_connectivity() ) {
8907
- // Reset connectivity test cache.
8908
- unset( $this->_storage->connectivity_test );
8909
-
8910
- $storage_keys_for_removal[] = 'connectivity_test';
8911
- }
8912
- }
8913
-
8914
- if ( $is_network_deactivation ) {
8915
- if ( isset( $this->_storage->sticky_optin_added_ms ) ) {
8916
- unset( $this->_storage->sticky_optin_added_ms );
8917
- }
8918
-
8919
- if ( ! empty( $storage_keys_for_removal ) ) {
8920
- $sites = self::get_sites();
8921
-
8922
- foreach ( $sites as $site ) {
8923
- $blog_id = self::get_site_blog_id( $site );
8924
-
8925
- foreach ( $storage_keys_for_removal as $key ) {
8926
- $this->_storage->remove( $key, false, $blog_id );
8927
- }
8928
-
8929
- $this->_storage->save( $blog_id );
8930
- }
8931
- }
8932
- }
8933
-
8934
- // Clear API cache on deactivation.
8935
- FS_Api::clear_cache();
8936
-
8937
- $this->remove_sdk_reference();
8938
- }
8939
-
8940
- /**
8941
- * @author Vova Feldman (@svovaf)
8942
- * @since 1.1.6
8943
- */
8944
- private function remove_sdk_reference() {
8945
- global $fs_active_plugins;
8946
-
8947
- foreach ( $fs_active_plugins->plugins as $sdk_path => $data ) {
8948
- if ( $this->_plugin_basename == $data->plugin_path ) {
8949
- unset( $fs_active_plugins->plugins[ $sdk_path ] );
8950
- break;
8951
- }
8952
- }
8953
-
8954
- fs_fallback_to_newest_active_sdk();
8955
- }
8956
-
8957
- /**
8958
- * @author Vova Feldman (@svovaf)
8959
- * @since 1.1.3
8960
- *
8961
- * @param bool $is_anonymous
8962
- * @param bool|int $network_or_blog_id Since 2.0.0
8963
- */
8964
- private function set_anonymous_mode( $is_anonymous = true, $network_or_blog_id = 0 ) {
8965
- // Store information regarding skip to try and opt-in the user
8966
- // again in the future.
8967
- $skip_info = array(
8968
- 'is' => $is_anonymous,
8969
- 'timestamp' => WP_FS__SCRIPT_START_TIME,
8970
- 'version' => $this->get_plugin_version(),
8971
- );
8972
-
8973
- if ( true === $network_or_blog_id ) {
8974
- $this->_storage->is_anonymous_ms = $skip_info;
8975
- } else {
8976
- $this->_storage->store( 'is_anonymous', $skip_info, $network_or_blog_id );
8977
- }
8978
-
8979
- $this->network_upgrade_mode_completed();
8980
-
8981
- // Update anonymous mode cache.
8982
- $this->_is_anonymous = $is_anonymous;
8983
- }
8984
-
8985
- /**
8986
- * @author Vova Feldman (@svovaf)
8987
- * @since 2.0.0
8988
- *
8989
- * @param int $blog_id Site ID.
8990
- * @param int $user_id User ID.
8991
- * @param string $domain Site domain.
8992
- * @param string $path Site path.
8993
- * @param int $network_id Network ID. Only relevant on multi-network installations.
8994
- * @param array $meta Metadata. Used to set initial site options.
8995
- *
8996
- * @uses Freemius::is_license_network_active() to check if the context license was network activated by the super-admin.
8997
- * @uses Freemius::is_network_connected() to check if the super-admin network opted-in.
8998
- * @uses Freemius::is_network_anonymous() to check if the super-admin network skipped.
8999
- * @uses Freemius::is_network_delegated_connection() to check if the super-admin network delegated the connection to the site admins.
9000
- */
9001
- public function _after_new_blog_callback( $blog_id, $user_id, $domain, $path, $network_id, $meta ) {
9002
- $this->_logger->entrance();
9003
-
9004
- if ( ! $this->_is_network_active ) {
9005
- FS_Clone_Manager::instance()->store_new_blog_install_info( $blog_id );
9006
- return;
9007
- }
9008
-
9009
- $site = null;
9010
- $new_blog_id = $blog_id;
9011
-
9012
- if ( $this->is_premium() &&
9013
- $this->is_network_connected() &&
9014
- is_object( $this->_license ) &&
9015
- $this->_license->can_activate( FS_Site::is_localhost_by_address( $domain ) ) &&
9016
- $this->is_license_network_active( $blog_id )
9017
- ) {
9018
- /**
9019
- * Running the premium version, the license was network activated, and the license can also be activated on the current site -> so try to opt-in with the license key.
9020
- */
9021
- $current_blog_id = get_current_blog_id();
9022
- $license = clone $this->_license;
9023
-
9024
- $this->switch_to_blog( $blog_id );
9025
-
9026
- // Opt-in with network user.
9027
- $this->install_with_user(
9028
- $this->get_network_user(),
9029
- $license->secret_key,
9030
- false,
9031
- false,
9032
- false
9033
- );
9034
-
9035
- if ( is_object( $this->_site ) ) {
9036
- if ( $this->_site->license_id == $license->id ) {
9037
- /**
9038
- * If the license was activated successfully, sync the license data from the remote server.
9039
- */
9040
- $this->_license = $license;
9041
- $this->sync_site_license();
9042
- }
9043
- }
9044
-
9045
- $site = $this->_site;
9046
-
9047
- $this->switch_to_blog( $current_blog_id );
9048
-
9049
- if ( is_object( $site ) ) {
9050
- FS_Clone_Manager::instance()->store_new_blog_install_info( $blog_id, $site );
9051
-
9052
- // Already connected (with or without a license), so no need to continue.
9053
- return;
9054
- }
9055
- }
9056
-
9057
- if ( $this->is_network_anonymous() ) {
9058
- /**
9059
- * Opt-in was network skipped so automatically skip the opt-in for the new site.
9060
- */
9061
- $this->skip_site_connection( $blog_id );
9062
- } else if ( $this->is_network_delegated_connection() ) {
9063
- /**
9064
- * Opt-in was network delegated so automatically delegate the opt-in for the new site's admin.
9065
- */
9066
- $this->delegate_site_connection( $blog_id );
9067
- } else if ( $this->is_network_connected() ) {
9068
- /**
9069
- * Opt-in was network activated so automatically opt-in with the network user and new site admin.
9070
- */
9071
- $current_blog_id = get_current_blog_id();
9072
-
9073
- $this->switch_to_blog( $blog_id );
9074
-
9075
- // Opt-in with network user.
9076
- $this->install_with_user(
9077
- $this->get_network_user(),
9078
- false,
9079
- false,
9080
- false,
9081
- false
9082
- );
9083
-
9084
- $site = $this->_site;
9085
-
9086
- $this->switch_to_blog( $current_blog_id );
9087
- } else {
9088
- /**
9089
- * If the super-admin mixed different options (connect, skip, delegated):
9090
- * a) If at least one site connection was delegated, then automatically delegate connection.
9091
- * b) Otherwise, it means that at least one site was skipped and at least one site was connected. For a simplified UX in the initial release of the multisite network integration, skip the connection for the newly created site. If the super-admin will want to opt-in they can still do that from the network level Account page.
9092
- */
9093
- $has_delegated_site = false;
9094
-
9095
- $sites = self::get_sites();
9096
- foreach ( $sites as $wp_site ) {
9097
- $blog_id = self::get_site_blog_id( $wp_site );
9098
-
9099
- if ( $this->is_site_delegated_connection( $blog_id ) ) {
9100
- $has_delegated_site = true;
9101
- break;
9102
- }
9103
- }
9104
-
9105
- if ( $has_delegated_site ) {
9106
- $this->delegate_site_connection( $blog_id );
9107
- } else {
9108
- $this->skip_site_connection( $blog_id );
9109
- }
9110
- }
9111
-
9112
- /**
9113
- * Store the new blog's information even if there's no install so that when a clone install is stored in the new blog's storage, we can try to resolve it automatically.
9114
- *
9115
- * @author Leo Fajardo (@leorw)
9116
- * @since 2.5.0
9117
- */
9118
- FS_Clone_Manager::instance()->store_new_blog_install_info( $new_blog_id, $site );
9119
- }
9120
-
9121
- /**
9122
- * @author Vova Feldman (@svovaf)
9123
- * @since 2.5.0
9124
- *
9125
- * @param \WP_Site $new_site
9126
- * @param array $args
9127
- */
9128
- public function _after_wp_initialize_site_callback( WP_Site $new_site, $args ) {
9129
- $this->_logger->entrance();
9130
-
9131
- $this->_after_new_blog_callback(
9132
- $new_site->id,
9133
- // Dummy user ID (not in use).
9134
- 0,
9135
- $new_site->domain,
9136
- $new_site->path,
9137
- $new_site->network_id,
9138
- // Dummy meta, not in use.
9139
- array()
9140
- );
9141
- }
9142
-
9143
- /**
9144
- * @author Vova Feldman (@svovaf)
9145
- * @since 1.1.3
9146
- *
9147
- * @param bool|int $network_or_blog_id Since 2.0.0.
9148
- */
9149
- private function reset_anonymous_mode( $network_or_blog_id = 0 ) {
9150
- if ( true === $network_or_blog_id ) {
9151
- unset( $this->_storage->is_anonymous_ms );
9152
- } else {
9153
- $this->_storage->remove( 'is_anonymous', true, $network_or_blog_id );
9154
- }
9155
-
9156
- /**
9157
- * Ensure that this field is also "false", otherwise, if the current module's type is "theme" and the module
9158
- * has no menus, the opt-in popup will not be shown immediately (in this case, the user will have to click
9159
- * on the admin notice that contains the opt-in link in order to trigger the opt-in popup).
9160
- *
9161
- * @author Leo Fajardo (@leorw)
9162
- * @since 1.2.2
9163
- */
9164
- if ( ! $this->_is_network_active ||
9165
- 0 === $network_or_blog_id ||
9166
- get_current_blog_id() == $network_or_blog_id ||
9167
- ( true === $network_or_blog_id && fs_is_network_admin() )
9168
- ) {
9169
- $this->_is_anonymous = null;
9170
- }
9171
- }
9172
-
9173
- /**
9174
- * This is used to ensure that before redirecting to the opt-in page after resetting the anonymous mode or
9175
- * deleting the account in the network level, the URL of the page to redirect to is correct.
9176
- *
9177
- * @author Leo Fajardo (@leorw)
9178
- *
9179
- * @since 2.1.3
9180
- */
9181
- private function maybe_set_slug_and_network_menu_exists_flag() {
9182
- if ( ! empty( $this->_dynamically_added_top_level_page_hook_name ) ) {
9183
- $this->_menu->set_slug_and_network_menu_exists_flag( $this->_menu->has_menu() ?
9184
- $this->_menu->get_slug() :
9185
- $this->_slug
9186
- );
9187
- }
9188
- }
9189
-
9190
- /**
9191
- * Clears the anonymous mode and redirects to the opt-in screen.
9192
- *
9193
- * @author Vova Feldman (@svovaf)
9194
- * @since 1.1.7
9195
- */
9196
- function connect_again() {
9197
- if ( ! $this->is_anonymous() ) {
9198
- return;
9199
- }
9200
-
9201
- $this->reset_anonymous_mode( fs_is_network_admin() );
9202
-
9203
- $this->maybe_set_slug_and_network_menu_exists_flag();
9204
-
9205
- fs_redirect( $this->get_activation_url() );
9206
- }
9207
-
9208
- /**
9209
- * Skip account connect, and set anonymous mode.
9210
- *
9211
- * @author Vova Feldman (@svovaf)
9212
- * @since 1.1.1
9213
- *
9214
- * @param array|null $sites Since 2.0.0. Specific sites.
9215
- * @param bool $skip_all_network Since 2.0.0. If true, skip connection for all sites.
9216
- */
9217
- function skip_connection( $sites = null, $skip_all_network = false ) {
9218
- $this->_logger->entrance();
9219
-
9220
- $this->_admin_notices->remove_sticky( 'connect_account' );
9221
-
9222
- if ( $skip_all_network ) {
9223
- $this->set_anonymous_mode( true, true );
9224
- }
9225
-
9226
- if ( ! $skip_all_network && empty( $sites ) ) {
9227
- $this->skip_site_connection();
9228
- } else {
9229
- $uids = array();
9230
-
9231
- if ( $skip_all_network ) {
9232
- $this->set_anonymous_mode( true, true );
9233
-
9234
- $sites = self::get_sites();
9235
- foreach ( $sites as $site ) {
9236
- $blog_id = self::get_site_blog_id( $site );
9237
- $this->skip_site_connection( $blog_id, false );
9238
- $uids[] = $this->get_anonymous_id( $blog_id );
9239
- }
9240
- } else if ( ! empty( $sites ) ) {
9241
- foreach ( $sites as $site ) {
9242
- $uids[] = $site['uid'];
9243
- $this->skip_site_connection( $site['blog_id'], false );
9244
- }
9245
- }
9246
-
9247
- // Send anonymous skip event.
9248
- // No user identified info nor any tracking will be sent after the user skips the opt-in.
9249
- $this->get_api_plugin_scope()->call( 'skip.json', 'put', array(
9250
- 'uids' => $uids,
9251
- ) );
9252
- }
9253
-
9254
- $this->network_upgrade_mode_completed();
9255
- }
9256
-
9257
- /**
9258
- * Skip connection for specific site in the network.
9259
- *
9260
- * @author Vova Feldman (@svovaf)
9261
- * @since 2.0.0
9262
- *
9263
- * @param int|null $blog_id
9264
- * @param bool $send_skip
9265
- */
9266
- private function skip_site_connection( $blog_id = null, $send_skip = true ) {
9267
- $this->_logger->entrance();
9268
-
9269
- $this->_admin_notices->remove_sticky( 'connect_account', $blog_id );
9270
-
9271
- $this->set_anonymous_mode( true, $blog_id );
9272
-
9273
- if ( $send_skip ) {
9274
- $this->get_api_plugin_scope()->call( 'skip.json', 'put', array(
9275
- 'uids' => array( $this->get_anonymous_id( $blog_id ) ),
9276
- ) );
9277
- }
9278
- }
9279
-
9280
- /**
9281
- * Plugin version update hook.
9282
- *
9283
- * @author Vova Feldman (@svovaf)
9284
- * @since 1.0.4
9285
- */
9286
- private function update_plugin_version_event() {
9287
- $this->_logger->entrance();
9288
-
9289
- if ( ! $this->is_registered() ) {
9290
- return;
9291
- }
9292
-
9293
- $this->schedule_install_sync();
9294
- // $this->sync_install( array(), true );
9295
- }
9296
-
9297
- /**
9298
- * Generate an MD5 signature of a plugins collection.
9299
- * This helper methods used to identify changes in a plugins collection.
9300
- *
9301
- * @author Vova Feldman (@svovaf)
9302
- * @since 2.0.0
9303
- *
9304
- * @param array [string]array $plugins
9305
- *
9306
- * @return string
9307
- */
9308
- private function get_plugins_thumbprint( $plugins ) {
9309
- ksort( $plugins );
9310
-
9311
- $thumbprint = '';
9312
- foreach ( $plugins as $basename => $data ) {
9313
- $thumbprint .= $data['slug'] . ',' .
9314
- $data['Version'] . ',' .
9315
- ( $data['is_active'] ? '1' : '0' ) . ';';
9316
- }
9317
-
9318
- return md5( $thumbprint );
9319
- }
9320
-
9321
- /**
9322
- * Return a list of modified plugins since the last sync.
9323
- *
9324
- * Note:
9325
- * There's no point to store a plugins counter since even if the number of
9326
- * plugins didn't change, we still need to check if the versions are all the
9327
- * same and the activity state is similar.
9328
- *
9329
- * @author Vova Feldman (@svovaf)
9330
- * @since 1.1.8
9331
- *
9332
- * @return array|false
9333
- */
9334
- private function get_plugins_data_for_api() {
9335
- // Alias.
9336
- $site_active_plugins_option_name = 'active_plugins';
9337
- $network_plugins_option_name = 'all_plugins';
9338
-
9339
- /**
9340
- * Collection of all site level active plugins.
9341
- */
9342
- $site_active_plugins_cache = self::$_accounts->get_option( $site_active_plugins_option_name );
9343
-
9344
- if ( ! is_object( $site_active_plugins_cache ) ) {
9345
- $site_active_plugins_cache = (object) array(
9346
- 'timestamp' => '',
9347
- 'md5' => '',
9348
- 'plugins' => array(),
9349
- );
9350
- }
9351
-
9352
- $time = time();
9353
-
9354
- if ( ! empty( $site_active_plugins_cache->timestamp ) &&
9355
- ( $time - $site_active_plugins_cache->timestamp ) < WP_FS__TIME_5_MIN_IN_SEC
9356
- ) {
9357
- // Don't send plugin updates if last update was in the past 5 min.
9358
- return false;
9359
- }
9360
-
9361
- // Write timestamp to lock the logic.
9362
- $site_active_plugins_cache->timestamp = $time;
9363
- self::$_accounts->set_option( $site_active_plugins_option_name, $site_active_plugins_cache, true );
9364
-
9365
- // Reload options from DB.
9366
- self::$_accounts->load( true );
9367
- $site_active_plugins_cache = self::$_accounts->get_option( $site_active_plugins_option_name );
9368
-
9369
- if ( $time != $site_active_plugins_cache->timestamp ) {
9370
- // If timestamp is different, then another thread captured the lock.
9371
- return false;
9372
- }
9373
-
9374
- /**
9375
- * Collection of all plugins (network level).
9376
- */
9377
- $network_plugins_cache = self::$_accounts->get_option( $network_plugins_option_name );
9378
-
9379
- if ( ! is_object( $network_plugins_cache ) ) {
9380
- $network_plugins_cache = (object) array(
9381
- 'timestamp' => '',
9382
- 'md5' => '',
9383
- 'plugins' => array(),
9384
- );
9385
- }
9386
-
9387
- // Check if there's a change in plugins.
9388
- $network_plugins = self::get_network_plugins();
9389
- $site_active_plugins = self::get_site_active_plugins();
9390
-
9391
- $network_plugins_thumbprint = $this->get_plugins_thumbprint( $network_plugins );
9392
- $site_active_plugins_thumbprint = $this->get_plugins_thumbprint( $site_active_plugins );
9393
-
9394
- // Check if plugins status changed (version or active/inactive).
9395
- $network_plugins_changed = ( $network_plugins_cache->md5 !== $network_plugins_thumbprint );
9396
- $site_active_plugins_changed = ( $site_active_plugins_cache->md5 !== $site_active_plugins_thumbprint );
9397
-
9398
- if ( ! $network_plugins_changed &&
9399
- ! $site_active_plugins_changed
9400
- ) {
9401
- // No changes.
9402
- return array();
9403
- }
9404
-
9405
- $plugins_update_data = array();
9406
-
9407
- foreach ( $network_plugins_cache->plugins as $basename => $data ) {
9408
- if ( ! isset( $network_plugins[ $basename ] ) ) {
9409
- // Plugin uninstalled.
9410
- $uninstalled_plugin_data = $data;
9411
- $uninstalled_plugin_data['is_active'] = false;
9412
- $uninstalled_plugin_data['is_uninstalled'] = true;
9413
- $plugins_update_data[] = $uninstalled_plugin_data;
9414
-
9415
- unset( $network_plugins[ $basename ] );
9416
-
9417
- unset( $network_plugins_cache->plugins[ $basename ] );
9418
- unset( $site_active_plugins_cache->plugins[ $basename ] );
9419
-
9420
- continue;
9421
- }
9422
-
9423
- $was_active = $data['is_active'] ||
9424
- ( isset( $site_active_plugins_cache->plugins[ $basename ] ) &&
9425
- true === $site_active_plugins_cache->plugins[ $basename ]['is_active'] );
9426
- $is_active = $network_plugins[ $basename ]['is_active'] ||
9427
- ( isset( $site_active_plugins[ $basename ] ) &&
9428
- $site_active_plugins[ $basename ]['is_active'] );
9429
-
9430
- if ( ! isset( $site_active_plugins_cache->plugins[ $basename ] ) &&
9431
- isset( $site_active_plugins[ $basename ] )
9432
- ) {
9433
- // Plugin was site level activated.
9434
- $site_active_plugins_cache->plugins[ $basename ] = $network_plugins[ $basename ];
9435
- $site_active_plugins_cache->plugins[ $basename ]['is_active'] = true;
9436
- } else if ( isset( $site_active_plugins_cache->plugins[ $basename ] ) &&
9437
- ! isset( $site_active_plugins[ $basename ] )
9438
- ) {
9439
- // Plugin was site level deactivated.
9440
- unset( $site_active_plugins_cache->plugins[ $basename ] );
9441
- }
9442
-
9443
- $prev_version = $data['version'];
9444
- $current_version = $network_plugins[ $basename ]['Version'];
9445
-
9446
- if ( $was_active !== $is_active || $prev_version !== $current_version ) {
9447
- // Plugin activated or deactivated, or version changed.
9448
-
9449
- if ( $was_active !== $is_active ) {
9450
- if ( $data['is_active'] != $network_plugins[ $basename ]['is_active'] ) {
9451
- $network_plugins_cache->plugins[ $basename ]['is_active'] = $data['is_active'];
9452
- }
9453
- }
9454
-
9455
- if ( $prev_version !== $current_version ) {
9456
- $network_plugins_cache->plugins[ $basename ]['Version'] = $current_version;
9457
- }
9458
-
9459
- $updated_plugin_data = $data;
9460
- $updated_plugin_data['is_active'] = $is_active;
9461
- $updated_plugin_data['version'] = $current_version;
9462
- $updated_plugin_data['title'] = $network_plugins[ $basename ]['Name'];
9463
- $plugins_update_data[] = $updated_plugin_data;
9464
- }
9465
- }
9466
-
9467
- // Find new plugins that weren't yet seen before.
9468
- foreach ( $network_plugins as $basename => $data ) {
9469
- if ( ! isset( $network_plugins_cache->plugins[ $basename ] ) ) {
9470
- // New plugin.
9471
- $new_plugin = array(
9472
- 'slug' => $data['slug'],
9473
- 'version' => $data['Version'],
9474
- 'title' => $data['Name'],
9475
- 'is_active' => $data['is_active'],
9476
- 'is_uninstalled' => false,
9477
- );
9478
-
9479
- $network_plugins_cache->plugins[ $basename ] = $new_plugin;
9480
-
9481
- $is_site_level_active = (
9482
- isset( $site_active_plugins[ $basename ] ) &&
9483
- $site_active_plugins[ $basename ]['is_active']
9484
- );
9485
-
9486
- /**
9487
- * If not network active, set the activity status based on the site-level plugin status.
9488
- */
9489
- if ( ! $new_plugin['is_active'] ) {
9490
- $new_plugin['is_active'] = $is_site_level_active;
9491
- }
9492
-
9493
- $plugins_update_data[] = $new_plugin;
9494
-
9495
- if ( isset( $site_active_plugins[ $basename ] ) ) {
9496
- $site_active_plugins_cache->plugins[ $basename ] = $new_plugin;
9497
- $site_active_plugins_cache->plugins[ $basename ]['is_active'] = $is_site_level_active;
9498
- }
9499
- }
9500
- }
9501
-
9502
- $site_active_plugins_cache->md5 = $site_active_plugins_thumbprint;
9503
- $site_active_plugins_cache->timestamp = $time;
9504
- self::$_accounts->set_option( $site_active_plugins_option_name, $site_active_plugins_cache, true );
9505
-
9506
- $network_plugins_cache->md5 = $network_plugins_thumbprint;
9507
- $network_plugins_cache->timestamp = $time;
9508
- self::$_accounts->set_option( $network_plugins_option_name, $network_plugins_cache, true );
9509
-
9510
- return $plugins_update_data;
9511
- }
9512
-
9513
- /**
9514
- * Return a list of modified themes since the last sync.
9515
- *
9516
- * Note:
9517
- * There's no point to store a themes counter since even if the number of
9518
- * themes didn't change, we still need to check if the versions are all the
9519
- * same and the activity state is similar.
9520
- *
9521
- * @author Vova Feldman (@svovaf)
9522
- * @since 1.1.8
9523
- *
9524
- * @return array|false
9525
- */
9526
- private function get_themes_data_for_api() {
9527
- // Alias.
9528
- $option_name = 'all_themes';
9529
-
9530
- $all_cached_themes = self::$_accounts->get_option( $option_name );
9531
-
9532
- if ( ! is_object( $all_cached_themes ) ) {
9533
- $all_cached_themes = (object) array(
9534
- 'timestamp' => '',
9535
- 'md5' => '',
9536
- 'themes' => array(),
9537
- );
9538
- }
9539
-
9540
- $time = time();
9541
-
9542
- if ( ! empty( $all_cached_themes->timestamp ) &&
9543
- ( $time - $all_cached_themes->timestamp ) < WP_FS__TIME_5_MIN_IN_SEC
9544
- ) {
9545
- // Don't send theme updates if last update was in the past 5 min.
9546
- return false;
9547
- }
9548
-
9549
- // Write timestamp to lock the logic.
9550
- $all_cached_themes->timestamp = $time;
9551
- self::$_accounts->set_option( $option_name, $all_cached_themes, true );
9552
-
9553
- // Reload options from DB.
9554
- self::$_accounts->load( true );
9555
- $all_cached_themes = self::$_accounts->get_option( $option_name );
9556
-
9557
- if ( $time != $all_cached_themes->timestamp ) {
9558
- // If timestamp is different, then another thread captured the lock.
9559
- return false;
9560
- }
9561
-
9562
- // Get active theme.
9563
- $active_theme = wp_get_theme();
9564
- $active_theme_stylesheet = $active_theme->get_stylesheet();
9565
-
9566
- // Check if there's a change in themes.
9567
- $all_themes = wp_get_themes();
9568
-
9569
- // Check if themes changed.
9570
- ksort( $all_themes );
9571
-
9572
- $themes_signature = '';
9573
- foreach ( $all_themes as $slug => $data ) {
9574
- $is_active = ( $slug === $active_theme_stylesheet );
9575
- $themes_signature .= $slug . ',' .
9576
- $data->version . ',' .
9577
- ( $is_active ? '1' : '0' ) . ';';
9578
- }
9579
-
9580
- // Check if themes status changed (version or active/inactive).
9581
- $themes_changed = ( $all_cached_themes->md5 !== md5( $themes_signature ) );
9582
-
9583
- $themes_update_data = array();
9584
-
9585
- if ( $themes_changed ) {
9586
- // Change in themes, report changes.
9587
-
9588
- // Update existing themes info.
9589
- foreach ( $all_cached_themes->themes as $slug => $data ) {
9590
- $is_active = ( $slug === $active_theme_stylesheet );
9591
-
9592
- if ( ! isset( $all_themes[ $slug ] ) ) {
9593
- // Plugin uninstalled.
9594
- $uninstalled_theme_data = $data;
9595
- $uninstalled_theme_data['is_active'] = false;
9596
- $uninstalled_theme_data['is_uninstalled'] = true;
9597
- $themes_update_data[] = $uninstalled_theme_data;
9598
-
9599
- unset( $all_themes[ $slug ] );
9600
- unset( $all_cached_themes->themes[ $slug ] );
9601
- } else if ( $data['is_active'] !== $is_active ||
9602
- $data['version'] !== $all_themes[ $slug ]->version
9603
- ) {
9604
- // Plugin activated or deactivated, or version changed.
9605
-
9606
- $all_cached_themes->themes[ $slug ]['is_active'] = $is_active;
9607
- $all_cached_themes->themes[ $slug ]['version'] = $all_themes[ $slug ]->version;
9608
-
9609
- $themes_update_data[] = $all_cached_themes->themes[ $slug ];
9610
- }
9611
- }
9612
-
9613
- // Find new themes that weren't yet seen before.
9614
- foreach ( $all_themes as $slug => $data ) {
9615
- if ( ! isset( $all_cached_themes->themes[ $slug ] ) ) {
9616
- $is_active = ( $slug === $active_theme_stylesheet );
9617
-
9618
- // New plugin.
9619
- $new_plugin = array(
9620
- 'slug' => $slug,
9621
- 'version' => $data->version,
9622
- 'title' => $data->name,
9623
- 'is_active' => $is_active,
9624
- 'is_uninstalled' => false,
9625
- );
9626
-
9627
- $themes_update_data[] = $new_plugin;
9628
- $all_cached_themes->themes[ $slug ] = $new_plugin;
9629
- }
9630
- }
9631
-
9632
- $all_cached_themes->md5 = md5( $themes_signature );
9633
- $all_cached_themes->timestamp = time();
9634
- self::$_accounts->set_option( $option_name, $all_cached_themes, true );
9635
- }
9636
-
9637
- return $themes_update_data;
9638
- }
9639
-
9640
- /**
9641
- * Get site data for API install request.
9642
- *
9643
- * @author Vova Feldman (@svovaf)
9644
- * @since 1.1.2
9645
- *
9646
- * @param string[] $override
9647
- * @param bool $include_plugins Since 1.1.8 by default include plugin changes.
9648
- * @param bool $include_themes Since 1.1.8 by default include plugin changes.
9649
- * @param bool $include_blog_data Since 2.3.0 by default include the current blog's data (language, charset, title, and URL).
9650
- *
9651
- * @return array
9652
- */
9653
- private function get_install_data_for_api(
9654
- array $override,
9655
- $include_plugins = true,
9656
- $include_themes = true,
9657
- $include_blog_data = true
9658
- ) {
9659
- if ( $this->is_extensions_tracking_allowed() ) {
9660
- if ( ! defined( 'WP_FS__TRACK_PLUGINS' ) || false !== WP_FS__TRACK_PLUGINS ) {
9661
- /**
9662
- * @since 1.1.8 Also send plugin updates.
9663
- */
9664
- if ( $include_plugins && ! isset( $override['plugins'] ) ) {
9665
- $plugins = $this->get_plugins_data_for_api();
9666
- if ( ! empty( $plugins ) ) {
9667
- $override['plugins'] = $plugins;
9668
- }
9669
- }
9670
- }
9671
-
9672
- if ( ! defined( 'WP_FS__TRACK_THEMES' ) || false !== WP_FS__TRACK_THEMES ) {
9673
- /**
9674
- * @since 1.1.8 Also send themes updates.
9675
- */
9676
- if ( $include_themes && ! isset( $override['themes'] ) ) {
9677
- $themes = $this->get_themes_data_for_api();
9678
- if ( ! empty( $themes ) ) {
9679
- $override['themes'] = $themes;
9680
- }
9681
- }
9682
- }
9683
- }
9684
-
9685
- $versions = $this->get_versions();
9686
-
9687
- $blog_data = $include_blog_data ?
9688
- array(
9689
- 'language' => get_bloginfo( 'language' ),
9690
- 'charset' => get_bloginfo( 'charset' ),
9691
- 'title' => get_bloginfo( 'name' ),
9692
- 'url' => self::get_site_url(),
9693
- ) :
9694
- array();
9695
-
9696
- return array_merge( $versions, $blog_data, array(
9697
- 'version' => $this->get_plugin_version(),
9698
- 'is_premium' => $this->is_premium(),
9699
- // Special params.
9700
- 'is_active' => true,
9701
- 'is_disconnected' => $this->is_tracking_prohibited(),
9702
- 'is_uninstalled' => false,
9703
- ), $override );
9704
- }
9705
-
9706
- /**
9707
- * Update installs details.
9708
- *
9709
- * @todo V1 of multiste network support doesn't support plugin and theme data sending.
9710
- *
9711
- * @author Vova Feldman (@svovaf)
9712
- * @since 2.0.0
9713
- *
9714
- * @param string[] string $override
9715
- * @param bool $only_diff
9716
- * @param bool $is_keepalive
9717
- * @param bool $include_plugins Since 1.1.8 by default include plugin changes.
9718
- * @param bool $include_themes Since 1.1.8 by default include plugin changes.
9719
- *
9720
- * @return array
9721
- */
9722
- private function get_installs_data_for_api(
9723
- array $override,
9724
- $only_diff = false,
9725
- $is_keepalive = false,
9726
- $include_plugins = true,
9727
- $include_themes = true
9728
- ) {
9729
- /**
9730
- * @since 1.1.8 Also send plugin updates.
9731
- */
9732
- // if ( $include_plugins && ! isset( $override['plugins'] ) ) {
9733
- // $plugins = $this->get_plugins_data_for_api();
9734
- // if ( ! empty( $plugins ) ) {
9735
- // $override['plugins'] = $plugins;
9736
- // }
9737
- // }
9738
- /**
9739
- * @since 1.1.8 Also send themes updates.
9740
- */
9741
- // if ( $include_themes && ! isset( $override['themes'] ) ) {
9742
- // $themes = $this->get_themes_data_for_api();
9743
- // if ( ! empty( $themes ) ) {
9744
- // $override['themes'] = $themes;
9745
- // }
9746
- // }
9747
-
9748
- // Common properties.
9749
- $versions = $this->get_versions();
9750
- $common = array_merge( $versions, array(
9751
- 'version' => $this->get_plugin_version(),
9752
- 'is_premium' => $this->is_premium(),
9753
- ), $override );
9754
-
9755
-
9756
- $is_common_diff_for_any_site = false;
9757
- $common_diff_union = array();
9758
-
9759
- $installs_data = array();
9760
-
9761
- $sites = self::get_sites();
9762
-
9763
- $subsite_data_by_install_id = array();
9764
- $install_url_by_install_id = array();
9765
-
9766
- foreach ( $sites as $site ) {
9767
- $blog_id = self::get_site_blog_id( $site );
9768
-
9769
- $install = $this->get_install_by_blog_id( $blog_id );
9770
-
9771
- if ( is_object( $install ) ) {
9772
- if ( $install->user_id != $this->_user->id ) {
9773
- // Install belongs to a different owner.
9774
- continue;
9775
- }
9776
-
9777
- if ( ! $this->is_premium() && $install->is_tracking_prohibited() ) {
9778
- // Don't send updates regarding opted-out installs.
9779
- continue;
9780
- }
9781
-
9782
- $install_data = $this->get_site_info( $site );
9783
-
9784
- if ( FS_Clone_Manager::instance()->is_temporary_duplicate_by_blog_id( $install_data['blog_id'] ) ) {
9785
- continue;
9786
- }
9787
-
9788
- $uid = $install_data['uid'];
9789
- $url = $install_data['url'];
9790
-
9791
- if ( isset( $subsite_data_by_install_id[ $install->id ] ) ) {
9792
- $clone_subsite_data = $subsite_data_by_install_id[ $install->id ];
9793
- $clone_install_url = $install_url_by_install_id[ $install->id ];
9794
-
9795
- if (
9796
- /**
9797
- * If we already have an install with the same URL as the subsite it's stored in, skip the current subsite. Otherwise, replace the existing install's data with the current subsite's install's data if the URLs match.
9798
- *
9799
- * @author Leo Fajardo (@leorw)
9800
- * @since 2.5.0
9801
- */
9802
- fs_strip_url_protocol( untrailingslashit( $clone_install_url ) ) === fs_strip_url_protocol( untrailingslashit( $clone_subsite_data['url'] ) ) ||
9803
- fs_strip_url_protocol( untrailingslashit( $install->url ) ) !== fs_strip_url_protocol( untrailingslashit( $url ) )
9804
- ) {
9805
- continue;
9806
- }
9807
- }
9808
-
9809
- unset( $install_data['blog_id'] );
9810
- unset( $install_data['uid'] );
9811
- unset( $install_data['url'] );
9812
-
9813
- $install_data['is_disconnected'] = $install->is_disconnected;
9814
- $install_data['is_active'] = $this->is_active_for_site( $blog_id );
9815
- $install_data['is_uninstalled'] = $install->is_uninstalled;
9816
-
9817
- $common_diff = null;
9818
- $is_common_diff = false;
9819
- if ( $only_diff ) {
9820
- $install_data = $this->get_install_diff_for_api( $install_data, $install, $override );
9821
- $common_diff = $this->get_install_diff_for_api( $common, $install, $override );
9822
-
9823
- $is_common_diff = ! empty( $common_diff );
9824
-
9825
- if ( $is_common_diff ) {
9826
- foreach ( $common_diff as $k => $v ) {
9827
- if ( ! isset( $common_diff_union[ $k ] ) ) {
9828
- $common_diff_union[ $k ] = $v;
9829
- }
9830
- }
9831
- }
9832
-
9833
- $is_common_diff_for_any_site = $is_common_diff_for_any_site || $is_common_diff;
9834
- }
9835
-
9836
- if ( ! empty( $install_data ) || $is_common_diff || $is_keepalive ) {
9837
- // Add install ID and site unique ID.
9838
- $install_data['id'] = $install->id;
9839
- $install_data['uid'] = $uid;
9840
- $install_data['url'] = $url;
9841
-
9842
- $subsite_data_by_install_id[ $install->id ] = $install_data;
9843
- $install_url_by_install_id[ $install->id ] = $install->url;
9844
- }
9845
- }
9846
- }
9847
-
9848
- restore_current_blog();
9849
-
9850
- $installs_data = array_merge(
9851
- $installs_data,
9852
- array_values( $subsite_data_by_install_id )
9853
- );
9854
-
9855
- if ( 0 < count( $installs_data ) && ( $is_common_diff_for_any_site || ! $only_diff ) ) {
9856
- if ( ! $only_diff ) {
9857
- $installs_data[] = $common;
9858
- } else if ( ! empty( $common_diff_union ) ) {
9859
- $installs_data[] = $common_diff_union;
9860
- }
9861
- }
9862
-
9863
- foreach ( $installs_data as &$data ) {
9864
- $data = (object) $data;
9865
- }
9866
-
9867
- return $installs_data;
9868
- }
9869
-
9870
- /**
9871
- * Compare site actual data to the stored install data and return the differences for an API data sync.
9872
- *
9873
- * @author Vova Feldman (@svovaf)
9874
- * @since 2.0.0
9875
- *
9876
- * @param array $site
9877
- * @param FS_Site $install
9878
- * @param string[] string $override
9879
- *
9880
- * @return array
9881
- */
9882
- private function get_install_diff_for_api( $site, $install, $override = array() ) {
9883
- $diff = array();
9884
- $special = array();
9885
- $special_override = false;
9886
-
9887
- foreach ( $site as $p => $v ) {
9888
- if ( property_exists( $install, $p ) ) {
9889
- if ( ( is_bool( $install->{$p} ) || ! empty( $install->{$p} ) ) &&
9890
- $install->{$p} != $v
9891
- ) {
9892
- $install->{$p} = $v;
9893
- $diff[ $p ] = $v;
9894
- }
9895
- } else {
9896
- $special[ $p ] = $v;
9897
-
9898
- if ( isset( $override[ $p ] ) ||
9899
- 'plugins' === $p ||
9900
- 'themes' === $p
9901
- ) {
9902
- $special_override = true;
9903
- }
9904
- }
9905
- }
9906
-
9907
- if ( $special_override || 0 < count( $diff ) ) {
9908
- // Add special params only if has at least one
9909
- // standard param, or if explicitly requested to
9910
- // override a special param or a param which is not exist
9911
- // in the install object.
9912
- $diff = array_merge( $diff, $special );
9913
- }
9914
-
9915
- return $diff;
9916
- }
9917
-
9918
- /**
9919
- * Update install only if changed.
9920
- *
9921
- * @author Vova Feldman (@svovaf)
9922
- * @since 1.0.9
9923
- *
9924
- * @param string[] string $override
9925
- * @param bool $flush
9926
- * @param bool $is_two_way_sync @since 2.5.0 If true and there's a successful API request, the install sync cron will be cleared.
9927
- *
9928
- * @return false|object|string
9929
- */
9930
- private function send_install_update( $override = array(), $flush = false, $is_two_way_sync = false ) {
9931
- $this->_logger->entrance();
9932
-
9933
- $check_properties = $this->get_install_data_for_api( $override );
9934
-
9935
- if ( $flush ) {
9936
- $params = $check_properties;
9937
- } else {
9938
- $params = $this->get_install_diff_for_api( $check_properties, $this->_site, $override );
9939
- }
9940
-
9941
- $keepalive_only_update = false;
9942
- if ( empty( $params ) ) {
9943
- $keepalive_only_update = $this->should_send_keepalive_update();
9944
-
9945
- if ( ! $keepalive_only_update ) {
9946
- /**
9947
- * There are no updates to send including keepalive.
9948
- *
9949
- * @author Leo Fajardo (@leorw)
9950
- * @since 2.2.3
9951
- */
9952
- return false;
9953
- }
9954
- }
9955
-
9956
- if ( $is_two_way_sync ) {
9957
- /**
9958
- * Update last install sync timestamp during a two-way sync call as we expect that updates are sent during this call.
9959
- *
9960
- * @author Leo Fajardo (@leorw)
9961
- * @since 2.2.3
9962
- */
9963
- if ( ! is_multisite() ) {
9964
- // Update last install sync timestamp.
9965
- $this->set_cron_execution_timestamp( 'install_sync' );
9966
- }
9967
-
9968
- $params['uid'] = $this->get_anonymous_id();
9969
- }
9970
-
9971
- $this->set_keepalive_timestamp();
9972
-
9973
- // Send updated values to FS.
9974
- $site = $this->api_site_call( '/', 'put', $params, true );
9975
-
9976
- if ( $is_two_way_sync && $this->is_api_result_entity( $site ) ) {
9977
- /**
9978
- * Clear scheduled install sync after a two-way sync call.
9979
- *
9980
- * @author Leo Fajardo (@leorw)
9981
- * @since 2.2.3
9982
- */
9983
- if ( ! is_multisite() ) {
9984
- // I successfully sent install update, clear scheduled sync if exist.
9985
- $this->clear_install_sync_cron();
9986
- }
9987
- }
9988
-
9989
- return $site;
9990
- }
9991
-
9992
- /**
9993
- * Update installs only if changed.
9994
- *
9995
- * @author Vova Feldman (@svovaf)
9996
- * @since 2.0.0
9997
- *
9998
- * @param string[] string $override
9999
- * @param bool $flush
10000
- * @param bool $is_two_way_sync @since 2.5.0 If true and there's a successful API request, the install sync cron will be cleared.
10001
- *
10002
- * @return false|object|string
10003
- */
10004
- private function send_installs_update( $override = array(), $flush = false, $is_two_way_sync = false ) {
10005
- $this->_logger->entrance();
10006
-
10007
- /**
10008
- * Pass `true` to use the network level storage since the update is for many installs.
10009
- *
10010
- * @author Leo Fajardo (@leorw)
10011
- * @since 2.2.3
10012
- */
10013
- $should_send_keepalive = $this->should_send_keepalive_update( true );
10014
-
10015
- $installs_data = $this->get_installs_data_for_api( $override, ! $flush, $should_send_keepalive );
10016
-
10017
- if ( empty( $installs_data ) ) {
10018
- return false;
10019
- }
10020
-
10021
- if ( $is_two_way_sync ) {
10022
- // Update last install sync timestamp during a two-way sync call as we expect that updates are sent during this call.
10023
- $this->set_cron_execution_timestamp( 'install_sync' );
10024
- }
10025
-
10026
- /**
10027
- * Pass `true` to use the network level storage since the update is for many installs.
10028
- *
10029
- * @author Leo Fajardo (@leorw)
10030
- * @since 2.2.3
10031
- */
10032
- $this->set_keepalive_timestamp( true );
10033
-
10034
- // Send updated values to FS.
10035
- $result = $this->get_api_user_scope()->call( "/plugins/{$this->_plugin->id}/installs.json", 'put', $installs_data );
10036
-
10037
- if ( $is_two_way_sync && $this->is_api_result_object( $result, 'installs' ) ) {
10038
- // I successfully sent a two-way installs update, clear the scheduled install sync if it exists.
10039
- $this->clear_install_sync_cron();
10040
- }
10041
-
10042
- return $result;
10043
- }
10044
-
10045
- /**
10046
- * @author Leo Fajardo (@leorw)
10047
- *
10048
- * @param bool|null $use_network_level_storage
10049
- *
10050
- * @return bool
10051
- */
10052
- private function should_send_keepalive_update( $use_network_level_storage = null ) {
10053
- $keepalive_timestamp = $this->_storage->get( 'keepalive_timestamp', 0, $use_network_level_storage );
10054
-
10055
- if ( $keepalive_timestamp < ( time() - WP_FS__TIME_WEEK_IN_SEC ) ) {
10056
- // If updated more than 7 days ago, trigger a keepalive and update the time it was triggered.
10057
- return true;
10058
- } else {
10059
- // If updated 7 days ago or less, "flip a coin", if the value is 7 trigger a keepalive and update the last time it was triggered.
10060
- return ( 7 == rand( 1, 7 ) );
10061
- }
10062
- }
10063
-
10064
- /**
10065
- * Syncs the install owner's data if needed (i.e., if the install owner is different from the loaded user).
10066
- *
10067
- * @author Leo Fajardo (@leorw)
10068
- * @since 2.3.2
10069
- */
10070
- private function maybe_sync_install_user() {
10071
- if ( $this->_user->id == $this->_site->user_id ) {
10072
- return;
10073
- }
10074
-
10075
- // Fetch user data and store if found.
10076
- $this->sync_user_by_current_install();
10077
- }
10078
-
10079
- /**
10080
- * Update install only if changed.
10081
- *
10082
- * @author Vova Feldman (@svovaf)
10083
- * @since 1.0.9
10084
- *
10085
- * @param string[] string $override
10086
- * @param bool $flush
10087
- */
10088
- function sync_install( $override = array(), $flush = false ) {
10089
- $this->_logger->entrance();
10090
-
10091
- $site = $this->send_install_update( $override, $flush, true );
10092
-
10093
- if ( false === $site ) {
10094
- // No sync required.
10095
- return;
10096
- }
10097
-
10098
- if ( ! $this->is_api_result_entity( $site ) ) {
10099
- // Failed to sync, don't update locally.
10100
- return;
10101
- }
10102
-
10103
- $this->_site = new FS_Site( $site );
10104
-
10105
- $this->_store_site( true );
10106
- }
10107
-
10108
- /**
10109
- * Update install only if changed.
10110
- *
10111
- * @author Vova Feldman (@svovaf)
10112
- * @since 1.0.9
10113
- *
10114
- * @param string[] string $override
10115
- * @param bool $flush
10116
- */
10117
- private function sync_installs( $override = array(), $flush = false ) {
10118
- $this->_logger->entrance();
10119
-
10120
- $result = $this->send_installs_update( $override, $flush, true );
10121
-
10122
- if ( false === $result ) {
10123
- // No sync required.
10124
- return;
10125
- }
10126
-
10127
- if ( ! $this->is_api_result_object( $result, 'installs' ) ) {
10128
- // Failed to sync, don't update locally.
10129
- return;
10130
- }
10131
-
10132
- $address_to_blog_map = $this->get_address_to_blog_map();
10133
-
10134
- foreach ( $result->installs as $install ) {
10135
- $this->_site = new FS_Site( $install );
10136
-
10137
- $address = trailingslashit( fs_strip_url_protocol( $install->url ) );
10138
- $blog_id = $address_to_blog_map[ $address ];
10139
-
10140
- $this->_store_site( true, $blog_id );
10141
- }
10142
- }
10143
-
10144
- /**
10145
- * Track install's custom event.
10146
- *
10147
- * IMPORTANT:
10148
- * Custom event tracking is currently only supported for specific clients.
10149
- * If you are not one of them, please don't use this method. If you will,
10150
- * the API will simply ignore your request based on the plugin ID.
10151
- *
10152
- * Need custom tracking for your plugin or theme?
10153
- * If you are interested in custom event tracking please contact yo@freemius.com
10154
- * for further details.
10155
- *
10156
- * @author Vova Feldman (@svovaf)
10157
- * @since 1.2.1
10158
- *
10159
- * @param string $name Event name.
10160
- * @param array $properties Associative key/value array with primitive values only
10161
- * @param bool $process_at A valid future date-time in the following format Y-m-d H:i:s.
10162
- * @param bool $once If true, event will be tracked only once. IMPORTANT: Still trigger the API call.
10163
- *
10164
- * @return object|false Event data or FALSE on failure.
10165
- *
10166
- * @throws \Freemius_InvalidArgumentException
10167
- */
10168
- public function track_event( $name, $properties = array(), $process_at = false, $once = false ) {
10169
- $this->_logger->entrance( http_build_query( array( 'name' => $name, 'once' => $once ) ) );
10170
-
10171
- if ( ! $this->is_registered() ) {
10172
- return false;
10173
- }
10174
-
10175
- $event = array( 'type' => $name );
10176
-
10177
- if ( is_numeric( $process_at ) && $process_at > time() ) {
10178
- $event['process_at'] = $process_at;
10179
- }
10180
-
10181
- if ( $once ) {
10182
- $event['once'] = true;
10183
- }
10184
-
10185
- if ( ! empty( $properties ) ) {
10186
- // Verify associative array values are primitive.
10187
- foreach ( $properties as $k => $v ) {
10188
- if ( ! is_scalar( $v ) ) {
10189
- throw new Freemius_InvalidArgumentException( 'The $properties argument must be an associative key/value array with primitive values only.' );
10190
- }
10191
- }
10192
-
10193
- $event['properties'] = $properties;
10194
- }
10195
-
10196
- $result = $this->get_api_site_scope()->call( 'events.json', 'post', $event );
10197
-
10198
- return $this->is_api_error( $result ) ?
10199
- false :
10200
- $result;
10201
- }
10202
-
10203
- /**
10204
- * Track install's custom event only once, but it still triggers the API call.
10205
- *
10206
- * IMPORTANT:
10207
- * Custom event tracking is currently only supported for specific clients.
10208
- * If you are not one of them, please don't use this method. If you will,
10209
- * the API will simply ignore your request based on the plugin ID.
10210
- *
10211
- * Need custom tracking for your plugin or theme?
10212
- * If you are interested in custom event tracking please contact yo@freemius.com
10213
- * for further details.
10214
- *
10215
- * @author Vova Feldman (@svovaf)
10216
- * @since 1.2.1
10217
- *
10218
- * @param string $name Event name.
10219
- * @param array $properties Associative key/value array with primitive values only
10220
- * @param bool $process_at A valid future date-time in the following format Y-m-d H:i:s.
10221
- *
10222
- * @return object|false Event data or FALSE on failure.
10223
- *
10224
- * @throws \Freemius_InvalidArgumentException
10225
- *
10226
- * @user Freemius::track_event()
10227
- */
10228
- public function track_event_once( $name, $properties = array(), $process_at = false ) {
10229
- return $this->track_event( $name, $properties, $process_at, true );
10230
- }
10231
-
10232
- /**
10233
- * Plugin uninstall hook.
10234
- *
10235
- * @author Vova Feldman (@svovaf)
10236
- * @since 1.0.1
10237
- *
10238
- * @param bool $check_user Enforce checking if user have plugins activation privileges.
10239
- */
10240
- function _uninstall_plugin_event( $check_user = true ) {
10241
- $this->_logger->entrance( 'slug = ' . $this->_slug );
10242
-
10243
- if ( $check_user && ! current_user_can( 'activate_plugins' ) ) {
10244
- return;
10245
- }
10246
-
10247
- $params = array();
10248
- $uninstall_reason = null;
10249
- if ( isset( $this->_storage->uninstall_reason ) ) {
10250
- $uninstall_reason = $this->_storage->uninstall_reason;
10251
- $params['reason_id'] = $uninstall_reason->id;
10252
- $params['reason_info'] = $uninstall_reason->info;
10253
- }
10254
-
10255
- if ( ! $this->is_registered() ) {
10256
- // Send anonymous uninstall event only if user submitted a feedback.
10257
- if ( isset( $uninstall_reason ) ) {
10258
- if ( isset( $uninstall_reason->is_anonymous ) && ! $uninstall_reason->is_anonymous ) {
10259
- $this->opt_in( false, false, false, false, true );
10260
- } else {
10261
- $params['uid'] = $this->get_anonymous_id();
10262
- $this->get_api_plugin_scope()->call( 'uninstall.json', 'put', $params );
10263
- }
10264
- }
10265
- } else {
10266
- $params = array_merge( $params, array(
10267
- 'is_active' => false,
10268
- 'is_uninstalled' => true,
10269
- ) );
10270
-
10271
- if ( $this->_is_network_active ) {
10272
- // Send uninstall event.
10273
- $this->send_installs_update( $params );
10274
- } else {
10275
- // Send uninstall event.
10276
- $this->send_install_update( $params );
10277
- }
10278
- }
10279
-
10280
- // @todo Decide if we want to delete plugin information from db.
10281
- }
10282
-
10283
- /**
10284
- * Set the basename of the current product and hook _activate_plugin_event_hook() to the activation action.
10285
- *
10286
- * @author Vova Feldman (@svovaf)
10287
- * @since 2.2.1
10288
- *
10289
- * @param string $is_premium
10290
- * @param string $caller
10291
- *
10292
- * @return string
10293
- */
10294
- function set_basename( $is_premium, $caller ) {
10295
- $basename = plugin_basename( $caller );
10296
-
10297
- $current_basename = $is_premium ?
10298
- $this->_premium_plugin_basename :
10299
- $this->_free_plugin_basename;
10300
-
10301
- if ( $current_basename == $basename ) {
10302
- // Basename value set correctly.
10303
- return;
10304
- }
10305
-
10306
- if ( $is_premium ) {
10307
- $this->_premium_plugin_basename = $basename;
10308
- } else {
10309
- $this->_free_plugin_basename = $basename;
10310
- }
10311
-
10312
- $plugin_dir = dirname( $this->_plugin_dir_path ) . '/';
10313
-
10314
- register_activation_hook(
10315
- $plugin_dir . $basename,
10316
- array( &$this, '_activate_plugin_event_hook' )
10317
- );
10318
- }
10319
-
10320
- /**
10321
- * @author Vova Feldman (@svovaf)
10322
- * @since 1.1.1
10323
- * @since 2.2.1 If the context product is in its premium version, use the current module's basename, even if it was renamed.
10324
- *
10325
- * @return string
10326
- */
10327
- function premium_plugin_basename() {
10328
- if ( ! isset( $this->_premium_plugin_basename ) ) {
10329
- $this->_premium_plugin_basename = $this->is_premium() ?
10330
- // The product is premium, so use the current basename.
10331
- $this->_plugin_basename :
10332
- $this->get_premium_slug() . '/' . basename( $this->_free_plugin_basename );
10333
- }
10334
-
10335
- return $this->_premium_plugin_basename;
10336
- }
10337
-
10338
- /**
10339
- * Uninstall plugin hook. Called only when connected his account with Freemius for active sites tracking.
10340
- *
10341
- * @author Vova Feldman (@svovaf)
10342
- * @since 1.0.2
10343
- */
10344
- public static function _uninstall_plugin_hook() {
10345
- self::_load_required_static();
10346
-
10347
- self::$_static_logger->entrance();
10348
-
10349
- if ( ! current_user_can( 'activate_plugins' ) ) {
10350
- return;
10351
- }
10352
-
10353
- $plugin_file = substr( current_filter(), strlen( 'uninstall_' ) );
10354
-
10355
- self::$_static_logger->info( 'plugin = ' . $plugin_file );
10356
-
10357
- define( 'WP_FS__UNINSTALL_MODE', true );
10358
-
10359
- $fs = self::get_instance_by_file( $plugin_file );
10360
-
10361
- if ( is_object( $fs ) ) {
10362
- $fs->remove_sdk_reference();
10363
-
10364
- self::require_plugin_essentials();
10365
-
10366
- if ( is_plugin_active( $fs->_free_plugin_basename ) ||
10367
- is_plugin_active( $fs->premium_plugin_basename() )
10368
- ) {
10369
- // Deleting Free or Premium plugin version while the other version still installed.
10370
- return;
10371
- }
10372
-
10373
- if (
10374
- ! $fs->is_clone() &&
10375
- /**
10376
- * If there's a context install, run this method only when there's also a context user (e.g., when cloning a subsite of a multisite network into a single-site installation, it's possible for an install to be associated with a non-existing user entity; we want Freemius to be off in this case, while we are trying to recover the user).
10377
- *
10378
- * @author Leo Fajardo
10379
- */
10380
- ( ! is_object( $fs->_site ) || $fs->is_registered() )
10381
- ) {
10382
- $fs->_uninstall_plugin_event();
10383
- }
10384
-
10385
- $fs->do_action( 'after_uninstall' );
10386
- }
10387
- }
10388
-
10389
- #----------------------------------------------------------------------------------
10390
- #region Plugin Information
10391
- #----------------------------------------------------------------------------------
10392
-
10393
- /**
10394
- * Load WordPress core plugin.php essential module.
10395
- *
10396
- * @author Vova Feldman (@svovaf)
10397
- * @since 1.1.1
10398
- */
10399
- private static function require_plugin_essentials() {
10400
- if ( ! function_exists( 'get_plugins' ) ) {
10401
- self::$_static_logger->log( 'Including wp-admin/includes/plugin.php...' );
10402
-
10403
- require_once ABSPATH . 'wp-admin/includes/plugin.php';
10404
- }
10405
- }
10406
-
10407
- /**
10408
- * Load WordPress core pluggable.php module.
10409
- *
10410
- * @author Vova Feldman (@svovaf)
10411
- * @since 1.1.2
10412
- */
10413
- private static function require_pluggable_essentials() {
10414
- if ( ! function_exists( 'wp_get_current_user' ) ) {
10415
- require_once ABSPATH . 'wp-includes/pluggable.php';
10416
- }
10417
- }
10418
-
10419
- /**
10420
- * Return plugin data.
10421
- *
10422
- * @author Vova Feldman (@svovaf)
10423
- * @since 1.0.1
10424
- *
10425
- * @param bool $reparse_plugin_metadata
10426
- *
10427
- * @return array
10428
- */
10429
- function get_plugin_data( $reparse_plugin_metadata = false ) {
10430
- if ( ! isset( $this->_plugin_data ) || $reparse_plugin_metadata ) {
10431
- self::require_plugin_essentials();
10432
-
10433
- if ( $this->is_plugin() ) {
10434
- /**
10435
- * @author Vova Feldman (@svovaf)
10436
- * @since 1.2.0 When using get_plugin_data() do NOT translate plugin data.
10437
- *
10438
- * @link https://github.com/Freemius/wordpress-sdk/issues/77
10439
- */
10440
- $plugin_data = get_plugin_data(
10441
- $this->_plugin_main_file_path,
10442
- false,
10443
- false
10444
- );
10445
- } else {
10446
- $theme_data = wp_get_theme();
10447
-
10448
- if ( $this->_plugin_basename !== $theme_data->get_stylesheet() && is_child_theme() ) {
10449
- $parent_theme = $theme_data->parent();
10450
-
10451
- if ( ( $parent_theme instanceof WP_Theme ) && $this->_plugin_basename === $parent_theme->get_stylesheet() ) {
10452
- $theme_data = $parent_theme;
10453
- }
10454
- }
10455
-
10456
- $plugin_data = array(
10457
- 'Name' => $theme_data->get( 'Name' ),
10458
- 'Version' => $theme_data->get( 'Version' ),
10459
- 'Author' => $theme_data->get( 'Author' ),
10460
- 'Description' => $theme_data->get( 'Description' ),
10461
- 'PluginURI' => $theme_data->get( 'ThemeURI' ),
10462
- );
10463
- }
10464
-
10465
- $this->_plugin_data = $plugin_data;
10466
- }
10467
-
10468
- return $this->_plugin_data;
10469
- }
10470
-
10471
- /**
10472
- * @author Vova Feldman (@svovaf)
10473
- * @since 1.0.1
10474
- * @since 1.2.2.5 If slug not set load slug by module ID.
10475
- *
10476
- * @return string Plugin slug.
10477
- */
10478
- function get_slug() {
10479
- if ( ! isset( $this->_slug ) ) {
10480
- $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array() );
10481
- $this->_slug = $id_slug_type_path_map[ $this->_module_id ]['slug'];
10482
- }
10483
-
10484
- return $this->_slug;
10485
- }
10486
-
10487
- /**
10488
- * @author Leo Fajardo (@leorw)
10489
- * @since 2.2.1
10490
- *
10491
- * @return string
10492
- */
10493
- function get_premium_slug() {
10494
- return is_object( $this->_plugin ) ?
10495
- $this->_plugin->premium_slug :
10496
- "{$this->_slug}-premium";
10497
- }
10498
-
10499
- /**
10500
- * Retrieve the desired folder name for the product.
10501
- *
10502
- * @author Vova Feldman (@svovaf)
10503
- * @since 1.2.1.7
10504
- *
10505
- * @return string Plugin slug.
10506
- */
10507
- function get_target_folder_name() {
10508
- return $this->can_use_premium_code() ?
10509
- $this->_plugin->premium_slug :
10510
- $this->_slug;
10511
- }
10512
-
10513
- /**
10514
- * @author Vova Feldman (@svovaf)
10515
- * @since 1.0.1
10516
- *
10517
- * @return number Plugin ID.
10518
- */
10519
- function get_id() {
10520
- return $this->_plugin->id;
10521
- }
10522
-
10523
- /**
10524
- * @author Leo Fajardo (@leorw)
10525
- * @since 2.2.4
10526
- *
10527
- * @return number|null Bundle ID.
10528
- */
10529
- function get_bundle_id() {
10530
- return ( isset( $this->_plugin->bundle_id ) && FS_Plugin::is_valid_id( $this->_plugin->bundle_id ) ) ?
10531
- $this->_plugin->bundle_id :
10532
- null;
10533
- }
10534
-
10535
- /**
10536
- * @author Vova Feldman (@svovaf)
10537
- * @since 2.3.1
10538
- *
10539
- * @return string|null Bundle public key.
10540
- */
10541
- function get_bundle_public_key() {
10542
- return isset( $this->_plugin->bundle_public_key ) ?
10543
- $this->_plugin->bundle_public_key :
10544
- null;
10545
- }
10546
-
10547
- /**
10548
- * @author Vova Feldman (@svovaf)
10549
- * @since 1.2.1.5
10550
- *
10551
- * @return string Freemius SDK version
10552
- */
10553
- function get_sdk_version() {
10554
- return $this->version;
10555
- }
10556
-
10557
- /**
10558
- * @author Vova Feldman (@svovaf)
10559
- * @since 1.2.1.5
10560
- *
10561
- * @return number Parent plugin ID (if parent exist).
10562
- */
10563
- function get_parent_id() {
10564
- return $this->is_addon() ?
10565
- $this->get_parent_instance()->get_id() :
10566
- $this->_plugin->id;
10567
- }
10568
-
10569
- /**
10570
- * @author Vova Feldman (@svovaf)
10571
- * @since 2.3.1
10572
- *
10573
- * @return string
10574
- */
10575
- function get_usage_tracking_terms_url() {
10576
- return $this->apply_filters(
10577
- 'usage_tracking_terms_url',
10578
- "https://freemius.com/wordpress/usage-tracking/{$this->_plugin->id}/{$this->_slug}/"
10579
- );
10580
- }
10581
-
10582
- /**
10583
- * @author Vova Feldman (@svovaf)
10584
- * @since 2.3.1
10585
- *
10586
- * @return string
10587
- */
10588
- function get_eula_url() {
10589
- return $this->apply_filters(
10590
- 'eula_url',
10591
- "https://freemius.com/terms/{$this->_plugin->id}/{$this->_slug}/"
10592
- );
10593
- }
10594
-
10595
- /**
10596
- * @author Vova Feldman (@svovaf)
10597
- * @since 1.0.1
10598
- *
10599
- * @return string Plugin public key.
10600
- */
10601
- function get_public_key() {
10602
- return $this->_plugin->public_key;
10603
- }
10604
-
10605
- /**
10606
- * Will be available only on sandbox mode.
10607
- *
10608
- * @author Vova Feldman (@svovaf)
10609
- * @since 1.0.4
10610
- *
10611
- * @return mixed Plugin secret key.
10612
- */
10613
- function get_secret_key() {
10614
- return $this->_plugin->secret_key;
10615
- }
10616
-
10617
- /**
10618
- * @author Vova Feldman (@svovaf)
10619
- * @since 1.1.1
10620
- *
10621
- * @return bool
10622
- */
10623
- function has_secret_key() {
10624
- return ! empty( $this->_plugin->secret_key );
10625
- }
10626
-
10627
- /**
10628
- * @author Vova Feldman (@svovaf)
10629
- * @since 1.0.9
10630
- *
10631
- * @param string|bool $premium_suffix
10632
- *
10633
- * @return string
10634
- */
10635
- function get_plugin_name( $premium_suffix = false ) {
10636
- $this->_logger->entrance();
10637
-
10638
- /**
10639
- * This `if-else` can be squeezed into a single `if` but I intentionally split it for code readability.
10640
- *
10641
- * @author Vova Feldman
10642
- */
10643
- if ( ! isset( $this->_plugin_name ) ) {
10644
- // Name is not yet set.
10645
- $this->set_name( $premium_suffix );
10646
- } else if (
10647
- ! empty( $premium_suffix ) &&
10648
- ( ! is_object( $this->_plugin ) || $this->_plugin->premium_suffix !== $premium_suffix )
10649
- ) {
10650
- // Name is already set, but there's a change in the premium suffix.
10651
- $this->set_name( $premium_suffix );
10652
- }
10653
-
10654
- return $this->_plugin_name;
10655
- }
10656
-
10657
- /**
10658
- * Calculates and stores the product's name. This helper function was created specifically for get_plugin_name() just to make the code clearer.
10659
- *
10660
- * @author Vova Feldman (@svovaf)
10661
- * @since 2.2.1
10662
- *
10663
- * @param string $premium_suffix
10664
- */
10665
- private function set_name( $premium_suffix = '' ) {
10666
- $plugin_data = $this->get_plugin_data();
10667
-
10668
- // Get name.
10669
- $this->_plugin_name = $plugin_data['Name'];
10670
-
10671
- if ( is_string( $premium_suffix ) ) {
10672
- $premium_suffix = trim( $premium_suffix );
10673
-
10674
- if ( ! empty( $premium_suffix ) ) {
10675
- // Check if plugin name contains " (premium)" or a custom suffix and remove it.
10676
- $suffix = ( ' ' . strtolower( $premium_suffix ) );
10677
- $suffix_len = strlen( $suffix );
10678
-
10679
- if ( strlen( $plugin_data['Name'] ) > $suffix_len &&
10680
- $suffix === substr( strtolower( $plugin_data['Name'] ), - $suffix_len )
10681
- ) {
10682
- $this->_plugin_name = substr( $plugin_data['Name'], 0, - $suffix_len );
10683
- }
10684
- }
10685
- }
10686
-
10687
- $this->_logger->departure( 'Name = ' . $this->_plugin_name );
10688
- }
10689
-
10690
- /**
10691
- * @author Vova Feldman (@svovaf)
10692
- * @since 1.0.0
10693
- *
10694
- * @param bool $reparse_plugin_metadata
10695
- *
10696
- * @return string
10697
- */
10698
- function get_plugin_version( $reparse_plugin_metadata = false ) {
10699
- $this->_logger->entrance();
10700
-
10701
- $plugin_data = $this->get_plugin_data( $reparse_plugin_metadata );
10702
-
10703
- $this->_logger->departure( 'Version = ' . $plugin_data['Version'] );
10704
-
10705
- return $this->apply_filters( 'plugin_version', $plugin_data['Version'] );
10706
- }
10707
-
10708
- /**
10709
- * @author Vova Feldman (@svovaf)
10710
- * @since 1.2.1.7
10711
- *
10712
- * @return string
10713
- */
10714
- function get_plugin_title() {
10715
- $this->_logger->entrance();
10716
-
10717
- $title = $this->_plugin->title;
10718
-
10719
- return $this->apply_filters( 'plugin_title', $title );
10720
- }
10721
-
10722
- /**
10723
- * @author Vova Feldman (@svovaf)
10724
- * @since 1.2.2.7
10725
- *
10726
- * @param bool $lowercase
10727
- *
10728
- * @return string
10729
- */
10730
- function get_module_label( $lowercase = false ) {
10731
- $label = $this->is_addon() ?
10732
- $this->get_text_inline( 'Add-On', 'addon' ) :
10733
- ( $this->is_plugin() ?
10734
- $this->get_text_inline( 'Plugin', 'plugin' ) :
10735
- $this->get_text_inline( 'Theme', 'theme' ) );
10736
-
10737
- if ( $lowercase ) {
10738
- $label = strtolower( $label );
10739
- }
10740
-
10741
- return $label;
10742
- }
10743
-
10744
- /**
10745
- * @author Vova Feldman (@svovaf)
10746
- * @since 1.0.4
10747
- *
10748
- * @return string
10749
- */
10750
- function get_plugin_basename() {
10751
- if ( ! isset( $this->_plugin_basename ) ) {
10752
- if ( $this->is_plugin() ) {
10753
- $this->_plugin_basename = plugin_basename( $this->_plugin_main_file_path );
10754
- } else {
10755
- $this->_plugin_basename = basename( dirname( $this->_plugin_main_file_path ) );
10756
- }
10757
- }
10758
-
10759
- return $this->_plugin_basename;
10760
- }
10761
-
10762
- function get_plugin_folder_name() {
10763
- $this->_logger->entrance();
10764
-
10765
- $plugin_folder = $this->_plugin_basename;
10766
-
10767
- while ( '.' !== dirname( $plugin_folder ) ) {
10768
- $plugin_folder = dirname( $plugin_folder );
10769
- }
10770
-
10771
- $this->_logger->departure( 'Folder Name = ' . $plugin_folder );
10772
-
10773
- return $plugin_folder;
10774
- }
10775
-
10776
- #endregion ------------------------------------------------------------------
10777
-
10778
- /* Account
10779
- ------------------------------------------------------------------------------------------------------------------*/
10780
-
10781
- /**
10782
- * Find plugin's slug by plugin's basename.
10783
- *
10784
- * @author Vova Feldman (@svovaf)
10785
- * @since 1.0.9
10786
- *
10787
- * @param string $plugin_base_name
10788
- *
10789
- * @return false|string
10790
- */
10791
- private static function find_slug_by_basename( $plugin_base_name ) {
10792
- $file_slug_map = self::$_accounts->get_option( 'file_slug_map', array() );
10793
-
10794
- if ( ! array( $file_slug_map ) || ! isset( $file_slug_map[ $plugin_base_name ] ) ) {
10795
- return false;
10796
- }
10797
-
10798
- return $file_slug_map[ $plugin_base_name ];
10799
- }
10800
-
10801
- /**
10802
- * Store the map between the plugin's basename to the slug.
10803
- *
10804
- * @author Vova Feldman (@svovaf)
10805
- * @since 1.0.9
10806
- */
10807
- private function store_file_slug_map() {
10808
- $file_slug_map = self::$_accounts->get_option( 'file_slug_map', array() );
10809
-
10810
- if ( ! array( $file_slug_map ) ) {
10811
- $file_slug_map = array();
10812
- }
10813
-
10814
- if ( ! isset( $file_slug_map[ $this->_plugin_basename ] ) ||
10815
- $file_slug_map[ $this->_plugin_basename ] !== $this->_slug
10816
- ) {
10817
- $file_slug_map[ $this->_plugin_basename ] = $this->_slug;
10818
- self::$_accounts->set_option( 'file_slug_map', $file_slug_map, true );
10819
- }
10820
- }
10821
-
10822
- /**
10823
- * @return array[number]FS_User
10824
- */
10825
- static function get_all_users() {
10826
- $users = self::maybe_get_entities_account_option( 'users', array() );
10827
-
10828
- if ( ! is_array( $users ) ) {
10829
- $users = array();
10830
- }
10831
-
10832
- return $users;
10833
- }
10834
-
10835
- /**
10836
- * @param string $module_type
10837
- * @param null|int $blog_id Since 2.0.0
10838
- *
10839
- * @return array[string]FS_Site
10840
- */
10841
- private static function get_all_sites(
10842
- $module_type = WP_FS__MODULE_TYPE_PLUGIN,
10843
- $blog_id = null,
10844
- $is_backup = false
10845
- ) {
10846
- $sites = self::get_account_option(
10847
- ( $is_backup ? 'prev_' : '' ) . 'sites',
10848
- $module_type,
10849
- $blog_id
10850
- );
10851
-
10852
- if ( ! is_array( $sites ) ) {
10853
- $sites = array();
10854
- }
10855
-
10856
- return $sites;
10857
- }
10858
-
10859
- /**
10860
- * @author Leo Fajardo (@leorw)
10861
- *
10862
- * @since 1.2.2
10863
- *
10864
- * @param string $option_name
10865
- * @param string $module_type
10866
- * @param null|int $network_level_or_blog_id Since 2.0.0
10867
- *
10868
- * @return mixed
10869
- */
10870
- private static function get_account_option( $option_name, $module_type = null, $network_level_or_blog_id = null ) {
10871
- if ( ! is_null( $module_type ) && WP_FS__MODULE_TYPE_PLUGIN !== $module_type ) {
10872
- $option_name = $module_type . '_' . $option_name;
10873
- }
10874
-
10875
- return self::maybe_get_entities_account_option( $option_name, array(), $network_level_or_blog_id );
10876
- }
10877
-
10878
- /**
10879
- * @author Leo Fajardo (@leorw)
10880
- *
10881
- * @since 1.2.2
10882
- *
10883
- * @param string $option_name
10884
- * @param mixed $option_value
10885
- * @param bool $store
10886
- * @param null|int $network_level_or_blog_id Since 2.0.0
10887
- */
10888
- private function set_account_option( $option_name, $option_value, $store, $network_level_or_blog_id = null ) {
10889
- self::set_account_option_by_module(
10890
- $this->_module_type,
10891
- $option_name,
10892
- $option_value,
10893
- $store,
10894
- $network_level_or_blog_id
10895
- );
10896
- }
10897
-
10898
- /**
10899
- * @author Vova Feldman (@svovaf)
10900
- *
10901
- * @since 1.2.2.7
10902
- *
10903
- * @param string $module_type
10904
- * @param string $option_name
10905
- * @param mixed $option_value
10906
- * @param bool $store
10907
- * @param null|int $network_level_or_blog_id Since 2.0.0
10908
- */
10909
- private static function set_account_option_by_module(
10910
- $module_type,
10911
- $option_name,
10912
- $option_value,
10913
- $store,
10914
- $network_level_or_blog_id = null
10915
- ) {
10916
- if ( WP_FS__MODULE_TYPE_PLUGIN != $module_type ) {
10917
- $option_name = $module_type . '_' . $option_name;
10918
- }
10919
-
10920
- self::$_accounts->set_option( $option_name, $option_value, $store, $network_level_or_blog_id );
10921
- }
10922
-
10923
- /**
10924
- * This method can also return non-entity or non-entities collection option like the `user_id_license_ids_map` option.
10925
- *
10926
- * @author Leo Fajardo (@leorw)
10927
- * @since 2.3.1
10928
- *
10929
- * @param string $option_name
10930
- * @param mixed $default
10931
- * @param null|bool|int $network_level_or_blog_id When an integer, use the given blog storage. When `true` use the multisite storage (if there's a network). When `false`, use the current context blog storage. When `null`, the decision which storage to use (MS vs. Current S) will be handled internally and determined based on the $option (based on self::$_SITE_LEVEL_PARAMS).
10932
- *
10933
- * @return mixed|FS_Plugin[]|FS_User[]|FS_Site[]|FS_Plugin_License[]|FS_Plugin_Plan[]|FS_Plugin_Tag[]
10934
- */
10935
- private static function maybe_get_entities_account_option( $option_name, $default = null, $network_level_or_blog_id = null ) {
10936
- $option = self::$_accounts->get_option( $option_name, $default, $network_level_or_blog_id );
10937
-
10938
- $class_name = '';
10939
-
10940
- if ( fs_starts_with( $option_name, WP_FS__MODULE_TYPE_THEME . '_' ) ) {
10941
- $option_name = str_replace( WP_FS__MODULE_TYPE_THEME . '_', '', $option_name );
10942
- }
10943
-
10944
- switch ( $option_name ) {
10945
- case 'plugins':
10946
- case 'themes':
10947
- case 'addons':
10948
- $class_name = FS_Plugin::get_class_name();
10949
- break;
10950
- case 'users':
10951
- $class_name = FS_User::get_class_name();
10952
- break;
10953
- case 'sites':
10954
- $class_name = FS_Site::get_class_name();
10955
- break;
10956
- case 'licenses':
10957
- case 'all_licenses':
10958
- $class_name = FS_Plugin_License::get_class_name();
10959
- break;
10960
- case 'plans':
10961
- $class_name = FS_Plugin_Plan::get_class_name();
10962
- break;
10963
- case 'updates':
10964
- $class_name = FS_Plugin_Tag::get_class_name();
10965
- break;
10966
- }
10967
-
10968
- if ( empty( $class_name ) ) {
10969
- return $option;
10970
- }
10971
-
10972
- return fs_get_entities( $option, $class_name );
10973
- }
10974
-
10975
- /**
10976
- * @author Vova Feldman (@svovaf)
10977
- * @since 1.0.6
10978
- *
10979
- * @param number|null $module_id
10980
- *
10981
- * @return FS_Plugin_License[]
10982
- */
10983
- private static function get_all_licenses( $module_id = null ) {
10984
- $licenses = self::get_account_option( 'all_licenses' );
10985
-
10986
- if ( ! is_array( $licenses ) ) {
10987
- $licenses = array();
10988
- }
10989
-
10990
- if ( is_null( $module_id ) ) {
10991
- return $licenses;
10992
- }
10993
-
10994
- $licenses = isset( $licenses[ $module_id ] ) ?
10995
- $licenses[ $module_id ] :
10996
- array();
10997
-
10998
- return $licenses;
10999
- }
11000
-
11001
- /**
11002
- * @author Leo Fajardo (@leorw)
11003
- * @since 2.0.0
11004
- *
11005
- * @return array
11006
- */
11007
- private static function get_all_licenses_by_module_type() {
11008
- $licenses = self::get_account_option( 'all_licenses' );
11009
-
11010
- $licenses_by_module_type = array(
11011
- WP_FS__MODULE_TYPE_PLUGIN => array(),
11012
- WP_FS__MODULE_TYPE_THEME => array()
11013
- );
11014
-
11015
- if ( ! is_array( $licenses ) ) {
11016
- return $licenses_by_module_type;
11017
- }
11018
-
11019
- foreach ( $licenses as $module_id => $module_licenses ) {
11020
- $fs = self::get_instance_by_id( $module_id );
11021
- if ( false === $fs ) {
11022
- continue;
11023
- }
11024
-
11025
- $licenses_by_module_type[ $fs->_module_type ] = array_merge( $licenses_by_module_type[ $fs->_module_type ], $module_licenses );
11026
- }
11027
-
11028
- return $licenses_by_module_type;
11029
- }
11030
-
11031
- /**
11032
- * @author Leo Fajardo (@leorw)
11033
- * @since 2.0.0
11034
- *
11035
- * @param number $module_id
11036
- * @param number|null $user_id
11037
- *
11038
- * @return array
11039
- */
11040
- private static function get_user_id_license_ids_map( $module_id, $user_id = null ) {
11041
- $all_modules_user_id_license_ids_map = self::get_account_option( 'user_id_license_ids_map' );
11042
-
11043
- if ( ! is_array( $all_modules_user_id_license_ids_map ) ) {
11044
- $all_modules_user_id_license_ids_map = array();
11045
- }
11046
-
11047
- $user_id_license_ids_map = isset( $all_modules_user_id_license_ids_map[ $module_id ] ) ?
11048
- $all_modules_user_id_license_ids_map[ $module_id ] :
11049
- array();
11050
-
11051
- if ( FS_User::is_valid_id( $user_id ) ) {
11052
- $user_id_license_ids_map = isset( $user_id_license_ids_map[ $user_id ] ) ?
11053
- $user_id_license_ids_map[ $user_id ] :
11054
- array();
11055
- }
11056
-
11057
- return $user_id_license_ids_map;
11058
- }
11059
-
11060
- /**
11061
- * @author Leo Fajardo (@leorw)
11062
- * @since 2.0.0
11063
- *
11064
- * @param array $new_user_id_license_ids_map
11065
- * @param number $module_id
11066
- * @param number|null $user_id
11067
- */
11068
- private static function store_user_id_license_ids_map( $new_user_id_license_ids_map, $module_id, $user_id = null ) {
11069
- $all_modules_user_id_license_ids_map = self::get_account_option( 'user_id_license_ids_map' );
11070
- if ( ! is_array( $all_modules_user_id_license_ids_map ) ) {
11071
- $all_modules_user_id_license_ids_map = array();
11072
- }
11073
-
11074
- if ( ! isset( $all_modules_user_id_license_ids_map[ $module_id ] ) ) {
11075
- $all_modules_user_id_license_ids_map[ $module_id ] = array();
11076
- }
11077
-
11078
- if ( FS_User::is_valid_id( $user_id ) ) {
11079
- $all_modules_user_id_license_ids_map[ $module_id ][ $user_id ] = $new_user_id_license_ids_map;
11080
- } else {
11081
- $all_modules_user_id_license_ids_map[ $module_id ] = $new_user_id_license_ids_map;
11082
- }
11083
-
11084
- self::$_accounts->set_option( 'user_id_license_ids_map', $all_modules_user_id_license_ids_map, true );
11085
- }
11086
-
11087
- /**
11088
- * Get a collection of the user's linked license IDs.
11089
- *
11090
- * @author Vova Feldman (@svovaf)
11091
- * @since 2.0.0
11092
- *
11093
- * @param number $user_id
11094
- *
11095
- * @return number[]
11096
- */
11097
- private function get_user_linked_license_ids( $user_id ) {
11098
- return self::get_user_id_license_ids_map( $this->_module_id, $user_id );
11099
- }
11100
-
11101
- /**
11102
- * Override the user's linked license IDs with a new IDs collection.
11103
- *
11104
- * @author Vova Feldman (@svovaf)
11105
- * @since 2.0.0
11106
- *
11107
- * @param number $user_id
11108
- * @param number[] $license_ids
11109
- */
11110
- private function set_user_linked_license_ids( $user_id, array $license_ids ) {
11111
- self::store_user_id_license_ids_map( $license_ids, $this->_module_id, $user_id );
11112
- }
11113
-
11114
- /**
11115
- * Link a specified license ID to a given user.
11116
- *
11117
- * @author Vova Feldman (@svovaf)
11118
- * @since 2.0.0
11119
- *
11120
- * @param number $license_id
11121
- * @param number $user_id
11122
- */
11123
- private function link_license_2_user( $license_id, $user_id ) {
11124
- $license_ids = $this->get_user_linked_license_ids( $user_id );
11125
-
11126
- if ( in_array( $license_id, $license_ids ) ) {
11127
- // License already linked.
11128
- return;
11129
- }
11130
-
11131
- $license_ids[] = $license_id;
11132
-
11133
- $this->set_user_linked_license_ids( $user_id, $license_ids );
11134
- }
11135
-
11136
- /**
11137
- * @param string|bool $module_type
11138
- *
11139
- * @return FS_Plugin_Plan[]
11140
- */
11141
- private static function get_all_plans( $module_type = false ) {
11142
- $plans = self::get_account_option( 'plans', $module_type );
11143
-
11144
- if ( ! is_array( $plans ) ) {
11145
- $plans = array();
11146
- }
11147
-
11148
- return $plans;
11149
- }
11150
-
11151
- /**
11152
- * @author Vova Feldman (@svovaf)
11153
- * @since 1.0.4
11154
- *
11155
- * @return FS_Plugin_Tag[]
11156
- */
11157
- private static function get_all_updates() {
11158
- $updates = self::maybe_get_entities_account_option( 'updates', array() );
11159
-
11160
- if ( ! is_array( $updates ) ) {
11161
- $updates = array();
11162
- }
11163
-
11164
- return $updates;
11165
- }
11166
-
11167
- /**
11168
- * @author Vova Feldman (@svovaf)
11169
- * @since 1.0.6
11170
- *
11171
- * @return array<number,FS_Plugin[]>|false
11172
- */
11173
- private static function get_all_addons() {
11174
- $addons = self::maybe_get_entities_account_option( 'addons', array() );
11175
-
11176
- if ( ! is_array( $addons ) ) {
11177
- $addons = array();
11178
- }
11179
-
11180
- return $addons;
11181
- }
11182
-
11183
- /**
11184
- * @author Vova Feldman (@svovaf)
11185
- * @since 1.0.6
11186
- *
11187
- * @return number[]|false
11188
- */
11189
- private static function get_all_account_addons() {
11190
- $addons = self::$_accounts->get_option( 'account_addons', array() );
11191
-
11192
- if ( ! is_array( $addons ) ) {
11193
- $addons = array();
11194
- }
11195
-
11196
- return $addons;
11197
- }
11198
-
11199
- /**
11200
- * Check if user has connected his account (opted-in).
11201
- *
11202
- * Note:
11203
- * If the user opted-in and opted-out on a later stage,
11204
- * this will still return true. If you want to check if the
11205
- * user is currently opted-in, use:
11206
- * `$fs->is_registered() && $fs->is_tracking_allowed()`
11207
- *
11208
- * @author Vova Feldman (@svovaf)
11209
- * @since 1.0.1
11210
- * @return bool
11211
- */
11212
- function is_registered() {
11213
- return is_object( $this->_user );
11214
- }
11215
-
11216
- /**
11217
- * Returns TRUE if the user opted-in and didn't disconnect (opt-out).
11218
- *
11219
- * @author Leo Fajardo (@leorw)
11220
- * @since 1.2.1.5
11221
- *
11222
- * @return bool
11223
- */
11224
- function is_tracking_allowed() {
11225
- return ( is_object( $this->_site ) && $this->_site->is_tracking_allowed() );
11226
- }
11227
-
11228
- /**
11229
- * @author Leo Fajardo (@leorw)
11230
- * @since 2.4.0
11231
- *
11232
- * @return bool
11233
- */
11234
- function is_bundle_license_auto_activation_enabled() {
11235
- return $this->is_addon() ?
11236
- ( is_object( $this->_parent ) && $this->_parent->is_bundle_license_auto_activation_enabled() ) :
11237
- $this->_is_bundle_license_auto_activation_enabled;
11238
- }
11239
-
11240
- /**
11241
- * @author Vova Feldman (@svovaf)
11242
- * @since 1.0.4
11243
- *
11244
- * @return FS_Plugin
11245
- */
11246
- function get_plugin() {
11247
- return $this->_plugin;
11248
- }
11249
-
11250
- /**
11251
- * @author Vova Feldman (@svovaf)
11252
- * @since 1.0.3
11253
- *
11254
- * @return FS_User
11255
- */
11256
- function get_user() {
11257
- return $this->_user;
11258
- }
11259
-
11260
- /**
11261
- * @author Vova Feldman (@svovaf)
11262
- * @since 1.0.3
11263
- *
11264
- * @return FS_Site
11265
- */
11266
- function get_site() {
11267
- return $this->_site;
11268
- }
11269
-
11270
- /**
11271
- * @author Leo Fajardo (@leorw)
11272
- * @since 2.5.0
11273
- */
11274
- function store_site( $site ) {
11275
- $this->_site = $site;
11276
- $this->_store_site( true );
11277
- }
11278
-
11279
- /**
11280
- * Deletes the current install with an option to back it up in case restoration will be needed (e.g., if the automatic clone resolution attempt fails).
11281
- *
11282
- * @author Leo Fajardo (@leorw)
11283
- * @since 2.5.0
11284
- */
11285
- function delete_current_install( $back_up ) {
11286
- // Back up and delete the unique ID.
11287
- if ( $back_up ) {
11288
- self::$_accounts->set_option( 'prev_unique_id', $this->get_anonymous_id() );
11289
- }
11290
-
11291
- self::$_accounts->set_option( 'unique_id', null );
11292
-
11293
- if ( $back_up ) {
11294
- // Back up the install before deleting it so that it can be restored later on if necessary (e.g., if the automatic clone resolution attempt fails).
11295
- $this->back_up_site();
11296
- }
11297
-
11298
- $this->_delete_site();
11299
- $this->_site = null;
11300
- }
11301
-
11302
- /**
11303
- * @author Leo Fajardo (@leorw)
11304
- * @since 2.5.0
11305
- */
11306
- function restore_backup_site() {
11307
- self::$_accounts->set_option(
11308
- 'unique_id',
11309
- self::$_accounts->get_option( 'prev_unique_id' )
11310
- );
11311
-
11312
- $sites = self::get_all_sites( $this->_module_type, null, true );
11313
- $this->store_site( clone $sites[ $this->_slug ] );
11314
- }
11315
-
11316
- /**
11317
- * Get plugin add-ons.
11318
- *
11319
- * @author Vova Feldman (@svovaf)
11320
- * @since 1.0.6
11321
- *
11322
- * @since 1.1.7.3 If not yet loaded, fetch data from the API.
11323
- *
11324
- * @param bool $flush
11325
- *
11326
- * @return FS_Plugin[]|false
11327
- */
11328
- function get_addons( $flush = false ) {
11329
- $this->_logger->entrance();
11330
-
11331
- if ( ! $this->_has_addons ) {
11332
- return false;
11333
- }
11334
-
11335
- $addons = $this->sync_addons( $flush );
11336
-
11337
- return ( ! is_array( $addons ) || empty( $addons ) ) ?
11338
- false :
11339
- $addons;
11340
- }
11341
-
11342
- /**
11343
- * @author Vova Feldman (@svovaf)
11344
- * @since 1.0.6
11345
- *
11346
- * @return number[]|false
11347
- */
11348
- function get_account_addons() {
11349
- $this->_logger->entrance();
11350
-
11351
- $addons = self::get_all_account_addons();
11352
-
11353
- if ( ! is_array( $addons ) ||
11354
- ! isset( $addons[ $this->_plugin->id ] ) ||
11355
- ! is_array( $addons[ $this->_plugin->id ] ) ||
11356
- 0 === count( $addons[ $this->_plugin->id ] )
11357
- ) {
11358
- return false;
11359
- }
11360
-
11361
- return $addons[ $this->_plugin->id ];
11362
- }
11363
-
11364
- /**
11365
- * Check if user has any
11366
- *
11367
- * @author Vova Feldman (@svovaf)
11368
- * @since 1.1.6
11369
- *
11370
- * @return bool
11371
- */
11372
- function has_account_addons() {
11373
- $addons = $this->get_account_addons();
11374
-
11375
- return is_array( $addons ) && ( 0 < count( $addons ) );
11376
- }
11377
-
11378
-
11379
- /**
11380
- * Get add-on by ID (from local data).
11381
- *
11382
- * @author Vova Feldman (@svovaf)
11383
- * @since 1.0.6
11384
- *
11385
- * @param number $id
11386
- *
11387
- * @return FS_Plugin|false
11388
- */
11389
- function get_addon( $id ) {
11390
- $this->_logger->entrance();
11391
-
11392
- $addons = $this->get_addons();
11393
-
11394
- if ( is_array( $addons ) ) {
11395
- foreach ( $addons as $addon ) {
11396
- if ( $id == $addon->id ) {
11397
- return $addon;
11398
- }
11399
- }
11400
- }
11401
-
11402
- return false;
11403
- }
11404
-
11405
- /**
11406
- * Get add-on by slug (from local data).
11407
- *
11408
- * @author Vova Feldman (@svovaf)
11409
- * @since 1.0.6
11410
- *
11411
- * @param string $slug
11412
- *
11413
- * @param bool $flush
11414
- *
11415
- * @return FS_Plugin|false
11416
- */
11417
- function get_addon_by_slug( $slug, $flush = false ) {
11418
- $this->_logger->entrance();
11419
-
11420
- $addons = $this->get_addons( $flush );
11421
-
11422
- if ( is_array( $addons ) ) {
11423
- foreach ( $addons as $addon ) {
11424
- if ( $slug === $addon->slug ) {
11425
- return $addon;
11426
- }
11427
- }
11428
- }
11429
-
11430
- return false;
11431
- }
11432
-
11433
- /**
11434
- * @var array<number,object[]> {
11435
- * @key number Add-on ID.
11436
- * @val object[] The add-on's plans and prices object.
11437
- * }
11438
- */
11439
- private $plans_and_pricing_by_addon_id;
11440
-
11441
- /**
11442
- * @author Leo Fajardo (@leorw)
11443
- * @since 2.3.0
11444
- *
11445
- * @return array<number,object[]> {
11446
- * @key number Add-on ID.
11447
- * @val object[] The add-on's plans and prices object.
11448
- * }
11449
- */
11450
- function _get_addons_plans_and_pricing_map_by_id() {
11451
- if ( ! isset( $this->plans_and_pricing_by_addon_id ) ) {
11452
- $result = $this->get_api_plugin_scope()->get( $this->add_show_pending( "/addons/pricing.json?type=visible" ) );
11453
-
11454
- $plans_and_pricing_by_addon_id = array();
11455
- if ( $this->is_api_result_object( $result, 'addons' ) ) {
11456
- foreach ( $result->addons as $addon ) {
11457
- $plans_and_pricing_by_addon_id[ $addon->id ] = $addon->plans;
11458
- }
11459
- }
11460
-
11461
- $this->plans_and_pricing_by_addon_id = $plans_and_pricing_by_addon_id;
11462
- }
11463
-
11464
- return $this->plans_and_pricing_by_addon_id;
11465
- }
11466
-
11467
- /**
11468
- * @author Leo Fajardo (@leorw)
11469
- * @since 2.3.0
11470
- *
11471
- * @param number $addon_id
11472
- * @param bool $is_installed
11473
- *
11474
- * @return array
11475
- */
11476
- function _get_addon_info( $addon_id, $is_installed ) {
11477
- $addon = $this->get_addon( $addon_id );
11478
-
11479
- if ( ! is_object( $addon ) ) {
11480
- // Unexpected call.
11481
- return array();
11482
- }
11483
-
11484
- $slug = $addon->slug;
11485
-
11486
- $addon_storage = FS_Storage::instance( WP_FS__MODULE_TYPE_PLUGIN, $slug );
11487
-
11488
- if ( ! fs_is_network_admin() ) {
11489
- // Get blog-level activated installations.
11490
- $sites = self::maybe_get_entities_account_option( 'sites', array() );
11491
- } else {
11492
- $sites = null;
11493
-
11494
- if ( $this->is_addon_activated( $addon_id ) &&
11495
- $this->get_addon_instance( $addon_id )->is_network_active()
11496
- ) {
11497
- if ( FS_Site::is_valid_id( $addon_storage->network_install_blog_id ) ) {
11498
- // Get network-level activated installations.
11499
- $sites = self::maybe_get_entities_account_option(
11500
- 'sites',
11501
- array(),
11502
- $addon_storage->network_install_blog_id
11503
- );
11504
- }
11505
- }
11506
- }
11507
-
11508
- $addon_info = array(
11509
- 'is_connected' => false,
11510
- 'slug' => $slug,
11511
- 'title' => $addon->title,
11512
- 'is_whitelabeled' => $addon_storage->is_whitelabeled
11513
- );
11514
-
11515
- if ( ! $is_installed ) {
11516
- $plans_and_pricing_by_addon_id = $this->_get_addons_plans_and_pricing_map_by_id();
11517
-
11518
- if ( isset( $plans_and_pricing_by_addon_id[ $addon_id ] ) ) {
11519
- $has_paid_plan = false;
11520
- $plans = $plans_and_pricing_by_addon_id[ $addon_id ];
11521
-
11522
- if ( is_array( $plans ) && count( $plans ) > 0 ) {
11523
- foreach ( $plans as $plan ) {
11524
- if ( isset( $plan->pricing ) &&
11525
- is_array( $plan->pricing ) &&
11526
- count( $plan->pricing ) > 0
11527
- ) {
11528
- $has_paid_plan = true;
11529
- break;
11530
- }
11531
- }
11532
- }
11533
-
11534
- $addon_info['has_paid_plan'] = $has_paid_plan;
11535
- }
11536
- }
11537
-
11538
- if ( ! is_array( $sites ) || ! isset( $sites[ $slug ] ) ) {
11539
- return $addon_info;
11540
- }
11541
-
11542
- $site = $sites[ $slug ];
11543
-
11544
- $addon_info['is_connected'] = (
11545
- ( $addon->parent_plugin_id == $this->get_id() ) &&
11546
- is_object( $site ) &&
11547
- FS_Site::is_valid_id( $site->id ) &&
11548
- FS_User::is_valid_id( $site->user_id ) &&
11549
- FS_Plugin_Plan::is_valid_id( $site->plan_id )
11550
- );
11551
-
11552
- if ( $addon_info['is_connected'] && $is_installed ) {
11553
- return $addon_info;
11554
- }
11555
-
11556
- $addon_info['site'] = $site;
11557
-
11558
- $plugins_data = self::maybe_get_entities_account_option( WP_FS__MODULE_TYPE_PLUGIN . 's', array() );
11559
- if ( isset( $plugins_data[ $slug ] ) ) {
11560
- $plugin_data = $plugins_data[ $slug ];
11561
-
11562
- $addon_info['version'] = $plugin_data->version;
11563
- }
11564
-
11565
- $all_plans = self::maybe_get_entities_account_option( 'plans', array() );
11566
- if ( isset( $all_plans[ $slug ] ) ) {
11567
- $plans = $all_plans[ $slug ];
11568
-
11569
- foreach ( $plans as $plan ) {
11570
- if ( $site->plan_id == Freemius::_decrypt( $plan->id ) ) {
11571
- $addon_info['plan_name'] = Freemius::_decrypt( $plan->name );
11572
- $addon_info['plan_title'] = Freemius::_decrypt( $plan->title );
11573
- break;
11574
- }
11575
- }
11576
- }
11577
-
11578
- $licenses = self::maybe_get_entities_account_option( 'all_licenses', array() );
11579
- if ( is_array( $licenses ) && isset( $licenses[ $addon_id ] ) ) {
11580
- foreach ( $licenses[ $addon_id ] as $license ) {
11581
- if ( $license->id == $site->license_id ) {
11582
- $addon_info['license'] = $license;
11583
- break;
11584
- }
11585
- }
11586
- }
11587
-
11588
- if ( isset( $addon_info['license'] ) ) {
11589
- if ( isset( $addon_storage->subscriptions ) &&
11590
- ! empty( $addon_storage->subscriptions )
11591
- ) {
11592
- $addon_subscriptions = fs_get_entities( $addon_storage->subscriptions, FS_Subscription::get_class_name() );
11593
-
11594
- foreach ( $addon_subscriptions as $subscription ) {
11595
- if ( $subscription->license_id == $site->license_id ) {
11596
- $addon_info['subscription'] = $subscription;
11597
- break;
11598
- }
11599
- }
11600
- }
11601
- }
11602
-
11603
- return $addon_info;
11604
- }
11605
-
11606
- /**
11607
- * @author Vova Feldman (@svovaf)
11608
- * @since 2.0.0
11609
- *
11610
- * @param number $user_id
11611
- *
11612
- * @return FS_User
11613
- */
11614
- static function _get_user_by_id( $user_id ) {
11615
- self::$_static_logger->entrance( "user_id = {$user_id}" );
11616
-
11617
- $users = self::get_all_users();
11618
-
11619
- if ( is_array( $users ) ) {
11620
- if ( isset( $users[ $user_id ] ) &&
11621
- $users[ $user_id ] instanceof FS_User &&
11622
- $user_id == $users[ $user_id ]->id
11623
- ) {
11624
- return $users[ $user_id ];
11625
- }
11626
-
11627
- // If user wasn't found by the key, iterate over all the users collection.
11628
- foreach ( $users as $user ) {
11629
- /**
11630
- * @var FS_User $user
11631
- */
11632
- if ( $user_id == $user->id ) {
11633
- return $user;
11634
- }
11635
- }
11636
- }
11637
-
11638
- return null;
11639
- }
11640
-
11641
- /**
11642
- * Checks if a Freemius user_id is associated with a super-admin.
11643
- *
11644
- * @author Vova Feldman (@svovaf)
11645
- * @since 2.0.0
11646
- *
11647
- * @param number $user_id
11648
- *
11649
- * @return bool
11650
- */
11651
- private static function is_super_admin( $user_id ) {
11652
- $is_super_admin = false;
11653
-
11654
- $user = self::_get_user_by_id( $user_id );
11655
-
11656
- if ( $user instanceof FS_User && ! empty( $user->email ) ) {
11657
- self::require_pluggable_essentials();
11658
-
11659
- $wp_user = get_user_by( 'email', $user->email );
11660
-
11661
- if ( $wp_user instanceof WP_User ) {
11662
- $super_admins = get_super_admins();
11663
- $is_super_admin = ( is_array( $super_admins ) && in_array( $wp_user->user_login, $super_admins ) );
11664
- }
11665
- }
11666
-
11667
- return $is_super_admin;
11668
- }
11669
-
11670
- #----------------------------------------------------------------------------------
11671
- #region Plans & Licensing
11672
- #----------------------------------------------------------------------------------
11673
-
11674
- /**
11675
- * Check if running premium plugin code.
11676
- *
11677
- * @author Vova Feldman (@svovaf)
11678
- * @since 1.0.5
11679
- *
11680
- * @return bool
11681
- */
11682
- function is_premium() {
11683
- /**
11684
- * `$this->_plugin` will be `false` when `is_activation_mode` calls this method directly from the
11685
- * `register_constructor_hooks` method.
11686
- *
11687
- * @author Leo Fajardo (@leorw)
11688
- * @since 2.2.3
11689
- */
11690
- return is_object( $this->_plugin ) ?
11691
- $this->_plugin->is_premium :
11692
- false;
11693
- }
11694
-
11695
- /**
11696
- * Get site's plan ID.
11697
- *
11698
- * @author Vova Feldman (@svovaf)
11699
- * @since 1.0.2
11700
- *
11701
- * @return number
11702
- */
11703
- function get_plan_id() {
11704
- return $this->_site->plan_id;
11705
- }
11706
-
11707
- /**
11708
- * Get site's plan title.
11709
- *
11710
- * @author Vova Feldman (@svovaf)
11711
- * @since 1.0.2
11712
- *
11713
- * @return string
11714
- */
11715
- function get_plan_title() {
11716
- $plan = $this->get_plan();
11717
-
11718
- return is_object( $plan ) ? $plan->title : 'PLAN_TITLE';
11719
- }
11720
-
11721
- /**
11722
- * Get site's plan name.
11723
- *
11724
- * @author Vova Feldman (@svovaf)
11725
- * @since 2.0.0
11726
- *
11727
- * @return string
11728
- */
11729
- function get_plan_name() {
11730
- $plan = $this->get_plan();
11731
-
11732
- return is_object( $plan ) ? $plan->name : 'PLAN_NAME';
11733
- }
11734
-
11735
- /**
11736
- * @author Vova Feldman (@svovaf)
11737
- * @since 1.0.9
11738
- *
11739
- * @return FS_Plugin_Plan|false
11740
- */
11741
- function get_plan() {
11742
- if ( ! is_object( $this->_site ) ) {
11743
- return false;
11744
- }
11745
-
11746
- return FS_Plugin_Plan::is_valid_id( $this->_site->plan_id ) ?
11747
- $this->_get_plan_by_id( $this->_site->plan_id ) :
11748
- false;
11749
- }
11750
-
11751
- /**
11752
- * @author Vova Feldman (@svovaf)
11753
- * @since 1.0.3
11754
- *
11755
- * @return bool
11756
- */
11757
- function is_trial() {
11758
- $this->_logger->entrance();
11759
-
11760
- if ( ! $this->is_registered() || ! is_object( $this->_site ) ) {
11761
- return false;
11762
- }
11763
-
11764
- return $this->_site->is_trial();
11765
- }
11766
-
11767
- /**
11768
- * Check if currently in a trial with payment method (credit card or paypal).
11769
- *
11770
- * @author Vova Feldman (@svovaf)
11771
- * @since 1.1.7
11772
- *
11773
- * @return bool
11774
- */
11775
- function is_paid_trial() {
11776
- $this->_logger->entrance();
11777
-
11778
- if ( ! $this->is_trial() ) {
11779
- return false;
11780
- }
11781
-
11782
- if ( ! $this->has_active_valid_license() ) {
11783
- return false;
11784
- }
11785
-
11786
- if ( $this->_site->trial_plan_id != $this->_license->plan_id ) {
11787
- return false;
11788
- }
11789
-
11790
- /**
11791
- * @var FS_Subscription $subscription
11792
- */
11793
- $subscription = $this->_get_subscription( $this->_license->id );
11794
-
11795
- return ( is_object( $subscription ) && $subscription->is_active() );
11796
- }
11797
-
11798
- /**
11799
- * Check if trial already utilized.
11800
- *
11801
- * @since 1.0.9
11802
- *
11803
- * @return bool
11804
- */
11805
- function is_trial_utilized() {
11806
- $this->_logger->entrance();
11807
-
11808
- if ( ! $this->is_registered() ) {
11809
- return false;
11810
- }
11811
-
11812
- return $this->_site->is_trial_utilized();
11813
- }
11814
-
11815
- /**
11816
- * Get trial plan information (if in trial).
11817
- *
11818
- * @author Vova Feldman (@svovaf)
11819
- * @since 1.0.9
11820
- *
11821
- * @return bool|FS_Plugin_Plan
11822
- */
11823
- function get_trial_plan() {
11824
- $this->_logger->entrance();
11825
-
11826
- if ( ! $this->is_trial() ) {
11827
- return false;
11828
- }
11829
-
11830
- // Try to load plan from local cache.
11831
- $trial_plan = $this->_get_plan_by_id( $this->_site->trial_plan_id );
11832
-
11833
- if ( ! is_object( $trial_plan ) ) {
11834
- $trial_plan = $this->_fetch_site_plan( $this->_site->trial_plan_id );
11835
-
11836
- /**
11837
- * If managed to fetch the plan, add it to the plans collection.
11838
- */
11839
- if ( $trial_plan instanceof FS_Plugin_Plan ) {
11840
- if ( ! is_array( $this->_plans ) ) {
11841
- $this->_plans = array();
11842
- }
11843
-
11844
- $this->_plans[] = $trial_plan;
11845
- $this->_store_plans();
11846
- }
11847
- }
11848
-
11849
- if ( $trial_plan instanceof FS_Plugin_Plan ) {
11850
- return $trial_plan;
11851
- }
11852
-
11853
- /**
11854
- * If for some reason failed to get the trial plan, fallback to a dummy name and title.
11855
- */
11856
- $trial_plan = new FS_Plugin_Plan();
11857
- $trial_plan->id = $this->_site->trial_plan_id;
11858
- $trial_plan->name = 'pro';
11859
- $trial_plan->title = 'Pro';
11860
-
11861
- return $trial_plan;
11862
- }
11863
-
11864
- /**
11865
- * Check if the user has an activate, non-expired license on current plugin's install.
11866
- *
11867
- * @since 1.0.9
11868
- *
11869
- * @return bool
11870
- */
11871
- function is_paying() {
11872
- $this->_logger->entrance();
11873
-
11874
- if ( ! $this->is_registered() ) {
11875
- return false;
11876
- }
11877
-
11878
- if ( ! $this->has_paid_plan() ) {
11879
- return false;
11880
- }
11881
-
11882
- return (
11883
- ! $this->is_trial() &&
11884
- 'free' !== $this->get_plan_name() &&
11885
- $this->has_active_valid_license()
11886
- );
11887
- }
11888
-
11889
- /**
11890
- * @author Vova Feldman (@svovaf)
11891
- * @since 1.0.4
11892
- *
11893
- * @return bool
11894
- */
11895
- function is_free_plan() {
11896
- if ( ! $this->is_registered() ) {
11897
- return true;
11898
- }
11899
-
11900
- if ( ! $this->has_paid_plan() ) {
11901
- return true;
11902
- }
11903
-
11904
- return (
11905
- 'free' === $this->get_plan_name() ||
11906
- ! $this->has_features_enabled_license()
11907
- );
11908
- }
11909
-
11910
- /**
11911
- * @author Vova Feldman (@svovaf)
11912
- * @since 1.0.5
11913
- *
11914
- * @return bool
11915
- */
11916
- function _has_premium_license() {
11917
- $this->_logger->entrance();
11918
-
11919
- $premium_license = $this->_get_available_premium_license();
11920
-
11921
- return ( false !== $premium_license );
11922
- }
11923
-
11924
- /**
11925
- * Check if user has any licenses associated with the plugin (including expired or blocking).
11926
- *
11927
- * @author Vova Feldman (@svovaf)
11928
- * @since 1.1.7.3
11929
- *
11930
- * @param bool $including_foreign
11931
- *
11932
- * @return bool
11933
- */
11934
- function has_any_license( $including_foreign = true ) {
11935
- if ( ! is_array( $this->_licenses ) || 0 === count( $this->_licenses ) ) {
11936
- return false;
11937
- }
11938
-
11939
- if ( $including_foreign ) {
11940
- return true;
11941
- }
11942
-
11943
- foreach ( $this->_licenses as $license ) {
11944
- if ( $this->_user->id == $license->user_id ) {
11945
- return true;
11946
- }
11947
- }
11948
-
11949
- return false;
11950
- }
11951
-
11952
- /**
11953
- * @author Vova Feldman (@svovaf)
11954
- * @since 1.0.5
11955
- *
11956
- * @param bool|null $is_localhost
11957
- *
11958
- * @return FS_Plugin_License|false
11959
- */
11960
- function _get_available_premium_license( $is_localhost = null ) {
11961
- $this->_logger->entrance();
11962
-
11963
- $licenses = $this->get_available_premium_licenses( $is_localhost );
11964
- if ( ! empty( $licenses ) ) {
11965
- return $licenses[0];
11966
- }
11967
-
11968
- return false;
11969
- }
11970
-
11971
- /**
11972
- * @author Vova Feldman (@svovaf)
11973
- * @since 1.0.5
11974
- *
11975
- * @param bool|null $is_localhost
11976
- *
11977
- * @return FS_Plugin_License[]
11978
- */
11979
- function get_available_premium_licenses( $is_localhost = null ) {
11980
- $this->_logger->entrance();
11981
-
11982
- $licenses = array();
11983
- if ( ! $this->has_paid_plan() ) {
11984
- return $licenses;
11985
- }
11986
-
11987
- if ( is_array( $this->_licenses ) ) {
11988
- foreach ( $this->_licenses as $license ) {
11989
- if ( ! $license->can_activate( $is_localhost ) ) {
11990
- continue;
11991
- }
11992
-
11993
- $licenses[] = $license;
11994
- }
11995
- }
11996
-
11997
- return $licenses;
11998
- }
11999
-
12000
- /**
12001
- * Sync local plugin plans with remote server.
12002
- *
12003
- * IMPORTANT: If for some reason a site is associated with deleted plan, we'll preserve the plan's information and append it as the last plan. This means that if plan is deleted, the is_plan() method will ALWAYS return true for any given argument (it becomes the most inclusive plan).
12004
- *
12005
- * @author Vova Feldman (@svovaf)
12006
- * @since 1.0.5
12007
- *
12008
- * @return FS_Plugin_Plan[]|object
12009
- */
12010
- function _sync_plans() {
12011
- $plans = $this->_fetch_plugin_plans();
12012
-
12013
- if ( $this->is_array_instanceof( $plans, 'FS_Plugin_Plan' ) ) {
12014
- $plans_map = array();
12015
- foreach ( $plans as $plan ) {
12016
- $plans_map[ $plan->id ] = true;
12017
- }
12018
-
12019
- $plans_ids_to_keep = $this->get_plans_ids_associated_with_installs();
12020
-
12021
- foreach ( $plans_ids_to_keep as $plan_id ) {
12022
- if ( isset( $plans_map[ $plan_id ] ) ) {
12023
- continue;
12024
- }
12025
-
12026
- $missing_plan = self::_get_plan_by_id( $plan_id );
12027
-
12028
- if ( is_object( $missing_plan ) ) {
12029
- $plans[] = $missing_plan;
12030
- }
12031
- }
12032
-
12033
- $this->_plans = $plans;
12034
- $this->_store_plans();
12035
- }
12036
-
12037
- $this->do_action( 'after_plans_sync', $plans );
12038
-
12039
- return $this->_plans;
12040
- }
12041
-
12042
- /**
12043
- * Check if specified plan exists locally. If not, fetch it and store it.
12044
- *
12045
- * @author Vova Feldman (@svovaf)
12046
- * @since 2.0.0
12047
- *
12048
- * @param number $plan_id
12049
- *
12050
- * @return \FS_Plugin_Plan|object The plan entity or the API error object on failure.
12051
- */
12052
- private function sync_plan_if_not_exist( $plan_id ) {
12053
- $plan = self::_get_plan_by_id( $plan_id );
12054
-
12055
- if ( is_object( $plan ) ) {
12056
- // Plan already exists.
12057
- return $plan;
12058
- }
12059
-
12060
- $plan = $this->fetch_plan_by_id( $plan_id );
12061
-
12062
- if ( $plan instanceof FS_Plugin_Plan ) {
12063
- $this->_plans[] = $plan;
12064
- $this->_store_plans();
12065
-
12066
- return $plan;
12067
- }
12068
-
12069
- return $plan;
12070
- }
12071
-
12072
- /**
12073
- * Check if specified license exists locally. If not, fetch it and store it.
12074
- *
12075
- * @author Vova Feldman (@svovaf)
12076
- * @since 2.0.0
12077
- *
12078
- * @param number $license_id
12079
- * @param string $license_key
12080
- *
12081
- * @return \FS_Plugin_Plan|object The plan entity or the API error object on failure.
12082
- */
12083
- private function sync_license_if_not_exist( $license_id, $license_key ) {
12084
- $license = $this->_get_license_by_id( $license_id );
12085
-
12086
- if ( is_object( $license ) ) {
12087
- // License already exists.
12088
- return $license;
12089
- }
12090
-
12091
- $license = $this->fetch_license_by_key( $license_id, $license_key );
12092
-
12093
- if ( $license instanceof FS_Plugin_License ) {
12094
- $this->_licenses[] = $license;
12095
-
12096
- $this->set_license( $license );
12097
-
12098
- $this->_store_licenses();
12099
-
12100
- return $license;
12101
- }
12102
-
12103
- return $license;
12104
- }
12105
-
12106
- /**
12107
- * Get a collection of unique plan IDs that are associated with any installs in the network.
12108
- *
12109
- * @author Leo Fajardo (@leorw)
12110
- * @since 2.0.0
12111
- *
12112
- * @return number[]
12113
- */
12114
- private function get_plans_ids_associated_with_installs() {
12115
- if ( ! is_multisite() ) {
12116
- if ( ! is_object( $this->_site ) ||
12117
- ! FS_Plugin_Plan::is_valid_id( $this->_site->plan_id )
12118
- ) {
12119
- return array();
12120
- }
12121
-
12122
- return array( $this->_site->plan_id );
12123
- }
12124
-
12125
- $plan_ids = array();
12126
- $sites = self::get_sites();
12127
- foreach ( $sites as $site ) {
12128
- $blog_id = self::get_site_blog_id( $site );
12129
- $install = $this->get_install_by_blog_id( $blog_id );
12130
-
12131
- if ( ! is_object( $install ) ||
12132
- ! FS_Plugin_Plan::is_valid_id( $install->plan_id )
12133
- ) {
12134
- continue;
12135
- }
12136
-
12137
- $plan_ids[ $install->plan_id ] = true;
12138
- }
12139
-
12140
- return array_keys( $plan_ids );
12141
- }
12142
-
12143
- /**
12144
- * Get a collection of unique license IDs that are associated with any installs in the network.
12145
- *
12146
- * @author Leo Fajardo (@leorw)
12147
- * @since 2.0.0
12148
- *
12149
- * @return number[]
12150
- */
12151
- private function get_license_ids_associated_with_installs() {
12152
- if ( ! $this->_is_network_active ) {
12153
- if ( ! is_object( $this->_site ) ||
12154
- ! FS_Plugin_License::is_valid_id( $this->_site->license_id )
12155
- ) {
12156
- return array();
12157
- }
12158
-
12159
- return array( $this->_site->license_id );
12160
- }
12161
-
12162
- $license_ids = array();
12163
- $sites = self::get_sites();
12164
- foreach ( $sites as $site ) {
12165
- $blog_id = self::get_site_blog_id( $site );
12166
- $install = $this->get_install_by_blog_id( $blog_id );
12167
-
12168
- if ( ! is_object( $install ) ||
12169
- ! FS_Plugin_License::is_valid_id( $install->license_id )
12170
- ) {
12171
- continue;
12172
- }
12173
-
12174
- $license_ids[ $install->license_id ] = true;
12175
- }
12176
-
12177
- return array_keys( $license_ids );
12178
- }
12179
-
12180
- /**
12181
- * @author Vova Feldman (@svovaf)
12182
- * @since 1.0.5
12183
- *
12184
- * @param number $id
12185
- *
12186
- * @return FS_Plugin_Plan|false
12187
- */
12188
- function _get_plan_by_id( $id ) {
12189
- $this->_logger->entrance();
12190
-
12191
- if ( ! is_array( $this->_plans ) || 0 === count( $this->_plans ) ) {
12192
- $this->_sync_plans();
12193
- }
12194
-
12195
- foreach ( $this->_plans as $plan ) {
12196
- if ( $id == $plan->id ) {
12197
- return $plan;
12198
- }
12199
- }
12200
-
12201
- return false;
12202
- }
12203
-
12204
- /**
12205
- * @author Vova Feldman (@svovaf)
12206
- * @since 1.1.8.1
12207
- *
12208
- * @param string $name
12209
- *
12210
- * @return FS_Plugin_Plan|false
12211
- */
12212
- private function get_plan_by_name( $name ) {
12213
- $this->_logger->entrance();
12214
-
12215
- if ( ! is_array( $this->_plans ) || 0 === count( $this->_plans ) ) {
12216
- $this->_sync_plans();
12217
- }
12218
-
12219
- foreach ( $this->_plans as $plan ) {
12220
- if ( $name == $plan->name ) {
12221
- return $plan;
12222
- }
12223
- }
12224
-
12225
- return false;
12226
- }
12227
-
12228
- /**
12229
- * Sync local licenses with remote server.
12230
- *
12231
- * @author Vova Feldman (@svovaf)
12232
- * @since 1.0.6
12233
- *
12234
- * @param number|bool $site_license_id
12235
- * @param number|null $blog_id
12236
- *
12237
- * @return FS_Plugin_License[]|object
12238
- */
12239
- function _sync_licenses( $site_license_id = false, $blog_id = null ) {
12240
- $this->_logger->entrance();
12241
-
12242
- $is_network_admin = fs_is_network_admin();
12243
-
12244
- if ( $is_network_admin && is_null( $blog_id ) ) {
12245
- $all_licenses = self::get_all_licenses( $this->_module_id );
12246
- } else {
12247
- $all_licenses = $this->get_user_licenses( $this->_user->id );
12248
- }
12249
-
12250
- $foreign_licenses = $this->get_foreign_licenses_info( $all_licenses, $site_license_id );
12251
-
12252
- $all_licenses_map = array();
12253
- foreach ( $all_licenses as $license ) {
12254
- $all_licenses_map[ $license->id ] = true;
12255
- }
12256
-
12257
- $licenses = $this->_fetch_licenses( false, $site_license_id, $foreign_licenses, $blog_id );
12258
-
12259
- if ( $this->is_array_instanceof( $licenses, 'FS_Plugin_License' ) ) {
12260
- $licenses_map = array();
12261
- foreach ( $licenses as $license ) {
12262
- $licenses_map[ $license->id ] = true;
12263
- }
12264
-
12265
- // $license_ids_to_keep = $this->get_license_ids_associated_with_installs();
12266
- // foreach ( $license_ids_to_keep as $license_id ) {
12267
- // if ( isset( $licenses_map[ $license_id ] ) ) {
12268
- // continue;
12269
- // }
12270
- //
12271
- // $missing_license = self::_get_license_by_id( $license_id, false );
12272
- // if ( is_object( $missing_license ) ) {
12273
- // $licenses[] = $missing_license;
12274
- // $licenses_map[ $missing_license->id ] = true;
12275
- // }
12276
- // }
12277
-
12278
- $user_license_ids = $this->get_user_linked_license_ids( $this->_user->id );
12279
-
12280
- foreach ( $user_license_ids as $key => $license_id ) {
12281
- if ( ! isset( $licenses_map[ $license_id ] ) ) {
12282
- // Remove access to licenses that no longer exist.
12283
- unset( $user_license_ids[ $key ] );
12284
- }
12285
- }
12286
-
12287
- if ( ! empty( $user_license_ids ) ) {
12288
- foreach ( $licenses_map as $license_id => $value ) {
12289
- if ( ! isset( $all_licenses_map[ $license_id ] ) ) {
12290
- // Associate new licenses with the user who triggered the license syncing.
12291
- $user_license_ids[] = $license_id;
12292
- }
12293
- }
12294
-
12295
- $user_license_ids = array_unique( $user_license_ids );
12296
- } else {
12297
- $user_license_ids = array_keys( $licenses_map );
12298
- }
12299
-
12300
- if ( ! $is_network_admin || ! is_null( $blog_id ) ) {
12301
- $user_licenses = array();
12302
- foreach ( $licenses as $license ) {
12303
- if ( ! in_array( $license->id, $user_license_ids ) ) {
12304
- continue;
12305
- }
12306
-
12307
- $user_licenses[] = $license;
12308
- }
12309
-
12310
- $this->_licenses = $user_licenses;
12311
- } else {
12312
- $this->_licenses = $licenses;
12313
- }
12314
-
12315
- $this->set_user_linked_license_ids( $this->_user->id, $user_license_ids );
12316
-
12317
- $this->_store_licenses( true, $this->_module_id, $licenses );
12318
- }
12319
-
12320
- // Update current license.
12321
- if ( is_object( $this->_license ) ) {
12322
- $license = $this->_get_license_by_id( $this->_license->id );
12323
-
12324
- if ( is_object( $license ) ) {
12325
- /**
12326
- * `$license` can be `false` in case a user change action has just been completed and this method
12327
- * has synced the `$this->_licenses` collection for the new user. In this case, the
12328
- * `$this->_licenses` collection may have only the newly activated license that is associated with
12329
- * the new user. `set_license` will eventually be called in the same request by the logic that
12330
- * follows outside this method which will detect that the install's license has been updated, and
12331
- * then `_update_site_license` will be called which in turn will call `set_license`.
12332
- *
12333
- * @author Leo Fajardo (@leorw)
12334
- * @since 2.3.2
12335
- */
12336
- $this->set_license( $license );
12337
- }
12338
- }
12339
-
12340
- return $this->_licenses;
12341
- }
12342
-
12343
- /**
12344
- * @author Vova Feldman (@svovaf)
12345
- * @since 1.0.5
12346
- *
12347
- * @param number $id
12348
- * @param bool $sync_licenses
12349
- *
12350
- * @return FS_Plugin_License|false
12351
- */
12352
- function _get_license_by_id( $id, $sync_licenses = true ) {
12353
- $this->_logger->entrance();
12354
-
12355
- if ( ! FS_Plugin_License::is_valid_id( $id ) ) {
12356
- return false;
12357
- }
12358
-
12359
- /**
12360
- * When running from the network level admin and opted-in from the network,
12361
- * check if the license exists in the network user licenses collection.
12362
- *
12363
- * @author Vova Feldman (@svovaf)
12364
- * @since 2.0.0
12365
- */
12366
- if ( fs_is_network_admin() &&
12367
- $this->is_network_registered() &&
12368
- ( ! is_object( $this->_user ) || $this->_storage->network_user_id != $this->_user->id )
12369
- ) {
12370
- $licenses = $this->get_user_licenses( $this->_storage->network_user_id );
12371
-
12372
- foreach ( $licenses as $license ) {
12373
- if ( $id == $license->id ) {
12374
- return $license;
12375
- }
12376
- }
12377
- }
12378
-
12379
- if ( ! $this->has_any_license() && $sync_licenses ) {
12380
- $this->_sync_licenses( $id );
12381
- }
12382
-
12383
- if ( is_array( $this->_licenses ) ) {
12384
- foreach ( $this->_licenses as $license ) {
12385
- if ( $id == $license->id ) {
12386
- return $license;
12387
- }
12388
- }
12389
- }
12390
-
12391
- return false;
12392
- }
12393
-
12394
- /**
12395
- * Get license by ID. Unlike _get_license_by_id(), this method only checks the local storage and return any license, whether it's associated with the current context user/install or not.
12396
- *
12397
- * @author Vova Feldman (@svovaf)
12398
- * @since 2.0.0
12399
- *
12400
- * @param number $id
12401
- *
12402
- * @return FS_Plugin_License
12403
- */
12404
- private function get_license_by_id( $id ) {
12405
- $licenses = self::get_all_licenses( $this->_module_id );
12406
-
12407
- if ( is_array( $licenses ) && ! empty( $licenses ) ) {
12408
- foreach ( $licenses as $license ) {
12409
- if ( $id == $license->id ) {
12410
- return $license;
12411
- }
12412
- }
12413
- }
12414
-
12415
- return null;
12416
- }
12417
-
12418
- /**
12419
- * Synchronize the site's context license by fetching the license form the API and updating the local data with it.
12420
- *
12421
- * @author Vova Feldman (@svovaf)
12422
- * @since 2.0.0
12423
- *
12424
- * @return \FS_Plugin_License|mixed
12425
- */
12426
- private function sync_site_license() {
12427
- $api = $this->get_api_user_scope();
12428
-
12429
- $result = $api->get( "/licenses/{$this->_license->id}.json?license_key=" . urlencode( $this->_license->secret_key ), true );
12430
-
12431
- if ( ! $this->is_api_result_entity( $result ) ) {
12432
- return $result;
12433
- }
12434
-
12435
- $license = $this->_update_site_license( new FS_Plugin_License( $result ) );
12436
- $this->_store_licenses();
12437
-
12438
- return $license;
12439
- }
12440
-
12441
- /**
12442
- * Get all user's available licenses for the current module.
12443
- *
12444
- * @author Vova Feldman (@svovaf)
12445
- * @since 2.0.0
12446
- *
12447
- * @param number $user_id
12448
- *
12449
- * @return FS_Plugin_License[]
12450
- */
12451
- private function get_user_licenses( $user_id ) {
12452
- $all_licenses = self::get_all_licenses( $this->_module_id );
12453
- if ( empty( $all_licenses ) ) {
12454
- return array();
12455
- }
12456
-
12457
- $user_license_ids = $this->get_user_linked_license_ids( $user_id );
12458
- if ( empty( $user_license_ids ) ) {
12459
- return array();
12460
- }
12461
-
12462
- $licenses = array();
12463
- foreach ( $all_licenses as $license ) {
12464
- if ( in_array( $license->id, $user_license_ids ) ) {
12465
- $licenses[] = $license;
12466
- }
12467
- }
12468
-
12469
- return $licenses;
12470
- }
12471
-
12472
- /**
12473
- * Checks if the context license is network activated except on the given blog ID.
12474
- *
12475
- * @author Vova Feldman (@svovaf)
12476
- * @since 2.0.0
12477
- *
12478
- * @param int $except_blog_id
12479
- *
12480
- * @return bool
12481
- */
12482
- private function is_license_network_active( $except_blog_id = 0 ) {
12483
- $this->_logger->entrance();
12484
-
12485
- if ( ! is_object( $this->_license ) ) {
12486
- return false;
12487
- }
12488
-
12489
- $sites = self::get_sites();
12490
-
12491
- if ( $this->_license->total_activations() < ( count( $sites ) - 1 ) ) {
12492
- // There are more sites than the number of activations, so license cannot be network activated.
12493
- return false;
12494
- }
12495
-
12496
- foreach ( $sites as $site ) {
12497
- $blog_id = self::get_site_blog_id( $site );
12498
-
12499
- if ( $except_blog_id == $blog_id ) {
12500
- // Skip excluded blog.
12501
- continue;
12502
- }
12503
-
12504
- $install = $this->get_install_by_blog_id( $blog_id );
12505
-
12506
- if ( is_object( $install ) && $install->license_id != $this->_license->id ) {
12507
- return false;
12508
- }
12509
- }
12510
-
12511
- return true;
12512
- }
12513
-
12514
- /**
12515
- * Checks if license can be activated on all the network sites (opted-in or skipped) that are not yet associated with a license. If possible, try to make the activation, if not return false.
12516
- *
12517
- * Notice: On success, this method will also update the license activations counters (without updating the license in the storage).
12518
- *
12519
- * @author Vova Feldman (@svovaf)
12520
- * @since 2.0.0
12521
- *
12522
- * @param \FS_User $user
12523
- * @param \FS_Plugin_License $license
12524
- *
12525
- * @return bool
12526
- */
12527
- private function try_activate_license_on_network( FS_User $user, FS_Plugin_License $license ) {
12528
- $this->_logger->entrance();
12529
-
12530
- $result = $this->can_activate_license_on_network( $license );
12531
-
12532
- if ( false === $result ) {
12533
- return false;
12534
- }
12535
-
12536
- $installs_without_license = $result['installs'];
12537
- if ( ! empty( $installs_without_license ) ) {
12538
- $this->activate_license_on_many_installs( $user, $license->secret_key, $installs_without_license );
12539
- }
12540
-
12541
- $disconnected_site_ids = $result['sites'];
12542
- if ( ! empty( $disconnected_site_ids ) ) {
12543
- $this->activate_license_on_many_sites( $user, $license->secret_key, $disconnected_site_ids );
12544
- }
12545
-
12546
- $this->link_license_2_user( $license->id, $user->id );
12547
-
12548
- // Sync license after activations.
12549
- $license->activated += $result['production_count'];
12550
- $license->activated_local += $result['localhost_count'];
12551
-
12552
- // $this->_store_licenses()
12553
-
12554
- return true;
12555
- }
12556
-
12557
- /**
12558
- * Checks if the given license can be activated on the whole network.
12559
- *
12560
- * @author Vova Feldman (@svovaf)
12561
- * @since 2.0.0
12562
- *
12563
- * @param \FS_Plugin_License $license
12564
- *
12565
- * @return false|array {
12566
- * @type array[int]FS_Site $installs Blog ID to install map.
12567
- * @type int[] $sites Non-connected blog IDs.
12568
- * @type int $production_count Production sites count.
12569
- * @type int $localhost_count Production sites count.
12570
- * }
12571
- */
12572
- private function can_activate_license_on_network( FS_Plugin_License $license ) {
12573
- $sites = self::get_sites();
12574
-
12575
- $production_count = 0;
12576
- $localhost_count = 0;
12577
-
12578
- $installs_without_license = array();
12579
- $disconnected_site_ids = array();
12580
-
12581
- foreach ( $sites as $site ) {
12582
- $blog_id = self::get_site_blog_id( $site );
12583
- $install = $this->get_install_by_blog_id( $blog_id );
12584
-
12585
- if ( is_object( $install ) ) {
12586
- if ( FS_Plugin_License::is_valid_id( $install->license_id ) ) {
12587
- // License already activated on the install.
12588
- continue;
12589
- }
12590
-
12591
- $url = $install->url;
12592
-
12593
- $installs_without_license[ $blog_id ] = $install;
12594
- } else {
12595
- $url = is_object( $site ) ?
12596
- $site->siteurl :
12597
- self::get_site_url( $blog_id );
12598
-
12599
- $disconnected_site_ids[] = $blog_id;
12600
- }
12601
-
12602
- if ( FS_Site::is_localhost_by_address( $url ) ) {
12603
- $localhost_count ++;
12604
- } else {
12605
- $production_count ++;
12606
- }
12607
- }
12608
-
12609
- if ( ! $license->can_activate_bulk( $production_count, $localhost_count ) ) {
12610
- return false;
12611
- }
12612
-
12613
- return array(
12614
- 'installs' => $installs_without_license,
12615
- 'sites' => $disconnected_site_ids,
12616
- 'production_count' => $production_count,
12617
- 'localhost_count' => $localhost_count,
12618
- );
12619
- }
12620
-
12621
- /**
12622
- * Activate a given license on a collection of installs.
12623
- *
12624
- * @author Vova Feldman (@svovaf)
12625
- * @since 2.0.0
12626
- *
12627
- * @param \FS_User $user
12628
- * @param string $license_key
12629
- * @param array $blog_2_install_map {
12630
- * @key int Blog ID.
12631
- * @value FS_Site Blog's associated install.
12632
- * }
12633
- *
12634
- * @return mixed|true
12635
- */
12636
- private function activate_license_on_many_installs(
12637
- FS_User $user,
12638
- $license_key,
12639
- array $blog_2_install_map
12640
- ) {
12641
- $params = array(
12642
- array( 'license_key' => $this->apply_filters( 'license_key', $license_key ) )
12643
- );
12644
-
12645
- $install_2_blog_map = array();
12646
- foreach ( $blog_2_install_map as $blog_id => $install ) {
12647
- $params[] = array( 'id' => $install->id );
12648
-
12649
- $install_2_blog_map[ $install->id ] = $blog_id;
12650
- }
12651
-
12652
- $result = $this->get_api_user_scope_by_user( $user )->call(
12653
- "plugins/{$this->_plugin->id}/installs.json",
12654
- 'PUT',
12655
- $params
12656
- );
12657
-
12658
- if ( ! $this->is_api_result_object( $result, 'installs' ) ) {
12659
- return $result;
12660
- }
12661
-
12662
- foreach ( $result->installs as $r_install ) {
12663
- $install = new FS_Site( $r_install );
12664
- $install->is_disconnected = false;
12665
-
12666
- // Update install.
12667
- $this->_store_site(
12668
- true,
12669
- $install_2_blog_map[ $r_install->id ],
12670
- $install
12671
- );
12672
- }
12673
-
12674
- return true;
12675
- }
12676
-
12677
- /**
12678
- * Activate a given license on a collection of blogs/sites that are not yet opted-in.
12679
- *
12680
- * @author Vova Feldman (@svovaf)
12681
- * @since 2.3.1
12682
- *
12683
- * @param \FS_User $user
12684
- * @param string $license_key
12685
- *
12686
- * @return true|mixed True if successful, otherwise, the API result.
12687
- */
12688
- private function activate_license_on_site( FS_User $user, $license_key ) {
12689
- return $this->activate_license_on_many_sites( $user, $license_key );
12690
- }
12691
-
12692
- /**
12693
- * Activate a given license on a collection of blogs/sites that are not yet opted-in.
12694
- *
12695
- * @author Vova Feldman (@svovaf)
12696
- * @since 2.0.0
12697
- *
12698
- * @param \FS_User $user
12699
- * @param string $license_key
12700
- * @param int[] $site_ids
12701
- *
12702
- * @return true|mixed True if successful, otherwise, the API result.
12703
- */
12704
- private function activate_license_on_many_sites(
12705
- FS_User $user,
12706
- $license_key,
12707
- array $site_ids = array()
12708
- ) {
12709
- $sites = array();
12710
- foreach ( $site_ids as $site_id ) {
12711
- $sites[] = $this->get_site_info( array( 'blog_id' => $site_id ) );
12712
- }
12713
-
12714
- // Install the plugin.
12715
- $result = $this->create_installs_with_user(
12716
- $user,
12717
- $license_key,
12718
- false,
12719
- $sites,
12720
- false,
12721
- true
12722
- );
12723
-
12724
- if ( ! $this->is_api_result_entity( $result ) &&
12725
- ! $this->is_api_result_object( $result, 'installs' )
12726
- ) {
12727
- return $result;
12728
- }
12729
-
12730
- $installs = array();
12731
-
12732
- if ( $this->is_api_result_entity( $result ) ) {
12733
- $install = new FS_Site( $result );
12734
-
12735
- $this->_user = $user;
12736
-
12737
- $this->_store_site( true, null, $install );
12738
-
12739
- $this->_site = $install;
12740
-
12741
- $this->reset_anonymous_mode();
12742
- } else {
12743
- foreach ( $result->installs as $install ) {
12744
- $installs[] = new FS_Site( $install );
12745
- }
12746
-
12747
- // Map site addresses to their blog IDs.
12748
- $address_to_blog_map = $this->get_address_to_blog_map();
12749
-
12750
- $first_blog_id = null;
12751
-
12752
- foreach ( $installs as $install ) {
12753
- $address = trailingslashit( fs_strip_url_protocol( $install->url ) );
12754
- $blog_id = $address_to_blog_map[ $address ];
12755
-
12756
- $this->_store_site( true, $blog_id, $install );
12757
-
12758
- $this->reset_anonymous_mode( $blog_id );
12759
-
12760
- if ( is_null( $first_blog_id ) ) {
12761
- $first_blog_id = $blog_id;
12762
- }
12763
- }
12764
-
12765
- if ( ! FS_Site::is_valid_id( $this->_storage->network_install_blog_id ) ) {
12766
- $this->_storage->network_install_blog_id = $first_blog_id;
12767
- }
12768
- }
12769
-
12770
- return true;
12771
- }
12772
-
12773
- /**
12774
- * Sync site's license with user licenses.
12775
- *
12776
- * @author Vova Feldman (@svovaf)
12777
- * @since 1.0.6
12778
- *
12779
- * @param FS_Plugin_License|null $new_license
12780
- *
12781
- * @return FS_Plugin_License|null
12782
- */
12783
- function _update_site_license( $new_license ) {
12784
- $this->_logger->entrance();
12785
-
12786
- /**
12787
- * In case this call will be removed in the future, the `_sync_licenses()` method needs to be updated
12788
- * accordingly so that it will also handle the case when an ownership change is done via license
12789
- * activation.
12790
- *
12791
- * @author Leo Fajardo (@leorw)
12792
- * @since 2.3.2
12793
- */
12794
- $this->set_license( $new_license );
12795
-
12796
- if ( ! is_object( $new_license ) ) {
12797
- $this->_site->license_id = null;
12798
- $this->_sync_site_subscription( null );
12799
-
12800
- return $this->_license;
12801
- }
12802
-
12803
- $this->_site->license_id = $this->_license->id;
12804
-
12805
- if ( ! is_array( $this->_licenses ) ) {
12806
- $this->_licenses = array();
12807
- }
12808
-
12809
- $is_license_found = false;
12810
- for ( $i = 0, $len = count( $this->_licenses ); $i < $len; $i ++ ) {
12811
- if ( $new_license->id == $this->_licenses[ $i ]->id ) {
12812
- $this->_licenses[ $i ] = $new_license;
12813
-
12814
- $is_license_found = true;
12815
- break;
12816
- }
12817
- }
12818
-
12819
- // If new license just append.
12820
- if ( ! $is_license_found ) {
12821
- $this->_licenses[] = $new_license;
12822
- }
12823
-
12824
- $this->_sync_site_subscription( $new_license );
12825
-
12826
- return $this->_license;
12827
- }
12828
-
12829
- /**
12830
- * @author Vova Feldman (@svovaf)
12831
- * @since 2.3.1
12832
- *
12833
- * @param \FS_Plugin_License $license
12834
- */
12835
- private function set_license( FS_Plugin_License $license = null ) {
12836
- $this->_license = $license;
12837
-
12838
- $this->maybe_update_whitelabel_flag( $license );
12839
- }
12840
-
12841
- /**
12842
- * @author Leo Fajardo (@leorw)
12843
- * @since 2.3.1
12844
- *
12845
- * @param FS_Plugin_License $license
12846
- */
12847
- private function maybe_update_whitelabel_flag( $license ) {
12848
- $is_whitelabeled = isset( $this->_storage->is_whitelabeled ) ?
12849
- $this->_storage->is_whitelabeled :
12850
- false;
12851
-
12852
- if ( is_object( $license ) ) {
12853
- $license_user = self::_get_user_by_id( $license->user_id );
12854
-
12855
- if ( ! is_object( $license_user ) ) {
12856
- // If foreign license, do not update the `is_whitelabeled` flag.
12857
- return;
12858
- }
12859
-
12860
- if ( $this->is_addon() ) {
12861
- /**
12862
- * Store the last license data to the parent's storage since it's needed only when showing the
12863
- * "Start Debug" dialog which is triggered from the "Account" page. This way, there's no need to
12864
- * iterate over the add-ons just to get the last license data.
12865
- */
12866
- $this->get_parent_instance()->store_last_activated_license_data( $license, $license_user );
12867
- } else {
12868
- $this->store_last_activated_license_data( $license );
12869
- }
12870
-
12871
- if ( $license->is_whitelabeled ) {
12872
- // Activated a developer license, data should be hidden.
12873
- $is_whitelabeled = true;
12874
- } else if ( $this->is_registered() && $this->_user->id == $license->user_id ) {
12875
- // The account owner activated a regular license key, no need to hide the data.
12876
- $is_whitelabeled = false;
12877
- }
12878
- }
12879
-
12880
- $this->_storage->is_whitelabeled = $is_whitelabeled;
12881
-
12882
- // Reset the whitelabeled status after update.
12883
- $this->is_whitelabeled = null;
12884
- if ( $this->is_addon() ) {
12885
- $parent_fs = $this->get_parent_instance();
12886
-
12887
- if ( is_object( $parent_fs ) ) {
12888
- $parent_fs->is_whitelabeled = null;
12889
- }
12890
- }
12891
- }
12892
-
12893
- /**
12894
- * @author Leo Fajardo (@leorw)
12895
- * @since 2.3.1
12896
- *
12897
- * @param FS_Plugin_License $license
12898
- * @param FS_User $license_user
12899
- */
12900
- private function store_last_activated_license_data( FS_Plugin_License $license, $license_user = null ) {
12901
- if ( ! is_object( $license_user ) ) {
12902
- $this->_storage->last_license_key = md5( $license->secret_key );
12903
- $this->_storage->last_license_user_id = null;
12904
- } else {
12905
- $this->_storage->last_license_user_key = md5( $license_user->secret_key );
12906
- $this->_storage->last_license_user_id = $license_user->id;
12907
- }
12908
- }
12909
-
12910
- /**
12911
- * @author Leo Fajardo (@leorw)
12912
- * @since 2.3.1
12913
- *
12914
- * @param bool $ignore_data_debug_mode
12915
- *
12916
- * @return bool
12917
- */
12918
- function is_whitelabeled_by_flag( $ignore_data_debug_mode = false ) {
12919
- if ( true !== $this->_storage->is_whitelabeled ) {
12920
- return false;
12921
- } else if ( $ignore_data_debug_mode ) {
12922
- return true;
12923
- }
12924
-
12925
- $fs = $this->is_addon() ?
12926
- $this->get_parent_instance() :
12927
- $this;
12928
-
12929
- return ! $fs->is_data_debug_mode();
12930
- }
12931
-
12932
- /**
12933
- * @author Leo Fajardo (@leorw)
12934
- * @since 2.3.1
12935
- *
12936
- * @return number
12937
- */
12938
- function get_last_license_user_id() {
12939
- return ( FS_User::is_valid_id( $this->_storage->last_license_user_id ) ) ?
12940
- $this->_storage->last_license_user_id :
12941
- null;
12942
- }
12943
-
12944
- /**
12945
- * @author Leo Fajardo (@leorw)
12946
- * @since 2.3.1
12947
- *
12948
- * @param int $blog_id
12949
- * @param bool $ignore_data_debug_mode
12950
- *
12951
- * @return bool
12952
- */
12953
- function is_whitelabeled( $ignore_data_debug_mode = false, $blog_id = null ) {
12954
- if ( ! is_null( $blog_id ) ) {
12955
- $this->switch_to_blog( $blog_id );
12956
- }
12957
-
12958
- if ( ! is_null( $this->is_whitelabeled ) ) {
12959
- $is_whitelabeled = $this->is_whitelabeled;
12960
- } else {
12961
- $is_whitelabeled = false;
12962
-
12963
- $is_whitelabeled_flag = $this->is_whitelabeled_by_flag( true );
12964
-
12965
- if ( ! $this->has_addons() ) {
12966
- $is_whitelabeled = $is_whitelabeled_flag;
12967
- } else if ( $is_whitelabeled_flag ) {
12968
- $is_whitelabeled = true;
12969
- } else {
12970
- $addon_ids = $this->get_updated_account_addons();
12971
- $installed_addons = $this->get_installed_addons();
12972
- foreach ( $installed_addons as $fs_addon ) {
12973
- $addon_ids[] = $fs_addon->get_id();
12974
- }
12975
-
12976
- if ( ! empty( $addon_ids ) ) {
12977
- $addon_ids = array_unique( $addon_ids );
12978
-
12979
- $is_network_level = (
12980
- fs_is_network_admin() &&
12981
- $this->is_network_active()
12982
- );
12983
-
12984
- foreach ( $addon_ids as $addon_id ) {
12985
- $addon = $this->get_addon( $addon_id );
12986
-
12987
- if ( ! is_object( $addon ) ) {
12988
- continue;
12989
- }
12990
-
12991
- $addon_storage = FS_Storage::instance( WP_FS__MODULE_TYPE_PLUGIN, $addon->slug );
12992
- $fs_addon = $this->is_addon_activated( $addon_id ) ?
12993
- self::get_addon_instance( $addon_id ) :
12994
- null;
12995
-
12996
- $was_addon_network_activated = false;
12997
-
12998
- if ( is_object( $fs_addon ) ) {
12999
- $was_addon_network_activated = $fs_addon->is_network_active();
13000
- } else if ( $is_network_level ) {
13001
- $was_addon_network_activated = $addon_storage->get( 'was_plugin_loaded', false, true );
13002
- }
13003
-
13004
- $network_delegated_connection = (
13005
- $was_addon_network_activated &&
13006
- $addon_storage->get( 'is_delegated_connection', false, true )
13007
- );
13008
-
13009
- if (
13010
- $is_network_level &&
13011
- ( ! $was_addon_network_activated || $network_delegated_connection )
13012
- ) {
13013
- $sites = self::get_sites();
13014
-
13015
- /**
13016
- * If in network admin area and the add-on was not network-activated or network-activated
13017
- * and network-delegated, find any add-on whose is_whitelabeled flag is true.
13018
- */
13019
- foreach ( $sites as $site ) {
13020
- $site_info = $this->get_site_info( $site );
13021
-
13022
- if ( $addon_storage->get( 'is_whitelabeled', false, $site_info['blog_id'] ) ) {
13023
- $is_whitelabeled = true;
13024
- break;
13025
- }
13026
- }
13027
-
13028
- if ( $is_whitelabeled ) {
13029
- break;
13030
- }
13031
- } else {
13032
- /**
13033
- * This will be executed when any of the following is met:
13034
- * 1. Add-on was network-activated, not network-delegated, and in network admin area.
13035
- * 2. Add-on was network-activated, network-delegated, and in site admin area.
13036
- * 3. Add-on was not network-activated and in site admin area.
13037
- */
13038
- if ( true === $addon_storage->is_whitelabeled ) {
13039
- $is_whitelabeled = true;
13040
- break;
13041
- }
13042
- }
13043
- }
13044
- }
13045
- }
13046
-
13047
- $this->is_whitelabeled = $is_whitelabeled;
13048
-
13049
- if ( ! $is_whitelabeled || ! $this->is_data_debug_mode() ) {
13050
- $this->_admin_notices->remove_sticky( 'data_debug_mode_enabled' );
13051
- }
13052
-
13053
- if ( ! is_null( $blog_id ) ) {
13054
- $this->restore_current_blog();
13055
- }
13056
- }
13057
-
13058
- return (
13059
- $is_whitelabeled &&
13060
- ( $ignore_data_debug_mode || ! $this->is_data_debug_mode() )
13061
- );
13062
- }
13063
-
13064
- /**
13065
- * Sync site's subscription.
13066
- *
13067
- * @author Vova Feldman (@svovaf)
13068
- * @since 1.0.9
13069
- *
13070
- * @param FS_Plugin_License|null $license
13071
- *
13072
- * @return bool|\FS_Subscription
13073
- */
13074
- private function _sync_site_subscription( $license ) {
13075
- if ( ! is_object( $license ) ) {
13076
- $this->delete_unused_subscriptions();
13077
-
13078
- return false;
13079
- }
13080
-
13081
- // Load subscription details if not lifetime.
13082
- $subscription = $license->is_lifetime() ?
13083
- false :
13084
- $this->_fetch_site_license_subscription();
13085
-
13086
- if ( is_object( $subscription ) && ! isset( $subscription->error ) ) {
13087
- $this->store_subscription( $subscription );
13088
- } else {
13089
- $this->delete_unused_subscriptions();
13090
- }
13091
-
13092
- return $subscription;
13093
- }
13094
-
13095
- /**
13096
- * @author Vova Feldman (@svovaf)
13097
- * @since 1.0.6
13098
- *
13099
- * @return bool|\FS_Plugin_License
13100
- */
13101
- function _get_license() {
13102
- if ( ! fs_is_network_admin() || is_object( $this->_license ) ) {
13103
- return $this->_license;
13104
- }
13105
-
13106
- return $this->_get_available_premium_license();
13107
- }
13108
-
13109
- /**
13110
- * @param number $license_id
13111
- *
13112
- * @return null|\FS_Subscription
13113
- */
13114
- function _get_subscription( $license_id ) {
13115
- if ( ! isset( $this->_storage->subscriptions ) ||
13116
- empty( $this->_storage->subscriptions )
13117
- ) {
13118
- return null;
13119
- }
13120
-
13121
- foreach ( fs_get_entities( $this->_storage->subscriptions, FS_Subscription::get_class_name() ) as $subscription ) {
13122
- if ( $subscription->license_id == $license_id ) {
13123
- return $subscription;
13124
- }
13125
- }
13126
-
13127
- return null;
13128
- }
13129
-
13130
- /**
13131
- * @author Leo Fajardo (@leorw)
13132
- * @since 2.0.0
13133
- *
13134
- * @param FS_Subscription $subscription
13135
- */
13136
- function store_subscription( FS_Subscription $subscription ) {
13137
- if ( ! isset( $this->_storage->subscriptions ) ) {
13138
- $this->_storage->subscriptions = array();
13139
- }
13140
-
13141
- if ( empty( $this->_storage->subscriptions ) || ! is_multisite() ) {
13142
- $this->_storage->subscriptions = array( $subscription );
13143
-
13144
- return;
13145
- }
13146
-
13147
- $subscriptions = fs_get_entities( $this->_storage->subscriptions, FS_Subscription::get_class_name() );
13148
-
13149
- $updated_subscription = false;
13150
- foreach ( $subscriptions as $key => $existing_subscription ) {
13151
- if ( $existing_subscription->id == $subscription->id ) {
13152
- $subscriptions[ $key ] = $subscription;
13153
- $updated_subscription = true;
13154
- break;
13155
- }
13156
- }
13157
-
13158
- if ( ! $updated_subscription ) {
13159
- $subscriptions[] = $subscription;
13160
- }
13161
-
13162
- $this->_storage->subscriptions = $subscriptions;
13163
- }
13164
-
13165
- /**
13166
- * @author Leo Fajardo (@leorw)
13167
- * @since 2.0.0
13168
- */
13169
- function delete_unused_subscriptions() {
13170
- if ( ! isset( $this->_storage->subscriptions ) ||
13171
- empty( $this->_storage->subscriptions ) ||
13172
- // Clean up only if there are already at least 3 subscriptions.
13173
- ( count( $this->_storage->subscriptions ) < 3 )
13174
- ) {
13175
- return;
13176
- }
13177
-
13178
- if ( ! is_multisite() ) {
13179
- // If not multisite, there should only be 1 subscription, so just clear the array.
13180
- $this->_storage->subscriptions = array();
13181
-
13182
- return;
13183
- }
13184
-
13185
- $subscriptions_to_keep_by_license_id_map = array();
13186
- $sites = self::get_sites();
13187
- foreach ( $sites as $site ) {
13188
- $blog_id = self::get_site_blog_id( $site );
13189
- $install = $this->get_install_by_blog_id( $blog_id );
13190
-
13191
- if ( ! is_object( $install ) ||
13192
- ! FS_Plugin_License::is_valid_id( $install->license_id )
13193
- ) {
13194
- continue;
13195
- }
13196
-
13197
- $subscriptions_to_keep_by_license_id_map[ $install->license_id ] = true;
13198
- }
13199
-
13200
- if ( empty( $subscriptions_to_keep_by_license_id_map ) ) {
13201
- $this->_storage->subscriptions = array();
13202
-
13203
- return;
13204
- }
13205
-
13206
- foreach ( $this->_storage->subscriptions as $key => $subscription ) {
13207
- if ( ! isset( $subscriptions_to_keep_by_license_id_map[ $subscription->license_id ] ) ) {
13208
- unset( $this->_storage->subscriptions[ $key ] );
13209
- }
13210
- }
13211
- }
13212
-
13213
- /**
13214
- * @author Vova Feldman (@svovaf)
13215
- * @since 1.0.2
13216
- *
13217
- * @param string $plan Plan name
13218
- * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
13219
- *
13220
- * @return bool
13221
- */
13222
- function is_plan( $plan, $exact = false ) {
13223
- $this->_logger->entrance();
13224
-
13225
- if ( ! $this->is_registered() ) {
13226
- return false;
13227
- }
13228
-
13229
- $plan = strtolower( $plan );
13230
-
13231
- $current_plan_name = $this->get_plan_name();
13232
-
13233
- if ( $current_plan_name === $plan ) {
13234
- // Exact plan.
13235
- return true;
13236
- } else if ( $exact ) {
13237
- // Required exact, but plans are different.
13238
- return false;
13239
- }
13240
-
13241
- $current_plan_order = - 1;
13242
- $required_plan_order = PHP_INT_MAX;
13243
- for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
13244
- if ( $plan === $this->_plans[ $i ]->name ) {
13245
- $required_plan_order = $i;
13246
- } else if ( $current_plan_name === $this->_plans[ $i ]->name ) {
13247
- $current_plan_order = $i;
13248
- }
13249
- }
13250
-
13251
- return ( $current_plan_order > $required_plan_order );
13252
- }
13253
-
13254
- /**
13255
- * Check if module has only one plan.
13256
- *
13257
- * @author Vova Feldman (@svovaf)
13258
- * @since 1.2.1.7
13259
- *
13260
- * @param bool $double_check In some cases developers prefer to release their paid offering as premium-only, even though there is a free version. For those cases, looking at the 'is_premium_only' value isn't enough because the result will return false even when the product has only signle paid plan.
13261
- *
13262
- * @return bool
13263
- */
13264
- function is_single_plan( $double_check = false ) {
13265
- $this->_logger->entrance();
13266
-
13267
- if ( ! $this->is_registered() ||
13268
- ! is_array( $this->_plans ) ||
13269
- 0 === count( $this->_plans )
13270
- ) {
13271
- return true;
13272
- }
13273
-
13274
- $has_free_plan = $this->has_free_plan();
13275
-
13276
- if ( ! $has_free_plan && $double_check ) {
13277
- foreach ( $this->_plans as $plan ) {
13278
- if ( $plan->is_free() ) {
13279
- $has_free_plan = true;
13280
- break;
13281
- }
13282
- }
13283
- }
13284
-
13285
- return ( 1 === ( count( $this->_plans ) - ( $has_free_plan ? 1 : 0 ) ) );
13286
- }
13287
-
13288
- /**
13289
- * Check if plan based on trial. If not in trial mode, should return false.
13290
- *
13291
- * @since 1.0.9
13292
- *
13293
- * @param string $plan Plan name
13294
- * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
13295
- *
13296
- * @return bool
13297
- */
13298
- function is_trial_plan( $plan, $exact = false ) {
13299
- $this->_logger->entrance();
13300
-
13301
- if ( ! $this->is_registered() ) {
13302
- return false;
13303
- }
13304
-
13305
- if ( ! $this->is_trial() ) {
13306
- return false;
13307
- }
13308
-
13309
- $trial_plan = $this->get_trial_plan();
13310
-
13311
- if ( $trial_plan->name === $plan ) {
13312
- // Exact plan.
13313
- return true;
13314
- } else if ( $exact ) {
13315
- // Required exact, but plans are different.
13316
- return false;
13317
- }
13318
-
13319
- $current_plan_order = - 1;
13320
- $required_plan_order = - 1;
13321
- for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
13322
- if ( $plan === $this->_plans[ $i ]->name ) {
13323
- $required_plan_order = $i;
13324
- } else if ( $trial_plan->name === $this->_plans[ $i ]->name ) {
13325
- $current_plan_order = $i;
13326
- }
13327
- }
13328
-
13329
- return ( $current_plan_order > $required_plan_order );
13330
- }
13331
-
13332
- /**
13333
- * Check if plugin has any paid plans.
13334
- *
13335
- * @author Vova Feldman (@svovaf)
13336
- * @since 1.0.7
13337
- *
13338
- * @return bool
13339
- */
13340
- function has_paid_plan() {
13341
- return $this->_has_paid_plans ||
13342
- FS_Plan_Manager::instance()->has_paid_plan( $this->_plans );
13343
- }
13344
-
13345
- /**
13346
- * Check if plugin has any plan with a trail.
13347
- *
13348
- * @author Vova Feldman (@svovaf)
13349
- * @since 1.0.9
13350
- *
13351
- * @return bool
13352
- */
13353
- function has_trial_plan() {
13354
- /**
13355
- * @author Vova Feldman(@svovaf)
13356
- * @since 1.2.1.5
13357
- *
13358
- * Allow setting a trial from the SDK without calling the API.
13359
- * But, if the user did opt-in, continue using the real data from the API.
13360
- */
13361
- if ( $this->_trial_days >= 0 ) {
13362
- return true;
13363
- }
13364
-
13365
- return $this->_storage->get( 'has_trial_plan', false );
13366
- }
13367
-
13368
- /**
13369
- * Check if plugin has any free plan, or is it premium only.
13370
- *
13371
- * Note: If no plans configured, assume plugin is free.
13372
- *
13373
- * @author Vova Feldman (@svovaf)
13374
- * @since 1.0.7
13375
- *
13376
- * @return bool
13377
- */
13378
- function has_free_plan() {
13379
- return ! $this->is_only_premium();
13380
- }
13381
-
13382
- /**
13383
- * Displays a license activation dialog box when the user clicks on the "Activate License"
13384
- * or "Change License" link on the plugins
13385
- * page.
13386
- *
13387
- * @author Leo Fajardo (@leorw)
13388
- * @since 1.1.9
13389
- */
13390
- function _add_license_activation_dialog_box() {
13391
- $vars = array(
13392
- 'id' => $this->_module_id,
13393
- );
13394
-
13395
- fs_require_template( 'forms/license-activation.php', $vars );
13396
- fs_require_template( 'forms/resend-key.php', $vars );
13397
- }
13398
-
13399
- /**
13400
- * Displays an email address update dialog box when the user clicks on the email address "Edit" button on the "Account" page.
13401
- *
13402
- * @author Leo Fajardo (@leorw)
13403
- * @since 2.5.0
13404
- */
13405
- function _add_email_address_update_dialog_box() {
13406
- $vars = array( 'id' => $this->_module_id );
13407
-
13408
- fs_require_template( 'forms/email-address-update.php', $vars );
13409
- }
13410
-
13411
- /**
13412
- * @author Leo Fajardo (@leorw)
13413
- * @since 2.5.0
13414
- */
13415
- function _add_email_address_update_option() {
13416
- if ( ! $this->should_handle_user_change() ) {
13417
- return;
13418
- }
13419
-
13420
- // Add email address update AJAX handler.
13421
- $this->add_ajax_action( 'update_email_address', array( &$this, '_email_address_update_ajax_handler' ) );
13422
- }
13423
-
13424
- /**
13425
- * @author Leo Fajardo (@leorw)
13426
- * @since 2.5.0
13427
- */
13428
- function _email_address_update_ajax_handler() {
13429
- $this->check_ajax_referer( 'update_email_address' );
13430
-
13431
- $new_email_address = fs_request_get( 'email_address' );
13432
- $transfer_type = fs_request_get( 'transfer_type' );
13433
-
13434
- $result = $this->update_email( $new_email_address );
13435
-
13436
- if ( ! FS_Api::is_api_error( $result ) ) {
13437
- self::shoot_ajax_success();
13438
- }
13439
-
13440
- $error = '';
13441
-
13442
- if ( FS_Api::is_api_error_object( $result ) ) {
13443
- switch ( $result->error->code ) {
13444
- case 'user_exist':
13445
- case 'account_verification_required':
13446
- $error = array(
13447
- 'code' => 'change_ownership',
13448
- 'url' => $this->get_account_url( 'change_owner', array(
13449
- 'state' => 'init',
13450
- 'candidate_email' => $new_email_address,
13451
- 'transfer_type' => $transfer_type,
13452
- ) ),
13453
- );
13454
-
13455
- break;
13456
- }
13457
- }
13458
-
13459
- if ( empty( $error ) ) {
13460
- $error = is_object( $result ) ?
13461
- var_export( $result->error, true ) :
13462
- $result;
13463
- }
13464
-
13465
- self::shoot_ajax_failure( $error );
13466
- }
13467
-
13468
- /**
13469
- * Returns a collection of IDs of installs that are associated with the context product and its add-ons, and activated with foreign licenses.
13470
- *
13471
- * @author Leo Fajardo (@leorw)
13472
- * @since 2.3.2
13473
- *
13474
- * @return number[]
13475
- */
13476
- function get_installs_ids_with_foreign_licenses() {
13477
- $installs = array();
13478
-
13479
- if (
13480
- is_object( $this->_license ) &&
13481
- $this->_site->user_id != $this->_license->user_id
13482
- ) {
13483
- $installs[] = $this->_site->id;
13484
- }
13485
-
13486
- /**
13487
- * Also try to get foreign licenses for the context product's add-ons.
13488
- */
13489
- $installs_by_slug_map = $this->get_parent_and_addons_installs_info();
13490
-
13491
- foreach ( $installs_by_slug_map as $slug => $install_info ) {
13492
- if ( $slug == $this->get_slug() ) {
13493
- continue;
13494
- }
13495
-
13496
- $install = $install_info['install'];
13497
- $license = $install_info['license'];
13498
-
13499
- if (
13500
- is_object( $license ) &&
13501
- $install->user_id != $license->user_id
13502
- ) {
13503
- $installs[] = $install->id;
13504
- }
13505
- }
13506
-
13507
- return $installs;
13508
- }
13509
-
13510
- /**
13511
- * Displays the "Change User" dialog box when the user clicks on the "Change User" button on the "Account" page.
13512
- *
13513
- * @author Leo Fajardo (@leorw)
13514
- * @since 2.3.2
13515
- *
13516
- * @param number[] $install_ids
13517
- */
13518
- function _add_user_change_dialog_box( $install_ids ) {
13519
- $vars = array(
13520
- 'id' => $this->_module_id,
13521
- 'license_owners' => $this->fetch_installs_licenses_owners_data( $install_ids )
13522
- );
13523
-
13524
- fs_require_template( 'forms/user-change.php', $vars );
13525
- }
13526
-
13527
- /**
13528
- * @author Leo Fajardo (@leorw)
13529
- * @since 2.3.1
13530
- */
13531
- function _add_data_debug_mode_dialog_box() {
13532
- $vars = array(
13533
- 'id' => $this->_module_id,
13534
- );
13535
-
13536
- fs_require_template( 'forms/data-debug-mode.php', $vars );
13537
- }
13538
-
13539
- /**
13540
- * Displays a subscription cancellation dialog box when the user clicks on the "Deactivate License"
13541
- * link on the "Account" page or deactivates a plugin and there's an active subscription that is
13542
- * either associated with a non-lifetime single-site license or non-lifetime multisite license that
13543
- * is only activated on a single production site.
13544
- *
13545
- * @author Leo Fajardo (@leorw)
13546
- * @since 2.2.1
13547
- *
13548
- * @param bool $is_license_deactivation
13549
- *
13550
- * @return array
13551
- */
13552
- function _get_subscription_cancellation_dialog_box_template_params( $is_license_deactivation = false ) {
13553
- if ( fs_is_network_admin() ) {
13554
- // Subscription cancellation dialog box is currently not supported for multisite networks.
13555
- return array();
13556
- }
13557
-
13558
- if ( $this->is_whitelabeled() ) {
13559
- return array();
13560
- }
13561
-
13562
- $license = $this->_get_license();
13563
-
13564
- /**
13565
- * If the installation is associated with a non-lifetime license, which is either a single-site or only activated on a single production site (or zero), and connected to an active subscription, suggest the customer to cancel the subscription upon deactivation.
13566
- *
13567
- * @author Leo Fajardo (@leorw) (Comment added by Vova Feldman @svovaf)
13568
- * @since 2.2.1
13569
- */
13570
- if ( ! is_object( $license ) ||
13571
- $license->is_lifetime() ||
13572
- ( ! $license->is_single_site() && $license->activated > 1 )
13573
- ) {
13574
- return array();
13575
- }
13576
-
13577
- /**
13578
- * @var FS_Subscription $subscription
13579
- */
13580
- $subscription = $this->_get_subscription( $license->id );
13581
- if ( ! is_object( $subscription ) || ! $subscription->is_active() ) {
13582
- return array();
13583
- }
13584
-
13585
- return array(
13586
- 'id' => $this->_module_id,
13587
- 'license' => $license,
13588
- 'has_trial' => $this->is_paid_trial(),
13589
- 'is_license_deactivation' => $is_license_deactivation,
13590
- );
13591
- }
13592
-
13593
- /**
13594
- * @author Leo Fajardo (@leorw)
13595
- * @since 2.0.2
13596
- */
13597
- function _add_premium_version_upgrade_selection_dialog_box() {
13598
- $modules_update = get_site_transient( $this->is_theme() ? 'update_themes' : 'update_plugins' );
13599
- if ( ! isset( $modules_update->response[ $this->_plugin_basename ] ) ) {
13600
- return;
13601
- }
13602
-
13603
- $vars = array(
13604
- 'id' => $this->_module_id,
13605
- 'new_version' => is_object( $modules_update->response[ $this->_plugin_basename ] ) ?
13606
- $modules_update->response[ $this->_plugin_basename ]->new_version :
13607
- $modules_update->response[ $this->_plugin_basename ]['new_version']
13608
- );
13609
-
13610
- fs_require_template( 'forms/premium-versions-upgrade-metadata.php', $vars );
13611
- fs_require_once_template( 'forms/premium-versions-upgrade-handler.php', $vars );
13612
- }
13613
-
13614
- /**
13615
- * Displays the opt-out dialog box when the user clicks on the "Opt Out" link on the "Plugins"
13616
- * page.
13617
- *
13618
- * @author Leo Fajardo (@leorw)
13619
- * @since 1.2.1.5
13620
- */
13621
- function _add_optout_dialog() {
13622
- if ( $this->is_theme() ) {
13623
- $vars = null;
13624
- fs_require_once_template( '/js/jquery.content-change.php', $vars );
13625
- }
13626
-
13627
- $vars = array( 'id' => $this->_module_id );
13628
- fs_require_template( 'forms/optout.php', $vars );
13629
- }
13630
-
13631
- /**
13632
- * Prepare page to include all required UI and logic for the license activation dialog.
13633
- *
13634
- * @author Vova Feldman (@svovaf)
13635
- * @since 1.2.0
13636
- */
13637
- function _add_license_activation() {
13638
- if ( $this->is_migration() ) {
13639
- return;
13640
- }
13641
-
13642
- if ( ! $this->is_user_admin() ) {
13643
- // Only admins can activate a license.
13644
- return;
13645
- }
13646
-
13647
- if ( ! $this->has_paid_plan() ) {
13648
- // Module doesn't have any paid plans.
13649
- return;
13650
- }
13651
-
13652
- if (
13653
- $this->has_premium_version() &&
13654
- ! $this->is_premium() &&
13655
- /**
13656
- * Also handle the case when an upgrade was made using the free version.
13657
- *
13658
- * @author Leo Fajardo (@leorw)
13659
- * @since 2.3.2
13660
- */
13661
- ! is_object( $this->_get_license() )
13662
- ) {
13663
- // Only add license activation logic to the premium version, or in case of a serviceware plugin, also in the free version.
13664
- return;
13665
- }
13666
-
13667
- // Add license activation link and AJAX request handler.
13668
- if ( self::is_plugins_page() ) {
13669
- $is_network_admin = fs_is_network_admin();
13670
-
13671
- if (
13672
- ( $is_network_admin && $this->is_network_active() && ! $this->is_network_delegated_connection() ) ||
13673
- ( ! $is_network_admin && ( ! $this->is_network_active() || $this->is_delegated_connection() ) )
13674
- ) {
13675
- if (
13676
- $this->is_premium() ||
13677
- ( $this->has_paid_plan() && ! $this->has_premium_version() )
13678
- ) {
13679
- /**
13680
- * @since 1.2.0 Add license action link only on plugins page.
13681
- */
13682
- $this->_add_license_action_link();
13683
- }
13684
- }
13685
- }
13686
-
13687
- // Add license activation AJAX callback.
13688
- $this->add_ajax_action( 'activate_license', array( &$this, '_activate_license_ajax_action' ) );
13689
-
13690
- // Add resend license AJAX callback.
13691
- $this->add_ajax_action( 'resend_license_key', array( &$this, '_resend_license_key_ajax_action' ) );
13692
- }
13693
-
13694
- /**
13695
- * Prepares page to include all required UI and logic for the "Change User" dialog.
13696
- *
13697
- * @author Leo Fajardo (@leorw)
13698
- * @since 2.3.2
13699
- */
13700
- function _add_user_change_option() {
13701
- if ( ! $this->should_handle_user_change() ) {
13702
- return;
13703
- }
13704
-
13705
- $installs_ids_with_foreign_licenses = $this->get_installs_ids_with_foreign_licenses();
13706
-
13707
- if ( empty( $installs_ids_with_foreign_licenses ) ) {
13708
- // Handle user change only when the parent product or one of its add-ons is activated with a foreign license.
13709
- return;
13710
- }
13711
-
13712
- // Add user change AJAX handler.
13713
- $this->add_ajax_action( 'change_user', array( &$this, '_user_change_ajax_action' ) );
13714
- }
13715
-
13716
- /**
13717
- * @author Leo Fajardo (@leorw)
13718
- * @since 2.3.2
13719
- */
13720
- function should_handle_user_change() {
13721
- if ( ! $this->is_user_admin() ) {
13722
- // Only admins can change user.
13723
- return false;
13724
- }
13725
-
13726
- if ( $this->is_addon() ) {
13727
- return false;
13728
- }
13729
-
13730
- if ( ! $this->is_registered() ) {
13731
- return false;
13732
- }
13733
-
13734
- if (
13735
- $this->is_network_active() &&
13736
- ( fs_is_network_admin() || ! $this->is_site_delegated_connection() )
13737
- ) {
13738
- // Handle only on site-level "Account" section for now.
13739
- return false;
13740
- }
13741
-
13742
- return true;
13743
- }
13744
-
13745
- /**
13746
- * @author Leo Fajardo (@leorw)
13747
- * @since 2.0.2
13748
- */
13749
- function _add_premium_version_upgrade_selection() {
13750
- if ( ! $this->is_user_admin() ) {
13751
- return;
13752
- }
13753
-
13754
- if ( ! $this->is_premium() || $this->has_any_active_valid_license() ) {
13755
- // This is relevant only to the free versions and premium versions without an active license.
13756
- return;
13757
- }
13758
-
13759
- if ( self::is_updates_page() || ( $this->is_plugin() && self::is_plugins_page() ) ) {
13760
- $this->_add_premium_version_upgrade_selection_action();
13761
- }
13762
- }
13763
-
13764
- /**
13765
- * @author Edgar Melkonyan
13766
- * @since 2.4.1
13767
- *
13768
- * @throws Freemius_Exception
13769
- */
13770
- function _toggle_whitelabel_mode_ajax_handler() {
13771
- $this->_logger->entrance();
13772
-
13773
- $this->check_ajax_referer( 'toggle_whitelabel_mode' );
13774
-
13775
- if ( ! $this->is_user_admin() ) {
13776
- // Only for admins.
13777
- self::shoot_ajax_failure();
13778
- }
13779
-
13780
- $license = $this->get_api_user_scope()->call(
13781
- "/licenses/{$this->_site->license_id}.json",
13782
- 'put',
13783
- array( 'is_whitelabeled' => ! $this->_license->is_whitelabeled )
13784
- );
13785
-
13786
- if ( ! $this->is_api_result_entity( $license ) ) {
13787
- self::shoot_ajax_failure(
13788
- FS_Api::is_api_error_object( $license ) ?
13789
- $license->error->message :
13790
- fs_text_inline( "An unknown error has occurred while trying to toggle the license's white-label mode.", 'unknown-error-occurred', $this->get_slug() )
13791
- );
13792
- }
13793
-
13794
- $this->_license->is_whitelabeled = $license->is_whitelabeled;
13795
- $this->_store_licenses();
13796
-
13797
- $this->_sync_license();
13798
-
13799
- if ( ! $license->is_whitelabeled ) {
13800
- $this->_admin_notices->remove_sticky( 'license_whitelabeled' );
13801
- } else {
13802
- $this->_admin_notices->add_sticky(
13803
- sprintf(
13804
- $this->get_text_inline(
13805
- 'Your %s license was flagged as white-labeled to hide sensitive information from the WP Admin (e.g. your email, license key, prices, billing address & invoices). If you ever wish to revert it back, you can easily do it through your %s. If this was a mistake you can also %s.',
13806
- 'license_whitelabeled'
13807
- ),
13808
- "<strong>{$this->get_plugin_title()}</strong>",
13809
- sprintf( '<a href="https://users.freemius.com" target="_blank">%s</a>', $this->get_text_inline( 'User Dashboard', 'user-dashboard' ) ),
13810
- sprintf( '<a href="#" class="fs-toggle-whitelabel-mode">%s</a>', $this->get_text_inline( 'revert it now', 'revert-it-now' ) )
13811
- ),
13812
- 'license_whitelabeled'
13813
- );
13814
- }
13815
-
13816
- self::shoot_ajax_response( array( 'success' => true ) );
13817
- }
13818
-
13819
- /**
13820
- * @author Leo Fajardo (@leorw)
13821
- * @since 2.3.0
13822
- */
13823
- function _add_beta_mode_update_handler() {
13824
- if ( ! $this->is_user_admin() ) {
13825
- return;
13826
- }
13827
-
13828
- if ( ! $this->is_premium() ) {
13829
- return;
13830
- }
13831
-
13832
- $this->add_ajax_action( 'set_beta_mode', array( &$this, '_set_beta_mode_ajax_handler' ) );
13833
- }
13834
-
13835
- /**
13836
- * @author Leo Fajardo (@leorw)
13837
- * @since 2.3.0
13838
- */
13839
- function _set_beta_mode_ajax_handler() {
13840
- $this->_logger->entrance();
13841
-
13842
- $this->check_ajax_referer( 'set_beta_mode' );
13843
-
13844
- if ( ! $this->is_user_admin() ) {
13845
- // Only for admins.
13846
- self::shoot_ajax_failure();
13847
- }
13848
-
13849
- $is_beta = trim( fs_request_get( 'is_beta', '', 'post' ) );
13850
-
13851
- if ( empty( $is_beta ) || ! in_array( $is_beta, array( 'true', 'false' ) ) ) {
13852
- self::shoot_ajax_failure();
13853
- }
13854
-
13855
- $site = $this->api_site_call(
13856
- '',
13857
- 'put',
13858
- array(
13859
- 'is_beta' => ( 'true' == $is_beta ),
13860
- 'fields' => 'is_beta'
13861
- )
13862
- );
13863
-
13864
- if ( ! $this->is_api_result_entity( $site ) ) {
13865
- self::shoot_ajax_failure(
13866
- FS_Api::is_api_error_object( $site ) ?
13867
- $site->error->message :
13868
- fs_text_inline( "An unknown error has occurred while trying to set the user's beta mode.", 'unknown-error-occurred', $this->get_slug() )
13869
- );
13870
- }
13871
-
13872
- $this->_site->is_beta = $site->is_beta;
13873
- $this->_store_site();
13874
-
13875
- self::shoot_ajax_response( array( 'success' => true ) );
13876
- }
13877
-
13878
- /**
13879
- * License activation WP AJAX handler.
13880
- *
13881
- * @author Leo Fajardo (@leorw)
13882
- * @since 1.1.9
13883
- *
13884
- * @uses Freemius::activate_license()
13885
- */
13886
- function _activate_license_ajax_action() {
13887
- $this->_logger->entrance();
13888
-
13889
- $this->check_ajax_referer( 'activate_license' );
13890
-
13891
- $license_key = trim( fs_request_get( 'license_key' ) );
13892
-
13893
- if ( empty( $license_key ) ) {
13894
- exit;
13895
- }
13896
-
13897
- $sites = fs_is_network_admin() ?
13898
- fs_request_get( 'sites', array(), 'post' ) :
13899
- array();
13900
-
13901
- $result = $this->activate_license(
13902
- $license_key,
13903
- $sites,
13904
- fs_request_get_bool( 'is_marketing_allowed', null ),
13905
- fs_request_get( 'blog_id', null ),
13906
- fs_request_get( 'module_id', null, 'post' ),
13907
- fs_request_get( 'user_id', null ),
13908
- fs_request_get_bool( 'is_extensions_tracking_allowed', null )
13909
- );
13910
-
13911
- if (
13912
- $result['success'] &&
13913
- $this->is_bundle_license_auto_activation_enabled()
13914
- ) {
13915
- $license = new FS_Plugin_License();
13916
- $license->secret_key = $license_key;
13917
-
13918
- $this->maybe_activate_bundle_license( $license, $sites );
13919
- }
13920
-
13921
- echo json_encode( $result );
13922
-
13923
- exit;
13924
- }
13925
-
13926
- /**
13927
- * User change WP AJAX handler.
13928
- *
13929
- * @author Leo Fajardo (@leorw)
13930
- * @since 2.3.2
13931
- */
13932
- function _user_change_ajax_action() {
13933
- $this->_logger->entrance();
13934
-
13935
- $this->check_ajax_referer( 'change_user' );
13936
-
13937
- $new_email_address = trim( fs_request_get( 'email_address', '' ) );
13938
- $new_user_id = fs_request_get( 'user_id' );
13939
-
13940
- if ( empty( $new_email_address ) && ! FS_User::is_valid_id( $new_user_id ) ) {
13941
- self::shoot_ajax_failure( fs_text_inline( 'Invalid new user ID or email address.', 'invalid-new-user-id-or-email', $this->get_slug() ) );
13942
- }
13943
-
13944
- $params = array();
13945
-
13946
- if ( ! empty( $new_email_address ) ) {
13947
- $params['user_email'] = $new_email_address;
13948
- } else {
13949
- $params['user_id'] = $new_user_id;
13950
- }
13951
-
13952
- $installs_info_by_slug_map = $this->get_parent_and_addons_installs_info();
13953
- $install_ids = array();
13954
-
13955
- foreach ( $installs_info_by_slug_map as $slug => $install_info ) {
13956
- $install_ids[ $slug ] = $install_info['install']->id;
13957
- }
13958
-
13959
- $params['install_ids'] = implode( ',', array_values( $install_ids ) );
13960
-
13961
- $install = $this->get_api_site_scope()->call( $this->add_show_pending( '/' ), 'put', $params );
13962
-
13963
- if ( FS_Api::is_api_error( $install ) ) {
13964
- $error = '';
13965
-
13966
- if ( is_object( $install ) ) {
13967
- switch ( $install->error->code ) {
13968
- case 'user_exist':
13969
- $error = (
13970
- $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...' .
13971
- $this->get_text_inline( 'Sorry, we could not complete the email update. Another user with the same email is already registered.', 'user-exist-message' ) . ' ' .
13972
- sprintf( $this->get_text_inline( 'If you would like to give up the ownership of the %s\'s account to %s click the Change Ownership button.', 'user-exist-message_ownership' ), $this->_module_type, '<b>' . $new_email_address . '</b>' ) .
13973
- sprintf(
13974
- '<a style="line-height: 40px;" href="%s"><button class="button button-primary">%s &nbsp;&#10140;</button></a>',
13975
- $this->get_account_url( 'change_owner', array(
13976
- 'state' => 'init',
13977
- 'candidate_email' => $new_email_address
13978
- ) ),
13979
- $this->get_text_inline( 'Change Ownership', 'change-ownership' )
13980
- )
13981
- );
13982
- break;
13983
- }
13984
- }
13985
-
13986
- if ( empty( $error ) ) {
13987
- $error = FS_Api::is_api_error_object( $install ) ?
13988
- $install->error->message :
13989
- var_export( $install->error, true );
13990
- }
13991
-
13992
- self::shoot_ajax_failure( $error );
13993
- } else {
13994
- if (
13995
- // If successful ownership change.
13996
- $this->get_user()->id != $install->user_id ||
13997
- ! empty( $new_email_address )
13998
- ) {
13999
- $this->complete_ownership_change_by_license( $install->user_id, $install_ids );
14000
- }
14001
- }
14002
-
14003
- self::shoot_ajax_success();
14004
- }
14005
-
14006
- /**
14007
- * @author Leo Fajardo (@leorw)
14008
- * @since 2.3.2.14
14009
- */
14010
- function starting_migration() {
14011
- if ( ! empty( $this->_storage->license_migration ) ) {
14012
- // Do not overwrite the data if already set.
14013
- return;
14014
- }
14015
-
14016
- $this->_storage->license_migration = array(
14017
- 'is_migrating' => true,
14018
- 'start_timestamp' => time()
14019
- );
14020
- }
14021
-
14022
- /**
14023
- * @author Leo Fajardo (@leorw)
14024
- * @since 2.3.2.14
14025
- */
14026
- function is_migration() {
14027
- if ( $this->is_addon() ) {
14028
- return $this->get_parent_instance()->is_migration();
14029
- }
14030
-
14031
- if ( empty( $this->_storage->license_migration ) ) {
14032
- return false;
14033
- }
14034
-
14035
- if ( ! $this->_storage->license_migration['is_migrating'] ) {
14036
- return false;
14037
- }
14038
-
14039
- return (
14040
- // Return `true` if the migration is within 5 minutes from the starting time.
14041
- ( time() - $this->_storage->license_migration['start_timestamp'] ) <= WP_FS__TIME_5_MIN_IN_SEC
14042
- );
14043
- }
14044
-
14045
- /**
14046
- *
14047
- * A helper method to activate migrated licenses. If the product is network activated and integrated, the method will network activate the license.
14048
- *
14049
- * @author Vova Feldman (@svovaf)
14050
- * @since 2.3.0
14051
- *
14052
- * @param string $license_key
14053
- * @param null|bool $is_marketing_allowed
14054
- * @param null|number $plugin_id
14055
- * @param array $sites
14056
- * @param int $blog_id
14057
- *
14058
- * @return array {
14059
- * @var bool $success
14060
- * @var string $error
14061
- * @var string $next_page
14062
- * }
14063
- *
14064
- * @uses Freemius::activate_license()
14065
- */
14066
- function activate_migrated_license(
14067
- $license_key,
14068
- $is_marketing_allowed = null,
14069
- $plugin_id = null,
14070
- $sites = array(),
14071
- $blog_id = null
14072
- ) {
14073
- $this->_logger->entrance();
14074
-
14075
- $result = $this->activate_license(
14076
- $license_key,
14077
- ( empty( $sites ) && is_null( $blog_id ) && $this->is_network_active() ) ?
14078
- $this->get_sites_for_network_level_optin() :
14079
- $sites,
14080
- $is_marketing_allowed,
14081
- $blog_id,
14082
- $plugin_id
14083
- );
14084
-
14085
- // No need to show the sticky after license activation notice after migrating a license.
14086
- $this->_admin_notices->remove_sticky( 'plan_upgraded' );
14087
-
14088
- return $result;
14089
- }
14090
-
14091
- /**
14092
- * @author Leo Fajardo (@leorw)
14093
- * @since 2.3.1
14094
- *
14095
- * @return string
14096
- */
14097
- function get_pricing_js_path() {
14098
- if ( ! isset( $this->_pricing_js_path ) ) {
14099
- $pricing_js_path = $this->apply_filters( 'freemius_pricing_js_path', '' );
14100
-
14101
- if ( empty( $pricing_js_path ) ) {
14102
- global $fs_active_plugins;
14103
-
14104
- foreach ( $fs_active_plugins->plugins as $sdk_path => $data ) {
14105
- if ( $data->plugin_path == $this->get_plugin_basename() ) {
14106
- $plugin_or_theme_root_dir = ( $this->is_plugin() ? WP_PLUGIN_DIR : get_theme_root( get_stylesheet() ) );
14107
-
14108
- $pricing_js_path = $plugin_or_theme_root_dir
14109
- . '/'
14110
- // The basename will be `plugins`, `themes`, or the basename of a custom plugins or themes directory.
14111
- . str_replace( '../' . basename( $plugin_or_theme_root_dir ) . '/', '', $sdk_path )
14112
- . '/includes/freemius-pricing/freemius-pricing.js';
14113
-
14114
- break;
14115
- }
14116
- }
14117
- }
14118
-
14119
- $this->_pricing_js_path = $pricing_js_path;
14120
- }
14121
-
14122
- return $this->_pricing_js_path;
14123
- }
14124
-
14125
- /**
14126
- * @author Leo Fajardo (@leorw)
14127
- * @since 2.3.1
14128
- *
14129
- * @return bool
14130
- */
14131
- function should_use_external_pricing() {
14132
- if ( is_null( $this->_use_external_pricing ) ) {
14133
- $pricing_js_path = $this->get_pricing_js_path();
14134
-
14135
- $this->_use_external_pricing = ( empty( $pricing_js_path ) || ! file_exists( $pricing_js_path ) );
14136
- }
14137
-
14138
- return $this->_use_external_pricing;
14139
- }
14140
-
14141
- /**
14142
- * The implementation of this method was previously in `_activate_license_ajax_action()`.
14143
- *
14144
- * @author Vova Feldman (@svovaf)
14145
- * @since 2.2.4
14146
- * @since 2.0.0 When a super-admin that hasn't connected before is network activating a license and excluding some of the sites for the license activation, go over the unselected sites in the network and if a site is not connected, skipped, nor delegated, if it's a freemium product then just skip the connection for the site, if it's a premium only product, delegate the connection and license activation to the site admin (Vova Feldman @svovaf).
14147
- * @param string $license_key
14148
- * @param array $sites
14149
- * @param null|bool $is_marketing_allowed
14150
- * @param null|int $blog_id
14151
- * @param null|number $plugin_id
14152
- * @param null|number $license_owner_id
14153
- *
14154
- * @return array {
14155
- * @var bool $success
14156
- * @var string $error
14157
- * @var string $next_page
14158
- * }
14159
- */
14160
- private function activate_license(
14161
- $license_key,
14162
- $sites = array(),
14163
- $is_marketing_allowed = null,
14164
- $blog_id = null,
14165
- $plugin_id = null,
14166
- $license_owner_id = null,
14167
- $is_extensions_tracking_allowed = null
14168
- ) {
14169
- $this->_logger->entrance();
14170
-
14171
- $license_key = trim( $license_key );
14172
-
14173
- $is_network_activation_or_migration = (
14174
- fs_is_network_admin() ||
14175
- ( ! empty( $sites ) && $this->is_migration() )
14176
- );
14177
-
14178
- if ( ! $is_network_activation_or_migration ) {
14179
- // If the license activation is executed outside the context of a network admin, ignore the sites collection.
14180
- $sites = array();
14181
- }
14182
-
14183
- $fs = ( empty($plugin_id) || $plugin_id == $this->_module_id ) ?
14184
- $this :
14185
- $this->get_addon_instance( $plugin_id );
14186
-
14187
- $this->update_extensions_tracking_flag( $is_extensions_tracking_allowed );
14188
-
14189
- $error = false;
14190
- $next_page = false;
14191
-
14192
- $has_valid_blog_id = is_numeric( $blog_id );
14193
-
14194
- $user = null;
14195
-
14196
- if ( $fs->is_addon() && $fs->get_parent_instance()->is_registered() ) {
14197
- /**
14198
- * When activating an add-on's license and the parent is opted-in, activate the license with the parent's opted-in user context.
14199
- *
14200
- * @author Vova Feldman (@svovaf)
14201
- */
14202
- $user = $fs->get_parent_instance()->get_current_or_network_user();
14203
- } else if ( $fs->is_registered() ) {
14204
- $user = $fs->get_current_or_network_user();
14205
- }
14206
-
14207
- if ( $has_valid_blog_id ) {
14208
- /**
14209
- * If a specific blog ID was provided, activate the license only on the specific blog that is associated with the given blog ID.
14210
- *
14211
- * @author Leo Fajardo (@leorw)
14212
- */
14213
- $fs->switch_to_blog( $blog_id );
14214
- }
14215
-
14216
- if ( is_object( $user ) ) {
14217
- if ( $is_network_activation_or_migration && ! $has_valid_blog_id ) {
14218
- // If no specific blog ID was provided, activate the license for all sites in the network.
14219
- $blog_2_install_map = array();
14220
- $site_ids = array();
14221
-
14222
- foreach ( $sites as $site ) {
14223
- if ( ! isset( $site['blog_id'] ) || ! is_numeric( $site['blog_id'] ) ) {
14224
- continue;
14225
- }
14226
-
14227
- $install = $fs->get_install_by_blog_id( $site['blog_id'] );
14228
-
14229
- if ( is_object( $install ) ) {
14230
- $blog_2_install_map[ $site['blog_id'] ] = $install;
14231
- } else {
14232
- $site_ids[] = $site['blog_id'];
14233
- }
14234
- }
14235
-
14236
- if ( ! empty( $blog_2_install_map ) ) {
14237
- $result = $fs->activate_license_on_many_installs( $user, $license_key, $blog_2_install_map );
14238
-
14239
- if ( true !== $result ) {
14240
- $error = FS_Api::is_api_error_object( $result ) ?
14241
- $result->error->message :
14242
- var_export( $result, true );
14243
- }
14244
- }
14245
-
14246
- if ( empty( $error ) && ! empty( $site_ids ) ) {
14247
- $result = $fs->activate_license_on_many_sites( $user, $license_key, $site_ids );
14248
-
14249
- if ( true !== $result ) {
14250
- $error = FS_Api::is_api_error_object( $result ) ?
14251
- $result->error->message :
14252
- var_export( $result, true );
14253
- }
14254
- }
14255
- } else {
14256
- if ( $fs->is_registered() ) {
14257
- $params = array(
14258
- 'license_key' => $fs->apply_filters( 'license_key', $license_key )
14259
- );
14260
-
14261
- $install_ids = array();
14262
-
14263
- $change_owner = FS_User::is_valid_id( $license_owner_id );
14264
-
14265
- if ( $change_owner ) {
14266
- $params['user_id'] = $license_owner_id;
14267
-
14268
- $installs_info_by_slug_map = $fs->get_parent_and_addons_installs_info();
14269
-
14270
- foreach ( $installs_info_by_slug_map as $slug => $install_info ) {
14271
- $install_ids[ $slug ] = $install_info['install']->id;
14272
- }
14273
-
14274
- $params['install_ids'] = implode( ',', array_values( $install_ids ) );
14275
- }
14276
-
14277
- $api = $fs->get_api_site_scope();
14278
-
14279
- $install = $api->call( $fs->add_show_pending( '/' ), 'put', $params );
14280
-
14281
- if ( FS_Api::is_api_error( $install ) ) {
14282
- $error = FS_Api::is_api_error_object( $install ) ?
14283
- $install->error->message :
14284
- var_export( $install->error, true );
14285
- } else {
14286
- $fs->reconnect_locally( $has_valid_blog_id );
14287
-
14288
- if (
14289
- $change_owner &&
14290
- // If successful ownership change.
14291
- $fs->get_user()->id != $install->user_id
14292
- ) {
14293
- $fs->complete_ownership_change_by_license( $install->user_id, $install_ids );
14294
- }
14295
- }
14296
- } else /* ( $fs->is_addon() && $fs->get_parent_instance()->is_registered() ) */ {
14297
- $result = $fs->activate_license_on_site( $user, $license_key );
14298
-
14299
- if ( true !== $result ) {
14300
- $error = FS_Api::is_api_error_object( $result ) ?
14301
- $result->error->message :
14302
- var_export( $result, true );
14303
- }
14304
- }
14305
- }
14306
-
14307
- if ( empty( $error ) ) {
14308
- $fs->network_upgrade_mode_completed();
14309
-
14310
- $fs->_user = $user;
14311
-
14312
- if ( fs_is_network_admin() && ! $has_valid_blog_id ) {
14313
- $fs->_site = $fs->get_network_install();
14314
- }
14315
-
14316
- $fs->_sync_license( true, $has_valid_blog_id );
14317
-
14318
- $this->maybe_sync_install_user();
14319
-
14320
- $next_page = $fs->is_addon() ?
14321
- $fs->get_parent_instance()->get_account_url() :
14322
- $fs->get_after_activation_url( 'after_connect_url' );
14323
- }
14324
- } else {
14325
- $next_page = $fs->opt_in(
14326
- false,
14327
- false,
14328
- false,
14329
- $license_key,
14330
- false,
14331
- false,
14332
- false,
14333
- $is_marketing_allowed,
14334
- $sites
14335
- );
14336
-
14337
- if ( isset( $next_page->error ) ) {
14338
- $error = $next_page->error;
14339
- } else {
14340
- if ( $is_network_activation_or_migration ) {
14341
- /**
14342
- * Get the list of sites that were just opted-in (and license activated).
14343
- * This is an optimization for the next part below saving some DB queries.
14344
- */
14345
- $connected_sites = array();
14346
- foreach ( $sites as $site ) {
14347
- if ( isset( $site['blog_id'] ) && is_numeric( $site['blog_id'] ) ) {
14348
- $connected_sites[ $site['blog_id'] ] = true;
14349
- }
14350
- }
14351
-
14352
- $all_sites = self::get_sites();
14353
- $pending_sites = array();
14354
-
14355
- /**
14356
- * Check if there are any sites that are not connected, skipped, nor delegated. For every site that falls into that category, if the product is freemium, skip the connection. If the product is premium only, delegate the connection to the site administrator.
14357
- *
14358
- * @author Vova Feldman (@svovaf)
14359
- */
14360
- foreach ( $all_sites as $site ) {
14361
- $blog_id = self::get_site_blog_id( $site );
14362
-
14363
- if ( isset( $connected_sites[ $blog_id ] ) ) {
14364
- // Site was just connected.
14365
- continue;
14366
- }
14367
-
14368
- if ( $fs->is_installed_on_site( $blog_id ) ) {
14369
- // Site was already connected before.
14370
- continue;
14371
- }
14372
-
14373
- if ( $fs->is_site_delegated_connection( $blog_id ) ) {
14374
- // Site's connection was delegated.
14375
- continue;
14376
- }
14377
-
14378
- if ( $fs->is_anonymous_site( $blog_id ) ) {
14379
- // Site connection was already skipped.
14380
- continue;
14381
- }
14382
-
14383
- $pending_sites[] = self::get_site_info( $site );
14384
- }
14385
-
14386
- if ( ! empty( $pending_sites ) ) {
14387
- if ( $fs->is_freemium() && $fs->is_enable_anonymous() ) {
14388
- $fs->skip_connection( $pending_sites );
14389
- } else {
14390
- $fs->delegate_connection( $pending_sites );
14391
- }
14392
- }
14393
- }
14394
- }
14395
- }
14396
-
14397
- if ( false === $error && true === $fs->_storage->require_license_activation ) {
14398
- $fs->_storage->require_license_activation = false;
14399
- }
14400
-
14401
- $result = array(
14402
- 'success' => ( false === $error )
14403
- );
14404
-
14405
- if ( false !== $error ) {
14406
- $result['error'] = $fs->apply_filters( 'opt_in_error_message', $error );
14407
- } else {
14408
- if ( $fs->is_addon() || $fs->has_addons() ) {
14409
- /**
14410
- * Purge the valid user licenses cache so that when the "Account" or the "Add-Ons" page is loaded,
14411
- * an updated valid user licenses collection will be fetched from the server which is used to also
14412
- * update the account add-ons (add-ons the user has licenses for).
14413
- *
14414
- * @author Leo Fajardo (@leorw)
14415
- * @since 2.2.4
14416
- */
14417
- $fs->purge_valid_user_licenses_cache();
14418
- }
14419
-
14420
- $result['next_page'] = $next_page;
14421
- }
14422
-
14423
- return $result;
14424
- }
14425
-
14426
- /**
14427
- * @author Leo Fajardo (@leorw)
14428
- * @since 2.3.2
14429
- *
14430
- * @return array {
14431
- * @key string Product slug.
14432
- * @value array {
14433
- * @property FS_Site $site
14434
- * @property FS_Plugin_License $license
14435
- * }
14436
- * }
14437
- */
14438
- private function get_parent_and_addons_installs_info() {
14439
- $fs = $this->is_addon() ?
14440
- $this->get_parent_instance() :
14441
- $this;
14442
-
14443
- $installed_addons_ids = array();
14444
-
14445
- $installed_addons_instances = $fs->get_installed_addons();
14446
- foreach ( $installed_addons_instances as $instance ) {
14447
- $installed_addons_ids[] = $instance->get_id();
14448
- }
14449
-
14450
- $addons_ids = array_unique( array_merge(
14451
- $installed_addons_ids,
14452
- $fs->get_updated_account_addons()
14453
- ) );
14454
-
14455
- // Add parent product info.
14456
- $installs_info_by_slug_map = array(
14457
- $fs->get_slug() => array(
14458
- 'install' => $fs->get_site(),
14459
- 'license' => $fs->_get_license()
14460
- )
14461
- );
14462
-
14463
- foreach ( $addons_ids as $addon_id ) {
14464
- $is_installed = isset( $installed_addons_ids_map[ $addon_id ] );
14465
-
14466
- $addon_info = $fs->_get_addon_info( $addon_id, $is_installed );
14467
-
14468
- if ( ! isset( $addon_info['is_connected'] ) || ! $addon_info['is_connected'] ) {
14469
- // Add-on is not associated with an install entity.
14470
- continue;
14471
- }
14472
-
14473
- $installs_info_by_slug_map[ $addon_info['slug'] ] = array(
14474
- 'install' => $addon_info['site'],
14475
- 'license' => isset( $addon_info['license'] ) ?
14476
- $addon_info['license'] :
14477
- null
14478
- );
14479
- }
14480
-
14481
- return $installs_info_by_slug_map;
14482
- }
14483
-
14484
- /**
14485
- * @author Leo Fajardo (@leorw)
14486
- * @since 1.2.3.1
14487
- */
14488
- function _network_activate_ajax_action() {
14489
- $this->_logger->entrance();
14490
-
14491
- $this->check_ajax_referer( 'network_activate' );
14492
-
14493
- $plugin_id = fs_request_get( 'module_id', '', 'post' );
14494
- $fs = ( $plugin_id == $this->_module_id ) ?
14495
- $this :
14496
- $this->get_addon_instance( $plugin_id );
14497
-
14498
- $error = false;
14499
-
14500
- $sites = fs_request_get( 'sites', array(), 'post' );
14501
- if ( is_array( $sites ) && ! empty( $sites ) ) {
14502
- $sites_by_action = array(
14503
- 'allow' => array(),
14504
- 'delegate' => array(),
14505
- 'skip' => array()
14506
- );
14507
-
14508
- foreach ( $sites as $site ) {
14509
- $sites_by_action[ $site['action'] ][] = $site;
14510
- }
14511
-
14512
- $total_sites = count( $sites );
14513
- $total_sites_to_delegate = count( $sites_by_action['delegate'] );
14514
-
14515
- $next_page = '';
14516
-
14517
- $has_any_install = fs_request_get_bool( 'has_any_install' );
14518
-
14519
- if ( $total_sites === $total_sites_to_delegate &&
14520
- ! $this->is_network_upgrade_mode() &&
14521
- ! $has_any_install
14522
- ) {
14523
- $this->delegate_connection();
14524
- } else {
14525
- if ( ! empty( $sites_by_action['delegate'] ) ) {
14526
- $this->delegate_connection( $sites_by_action['delegate'] );
14527
- }
14528
-
14529
- if ( ! empty( $sites_by_action['skip'] ) ) {
14530
- $this->skip_connection( $sites_by_action['skip'] );
14531
- }
14532
-
14533
- if ( empty( $sites_by_action['allow'] ) ) {
14534
- if ( $has_any_install ) {
14535
- $first_install = $fs->find_first_install();
14536
-
14537
- if ( ! is_null( $first_install ) ) {
14538
- $fs->_site = $first_install['install'];
14539
- $fs->_storage->network_install_blog_id = $first_install['blog_id'];
14540
-
14541
- $fs->_user = self::_get_user_by_id( $fs->_site->user_id );
14542
- $fs->_storage->network_user_id = $fs->_user->id;
14543
- }
14544
- }
14545
- } else {
14546
- if ( ! $fs->is_registered() || ! $this->_is_network_active ) {
14547
- $next_page = $fs->opt_in(
14548
- false,
14549
- false,
14550
- false,
14551
- false,
14552
- false,
14553
- false,
14554
- false,
14555
- fs_request_get_bool( 'is_marketing_allowed', null ),
14556
- $sites_by_action['allow']
14557
- );
14558
- } else {
14559
- $next_page = $fs->install_with_user(
14560
- $this->get_network_user(),
14561
- false,
14562
- false,
14563
- false,
14564
- true,
14565
- $sites_by_action['allow']
14566
- );
14567
- }
14568
-
14569
- if ( is_object( $next_page ) && isset( $next_page->error ) ) {
14570
- $error = $next_page->error;
14571
- }
14572
- }
14573
- }
14574
-
14575
- if ( empty( $next_page ) ) {
14576
- $next_page = $this->get_after_activation_url( 'after_network_activation_url' );
14577
- }
14578
- } else {
14579
- $error = $this->get_text_inline( 'Invalid site details collection.', 'invalid_site_details_collection' );
14580
- }
14581
-
14582
- $result = array(
14583
- 'success' => ( false === $error )
14584
- );
14585
-
14586
- if ( false !== $error ) {
14587
- $result['error'] = $error;
14588
- } else {
14589
- $result['next_page'] = $next_page;
14590
- }
14591
-
14592
- echo json_encode( $result );
14593
-
14594
- exit;
14595
- }
14596
-
14597
- /**
14598
- * Billing update AJAX callback.
14599
- *
14600
- * @author Vova Feldman (@svovaf)
14601
- * @since 1.2.1.5
14602
- */
14603
- function _update_billing_ajax_action() {
14604
- $this->_logger->entrance();
14605
-
14606
- $this->check_ajax_referer( 'update_billing' );
14607
-
14608
- if ( ! $this->is_user_admin() ) {
14609
- // Only for admins.
14610
- self::shoot_ajax_failure();
14611
- }
14612
-
14613
- $billing = fs_request_get( 'billing' );
14614
-
14615
- $api = $this->get_api_user_scope();
14616
- $result = $api->call( '/billing.json', 'put', array_merge( $billing, array(
14617
- 'plugin_id' => $this->get_parent_id(),
14618
- ) ) );
14619
-
14620
- if ( ! $this->is_api_result_entity( $result ) ) {
14621
- self::shoot_ajax_failure();
14622
- }
14623
-
14624
- // Purge cached billing.
14625
- $this->get_api_user_scope()->purge_cache( 'billing.json' );
14626
-
14627
- self::shoot_ajax_success();
14628
- }
14629
-
14630
- /**
14631
- * Trial start for anonymous users (AJAX callback).
14632
- *
14633
- * @author Vova Feldman (@svovaf)
14634
- * @since 1.2.1.5
14635
- */
14636
- function _start_trial_ajax_action() {
14637
- $this->_logger->entrance();
14638
-
14639
- $this->check_ajax_referer( 'start_trial' );
14640
-
14641
- if ( ! $this->is_user_admin() ) {
14642
- // Only for admins.
14643
- self::shoot_ajax_failure();
14644
- }
14645
-
14646
- $trial_data = fs_request_get( 'trial' );
14647
-
14648
- $next_page = $this->opt_in(
14649
- false,
14650
- false,
14651
- false,
14652
- false,
14653
- false,
14654
- $trial_data['plan_id']
14655
- );
14656
-
14657
- if ( is_object( $next_page ) && $this->is_api_error( $next_page ) ) {
14658
- self::shoot_ajax_failure(
14659
- isset( $next_page->error ) ?
14660
- $next_page->error->message :
14661
- var_export( $next_page, true )
14662
- );
14663
- }
14664
-
14665
- $this->shoot_ajax_success( array(
14666
- 'next_page' => $next_page,
14667
- ) );
14668
- }
14669
-
14670
- /**
14671
- * @author Leo Fajardo (@leorw)
14672
- * @since 1.2.0
14673
- */
14674
- function _resend_license_key_ajax_action() {
14675
- $this->_logger->entrance();
14676
-
14677
- $this->check_ajax_referer( 'resend_license_key' );
14678
-
14679
- $email_address = sanitize_email( trim( fs_request_get( 'email', '', 'post' ) ) );
14680
-
14681
- if ( empty( $email_address ) ) {
14682
- exit;
14683
- }
14684
-
14685
- $error = false;
14686
-
14687
- $api = $this->get_api_plugin_scope();
14688
- $result = $api->call( '/licenses/resend.json', 'post',
14689
- array(
14690
- 'email' => $email_address,
14691
- 'url' => home_url(),
14692
- )
14693
- );
14694
-
14695
- if ( is_object( $result ) && isset( $result->error ) ) {
14696
- $error = $result->error;
14697
-
14698
- if ( in_array( $error->code, array( 'invalid_email', 'no_user' ) ) ) {
14699
- $error = $this->get_text_inline( "We couldn't find your email address in the system, are you sure it's the right address?", 'email-not-found' );
14700
- } else if ( 'no_license' === $error->code ) {
14701
- $error = $this->get_text_inline( "We can't see any active licenses associated with that email address, are you sure it's the right address?", 'no-active-licenses' );
14702
- } else {
14703
- $error = $error->message;
14704
- }
14705
- }
14706
-
14707
- $licenses = array(
14708
- 'success' => ( false === $error )
14709
- );
14710
-
14711
- if ( false !== $error ) {
14712
- $licenses['error'] = sprintf( '%s... %s', $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ), strtolower( $error ) );
14713
- }
14714
-
14715
- echo json_encode( $licenses );
14716
-
14717
- exit;
14718
- }
14719
-
14720
- /**
14721
- * @author Vova Feldman (@svovaf)
14722
- * @since 1.2.1.8
14723
- *
14724
- * @var string
14725
- */
14726
- private static $_pagenow;
14727
-
14728
- /**
14729
- * Get current page or the referer if executing a WP AJAX request.
14730
- *
14731
- * @author Vova Feldman (@svovaf)
14732
- * @since 1.2.1.8
14733
- *
14734
- * @return string
14735
- */
14736
- static function get_current_page() {
14737
- if ( ! isset( self::$_pagenow ) ) {
14738
- global $pagenow;
14739
- if ( empty( $pagenow ) && is_admin() && is_multisite() ) {
14740
- /**
14741
- * It appears that `$pagenow` is not yet initialized in some network admin pages when this method
14742
- * is called, so initialize it here using some pieces of code from `wp-includes/vars.php`.
14743
- *
14744
- * @author Leo Fajardo (@leorw)
14745
- * @since 2.2.3
14746
- */
14747
- if ( is_network_admin() ) {
14748
- preg_match( '#/wp-admin/network/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches );
14749
- } else if ( is_user_admin() ) {
14750
- preg_match( '#/wp-admin/user/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches );
14751
- } else {
14752
- preg_match( '#/wp-admin/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches );
14753
- }
14754
-
14755
- $pagenow = $self_matches[1];
14756
- $pagenow = trim( $pagenow, '/' );
14757
- $pagenow = preg_replace( '#\?.*?$#', '', $pagenow );
14758
- if ( '' === $pagenow || 'index' === $pagenow || 'index.php' === $pagenow ) {
14759
- $pagenow = 'index.php';
14760
- } else {
14761
- preg_match( '#(.*?)(/|$)#', $pagenow, $self_matches );
14762
- $pagenow = strtolower( $self_matches[1] );
14763
- if ( '.php' !== substr($pagenow, -4, 4) )
14764
- $pagenow .= '.php'; // for Options +Multiviews: /wp-admin/themes/index.php (themes.php is queried)
14765
- }
14766
- }
14767
-
14768
- self::$_pagenow = $pagenow;
14769
-
14770
- if ( self::is_ajax() &&
14771
- 'admin-ajax.php' === $pagenow
14772
- ) {
14773
- $referer = fs_get_raw_referer();
14774
-
14775
- if ( is_string( $referer ) ) {
14776
- $parts = explode( '?', $referer );
14777
-
14778
- self::$_pagenow = basename( $parts[0] );
14779
- }
14780
- }
14781
- }
14782
-
14783
- return self::$_pagenow;
14784
- }
14785
-
14786
- /**
14787
- * Helper method to check if user in the plugins page.
14788
- *
14789
- * @author Vova Feldman (@svovaf)
14790
- * @since 1.2.1.5
14791
- *
14792
- * @return bool
14793
- */
14794
- static function is_plugins_page() {
14795
- return ( 'plugins.php' === self::get_current_page() );
14796
- }
14797
-
14798
- /**
14799
- * @author Leo Fajardo (@leorw)
14800
- * @since 2.2.3
14801
- *
14802
- * @return bool
14803
- */
14804
- static function is_plugin_install_page() {
14805
- return ( 'plugin-install.php' === self::get_current_page() );
14806
- }
14807
-
14808
- /**
14809
- * @author Leo Fajardo (@leorw)
14810
- * @since 2.0.2
14811
- *
14812
- * @return bool
14813
- */
14814
- static function is_updates_page() {
14815
- return ( 'update-core.php' === self::get_current_page() );
14816
- }
14817
-
14818
- /**
14819
- * Helper method to check if user in the themes page.
14820
- *
14821
- * @author Vova Feldman (@svovaf)
14822
- * @since 1.2.2.6
14823
- *
14824
- * @return bool
14825
- */
14826
- static function is_themes_page() {
14827
- return ( 'themes.php' === self::get_current_page() );
14828
- }
14829
-
14830
- #----------------------------------------------------------------------------------
14831
- #region Affiliation
14832
- #----------------------------------------------------------------------------------
14833
-
14834
- /**
14835
- * @author Leo Fajardo (@leorw)
14836
- * @since 1.2.3
14837
- *
14838
- * @return bool
14839
- */
14840
- function has_affiliate_program() {
14841
- if ( ! is_object( $this->_plugin ) ) {
14842
- return false;
14843
- }
14844
-
14845
- return $this->_plugin->has_affiliate_program();
14846
- }
14847
-
14848
- /**
14849
- * @author Leo Fajardo (@leorw)
14850
- * @since 1.2.4
14851
- */
14852
- private function fetch_affiliate_terms() {
14853
- if ( ! is_object( $this->plugin_affiliate_terms ) ) {
14854
- $plugins_api = $this->get_api_plugin_scope();
14855
- $affiliate_terms = $plugins_api->get( '/aff.json?type=affiliation', false );
14856
-
14857
- if ( ! $this->is_api_result_entity( $affiliate_terms ) ) {
14858
- return;
14859
- }
14860
-
14861
- $this->plugin_affiliate_terms = new FS_AffiliateTerms( $affiliate_terms );
14862
- }
14863
- }
14864
-
14865
- /**
14866
- * @author Leo Fajardo (@leorw)
14867
- * @since 1.2.4
14868
- */
14869
- private function fetch_affiliate_and_custom_terms() {
14870
- if ( ! empty( $this->_storage->affiliate_application_data ) ) {
14871
- $application_data = $this->_storage->affiliate_application_data;
14872
- $flush = ( ! isset( $application_data['status'] ) || 'pending' === $application_data['status'] );
14873
-
14874
- $users_api = $this->get_api_user_scope();
14875
- $result = $users_api->get( "/plugins/{$this->_plugin->id}/aff/{$this->plugin_affiliate_terms->id}/affiliates.json", $flush );
14876
- if ( $this->is_api_result_object( $result, 'affiliates' ) ) {
14877
- if ( ! empty( $result->affiliates ) ) {
14878
- $affiliate = new FS_Affiliate( $result->affiliates[0] );
14879
-
14880
- if ( ! isset( $application_data['status'] ) || $application_data['status'] !== $affiliate->status ) {
14881
- $application_data['status'] = $affiliate->status;
14882
- $this->_storage->affiliate_application_data = $application_data;
14883
- }
14884
-
14885
- if ( $affiliate->is_using_custom_terms ) {
14886
- $affiliate_terms = $users_api->get( "/plugins/{$this->_plugin->id}/affiliates/{$affiliate->id}/aff/{$affiliate->custom_affiliate_terms_id}.json", $flush );
14887
- if ( $this->is_api_result_entity( $affiliate_terms ) ) {
14888
- $this->custom_affiliate_terms = new FS_AffiliateTerms( $affiliate_terms );
14889
- }
14890
- }
14891
-
14892
- $this->affiliate = $affiliate;
14893
- }
14894
- }
14895
- }
14896
- }
14897
-
14898
- /**
14899
- * @author Leo Fajardo (@leorw)
14900
- * @since 1.2.3
14901
- */
14902
- private function fetch_affiliate_and_terms() {
14903
- $this->_logger->entrance();
14904
-
14905
- $this->fetch_affiliate_terms();
14906
- $this->fetch_affiliate_and_custom_terms();
14907
- }
14908
-
14909
- /**
14910
- * @author Leo Fajardo (@leorw)
14911
- * @since 1.2.3
14912
- *
14913
- * @return FS_Affiliate
14914
- */
14915
- function get_affiliate() {
14916
- return $this->affiliate;
14917
- }
14918
-
14919
-
14920
- /**
14921
- * @author Leo Fajardo (@leorw)
14922
- * @since 1.2.3
14923
- *
14924
- * @return FS_AffiliateTerms
14925
- */
14926
- function get_affiliate_terms() {
14927
- return is_object( $this->custom_affiliate_terms ) ?
14928
- $this->custom_affiliate_terms :
14929
- $this->plugin_affiliate_terms;
14930
- }
14931
-
14932
- /**
14933
- * @author Leo Fajardo (@leorw)
14934
- * @since 1.2.3
14935
- */
14936
- function _submit_affiliate_application() {
14937
- $this->_logger->entrance();
14938
-
14939
- $this->check_ajax_referer( 'submit_affiliate_application' );
14940
-
14941
- if ( ! $this->is_user_admin() ) {
14942
- // Only for admins.
14943
- self::shoot_ajax_failure();
14944
- }
14945
-
14946
- $affiliate = fs_request_get( 'affiliate' );
14947
-
14948
- if ( empty( $affiliate['promotion_methods'] ) ) {
14949
- unset( $affiliate['promotion_methods'] );
14950
- }
14951
-
14952
- if ( ! empty( $affiliate['additional_domains'] ) ) {
14953
- $affiliate['additional_domains'] = array_unique( $affiliate['additional_domains'] );
14954
- }
14955
-
14956
- if ( ! $this->is_registered() ) {
14957
- // Opt in but don't track usage.
14958
- $next_page = $this->opt_in(
14959
- false,
14960
- false,
14961
- false,
14962
- false,
14963
- false,
14964
- false,
14965
- true
14966
- );
14967
-
14968
- if ( is_object( $next_page ) && $this->is_api_error( $next_page ) ) {
14969
- self::shoot_ajax_failure(
14970
- isset( $next_page->error ) ?
14971
- $next_page->error->message :
14972
- var_export( $next_page, true )
14973
- );
14974
- } else if ( $this->is_pending_activation() ) {
14975
- self::shoot_ajax_failure( $this->get_text_inline( 'Account is pending activation.', 'account-is-pending-activation' ) );
14976
- }
14977
- }
14978
-
14979
- $this->fetch_affiliate_terms();
14980
-
14981
- $api = $this->get_api_user_scope();
14982
- $result = $api->call(
14983
- ( "/plugins/{$this->_plugin->id}/aff/{$this->plugin_affiliate_terms->id}/affiliates.json" ),
14984
- 'post',
14985
- $affiliate
14986
- );
14987
-
14988
- if ( $this->is_api_error( $result ) ) {
14989
- self::shoot_ajax_failure(
14990
- isset( $result->error ) ?
14991
- $result->error->message :
14992
- var_export( $result, true )
14993
- );
14994
- } else {
14995
- if ( $this->_admin_notices->has_sticky( 'affiliate_program' ) ) {
14996
- $this->_admin_notices->remove_sticky( 'affiliate_program' );
14997
- }
14998
-
14999
- $affiliate_application_data = array(
15000
- 'status' => 'pending',
15001
- 'stats_description' => $affiliate['stats_description'],
15002
- 'promotion_method_description' => $affiliate['promotion_method_description'],
15003
- );
15004
-
15005
- if ( ! empty( $affiliate['promotion_methods'] ) ) {
15006
- $affiliate_application_data['promotion_methods'] = $affiliate['promotion_methods'];
15007
- }
15008
-
15009
- if ( ! empty( $affiliate['domain'] ) ) {
15010
- $affiliate_application_data['domain'] = $affiliate['domain'];
15011
- }
15012
-
15013
- if ( ! empty( $affiliate['additional_domains'] ) ) {
15014
- $affiliate_application_data['additional_domains'] = $affiliate['additional_domains'];
15015
- }
15016
-
15017
- $this->_storage->affiliate_application_data = $affiliate_application_data;
15018
- }
15019
-
15020
- // Purge cached affiliate.
15021
- $api->purge_cache( 'affiliate.json' );
15022
-
15023
- self::shoot_ajax_success( $result );
15024
- }
15025
-
15026
- /**
15027
- * @author Leo Fajardo (@leorw)
15028
- * @since 1.2.3
15029
- *
15030
- * @return array|null
15031
- */
15032
- function get_affiliate_application_data() {
15033
- if ( empty( $this->_storage->affiliate_application_data ) ) {
15034
- return null;
15035
- }
15036
-
15037
- return $this->_storage->affiliate_application_data;
15038
- }
15039
-
15040
- #endregion Affiliation ------------------------------------------------------------
15041
-
15042
- #----------------------------------------------------------------------------------
15043
- #region URL Generators
15044
- #----------------------------------------------------------------------------------
15045
-
15046
- /**
15047
- * Alias to pricing_url().
15048
- *
15049
- * @author Vova Feldman (@svovaf)
15050
- * @since 1.0.2
15051
- *
15052
- * @uses pricing_url()
15053
- *
15054
- * @param string $period Billing cycle
15055
- * @param bool $is_trial
15056
- *
15057
- * @return string
15058
- */
15059
- function get_upgrade_url( $period = WP_FS__PERIOD_ANNUALLY, $is_trial = false ) {
15060
- return $this->pricing_url( $period, $is_trial );
15061
- }
15062
-
15063
- /**
15064
- * @author Vova Feldman (@svovaf)
15065
- * @since 1.0.9
15066
- *
15067
- * @uses get_upgrade_url()
15068
- *
15069
- * @return string
15070
- */
15071
- function get_trial_url() {
15072
- return $this->get_upgrade_url( WP_FS__PERIOD_ANNUALLY, true );
15073
- }
15074
-
15075
- /**
15076
- * @author Leo Fajardo (@leorw)
15077
- * @since 2.1.4
15078
- *
15079
- * @param string $new_version
15080
- *
15081
- * @return string
15082
- */
15083
- function version_upgrade_checkout_link( $new_version ) {
15084
- if ( ! is_object( $this->_license ) ) {
15085
- $url = $this->pricing_url();
15086
-
15087
- $purchase_license_text = $this->get_text_inline( 'Buy a license now', 'buy-license-now' );
15088
- } else {
15089
- $subscription = $this->_get_subscription( $this->_license->id );
15090
-
15091
- $url = $this->checkout_url(
15092
- is_object( $subscription ) ?
15093
- ( 1 == $subscription->billing_cycle ? WP_FS__PERIOD_MONTHLY : WP_FS__PERIOD_ANNUALLY ) :
15094
- WP_FS__PERIOD_LIFETIME,
15095
- false,
15096
- array( 'licenses' => $this->_license->quota )
15097
- );
15098
-
15099
- $purchase_license_text = $this->get_text_inline( 'Renew your license now', 'renew-license-now' );
15100
- }
15101
-
15102
- return sprintf(
15103
- $this->get_text_inline( '%s to access version %s security & feature updates, and support.', 'x-for-updates-and-support' ),
15104
- sprintf( '<a href="%s">%s</a>', $url, $purchase_license_text ),
15105
- $new_version
15106
- );
15107
- }
15108
-
15109
- /**
15110
- * Plugin's pricing URL.
15111
- *
15112
- * @author Vova Feldman (@svovaf)
15113
- * @since 1.0.4
15114
- *
15115
- * @param string $billing_cycle Billing cycle
15116
- *
15117
- * @param bool $is_trial
15118
- *
15119
- * @return string
15120
- */
15121
- function pricing_url( $billing_cycle = WP_FS__PERIOD_ANNUALLY, $is_trial = false ) {
15122
- $this->_logger->entrance();
15123
-
15124
- $params = array(
15125
- 'billing_cycle' => $billing_cycle
15126
- );
15127
-
15128
- if ( $is_trial ) {
15129
- $params['trial'] = 'true';
15130
- }
15131
-
15132
- $url = $this->is_addon() ?
15133
- $this->_parent->addon_url( $this->_slug ) :
15134
- $this->_get_admin_page_url( 'pricing', $params );
15135
-
15136
- return $this->apply_filters( 'pricing_url', $url );
15137
- }
15138
-
15139
- /**
15140
- * Checkout page URL.
15141
- *
15142
- * @author Vova Feldman (@svovaf)
15143
- * @since 1.0.6
15144
- *
15145
- * @param string $billing_cycle Billing cycle
15146
- * @param bool $is_trial
15147
- * @param array $extra (optional) Extra parameters, override other query params.
15148
- * @param bool|null $network
15149
- *
15150
- * @return string
15151
- */
15152
- function checkout_url(
15153
- $billing_cycle = WP_FS__PERIOD_ANNUALLY,
15154
- $is_trial = false,
15155
- $extra = array(),
15156
- $network = null
15157
- ) {
15158
- $this->_logger->entrance();
15159
-
15160
- $params = array(
15161
- 'checkout' => 'true',
15162
- 'billing_cycle' => $billing_cycle,
15163
- );
15164
-
15165
- if ( $is_trial ) {
15166
- $params['trial'] = 'true';
15167
- }
15168
-
15169
- /**
15170
- * Params in extra override other params.
15171
- */
15172
- $params = array_merge( $params, $extra );
15173
-
15174
- return $this->_get_admin_page_url( 'pricing', $params, $network );
15175
- }
15176
-
15177
- /**
15178
- * Add-on checkout URL.
15179
- *
15180
- * @author Vova Feldman (@svovaf)
15181
- * @since 1.1.7
15182
- *
15183
- * @param number $addon_id
15184
- * @param number $pricing_id
15185
- * @param string $billing_cycle
15186
- * @param bool $is_trial
15187
- * @param bool|null $network
15188
- *
15189
- * @return string
15190
- */
15191
- function addon_checkout_url(
15192
- $addon_id,
15193
- $pricing_id,
15194
- $billing_cycle = WP_FS__PERIOD_ANNUALLY,
15195
- $is_trial = false,
15196
- $network = null
15197
- ) {
15198
- return $this->checkout_url( $billing_cycle, $is_trial, array(
15199
- 'plugin_id' => $addon_id,
15200
- 'pricing_id' => $pricing_id,
15201
- ), $network );
15202
- }
15203
-
15204
- #endregion
15205
-
15206
- #endregion ------------------------------------------------------------------
15207
-
15208
- /**
15209
- * Check if plugin has any add-ons.
15210
- *
15211
- * @author Vova Feldman (@svovaf)
15212
- * @since 1.0.5
15213
- *
15214
- * @since 1.1.7.3 Base logic only on the parameter provided by the developer in the init function.
15215
- *
15216
- * @return bool
15217
- */
15218
- function has_addons() {
15219
- $this->_logger->entrance();
15220
-
15221
- return $this->_has_addons;
15222
- }
15223
-
15224
- /**
15225
- * Check if plugin can work in anonymous mode.
15226
- *
15227
- * @author Vova Feldman (@svovaf)
15228
- * @since 1.0.9
15229
- *
15230
- * @return bool
15231
- *
15232
- * @deprecated Please use is_enable_anonymous() instead.
15233
- */
15234
- function enable_anonymous() {
15235
- return $this->_enable_anonymous;
15236
- }
15237
-
15238
- /**
15239
- * Check if plugin can work in anonymous mode.
15240
- *
15241
- * @author Vova Feldman (@svovaf)
15242
- * @since 1.1.9
15243
- *
15244
- * @return bool
15245
- */
15246
- function is_enable_anonymous() {
15247
- return $this->_enable_anonymous;
15248
- }
15249
-
15250
- /**
15251
- * Check if plugin is premium only (no free plans).
15252
- *
15253
- * @author Vova Feldman (@svovaf)
15254
- * @since 1.1.9
15255
- *
15256
- * @return bool
15257
- */
15258
- function is_only_premium() {
15259
- return $this->_is_premium_only;
15260
- }
15261
-
15262
- /**
15263
- * Checks if the plugin's type is "plugin". The other type is "theme".
15264
- *
15265
- * @author Leo Fajardo (@leorw)
15266
- * @since 1.2.2
15267
- *
15268
- * @return bool
15269
- */
15270
- function is_plugin() {
15271
- return ( WP_FS__MODULE_TYPE_PLUGIN === $this->_module_type );
15272
- }
15273
-
15274
- /**
15275
- * @author Leo Fajardo (@leorw)
15276
- * @since 1.2.2
15277
- *
15278
- * @return string
15279
- */
15280
- function get_module_type() {
15281
- if ( ! isset( $this->_module_type ) ) {
15282
- $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array() );
15283
- $this->_module_type = $id_slug_type_path_map[ $this->_module_id ]['type'];
15284
- }
15285
-
15286
- return $this->_module_type;
15287
- }
15288
-
15289
- /**
15290
- * @author Leo Fajardo (@leorw)
15291
- * @since 1.2.2
15292
- *
15293
- * @return string
15294
- */
15295
- function get_plugin_main_file_path() {
15296
- return $this->_plugin_main_file_path;
15297
- }
15298
-
15299
- /**
15300
- * Check if module has a premium code version.
15301
- *
15302
- * Serviceware module might be freemium without any
15303
- * premium code version, where the paid features
15304
- * are all part of the service.
15305
- *
15306
- * @author Vova Feldman (@svovaf)
15307
- * @since 1.2.1.6
15308
- *
15309
- * @return bool
15310
- */
15311
- function has_premium_version() {
15312
- return $this->_has_premium_version;
15313
- }
15314
-
15315
- /**
15316
- * Check if feature supported with current site's plan.
15317
- *
15318
- * @author Vova Feldman (@svovaf)
15319
- * @since 1.0.1
15320
- *
15321
- * @todo IMPLEMENT
15322
- *
15323
- * @param number $feature_id
15324
- *
15325
- * @throws Exception
15326
- */
15327
- function is_feature_supported( $feature_id ) {
15328
- throw new Exception( 'not implemented' );
15329
- }
15330
-
15331
- /**
15332
- * @author Vova Feldman (@svovaf)
15333
- * @since 1.0.1
15334
- *
15335
- * @return bool Is running in SSL/HTTPS
15336
- */
15337
- function is_ssl() {
15338
- return WP_FS__IS_HTTPS;
15339
- }
15340
-
15341
- /**
15342
- * @author Vova Feldman (@svovaf)
15343
- * @since 1.0.9
15344
- *
15345
- * @return bool Is running in AJAX call.
15346
- *
15347
- * @link http://wordpress.stackexchange.com/questions/70676/how-to-check-if-i-am-in-admin-ajax
15348
- */
15349
- static function is_ajax() {
15350
- return ( defined( 'DOING_AJAX' ) && DOING_AJAX );
15351
- }
15352
-
15353
- /**
15354
- * Check if it's an AJAX call targeted for the current module.
15355
- *
15356
- * @author Vova Feldman (@svovaf)
15357
- * @since 1.2.0
15358
- *
15359
- * @param array|string $actions Collection of AJAX actions.
15360
- *
15361
- * @return bool
15362
- */
15363
- function is_ajax_action( $actions ) {
15364
- // Verify it's an ajax call.
15365
- if ( ! self::is_ajax() ) {
15366
- return false;
15367
- }
15368
-
15369
- // Verify the call is relevant for the plugin.
15370
- if ( $this->_module_id != fs_request_get( 'module_id' ) ) {
15371
- return false;
15372
- }
15373
-
15374
- // Verify it's one of the specified actions.
15375
- if ( is_string( $actions ) ) {
15376
- $actions = explode( ',', $actions );
15377
- }
15378
-
15379
- if ( is_array( $actions ) && 0 < count( $actions ) ) {
15380
- $ajax_action = fs_request_get( 'action' );
15381
-
15382
- foreach ( $actions as $action ) {
15383
- if ( $ajax_action === $this->get_action_tag( $action ) ) {
15384
- return true;
15385
- }
15386
- }
15387
- }
15388
-
15389
- return false;
15390
- }
15391
-
15392
- /**
15393
- * Check if it's an AJAX call targeted for current request.
15394
- *
15395
- * @author Vova Feldman (@svovaf)
15396
- * @since 1.2.0
15397
- *
15398
- * @param array|string $actions Collection of AJAX actions.
15399
- * @param number|null $module_id
15400
- *
15401
- * @return bool
15402
- */
15403
- static function is_ajax_action_static( $actions, $module_id = null ) {
15404
- // Verify it's an ajax call.
15405
- if ( ! self::is_ajax() ) {
15406
- return false;
15407
- }
15408
-
15409
-
15410
- if ( ! empty( $module_id ) ) {
15411
- // Verify the call is relevant for the plugin.
15412
- if ( $module_id != fs_request_get( 'module_id' ) ) {
15413
- return false;
15414
- }
15415
- }
15416
-
15417
- // Verify it's one of the specified actions.
15418
- if ( is_string( $actions ) ) {
15419
- $actions = explode( ',', $actions );
15420
- }
15421
-
15422
- if ( is_array( $actions ) && 0 < count( $actions ) ) {
15423
- $ajax_action = fs_request_get( 'action' );
15424
-
15425
- foreach ( $actions as $action ) {
15426
- if ( $ajax_action === self::get_ajax_action_static( $action, $module_id ) ) {
15427
- return true;
15428
- }
15429
- }
15430
- }
15431
-
15432
- return false;
15433
- }
15434
-
15435
- /**
15436
- * @author Vova Feldman (@svovaf)
15437
- * @since 1.1.7
15438
- *
15439
- * @return bool
15440
- */
15441
- static function is_cron() {
15442
- return ( defined( 'DOING_CRON' ) && DOING_CRON );
15443
- }
15444
-
15445
- /**
15446
- * @author Leo Fajardo (@leorw)
15447
- * @since 2.5.0
15448
- *
15449
- * @return bool
15450
- */
15451
- static function is_admin_post() {
15452
- return ( 'admin-post.php' === self::get_current_page() );
15453
- }
15454
-
15455
- /**
15456
- * Check if a real user is visiting the admin dashboard.
15457
- *
15458
- * @author Vova Feldman (@svovaf)
15459
- * @since 1.1.7
15460
- *
15461
- * @return bool
15462
- */
15463
- function is_user_in_admin() {
15464
- return (
15465
- is_admin() &&
15466
- ! self::is_ajax() &&
15467
- ! self::is_cron() &&
15468
- ! self::is_admin_post()
15469
- );
15470
- }
15471
-
15472
- /**
15473
- * Check if a real user is in the customizer view.
15474
- *
15475
- * @author Vova Feldman (@svovaf)
15476
- * @since 1.2.2.7
15477
- *
15478
- * @return bool
15479
- */
15480
- static function is_customizer() {
15481
- return is_customize_preview();
15482
- }
15483
-
15484
- /**
15485
- * Check if running in HTTPS and if site's plan matching the specified plan.
15486
- *
15487
- * @param string $plan
15488
- * @param bool $exact
15489
- *
15490
- * @return bool
15491
- */
15492
- function is_ssl_and_plan( $plan, $exact = false ) {
15493
- return ( $this->is_ssl() && $this->is_plan( $plan, $exact ) );
15494
- }
15495
-
15496
- /**
15497
- * Construct plugin's settings page URL.
15498
- *
15499
- * @author Vova Feldman (@svovaf)
15500
- * @since 1.0.4
15501
- *
15502
- * @param string $page
15503
- * @param array $params
15504
- * @param bool|null $network
15505
- *
15506
- * @return string
15507
- */
15508
- function _get_admin_page_url( $page = '', $params = array(), $network = null ) {
15509
- if ( is_null( $network ) ) {
15510
- $network = (
15511
- $this->_is_network_active &&
15512
- ( fs_is_network_admin() || ! $this->is_delegated_connection() )
15513
- );
15514
- }
15515
-
15516
- if ( 0 < count( $params ) ) {
15517
- foreach ( $params as $k => $v ) {
15518
- $params[ $k ] = urlencode( $v );
15519
- }
15520
- }
15521
-
15522
- $page_param = $this->_menu->get_slug( $page );
15523
-
15524
- if ( empty( $page ) &&
15525
- // Show the opt-in as an overlay for free wp.org themes or themes without any settings page.
15526
- $this->show_opt_in_on_themes_page()
15527
- ) {
15528
- $params[ $this->get_unique_affix() . '_show_optin' ] = 'true';
15529
-
15530
- return add_query_arg(
15531
- $params,
15532
- $this->admin_url( 'themes.php', 'admin', $network )
15533
- );
15534
- }
15535
-
15536
- if ( ! $this->has_settings_menu() ) {
15537
- if ( ! empty( $page ) ) {
15538
- // Module doesn't have a setting page, but since the request is for
15539
- // a specific Freemius page, use the admin.php path.
15540
- return add_query_arg( array_merge( $params, array(
15541
- 'page' => $page_param,
15542
- ) ), $this->admin_url( 'admin.php', 'admin', $network ) );
15543
- } else {
15544
- if ( $this->is_activation_mode() ) {
15545
- /**
15546
- * @author Vova Feldman
15547
- * @since 1.2.1.6
15548
- *
15549
- * If plugin doesn't have a settings page, create one for the opt-in screen.
15550
- */
15551
- return add_query_arg( array_merge( $params, array(
15552
- 'page' => $this->_slug,
15553
- ) ), $this->admin_url( 'admin.php', 'admin', $network ) );
15554
- } else {
15555
- // Plugin without a settings page.
15556
- return add_query_arg(
15557
- $params,
15558
- $this->admin_url( 'plugins.php', 'admin', $network )
15559
- );
15560
- }
15561
- }
15562
- }
15563
-
15564
- // Module has a submenu settings page.
15565
- if ( ! $this->_menu->is_top_level() ) {
15566
- $parent_slug = $this->_menu->get_parent_slug();
15567
- $menu_file = ( false !== strpos( $parent_slug, '.php' ) ) ?
15568
- $parent_slug :
15569
- 'admin.php';
15570
-
15571
- return add_query_arg( array_merge( $params, array(
15572
- 'page' => $page_param,
15573
- ) ), $this->admin_url( $menu_file, 'admin', $network ) );
15574
- }
15575
-
15576
- // Module has a top level CPT settings page.
15577
- if ( $this->_menu->is_cpt() ) {
15578
- if ( empty( $page ) && $this->is_activation_mode() ) {
15579
- return add_query_arg( array_merge( $params, array(
15580
- 'page' => $page_param
15581
- ) ), $this->admin_url( 'admin.php', 'admin', $network ) );
15582
- } else {
15583
- if ( ! empty( $page ) ) {
15584
- $params['page'] = $page_param;
15585
- }
15586
-
15587
- return add_query_arg(
15588
- $params,
15589
- $this->admin_url( $this->_menu->get_raw_slug(), 'admin', $network )
15590
- );
15591
- }
15592
- }
15593
-
15594
- // Module has a custom top level settings page.
15595
- return add_query_arg( array_merge( $params, array(
15596
- 'page' => $page_param,
15597
- ) ), $this->admin_url( 'admin.php', 'admin', $network ) );
15598
- }
15599
-
15600
- #--------------------------------------------------------------------------------
15601
- #region Multisite
15602
- #--------------------------------------------------------------------------------
15603
-
15604
- /**
15605
- * @author Leo Fajardo (@leorw)
15606
- * @since 2.0.0
15607
- *
15608
- * @return bool
15609
- */
15610
- function is_network_active() {
15611
- return $this->_is_network_active;
15612
- }
15613
-
15614
- /**
15615
- * Delegate activation for the given sites in the network (or all sites if `null`) to site admins.
15616
- *
15617
- * @author Leo Fajardo (@leorw)
15618
- * @since 2.0.0
15619
- *
15620
- * @param array|null $sites
15621
- */
15622
- private function delegate_connection( $sites = null ) {
15623
- $this->_logger->entrance();
15624
-
15625
- $this->_admin_notices->remove_sticky( 'connect_account' );
15626
-
15627
- if ( is_null( $sites ) ) {
15628
- // All sites delegation.
15629
- $this->_storage->store( 'is_delegated_connection', true, true, true );
15630
- } else {
15631
- // Specified sites delegation.
15632
- foreach ( $sites as $site ) {
15633
- $this->delegate_site_connection( $site['blog_id'] );
15634
- }
15635
- }
15636
-
15637
- $this->network_upgrade_mode_completed();
15638
- }
15639
-
15640
- /**
15641
- * Delegate specific network site conncetion to the site admin.
15642
- *
15643
- * @author Vova Feldman (@svovaf)
15644
- * @since 2.0.0
15645
- *
15646
- * @param int $blog_id
15647
- */
15648
- private function delegate_site_connection( $blog_id ) {
15649
- $this->_storage->store( 'is_delegated_connection', true, $blog_id, true );
15650
- }
15651
-
15652
- /**
15653
- * Check if super-admin delegated the connection of ALL sites to the site admins.
15654
- *
15655
- * @author Vova Feldman (@svovaf)
15656
- * @since 2.0.0
15657
- *
15658
- * @return bool
15659
- */
15660
- function is_network_delegated_connection() {
15661
- if ( ! $this->_is_network_active ) {
15662
- return false;
15663
- }
15664
-
15665
- return $this->_storage->get( 'is_delegated_connection', false, true );
15666
- }
15667
-
15668
- /**
15669
- * @author Leo Fajardo (@leorw)
15670
- * @since 2.0.0
15671
- *
15672
- * @param int $blog_id
15673
- *
15674
- * @return bool
15675
- */
15676
- function is_site_delegated_connection( $blog_id = 0 ) {
15677
- if ( ! $this->_is_network_active ) {
15678
- return false;
15679
- }
15680
-
15681
- if ( 0 == $blog_id ) {
15682
- $blog_id = get_current_blog_id();
15683
- }
15684
-
15685
- return $this->_storage->get( 'is_delegated_connection', false, $blog_id );
15686
- }
15687
-
15688
- /**
15689
- * Check if delegated the connection. When running within the the network admin,
15690
- * and haven't specified the blog ID, checks if network level delegated. If running
15691
- * within a site admin or specified a blog ID, check if delegated the connection for
15692
- * the current context site.
15693
- *
15694
- * If executed outside the the admin, check if delegated the connection
15695
- * for the current context site OR the whole network.
15696
- *
15697
- * @author Vova Feldman (@svovaf)
15698
- * @since 2.0.0
15699
- *
15700
- * @param int $blog_id If set, checks if network delegated or blog specific delegated.
15701
- *
15702
- * @return bool
15703
- */
15704
- function is_delegated_connection( $blog_id = 0 ) {
15705
- if ( ! $this->_is_network_active ) {
15706
- return false;
15707
- }
15708
-
15709
- if ( fs_is_network_admin() && 0 == $blog_id ) {
15710
- return $this->is_network_delegated_connection();
15711
- }
15712
-
15713
- return (
15714
- $this->is_network_delegated_connection() ||
15715
- $this->is_site_delegated_connection( $blog_id )
15716
- );
15717
- }
15718
-
15719
- /**
15720
- * Check if the current module is active for the site.
15721
- *
15722
- * @author Vova Feldman (@svovaf)
15723
- * @since 2.0.0
15724
- *
15725
- * @param int $blog_id
15726
- *
15727
- * @return bool
15728
- */
15729
- function is_active_for_site( $blog_id ) {
15730
- if ( ! is_multisite() ) {
15731
- // Not a multisite and this code is executed, means that the plugin is active.
15732
- return true;
15733
- }
15734
-
15735
- if ( $this->is_theme() ) {
15736
- // All themes are site level activated.
15737
- return true;
15738
- }
15739
-
15740
- if ( $this->_is_network_active ) {
15741
- // Plugin was network activated so it's active.
15742
- return true;
15743
- }
15744
-
15745
- return in_array( $this->_plugin_basename, (array) get_blog_option( $blog_id, 'active_plugins', array() ) );
15746
- }
15747
-
15748
- /**
15749
- * @todo Implement pagination when accessing the subsites collection.
15750
- *
15751
- * @author Leo Fajardo (@leorw)
15752
- * @since 2.0.0
15753
- *
15754
- * @param int $limit Default to 1,000
15755
- * @param int $offset Default to 0
15756
- *
15757
- * @return array Active & public sites collection.
15758
- */
15759
- static function get_sites( $limit = 1000, $offset = 0 ) {
15760
- if ( ! is_multisite() ) {
15761
- return array();
15762
- }
15763
-
15764
- /**
15765
- * For consistency with get_blog_list() which only return active public sites.
15766
- *
15767
- * @author Vova Feldman (@svovaf)
15768
- */
15769
- $args = array(
15770
- /**
15771
- * Commented out in order to handle the migration of site options whether the site is public or not.
15772
- *
15773
- * @author Leo Fajardo (@leorw)
15774
- * @since 2.2.1
15775
- */
15776
- // 'public' => 1,
15777
- 'archived' => 0,
15778
- 'mature' => 0,
15779
- 'spam' => 0,
15780
- 'deleted' => 0,
15781
- 'number' => $limit,
15782
- 'offset' => $offset,
15783
- );
15784
-
15785
- if ( function_exists( 'get_sites' ) ) {
15786
- // For WP 4.6 and above.
15787
- return get_sites( $args );
15788
- } else if ( function_exists( 'wp_' . 'get_sites' ) ) {
15789
- // For WP 3.7 to WP 4.5.
15790
- /**
15791
- * This is a hack suggested previously proposed by the TRT. Our SDK is compliant with older WP versions and we'd like to keep it that way.
15792
- *
15793
- * @todo Remove this hack once this false-positive error is removed from the Theme Sniffer.
15794
- *
15795
- * @since 2.3.3
15796
- * @author Vova Feldman (@svovaf)
15797
- */
15798
- $fn = 'wp_' . 'get_sites';
15799
- return $fn( $args );
15800
- } else {
15801
- // For WP 3.6 and below.
15802
- return get_blog_list( 0, 'all' );
15803
- }
15804
- }
15805
-
15806
- /**
15807
- * Checks if a given blog is active.
15808
- *
15809
- * @author Vova Feldman (@svovaf)
15810
- * @since 2.0.0
15811
- *
15812
- * @param $blog_id
15813
- *
15814
- * @return bool
15815
- */
15816
- private static function is_site_active( $blog_id ) {
15817
- global $wpdb;
15818
-
15819
- $blog_info = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->blogs} WHERE blog_id = %d", $blog_id ) );
15820
-
15821
- if ( ! is_object( $blog_info ) ) {
15822
- return false;
15823
- }
15824
-
15825
- return (
15826
- true == $blog_info->public &&
15827
- false == $blog_info->archived &&
15828
- false == $blog_info->mature &&
15829
- false == $blog_info->spam &&
15830
- false == $blog_info->deleted
15831
- );
15832
- }
15833
-
15834
- /**
15835
- * Get a mapping between the site addresses to their blog IDs.
15836
- *
15837
- * @author Vova Feldman (@svovaf)
15838
- * @since 2.0.0
15839
- *
15840
- * @return array {
15841
- * @key string Site address without protocol with a trailing slash.
15842
- * @value int Site's blog ID.
15843
- * }
15844
- */
15845
- private function get_address_to_blog_map() {
15846
- $sites = self::get_sites();
15847
-
15848
- // Map site addresses to their blog IDs.
15849
- $address_to_blog_map = array();
15850
- foreach ( $sites as $site ) {
15851
- $blog_id = self::get_site_blog_id( $site );
15852
- $address = trailingslashit( fs_strip_url_protocol( self::get_site_url( $blog_id ) ) );
15853
- $address_to_blog_map[ $address ] = $blog_id;
15854
- }
15855
-
15856
- return $address_to_blog_map;
15857
- }
15858
-
15859
- /**
15860
- * Get a mapping between the site addresses to their blog IDs.
15861
- *
15862
- * @author Vova Feldman (@svovaf)
15863
- * @since 2.0.0
15864
- *
15865
- * @return array {
15866
- * @key int Site's blog ID.
15867
- * @value FS_Site Associated install.
15868
- * }
15869
- */
15870
- function get_blog_install_map() {
15871
- $sites = self::get_sites();
15872
-
15873
- // Map site blog ID to its install.
15874
- $install_map = array();
15875
-
15876
- foreach ( $sites as $site ) {
15877
- $blog_id = self::get_site_blog_id( $site );
15878
- $install = $this->get_install_by_blog_id( $blog_id );
15879
-
15880
- if ( is_object( $install ) ) {
15881
- $install_map[ $blog_id ] = $install;
15882
- }
15883
- }
15884
-
15885
- return $install_map;
15886
- }
15887
-
15888
- /**
15889
- * Gets a map of module IDs that the given user has opted-in to.
15890
- *
15891
- * @author Leo Fajardo (@leorw)
15892
- * @since 2.1.0
15893
- *
15894
- * @param number $fs_user_id
15895
- *
15896
- * @return array {
15897
- * @key number $plugin_id
15898
- * @value bool Always true.
15899
- * }
15900
- */
15901
- private static function get_user_opted_in_module_ids_map( $fs_user_id ) {
15902
- self::$_static_logger->entrance();
15903
-
15904
- if ( ! is_multisite() ) {
15905
- $installs = array_merge(
15906
- self::get_all_sites( WP_FS__MODULE_TYPE_PLUGIN ),
15907
- self::get_all_sites( WP_FS__MODULE_TYPE_THEME )
15908
- );
15909
- } else {
15910
- $sites = self::get_sites();
15911
-
15912
- $installs = array();
15913
- foreach ( $sites as $site ) {
15914
- $blog_id = self::get_site_blog_id( $site );
15915
-
15916
- $installs = array_merge(
15917
- $installs,
15918
- self::get_all_sites( WP_FS__MODULE_TYPE_PLUGIN, $blog_id ),
15919
- self::get_all_sites( WP_FS__MODULE_TYPE_THEME, $blog_id )
15920
- );
15921
- }
15922
- }
15923
-
15924
- $module_ids_map = array();
15925
- foreach ( $installs as $install ) {
15926
- if ( is_object( $install ) &&
15927
- FS_Site::is_valid_id( $install->id ) &&
15928
- FS_User::is_valid_id( $install->user_id ) &&
15929
- ( $install->user_id == $fs_user_id )
15930
- ) {
15931
- $module_ids_map[ $install->plugin_id ] = true;
15932
- }
15933
- }
15934
-
15935
- return $module_ids_map;
15936
- }
15937
-
15938
- /**
15939
- * @author Leo Fajardo (@leorw)
15940
- *
15941
- * @return null|array {
15942
- * 'install' => FS_Site Module's install,
15943
- * 'blog_id' => string The associated blog ID.
15944
- * }
15945
- */
15946
- function find_first_install() {
15947
- $sites = self::get_sites();
15948
-
15949
- foreach ( $sites as $site ) {
15950
- $blog_id = self::get_site_blog_id( $site );
15951
- $install = $this->get_install_by_blog_id( $blog_id );
15952
-
15953
- if ( is_object( $install ) ) {
15954
- return array(
15955
- 'install' => $install,
15956
- 'blog_id' => $blog_id
15957
- );
15958
- }
15959
- }
15960
-
15961
- return null;
15962
- }
15963
-
15964
- /**
15965
- * Switches the Freemius site level context to a specified blog.
15966
- *
15967
- * @author Vova Feldman (@svovaf)
15968
- * @since 2.0.0
15969
- *
15970
- * @param int $blog_id
15971
- * @param FS_Site $install
15972
- * @param bool $flush
15973
- *
15974
- * @return bool Since 2.3.1 returns if a switch was made.
15975
- */
15976
- function switch_to_blog( $blog_id, FS_Site $install = null, $flush = false ) {
15977
- if ( ! is_numeric( $blog_id ) ) {
15978
- return false;
15979
- }
15980
-
15981
- if ( ! $flush && $blog_id == $this->_context_is_network_or_blog_id ) {
15982
- return false;
15983
- }
15984
-
15985
- switch_to_blog( $blog_id );
15986
- $this->_context_is_network_or_blog_id = $blog_id;
15987
-
15988
- self::$_accounts->set_site_blog_context( $blog_id );
15989
- $this->_storage->set_site_blog_context( $blog_id );
15990
- $this->_storage->set_network_active( $this->_is_network_active, $this->is_delegated_connection( $blog_id ) );
15991
-
15992
- $this->_site = is_object( $install ) ?
15993
- $install :
15994
- $this->get_install_by_blog_id( $blog_id );
15995
-
15996
- $this->_user = false;
15997
- $this->_licenses = false;
15998
- $this->_license = null;
15999
- $this->is_whitelabeled = null;
16000
-
16001
- if ( is_object( $this->_site ) ) {
16002
- // Try to fetch user from install.
16003
- $this->_user = self::_get_user_by_id( $this->_site->user_id );
16004
-
16005
- if ( ! is_object( $this->_user ) &&
16006
- FS_User::is_valid_id( $this->_storage->prev_user_id )
16007
- ) {
16008
- // Try to fetch previously saved user.
16009
- $this->_user = self::_get_user_by_id( $this->_storage->prev_user_id );
16010
-
16011
- if ( ! is_object( $this->_user ) ) {
16012
- // Fallback to network's user.
16013
- $this->_user = $this->get_network_user();
16014
- }
16015
- }
16016
-
16017
- $all_plugin_licenses = self::get_all_licenses( $this->_module_id );
16018
-
16019
- if ( ! empty( $all_plugin_licenses ) ) {
16020
- if ( ! FS_Plugin_License::is_valid_id( $this->_site->license_id ) ) {
16021
- $this->_license = null;
16022
- } else {
16023
- $license_found = false;
16024
- foreach ( $all_plugin_licenses as $license ) {
16025
- if ( $license->id == $this->_site->license_id ) {
16026
- // License found.
16027
- $this->_license = $license;
16028
- $license_found = true;
16029
- break;
16030
- }
16031
- }
16032
-
16033
- if ( $license_found ) {
16034
- $this->link_license_2_user( $this->_license->id, $this->_user->id );
16035
- }
16036
- }
16037
-
16038
- $this->_licenses = $this->get_user_licenses( $this->_user->id );
16039
- }
16040
- }
16041
-
16042
- unset( $this->_site_api );
16043
- unset( $this->_user_api );
16044
-
16045
- return true;
16046
- }
16047
-
16048
- /**
16049
- * Restore the blog context to the blog that originally loaded the module.
16050
- *
16051
- * @author Vova Feldman (@svovaf)
16052
- * @since 2.0.0
16053
- */
16054
- function restore_current_blog() {
16055
- $this->switch_to_blog( $this->_blog_id );
16056
- }
16057
-
16058
- /**
16059
- * @author Vova Feldman (@svovaf)
16060
- * @since 2.0.0
16061
- *
16062
- * @param array|WP_Site $site
16063
- *
16064
- * @return int
16065
- */
16066
- static function get_site_blog_id( &$site ) {
16067
- return ( $site instanceof WP_Site ) ?
16068
- $site->blog_id :
16069
- ( is_object( $site ) && isset( $site->userblog_id ) ?
16070
- $site->userblog_id :
16071
- $site['blog_id'] );
16072
- }
16073
-
16074
- /**
16075
- * @author Leo Fajardo (@leorw)
16076
- * @since 2.0.0
16077
- *
16078
- * @param array|WP_Site|null $site
16079
- *
16080
- * @return array
16081
- */
16082
- function get_site_info( $site = null ) {
16083
- $this->_logger->entrance();
16084
-
16085
- $switched = false;
16086
-
16087
- if ( is_null( $site ) ) {
16088
- $url = self::get_site_url();
16089
- $name = get_bloginfo( 'name' );
16090
- $blog_id = null;
16091
- } else {
16092
- $blog_id = self::get_site_blog_id( $site );
16093
-
16094
- if ( get_current_blog_id() != $blog_id ) {
16095
- switch_to_blog( $blog_id );
16096
- $switched = true;
16097
- }
16098
-
16099
- if ( $site instanceof WP_Site ) {
16100
- $url = $site->siteurl;
16101
- $name = $site->blogname;
16102
- } else {
16103
- $url = self::get_site_url( $blog_id );
16104
- $name = get_bloginfo( 'name' );
16105
- }
16106
- }
16107
-
16108
- $info = array(
16109
- 'uid' => $this->get_anonymous_id( $blog_id ),
16110
- 'url' => $url,
16111
- 'title' => $name,
16112
- 'language' => get_bloginfo( 'language' ),
16113
- 'charset' => get_bloginfo( 'charset' ),
16114
- );
16115
-
16116
- if ( is_numeric( $blog_id ) ) {
16117
- $info['blog_id'] = $blog_id;
16118
- }
16119
-
16120
- if ( $switched ) {
16121
- restore_current_blog();
16122
- }
16123
-
16124
- return $info;
16125
- }
16126
-
16127
- /**
16128
- * Load the module's install based on the blog ID.
16129
- *
16130
- * @author Vova Feldman (@svovaf)
16131
- * @since 2.0.0
16132
- *
16133
- * @param int|null $blog_id
16134
- *
16135
- * @return FS_Site
16136
- */
16137
- function get_install_by_blog_id( $blog_id = null ) {
16138
- $installs = self::get_all_sites( $this->_module_type, $blog_id );
16139
- $install = isset( $installs[ $this->_slug ] ) ? $installs[ $this->_slug ] : null;
16140
-
16141
- if ( is_object( $install ) &&
16142
- is_numeric( $install->id ) &&
16143
- is_numeric( $install->user_id ) &&
16144
- FS_Plugin_Plan::is_valid_id( $install->plan_id )
16145
- ) {
16146
- // Load site.
16147
- $install = clone $install;
16148
- }
16149
-
16150
- return $install;
16151
- }
16152
-
16153
- /**
16154
- * Check if module is installed on a specified site.
16155
- *
16156
- * @author Vova Feldman (@svovaf)
16157
- * @since 2.0.0
16158
- *
16159
- * @param int|null $blog_id
16160
- *
16161
- * @return bool
16162
- */
16163
- function is_installed_on_site( $blog_id = null ) {
16164
- $installs = self::get_all_sites( $this->_module_type, $blog_id );
16165
- $install = isset( $installs[ $this->_slug ] ) ? $installs[ $this->_slug ] : null;
16166
-
16167
- return (
16168
- is_object( $install ) &&
16169
- is_numeric( $install->id ) &&
16170
- is_numeric( $install->user_id ) &&
16171
- FS_Plugin_Plan::is_valid_id( $install->plan_id )
16172
- );
16173
- }
16174
-
16175
- /**
16176
- * Check if super-admin connected at least one site via the network opt-in.
16177
- *
16178
- * @author Vova Feldman (@svovaf)
16179
- * @since 2.0.0
16180
- *
16181
- * @return bool
16182
- */
16183
- function is_network_registered() {
16184
- if ( ! $this->_is_network_active ) {
16185
- return false;
16186
- }
16187
-
16188
- return FS_User::is_valid_id( $this->_storage->network_user_id );
16189
- }
16190
-
16191
- /**
16192
- * Returns the main user associated with the network.
16193
- *
16194
- * @author Vova Feldman (@svovaf)
16195
- * @since 2.0.0
16196
- *
16197
- * @return FS_User
16198
- */
16199
- function get_network_user() {
16200
- if ( ! $this->_is_network_active ) {
16201
- return null;
16202
- }
16203
-
16204
- return FS_User::is_valid_id( $this->_storage->network_user_id ) ?
16205
- self::_get_user_by_id( $this->_storage->network_user_id ) :
16206
- null;
16207
- }
16208
-
16209
- /**
16210
- * Returns the current context user or the network's main user.
16211
- *
16212
- * @author Vova Feldman (@svovaf)
16213
- * @since 2.0.0
16214
- *
16215
- * @return FS_User
16216
- */
16217
- function get_current_or_network_user() {
16218
- return ( $this->_user instanceof FS_User ) ?
16219
- $this->_user :
16220
- $this->get_network_user();
16221
- }
16222
-
16223
- /**
16224
- * Returns the main install associated with the network.
16225
- *
16226
- * @author Vova Feldman (@svovaf)
16227
- * @since 2.0.0
16228
- *
16229
- * @return FS_Site
16230
- */
16231
- function get_network_install() {
16232
- if ( ! $this->_is_network_active ) {
16233
- return null;
16234
- }
16235
-
16236
- return FS_Site::is_valid_id( $this->_storage->network_install_blog_id ) ?
16237
- $this->get_install_by_blog_id( $this->_storage->network_install_blog_id ) :
16238
- null;
16239
- }
16240
-
16241
- /**
16242
- * Returns the blog ID that is associated with the main install.
16243
- *
16244
- * @author Leo Fajardo (@leorw)
16245
- * @since 2.0.0
16246
- *
16247
- * @return int|null
16248
- */
16249
- function get_network_install_blog_id() {
16250
- if ( ! $this->_is_network_active ) {
16251
- return null;
16252
- }
16253
-
16254
- return FS_Site::is_valid_id( $this->_storage->network_install_blog_id ) ?
16255
- $this->_storage->network_install_blog_id :
16256
- null;
16257
- }
16258
-
16259
- /**
16260
- * Returns the current context install or the network's main install.
16261
- *
16262
- * @author Vova Feldman (@svovaf)
16263
- * @since 2.0.0
16264
- *
16265
- * @return FS_Site
16266
- */
16267
- function get_current_or_network_install() {
16268
- return ( $this->_site instanceof FS_Site ) ?
16269
- $this->_site :
16270
- $this->get_network_install();
16271
- }
16272
-
16273
- /**
16274
- * Check if executing a site level action from the network level admin.
16275
- *
16276
- * @author Vova Feldman (@svovaf)
16277
- * @since 2.0.0
16278
- *
16279
- * @return false|int If yes, return the requested blog ID.
16280
- */
16281
- private function is_network_level_site_specific_action() {
16282
- if ( ! $this->_is_network_active ) {
16283
- return false;
16284
- }
16285
-
16286
- if ( ! fs_is_network_admin() ) {
16287
- return false;
16288
- }
16289
-
16290
- $blog_id = fs_request_get( 'blog_id', '' );
16291
-
16292
- return is_numeric( $blog_id ) ? $blog_id : false;
16293
- }
16294
-
16295
- /**
16296
- * Check if executing an action from the network level admin.
16297
- *
16298
- * @author Vova Feldman (@svovaf)
16299
- * @since 2.0.0
16300
- *
16301
- * @return bool
16302
- */
16303
- private function is_network_level_action() {
16304
- return ( $this->_is_network_active && fs_is_network_admin() );
16305
- }
16306
-
16307
- /**
16308
- * Needs to be executed after site deactivation, archive, deletion, or flag as spam.
16309
- * The logic updates the network level user and blog, and reschedule the crons if the cron executing site matching the site that is no longer publicly active.
16310
- *
16311
- * @author Vova Feldman (@svovaf)
16312
- * @since 2.0.0
16313
- *
16314
- * @param int $context_blog_id
16315
- */
16316
- private function update_multisite_data_after_site_deactivation( $context_blog_id = 0 ) {
16317
- $this->_logger->entrance();
16318
-
16319
- if ( $this->_is_network_active ) {
16320
- if ( $context_blog_id == $this->_storage->network_install_blog_id ) {
16321
- $installs_map = $this->get_blog_install_map();
16322
-
16323
- foreach ( $installs_map as $blog_id => $install ) {
16324
- /**
16325
- * @var FS_Site $install
16326
- */
16327
- if ( $context_blog_id == $blog_id ) {
16328
- continue;
16329
- }
16330
-
16331
- if ( $install->user_id != $this->_storage->network_user_id ) {
16332
- continue;
16333
- }
16334
-
16335
- // Switch reference to a blog that is opted-in and belong to the same super-admin.
16336
- $this->_storage->network_install_blog_id = $blog_id;
16337
- break;
16338
- }
16339
- }
16340
- }
16341
-
16342
- if ( ! $this->is_registered() ) {
16343
- return;
16344
- }
16345
-
16346
- if ( $this->is_sync_cron_scheduled() &&
16347
- $context_blog_id == $this->get_sync_cron_blog_id()
16348
- ) {
16349
- $this->schedule_sync_cron( WP_FS__SCRIPT_START_TIME, true, $context_blog_id );
16350
- }
16351
-
16352
- if ( $this->is_install_sync_scheduled() &&
16353
- $context_blog_id == $this->get_install_sync_cron_blog_id()
16354
- ) {
16355
- $this->schedule_install_sync( $context_blog_id );
16356
- }
16357
- }
16358
-
16359
- /**
16360
- * Executed after site deactivation, archive, or flag as spam.
16361
- *
16362
- * @author Vova Feldman (@svovaf)
16363
- * @since 2.0.0
16364
- *
16365
- * @param int $context_blog_id
16366
- */
16367
- public function _after_site_deactivated_callback( $context_blog_id = 0 ) {
16368
- $this->_logger->entrance();
16369
-
16370
- $install = $this->get_install_by_blog_id( $context_blog_id );
16371
-
16372
- if ( ! is_object( $install ) ) {
16373
- // Site not connected.
16374
- return;
16375
- }
16376
-
16377
- $this->update_multisite_data_after_site_deactivation( $context_blog_id );
16378
-
16379
- if ( ! $this->is_registered() ) {
16380
- return;
16381
- }
16382
-
16383
- $current_blog_id = get_current_blog_id();
16384
-
16385
- $this->switch_to_blog( $context_blog_id );
16386
-
16387
- // Send deactivation event.
16388
- $this->sync_install( array(
16389
- 'is_active' => false,
16390
- ) );
16391
-
16392
- $this->switch_to_blog( $current_blog_id );
16393
- }
16394
-
16395
- /**
16396
- * Executed after site deletion.
16397
- *
16398
- * @author Vova Feldman (@svovaf)
16399
- * @since 2.0.0
16400
- *
16401
- * @param int $context_blog_id
16402
- * @param bool $drop True if site's database tables should be dropped. Default is false.
16403
- */
16404
- public function _after_site_deleted_callback( $context_blog_id = 0, $drop = false ) {
16405
- $this->_logger->entrance();
16406
-
16407
- $install = $this->get_install_by_blog_id( $context_blog_id );
16408
-
16409
- if ( ! is_object( $install ) ) {
16410
- // Site not connected.
16411
- return;
16412
- }
16413
-
16414
- $this->update_multisite_data_after_site_deactivation( $context_blog_id );
16415
-
16416
- if ( ! $this->is_registered() ) {
16417
- return;
16418
- }
16419
-
16420
- $current_blog_id = get_current_blog_id();
16421
-
16422
- $this->switch_to_blog( $context_blog_id );
16423
-
16424
- if ( $drop ) {
16425
- // Delete install if dropping site DB.
16426
- $this->delete_account_event();
16427
- } else {
16428
- // Send deactivation event.
16429
- $this->sync_install( array(
16430
- 'is_active' => false,
16431
- ) );
16432
- }
16433
-
16434
- $this->switch_to_blog( $current_blog_id );
16435
- }
16436
-
16437
- /**
16438
- * Executed after site deletion, called from wp_delete_site
16439
- *
16440
- * @author Dario Curvino (@dudo)
16441
- * @since 2.5.0
16442
- *
16443
- * @param WP_Site $old_site
16444
- */
16445
- public function _after_wpsite_deleted_callback( WP_Site $old_site ) {
16446
- $this->_logger->entrance();
16447
-
16448
- $this->_after_site_deleted_callback( $old_site->blog_id, true );
16449
- }
16450
-
16451
- /**
16452
- * Executed after site re-activation.
16453
- *
16454
- * @author Vova Feldman (@svovaf)
16455
- * @since 2.0.0
16456
- *
16457
- * @param int $context_blog_id
16458
- */
16459
- public function _after_site_reactivated_callback( $context_blog_id = 0 ) {
16460
- $this->_logger->entrance();
16461
-
16462
- $install = $this->get_install_by_blog_id( $context_blog_id );
16463
-
16464
- if ( ! is_object( $install ) ) {
16465
- // Site not connected.
16466
- return;
16467
- }
16468
-
16469
- if ( ! self::is_site_active( $context_blog_id ) ) {
16470
- // Site not yet active (can be in spam mode, archived, deleted...).
16471
- return;
16472
- }
16473
-
16474
- $current_blog_id = get_current_blog_id();
16475
-
16476
- $this->switch_to_blog( $context_blog_id );
16477
-
16478
- // Send re-activation event.
16479
- $this->sync_install( array(
16480
- 'is_active' => true,
16481
- ) );
16482
-
16483
- $this->switch_to_blog( $current_blog_id );
16484
- }
16485
-
16486
- #endregion Multisite
16487
-
16488
- /**
16489
- * @author Leo Fajardo (@leorw)
16490
- *
16491
- * @param string $path
16492
- * @param string $scheme
16493
- * @param bool $network
16494
- *
16495
- * @return string
16496
- */
16497
- private function admin_url( $path = '', $scheme = 'admin', $network = true ) {
16498
- return ( $this->_is_network_active && $network ) ?
16499
- network_admin_url( $path, $scheme ) :
16500
- admin_url( $path, $scheme );
16501
- }
16502
-
16503
- /**
16504
- * Check if currently in a specified admin page.
16505
- *
16506
- * @author Vova Feldman (@svovaf)
16507
- * @since 1.2.2.7
16508
- *
16509
- * @param string $page
16510
- *
16511
- * @return bool
16512
- */
16513
- function is_admin_page( $page ) {
16514
- return ( $this->_menu->get_slug( $page ) === fs_request_get( 'page', '', 'get' ) );
16515
- }
16516
-
16517
- /**
16518
- * Check if currently in the product's main admin page.
16519
- *
16520
- * @author Vova Feldman (@svovaf)
16521
- * @since 2.3.1
16522
- *
16523
- * @return bool
16524
- */
16525
- function is_main_admin_page() {
16526
- return $this->is_admin_page( '' );
16527
- }
16528
-
16529
- /**
16530
- * Get module's main admin setting page URL.
16531
- *
16532
- * @author Vova Feldman (@svovaf)
16533
- * @since 1.2.2.7
16534
- *
16535
- * @return string
16536
- */
16537
- function main_menu_url() {
16538
- return $this->_menu->main_menu_url();
16539
- }
16540
-
16541
- /**
16542
- * Check if currently on the theme's setting page or
16543
- * on any of the Freemius added pages (via tabs).
16544
- *
16545
- * @author Vova Feldman (@svovaf)
16546
- * @since 1.2.2.7
16547
- *
16548
- * @return bool
16549
- *
16550
- * @deprecated Please use is_product_settings_page() instead;
16551
- */
16552
- function is_theme_settings_page() {
16553
- return $this->is_product_settings_page();
16554
- }
16555
-
16556
- /**
16557
- * Check if currently on the product's main setting page or on any of the Freemius added pages (via tabs).
16558
- *
16559
- * @author Vova Feldman (@svovaf)
16560
- * @since 1.2.2.7
16561
- *
16562
- * @return bool
16563
- */
16564
- function is_product_settings_page() {
16565
- return fs_starts_with(
16566
- fs_request_get( 'page', '', 'get' ),
16567
- $this->_menu->get_slug()
16568
- );
16569
- }
16570
-
16571
- /**
16572
- * Plugin's account page + sync license URL.
16573
- *
16574
- * @author Vova Feldman (@svovaf)
16575
- * @since 1.1.9.1
16576
- *
16577
- * @param bool|number $plugin_id
16578
- * @param bool $add_action_nonce
16579
- * @param array $params
16580
- *
16581
- * @return string
16582
- */
16583
- function _get_sync_license_url( $plugin_id = false, $add_action_nonce = true, $params = array() ) {
16584
- if ( is_numeric( $plugin_id ) ) {
16585
- $params['plugin_id'] = $plugin_id;
16586
- }
16587
-
16588
- return $this->get_account_url(
16589
- $this->get_unique_affix() . '_sync_license',
16590
- $params,
16591
- $add_action_nonce
16592
- );
16593
- }
16594
-
16595
- /**
16596
- * Plugin's account URL.
16597
- *
16598
- * @author Vova Feldman (@svovaf)
16599
- * @since 1.0.4
16600
- *
16601
- * @param bool|string $action
16602
- * @param array $params
16603
- *
16604
- * @param bool $add_action_nonce
16605
- *
16606
- * @return string
16607
- */
16608
- function get_account_url( $action = false, $params = array(), $add_action_nonce = true ) {
16609
- if ( is_string( $action ) ) {
16610
- $params['fs_action'] = $action;
16611
- }
16612
-
16613
- self::require_pluggable_essentials();
16614
-
16615
- return ( $add_action_nonce && is_string( $action ) ) ?
16616
- fs_nonce_url( $this->_get_admin_page_url( 'account', $params ), $action ) :
16617
- $this->_get_admin_page_url( 'account', $params );
16618
- }
16619
-
16620
- /**
16621
- * @author Vova Feldman (@svovaf)
16622
- * @since 1.2.0
16623
- *
16624
- * @param string $tab
16625
- * @param bool $action
16626
- * @param array $params
16627
- * @param bool $add_action_nonce
16628
- *
16629
- * @return string
16630
- *
16631
- * @uses get_account_url()
16632
- */
16633
- function get_account_tab_url( $tab, $action = false, $params = array(), $add_action_nonce = true ) {
16634
- $params['tab'] = $tab;
16635
-
16636
- return $this->get_account_url( $action, $params, $add_action_nonce );
16637
- }
16638
-
16639
- /**
16640
- * Plugin's account URL.
16641
- *
16642
- * @author Vova Feldman (@svovaf)
16643
- * @since 1.0.4
16644
- *
16645
- * @param bool|string $topic
16646
- * @param bool|string $message
16647
- *
16648
- * @return string
16649
- */
16650
- function contact_url( $topic = false, $message = false ) {
16651
- $params = array();
16652
- if ( is_string( $topic ) ) {
16653
- $params['topic'] = $topic;
16654
- }
16655
- if ( is_string( $message ) ) {
16656
- $params['message'] = $message;
16657
- }
16658
-
16659
- if ( $this->is_addon() ) {
16660
- $params['addon_id'] = $this->get_id();
16661
-
16662
- return $this->get_parent_instance()->_get_admin_page_url( 'contact', $params );
16663
- } else {
16664
- return $this->_get_admin_page_url( 'contact', $params );
16665
- }
16666
- }
16667
-
16668
- /**
16669
- * Add-on direct info URL.
16670
- *
16671
- * @author Vova Feldman (@svovaf)
16672
- * @since 1.1.0
16673
- *
16674
- * @param string $slug
16675
- *
16676
- * @return string
16677
- */
16678
- function addon_url( $slug ) {
16679
- return $this->_get_admin_page_url( 'addons', array(
16680
- 'slug' => $slug
16681
- ) );
16682
- }
16683
-
16684
- /**
16685
- * Add-ons URL.
16686
- *
16687
- * @author Vova Feldman (@svovaf)
16688
- * @since 2.4.5
16689
- *
16690
- * @return string
16691
- */
16692
- function get_addons_url() {
16693
- return $this->_get_admin_page_url( 'addons' );
16694
- }
16695
-
16696
- /* Logger
16697
- ------------------------------------------------------------------------------------------------------------------*/
16698
- /**
16699
- * @param string $id
16700
- * @param bool $prefix_slug
16701
- *
16702
- * @return FS_Logger
16703
- */
16704
- function get_logger( $id = '', $prefix_slug = true ) {
16705
- return FS_Logger::get_logger( ( $prefix_slug ? $this->_slug : '' ) . ( ( ! $prefix_slug || empty( $id ) ) ? '' : '_' ) . $id );
16706
- }
16707
-
16708
- /**
16709
- * Note: This method is used externally so don't delete it.
16710
- *
16711
- * @param $id
16712
- * @param bool $load_options
16713
- * @param bool $prefix_slug
16714
- *
16715
- * @return FS_Option_Manager
16716
- */
16717
- function get_options_manager( $id, $load_options = false, $prefix_slug = true ) {
16718
- return FS_Option_Manager::get_manager( ( $prefix_slug ? $this->_slug : '' ) . ( ( ! $prefix_slug || empty( $id ) ) ? '' : '_' ) . $id, $load_options );
16719
- }
16720
-
16721
- /* Security
16722
- ------------------------------------------------------------------------------------------------------------------*/
16723
- private static function _encrypt( $str ) {
16724
- if ( is_null( $str ) ) {
16725
- return null;
16726
- }
16727
-
16728
- /**
16729
- * The encrypt/decrypt functions are used to protect
16730
- * the user from messing up with some of the sensitive
16731
- * data stored for the module as a JSON in the database.
16732
- *
16733
- * I used the same suggested hack by the theme review team.
16734
- * For more details, look at the function `Base64UrlDecode()`
16735
- * in `./sdk/FreemiusBase.php`.
16736
- *
16737
- * @todo Remove this hack once the base64 error is removed from the Theme Check.
16738
- *
16739
- * @author Vova Feldman (@svovaf)
16740
- * @since 1.2.2
16741
- */
16742
- $fn = 'base64' . '_encode';
16743
-
16744
- return $fn( $str );
16745
- }
16746
-
16747
- static function _decrypt( $str ) {
16748
- if ( is_null( $str ) ) {
16749
- return null;
16750
- }
16751
-
16752
- /**
16753
- * The encrypt/decrypt functions are used to protect
16754
- * the user from messing up with some of the sensitive
16755
- * data stored for the module as a JSON in the database.
16756
- *
16757
- * I used the same suggested hack by the theme review team.
16758
- * For more details, look at the function `Base64UrlDecode()`
16759
- * in `./sdk/FreemiusBase.php`.
16760
- *
16761
- * @todo Remove this hack once the base64 error is removed from the Theme Check.
16762
- *
16763
- * @author Vova Feldman (@svovaf)
16764
- * @since 1.2.2
16765
- */
16766
- $fn = 'base64' . '_decode';
16767
-
16768
- return $fn( $str );
16769
- }
16770
-
16771
- /**
16772
- * @author Vova Feldman (@svovaf)
16773
- * @since 1.0.5
16774
- *
16775
- * @param FS_Entity $entity
16776
- *
16777
- * @return FS_Entity Return an encrypted clone entity.
16778
- */
16779
- private static function _encrypt_entity( FS_Entity $entity ) {
16780
- $clone = clone $entity;
16781
- $props = get_object_vars( $entity );
16782
-
16783
- foreach ( $props as $key => $val ) {
16784
- $clone->{$key} = self::_encrypt( $val );
16785
- }
16786
-
16787
- return $clone;
16788
- }
16789
-
16790
- /**
16791
- * @author Vova Feldman (@svovaf)
16792
- * @since 1.0.5
16793
- *
16794
- * @param FS_Entity $entity
16795
- *
16796
- * @return FS_Entity Return an decrypted clone entity.
16797
- */
16798
- private static function decrypt_entity( FS_Entity $entity ) {
16799
- $clone = clone $entity;
16800
- $props = get_object_vars( $entity );
16801
-
16802
- foreach ( $props as $key => $val ) {
16803
- $clone->{$key} = self::_decrypt( $val );
16804
- }
16805
-
16806
- return $clone;
16807
- }
16808
-
16809
- /**
16810
- * Tries to activate account based on POST params.
16811
- *
16812
- * @author Vova Feldman (@svovaf)
16813
- * @since 1.0.2
16814
- *
16815
- * @deprecated Not in use, outdated.
16816
- */
16817
- function _activate_account() {
16818
- if ( $this->is_registered() ) {
16819
- // Already activated.
16820
- return;
16821
- }
16822
-
16823
- self::_clean_admin_content_section();
16824
-
16825
- if ( fs_request_is_action( 'activate' ) && fs_request_is_post() ) {
16826
- // check_admin_referer( 'activate_' . $this->_plugin->public_key );
16827
-
16828
- // Verify matching plugin details.
16829
- if ( $this->_plugin->id != fs_request_get( 'plugin_id' ) || $this->_slug != fs_request_get( 'plugin_slug' ) ) {
16830
- return;
16831
- }
16832
-
16833
- $user = new FS_User();
16834
- $user->id = fs_request_get( 'user_id' );
16835
- $user->public_key = fs_request_get( 'user_public_key' );
16836
- $user->secret_key = fs_request_get( 'user_secret_key' );
16837
- $user->email = fs_request_get( 'user_email' );
16838
- $user->first = fs_request_get( 'user_first' );
16839
- $user->last = fs_request_get( 'user_last' );
16840
- $user->is_verified = fs_request_get_bool( 'user_is_verified' );
16841
-
16842
- $site = new FS_Site();
16843
- $site->id = fs_request_get( 'install_id' );
16844
- $site->public_key = fs_request_get( 'install_public_key' );
16845
- $site->secret_key = fs_request_get( 'install_secret_key' );
16846
- $site->plan_id = fs_request_get( 'plan_id' );
16847
-
16848
- $plans = array();
16849
- $plans_data = json_decode( urldecode( fs_request_get( 'plans' ) ) );
16850
- foreach ( $plans_data as $p ) {
16851
- $plan = new FS_Plugin_Plan( $p );
16852
- if ( $site->plan_id == $plan->id ) {
16853
- $plan->title = fs_request_get( 'plan_title' );
16854
- $plan->name = fs_request_get( 'plan_name' );
16855
- }
16856
-
16857
- $plans[] = $plan;
16858
- }
16859
-
16860
- $this->_set_account( $user, $site, $plans );
16861
-
16862
- // Reload the page with the keys.
16863
- fs_redirect( $this->_get_admin_page_url() );
16864
- }
16865
- }
16866
-
16867
- /**
16868
- * @author Vova Feldman (@svovaf)
16869
- * @since 1.0.7
16870
- *
16871
- * @param string $email
16872
- *
16873
- * @return FS_User|false
16874
- */
16875
- static function _get_user_by_email( $email ) {
16876
- self::$_static_logger->entrance();
16877
-
16878
- $email = trim( strtolower( $email ) );
16879
-
16880
- $users = self::get_all_users();
16881
-
16882
- if ( is_array( $users ) ) {
16883
- foreach ( $users as $user ) {
16884
- if ( $email === trim( strtolower( $user->email ) ) ) {
16885
- return $user;
16886
- }
16887
- }
16888
- }
16889
-
16890
- return false;
16891
- }
16892
-
16893
- #----------------------------------------------------------------------------------
16894
- #region Account (Loading, Updates & Activation)
16895
- #----------------------------------------------------------------------------------
16896
-
16897
- /***
16898
- * Load account information (user + site).
16899
- *
16900
- * @author Vova Feldman (@svovaf)
16901
- * @since 1.0.1
16902
- */
16903
- private function _load_account() {
16904
- $this->_logger->entrance();
16905
-
16906
- $this->do_action( 'before_account_load' );
16907
-
16908
- $users = self::get_all_users();
16909
- $plans = self::get_all_plans( $this->_module_type );
16910
-
16911
- if ( $this->_logger->is_on() && is_admin() ) {
16912
- $this->_logger->log( 'users = ' . var_export( $users, true ) );
16913
- $this->_logger->log( 'plans = ' . var_export( $plans, true ) );
16914
- }
16915
-
16916
- $site = fs_is_network_admin() ?
16917
- $this->get_network_install() :
16918
- $this->get_install_by_blog_id();
16919
-
16920
- if ( fs_is_network_admin() &&
16921
- $this->is_network_active() &&
16922
- ! is_object( $site ) &&
16923
- FS_Site::is_valid_id( $this->_storage->network_install_blog_id )
16924
- ) {
16925
- $first_install = $this->find_first_install();
16926
-
16927
- if ( is_null( $first_install ) ) {
16928
- unset( $this->_storage->network_install_blog_id );
16929
- } else {
16930
- $site = $first_install['install'];
16931
- $this->_storage->network_install_blog_id = $first_install['blog_id'];
16932
- }
16933
- }
16934
-
16935
- if ( is_object( $site ) &&
16936
- is_numeric( $site->id ) &&
16937
- is_numeric( $site->user_id ) &&
16938
- FS_Plugin_Plan::is_valid_id( $site->plan_id )
16939
- ) {
16940
- // Load site.
16941
- $this->_site = $site;
16942
- }
16943
-
16944
- $user = null;
16945
- if ( fs_is_network_admin() && $this->_is_network_active ) {
16946
- $user = $this->get_network_user();
16947
- }
16948
-
16949
- if ( is_object( $user ) ) {
16950
- $this->_user = clone $user;
16951
- } else if ( $this->_site ) {
16952
- $user = self::_get_user_by_id( $this->_site->user_id );
16953
-
16954
- if ( ! is_object( $user ) && FS_User::is_valid_id( $this->_storage->prev_user_id ) ) {
16955
- /**
16956
- * Try to load the previous owner. This recovery is used for the following use-case:
16957
- * 1. Opt-in
16958
- * 2. Cloning site1 to site2
16959
- * 3. Ownership switch in site1 (same applies for site2)
16960
- * 4. Install data sync on site2
16961
- * 5. Now site2's install is associated with the new owner which does not exists locally.
16962
- */
16963
- $user = self::_get_user_by_id( $this->_storage->prev_user_id );
16964
- }
16965
-
16966
- if ( ! is_object( $user ) ) {
16967
- /**
16968
- * This is a special fault tolerance mechanism to handle a scenario that the user data is missing.
16969
- */
16970
- if (
16971
- ! isset( $this->_storage->user_recovery_from_install_last_attempt_timestamp ) ||
16972
- time() > ( $this->_storage->user_recovery_from_install_last_attempt_timestamp + FS_Clone_Manager::CLONE_RESOLUTION_MAX_EXECUTION_TIME )
16973
- ) {
16974
- $user = $this->sync_user_by_current_install();
16975
- } else {
16976
- return;
16977
- }
16978
-
16979
- if ( is_object( $user ) ) {
16980
- $this->_storage->user_was_recovered_from_install = true;
16981
- } else {
16982
- $this->_storage->user_recovery_from_install_attempts = isset( $this->_storage->user_recovery_from_install_attempts ) ?
16983
- ( $this->_storage->user_recovery_from_install_attempts + 1 ) :
16984
- 1;
16985
-
16986
- if ( $this->_storage->user_recovery_from_install_attempts >= 3 ) {
16987
- $this->delete_current_install( false );
16988
- } else {
16989
- $this->_storage->user_recovery_from_install_last_attempt_timestamp = time();
16990
-
16991
- return;
16992
- }
16993
- }
16994
- }
16995
-
16996
- $this->_user = ( $user instanceof FS_User ) ?
16997
- clone $user :
16998
- null;
16999
- }
17000
-
17001
- if ( is_object( $this->_user ) ) {
17002
- // Load licenses.
17003
- $this->_licenses = $this->get_user_licenses( $this->_user->id );
17004
- }
17005
-
17006
- if ( is_object( $this->_site ) ) {
17007
- // Load plans.
17008
- $this->_plans = isset( $plans[ $this->_slug ] ) ?
17009
- $plans[ $this->_slug ] :
17010
- array();
17011
-
17012
- if ( ! is_array( $this->_plans ) || empty( $this->_plans ) ) {
17013
- $this->_sync_plans();
17014
- } else {
17015
- for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
17016
- if ( $this->_plans[ $i ] instanceof FS_Plugin_Plan ) {
17017
- $this->_plans[ $i ] = self::decrypt_entity( $this->_plans[ $i ] );
17018
- } else {
17019
- unset( $this->_plans[ $i ] );
17020
- }
17021
- }
17022
- }
17023
-
17024
- $this->_license = $this->_get_license_by_id( $this->_site->license_id );
17025
-
17026
- if ( $this->_site->version != $this->get_plugin_version() ) {
17027
- // If stored install version is different than current installed plugin version,
17028
- // then update plugin version event.
17029
- $this->update_plugin_version_event();
17030
- }
17031
- }
17032
-
17033
- if ( true === $this->_storage->require_license_activation &&
17034
- ! fs_request_get_bool( 'require_license', true )
17035
- ) {
17036
- $this->_storage->require_license_activation = false;
17037
- }
17038
-
17039
- if ( $this->is_theme() ) {
17040
- $this->_register_account_hooks();
17041
- }
17042
-
17043
- if (
17044
- $this->is_user_in_admin() &&
17045
- $this->is_clone() &&
17046
- empty( FS_Clone_Manager::instance()->get_clone_identification_timestamp() )
17047
- ) {
17048
- FS_Clone_Manager::instance()->store_clone_identification_timestamp();
17049
- }
17050
- }
17051
-
17052
- /**
17053
- * Special user recovery mechanism.
17054
- *
17055
- * @author Vova Feldman (@svovaf)
17056
- * @since 2.0.0
17057
- *
17058
- * @param number|null $site_user_id
17059
- *
17060
- * @return \FS_User|mixed
17061
- */
17062
- private function sync_user_by_current_install( $site_user_id = null ) {
17063
- $site_user_id = FS_Site::is_valid_id( $site_user_id ) ?
17064
- $site_user_id :
17065
- $this->_site->user_id;
17066
-
17067
- $api = $this->get_api_site_scope();
17068
-
17069
- $uid = $this->get_anonymous_id();
17070
- $request_path = "/users/{$site_user_id}.json?uid={$uid}";
17071
-
17072
- $result = $api->get( $request_path, false, WP_FS__TIME_10_MIN_IN_SEC );
17073
-
17074
- if ( $this->is_api_result_entity( $result ) ) {
17075
- $user = new FS_User( $result );
17076
- $this->_user = $user;
17077
- $this->_store_user();
17078
-
17079
- return $user;
17080
- }
17081
-
17082
- $error_code = FS_Api::get_error_code( $result );
17083
-
17084
- if ( in_array( $error_code, array( 'invalid_unique_id', 'user_cannot_be_recovered' ) ) ) {
17085
- /**
17086
- * Those API errors will continue coming and are not recoverable with the
17087
- * current site's data. Therefore, extend the API call's cached result to 7 days.
17088
- */
17089
- $api->update_cache_expiration( $request_path, WP_FS__TIME_WEEK_IN_SEC );
17090
- }
17091
-
17092
- return $result;
17093
- }
17094
-
17095
- /**
17096
- * @author Vova Feldman (@svovaf)
17097
- * @since 1.0.1
17098
- *
17099
- * @param FS_User $user
17100
- * @param FS_Site $site
17101
- * @param bool|array $plans
17102
- */
17103
- private function _set_account( FS_User $user, FS_Site $site, $plans = false ) {
17104
- $site->user_id = $user->id;
17105
-
17106
- $this->_site = $site;
17107
- $this->_user = $user;
17108
- if ( false !== $plans ) {
17109
- $this->_plans = $plans;
17110
- }
17111
-
17112
- $this->send_install_update();
17113
-
17114
- $this->_store_account();
17115
-
17116
- }
17117
-
17118
- /**
17119
- * Get a sanitized array with the WordPress version, SDK version, and PHP version.
17120
- * Each version is trimmed after the 16th char.
17121
- *
17122
- * @author Vova Feldman (@svovaf)
17123
- * @since 2.2.1
17124
- *
17125
- * @return array
17126
- */
17127
- private function get_versions() {
17128
- $versions = array();
17129
- $versions['platform_version'] = get_bloginfo( 'version' );
17130
- $versions['sdk_version'] = $this->version;
17131
- $versions['programming_language_version'] = phpversion();
17132
-
17133
- foreach ( $versions as $k => $version ) {
17134
- if ( is_string( $versions[ $k ] ) && ! empty( $versions[ $k ] ) ) {
17135
- $versions[ $k ] = substr( $versions[ $k ], 0, 16 );
17136
- }
17137
- }
17138
-
17139
- return $versions;
17140
- }
17141
-
17142
- /**
17143
- * @author Leo Fajardo (@leorw)
17144
- * @since 2.3.0
17145
- *
17146
- * @return bool
17147
- */
17148
- function has_beta_update() {
17149
- return (
17150
- ! empty( $this->_storage->beta_data ) &&
17151
- ( true === $this->_storage->beta_data['is_beta'] ) &&
17152
- version_compare( $this->_storage->beta_data['version'], $this->get_plugin_version(), '>' )
17153
- );
17154
- }
17155
-
17156
- /**
17157
- * @author Leo Fajardo (@leorw)
17158
- * @since 2.3.0
17159
- *
17160
- * @return bool
17161
- */
17162
- function is_beta() {
17163
- return (
17164
- ! empty( $this->_storage->beta_data ) &&
17165
- ( true === $this->_storage->beta_data['is_beta'] ) &&
17166
- ( $this->get_plugin_version() === $this->_storage->beta_data['version'] )
17167
- );
17168
- }
17169
-
17170
- /**
17171
- * @author Vova Feldman (@svovaf)
17172
- * @since 1.1.7.4
17173
- *
17174
- * @param array $override_with
17175
- * @param bool|int|null $network_level_or_blog_id If true, return params for network level opt-in. If integer, get params for specified blog in the network.
17176
- *
17177
- * @return array
17178
- */
17179
- function get_opt_in_params( $override_with = array(), $network_level_or_blog_id = null ) {
17180
- $this->_logger->entrance();
17181
-
17182
- $current_user = self::_get_current_wp_user();
17183
-
17184
- $activation_action = $this->get_unique_affix() . '_activate_new';
17185
- $return_url = $this->is_anonymous() ?
17186
- // If skipped already, then return to the account page.
17187
- $this->get_account_url( $activation_action, array(), false ) :
17188
- // Return to the module's main page.
17189
- $this->get_after_activation_url( 'after_connect_url', array( 'fs_action' => $activation_action ) );
17190
-
17191
- $versions = $this->get_versions();
17192
-
17193
- $params = array_merge( $versions, array(
17194
- 'user_firstname' => $current_user->user_firstname,
17195
- 'user_lastname' => $current_user->user_lastname,
17196
- 'user_nickname' => $current_user->user_nicename,
17197
- 'user_email' => $current_user->user_email,
17198
- 'user_ip' => WP_FS__REMOTE_ADDR,
17199
- 'plugin_slug' => $this->_slug,
17200
- 'plugin_id' => $this->get_id(),
17201
- 'plugin_public_key' => $this->get_public_key(),
17202
- 'plugin_version' => $this->get_plugin_version(),
17203
- 'return_url' => fs_nonce_url( $return_url, $activation_action ),
17204
- 'account_url' => fs_nonce_url( $this->_get_admin_page_url(
17205
- 'account',
17206
- array( 'fs_action' => 'sync_user' )
17207
- ), 'sync_user' ),
17208
- 'is_premium' => $this->is_premium(),
17209
- 'is_active' => true,
17210
- 'is_uninstalled' => false,
17211
- ) );
17212
-
17213
- if ( $this->is_addon() ) {
17214
- $parent_fs = $this->get_parent_instance();
17215
-
17216
- $params['parent_plugin_slug'] = $parent_fs->_slug;
17217
- $params['parent_plugin_id'] = $parent_fs->get_id();
17218
- }
17219
-
17220
- if ( true === $network_level_or_blog_id ) {
17221
- if ( ! isset( $override_with['sites'] ) ) {
17222
- $params['sites'] = $this->get_sites_for_network_level_optin();
17223
- }
17224
- } else {
17225
- $site = is_numeric( $network_level_or_blog_id ) ?
17226
- array( 'blog_id' => $network_level_or_blog_id ) :
17227
- null;
17228
-
17229
- $site = $this->get_site_info( $site );
17230
-
17231
- $params = array_merge( $params, array(
17232
- 'site_uid' => $site['uid'],
17233
- 'site_url' => $site['url'],
17234
- 'site_name' => $site['title'],
17235
- 'language' => $site['language'],
17236
- 'charset' => $site['charset'],
17237
- ) );
17238
- }
17239
-
17240
- if ( $this->is_pending_activation() &&
17241
- ! empty( $this->_storage->pending_license_key )
17242
- ) {
17243
- $params['license_key'] = $this->_storage->pending_license_key;
17244
- }
17245
-
17246
- if ( WP_FS__SKIP_EMAIL_ACTIVATION && $this->has_secret_key() ) {
17247
- // Even though rand() is known for its security issues,
17248
- // the timestamp adds another layer of protection.
17249
- // It would be very hard for an attacker to get the secret key form here.
17250
- // Plus, this should never run in production since the secret should never
17251
- // be included in the production version.
17252
- $params['ts'] = WP_FS__SCRIPT_START_TIME;
17253
- $params['salt'] = md5( uniqid( rand() ) );
17254
- $params['secure'] = md5(
17255
- $params['ts'] .
17256
- $params['salt'] .
17257
- $this->get_secret_key()
17258
- );
17259
- }
17260
-
17261
- if ( is_multisite() && function_exists( 'get_network' ) ) {
17262
- $params['network_uid'] = $this->get_anonymous_network_id();
17263
- }
17264
-
17265
- return array_merge( $params, $override_with );
17266
- }
17267
-
17268
- /**
17269
- * 1. If successful opt-in or pending activation returns the next page that the user should be redirected to.
17270
- * 2. If there was an API error, return the API result.
17271
- *
17272
- * @author Vova Feldman (@svovaf)
17273
- * @since 1.1.7.4
17274
- *
17275
- * @param string|bool $email
17276
- * @param string|bool $first
17277
- * @param string|bool $last
17278
- * @param string|bool $license_key
17279
- * @param bool $is_uninstall If "true", this means that the module is currently being uninstalled.
17280
- * In this case, the user and site info will be sent to the server but no
17281
- * data will be saved to the WP installation's database.
17282
- * @param number|bool $trial_plan_id
17283
- * @param bool $is_disconnected Whether or not to opt in without tracking.
17284
- * @param null|bool $is_marketing_allowed
17285
- * @param array $sites If network-level opt-in, an array of containing details of sites.
17286
- * @param bool $redirect
17287
- *
17288
- * @return string|object
17289
- * @use WP_Error
17290
- */
17291
- function opt_in(
17292
- $email = false,
17293
- $first = false,
17294
- $last = false,
17295
- $license_key = false,
17296
- $is_uninstall = false,
17297
- $trial_plan_id = false,
17298
- $is_disconnected = false,
17299
- $is_marketing_allowed = null,
17300
- $sites = array(),
17301
- $redirect = true
17302
- ) {
17303
- $this->_logger->entrance();
17304
-
17305
- if ( false === $email ) {
17306
- $current_user = self::_get_current_wp_user();
17307
- $email = $current_user->user_email;
17308
- }
17309
-
17310
- /**
17311
- * @since 1.2.1 If activating with license key, ignore the context-user
17312
- * since the user will be automatically loaded from the license.
17313
- */
17314
- if ( empty( $license_key ) ) {
17315
- // Clean up pending license if opt-ing in again.
17316
- $this->_storage->remove( 'pending_license_key' );
17317
-
17318
- if ( ! $is_uninstall ) {
17319
- $fs_user = Freemius::_get_user_by_email( $email );
17320
- if ( is_object( $fs_user ) && ! $this->is_pending_activation() ) {
17321
- return $this->install_with_user(
17322
- $fs_user,
17323
- false,
17324
- $trial_plan_id,
17325
- $redirect,
17326
- true,
17327
- $sites
17328
- );
17329
- }
17330
- }
17331
- }
17332
-
17333
- $user_info = array();
17334
- if ( ! empty( $email ) ) {
17335
- $user_info['user_email'] = $email;
17336
- }
17337
- if ( ! empty( $first ) ) {
17338
- $user_info['user_firstname'] = $first;
17339
- }
17340
- if ( ! empty( $last ) ) {
17341
- $user_info['user_lastname'] = $last;
17342
- }
17343
-
17344
- if ( ! empty( $sites ) ) {
17345
- $is_network = true;
17346
-
17347
- $user_info['sites'] = $sites;
17348
- } else {
17349
- $is_network = false;
17350
- }
17351
-
17352
- $params = $this->get_opt_in_params( $user_info, $is_network );
17353
-
17354
- $filtered_license_key = false;
17355
- if ( is_string( $license_key ) ) {
17356
- $filtered_license_key = $this->apply_filters( 'license_key', $license_key );
17357
- $params['license_key'] = $filtered_license_key;
17358
- } else if ( FS_Plugin_Plan::is_valid_id( $trial_plan_id ) ) {
17359
- $params['trial_plan_id'] = $trial_plan_id;
17360
- }
17361
-
17362
- if ( $is_uninstall ) {
17363
- $params['uninstall_params'] = array(
17364
- 'reason_id' => $this->_storage->uninstall_reason->id,
17365
- 'reason_info' => $this->_storage->uninstall_reason->info
17366
- );
17367
- }
17368
-
17369
- if ( isset( $params['license_key'] ) ) {
17370
- $fs_user = Freemius::_get_user_by_email( $email );
17371
-
17372
- if ( is_object( $fs_user ) ) {
17373
- /**
17374
- * If opting in with a context license and the context WP Admin user already opted in
17375
- * before from the current site, add the user context security params to avoid the
17376
- * unnecessary email activation when the context license is owned by the same context user.
17377
- *
17378
- * @author Leo Fajardo (@leorw)
17379
- * @since 1.2.3
17380
- */
17381
- $params = array_merge( $params, FS_Security::instance()->get_context_params(
17382
- $fs_user,
17383
- false,
17384
- 'install_with_existing_user'
17385
- ) );
17386
- }
17387
- }
17388
-
17389
- if ( is_bool( $is_marketing_allowed ) ) {
17390
- $params['is_marketing_allowed'] = $is_marketing_allowed;
17391
- }
17392
-
17393
- $params['is_disconnected'] = $is_disconnected;
17394
- $params['format'] = 'json';
17395
-
17396
- $request = array(
17397
- 'method' => 'POST',
17398
- 'body' => $params,
17399
- 'timeout' => 60,
17400
- );
17401
-
17402
- $url = $this->add_show_pending( WP_FS__ADDRESS . '/action/service/user/install/' );
17403
- $response = self::safe_remote_post( $url, $request );
17404
-
17405
- if ( is_wp_error( $response ) ) {
17406
- /**
17407
- * @var WP_Error $response
17408
- */
17409
- $result = new stdClass();
17410
-
17411
- $error_code = $response->get_error_code();
17412
- $error_type = str_replace( ' ', '', ucwords( str_replace( '_', ' ', $error_code ) ) );
17413
-
17414
- $result->error = (object) array(
17415
- 'type' => $error_type,
17416
- 'message' => $response->get_error_message(),
17417
- 'code' => $error_code,
17418
- 'http' => 402
17419
- );
17420
-
17421
- $this->maybe_modify_api_curl_error_message( $result );
17422
-
17423
- return $result;
17424
- }
17425
-
17426
- // Module is being uninstalled, don't handle the returned data.
17427
- if ( $is_uninstall ) {
17428
- return true;
17429
- }
17430
-
17431
- /**
17432
- * When json_decode() executed on PHP 5.2 with an invalid JSON, it will throw a PHP warning. Unfortunately, the new Theme Check doesn't allow PHP silencing and the theme review team isn't open to change that, therefore, instead of using `@json_decode()` we had to use the method without the `@` directive.
17433
- *
17434
- * @author Vova Feldman (@svovaf)
17435
- * @since 1.2.3
17436
- * @link https://themes.trac.wordpress.org/ticket/46134#comment:5
17437
- * @link https://themes.trac.wordpress.org/ticket/46134#comment:9
17438
- * @link https://themes.trac.wordpress.org/ticket/46134#comment:12
17439
- * @link https://themes.trac.wordpress.org/ticket/46134#comment:14
17440
- */
17441
- $decoded = is_string( $response['body'] ) ?
17442
- json_decode( $response['body'] ) :
17443
- null;
17444
-
17445
- if ( empty( $decoded ) ) {
17446
- return false;
17447
- }
17448
-
17449
- if ( ! $this->is_api_result_object( $decoded ) ) {
17450
- if ( ! empty( $params['license_key'] ) ) {
17451
- // Pass the fully entered license key to the failure handler.
17452
- $params['license_key'] = $license_key;
17453
- }
17454
-
17455
- return $is_uninstall ?
17456
- $decoded :
17457
- $this->apply_filters( 'after_install_failure', $decoded, $params );
17458
- } else if ( isset( $decoded->pending_activation ) && $decoded->pending_activation ) {
17459
- if ( $is_network ) {
17460
- $site_ids = array();
17461
- foreach ( $sites as $site ) {
17462
- $site_ids[] = $site['blog_id'];
17463
- }
17464
-
17465
- /**
17466
- * Store the sites so that they can be installed once the user has clicked on the activation link
17467
- * in the email.
17468
- *
17469
- * @author Leo Fajardo (@leorw)
17470
- */
17471
- $this->_storage->pending_sites_info = array(
17472
- 'blog_ids' => $site_ids,
17473
- 'license_key' => $license_key,
17474
- 'trial_plan_id' => $trial_plan_id
17475
- );
17476
- }
17477
-
17478
- // Pending activation, add message.
17479
- return $this->set_pending_confirmation(
17480
- ( isset( $decoded->email ) ?
17481
- $decoded->email :
17482
- true ),
17483
- false,
17484
- $filtered_license_key,
17485
- ! empty( $params['trial_plan_id'] ),
17486
- isset( $decoded->is_suspicious_email ) && $decoded->is_suspicious_email
17487
- );
17488
- } else if ( isset( $decoded->install_secret_key ) ) {
17489
- return $this->install_with_new_user(
17490
- $decoded->user_id,
17491
- $decoded->user_public_key,
17492
- $decoded->user_secret_key,
17493
- ( isset( $decoded->is_marketing_allowed ) && ! is_null( $decoded->is_marketing_allowed ) ?
17494
- $decoded->is_marketing_allowed :
17495
- null ),
17496
- ( isset( $decoded->is_extensions_tracking_allowed ) && ! is_null( $decoded->is_extensions_tracking_allowed ) ?
17497
- $decoded->is_extensions_tracking_allowed :
17498
- null ),
17499
- $decoded->install_id,
17500
- $decoded->install_public_key,
17501
- $decoded->install_secret_key,
17502
- false
17503
- );
17504
- } else if ( is_array( $decoded->installs ) ) {
17505
- return $this->install_many_with_new_user(
17506
- $decoded->user_id,
17507
- $decoded->user_public_key,
17508
- $decoded->user_secret_key,
17509
- ( isset( $decoded->is_marketing_allowed ) && ! is_null( $decoded->is_marketing_allowed ) ?
17510
- $decoded->is_marketing_allowed :
17511
- null ),
17512
- ( isset( $decoded->is_extensions_tracking_allowed ) && ! is_null( $decoded->is_extensions_tracking_allowed ) ?
17513
- $decoded->is_extensions_tracking_allowed :
17514
- null ),
17515
- $decoded->installs,
17516
- false
17517
- );
17518
- }
17519
-
17520
- return $decoded;
17521
- }
17522
-
17523
- /**
17524
- * Set user and site identities.
17525
- *
17526
- * @author Vova Feldman (@svovaf)
17527
- * @since 1.0.9
17528
- *
17529
- * @param FS_User $user
17530
- * @param FS_Site $site
17531
- * @param bool $redirect
17532
- * @param bool $auto_install Since 1.2.1.7 If `true` and setting up an account with a valid license, will
17533
- * redirect (or return a URL) to the account page with a special parameter to
17534
- * trigger the auto installation processes.
17535
- *
17536
- * @return string If redirect is `false`, returns the next page the user should be redirected to.
17537
- */
17538
- function setup_account(
17539
- FS_User $user,
17540
- FS_Site $site,
17541
- $redirect = true,
17542
- $auto_install = false
17543
- ) {
17544
- return $this->setup_network_account(
17545
- $user,
17546
- array( $site ),
17547
- $redirect,
17548
- $auto_install,
17549
- false
17550
- );
17551
- }
17552
-
17553
- /**
17554
- * Set user and site identities.
17555
- *
17556
- * @author Vova Feldman (@svovaf)
17557
- * @since 2.0.0
17558
- *
17559
- * @param FS_User $user
17560
- * @param FS_Site[] $installs
17561
- * @param bool $redirect
17562
- * @param bool $auto_install Since 1.2.1.7 If `true` and setting up an account with a valid license, will redirect (or return a URL) to the account page with a special parameter to trigger the auto installation processes.
17563
- * @param bool $is_network_level_opt_in
17564
- *
17565
- * @return string If redirect is `false`, returns the next page the user should be redirected to.
17566
- */
17567
- function setup_network_account(
17568
- FS_User $user,
17569
- array $installs,
17570
- $redirect = true,
17571
- $auto_install = false,
17572
- $is_network_level_opt_in = true
17573
- ) {
17574
- $first_install = $installs[0];
17575
-
17576
- $this->_user = $user;
17577
- $this->_site = $first_install;
17578
-
17579
- $this->_sync_plans();
17580
-
17581
- if ( $this->_storage->handle_gdpr_admin_notice &&
17582
- $this->should_handle_gdpr_admin_notice() &&
17583
- FS_GDPR_Manager::instance()->should_show_opt_in_notice()
17584
- ) {
17585
- /**
17586
- * Clear user lock after an opt-in.
17587
- */
17588
- require_once WP_FS__DIR_INCLUDES . '/class-fs-user-lock.php';
17589
- FS_User_Lock::instance()->unlock();
17590
- }
17591
-
17592
- if ( 1 < count( $installs ) ) {
17593
- // Only network level opt-in can have more than one install.
17594
- $is_network_level_opt_in = true;
17595
- }
17596
- // $is_network_level_opt_in = self::is_ajax_action_static( 'network_activate', $this->_module_id );
17597
- // If Freemius was OFF before, turn it on.
17598
- $this->turn_on();
17599
-
17600
- $this->handle_account_connection(
17601
- $installs,
17602
- ( ! $this->_is_network_active || ! $is_network_level_opt_in )
17603
- );
17604
-
17605
- if ( is_numeric( $first_install->license_id ) ) {
17606
- $this->set_license( $this->_get_license_by_id( $first_install->license_id ) );
17607
- }
17608
-
17609
- $this->_admin_notices->remove_sticky( 'connect_account' );
17610
-
17611
- if ( $this->is_pending_activation() || ! $this->has_settings_menu() ) {
17612
- // Remove pending activation sticky notice (if still exist).
17613
- $this->_admin_notices->remove_sticky( 'activation_pending' );
17614
-
17615
- // Remove plugin from pending activation mode.
17616
- unset( $this->_storage->is_pending_activation );
17617
-
17618
- if ( ! $this->is_paying_or_trial() ) {
17619
- $this->_admin_notices->add_sticky(
17620
- sprintf( $this->get_text_inline( '%s activation was successfully completed.', 'plugin-x-activation-message' ), '<b>' . $this->get_plugin_name() . '</b>' ),
17621
- 'activation_complete'
17622
- );
17623
- }
17624
- }
17625
-
17626
- if ( $this->is_paying_or_trial() ) {
17627
- if ( ! $this->is_premium() ||
17628
- ! $this->has_premium_version() ||
17629
- ! $this->has_settings_menu()
17630
- ) {
17631
- if ( $this->is_paying() ) {
17632
- $this->_admin_notices->add_sticky(
17633
- sprintf(
17634
- $this->get_text_inline( 'Your account was successfully activated with the %s plan.', 'activation-with-plan-x-message' ),
17635
- $this->get_plan_title()
17636
- ) . $this->get_complete_upgrade_instructions(),
17637
- 'plan_upgraded',
17638
- $this->get_text_x_inline( 'Yee-haw', 'interjection expressing joy or exuberance', 'yee-haw' ) . '!'
17639
- );
17640
- } else {
17641
- $trial_plan = $this->get_trial_plan();
17642
-
17643
- $this->_admin_notices->add_sticky(
17644
- sprintf(
17645
- $this->get_text_inline( 'Your trial has been successfully started.', 'trial-started-message' ),
17646
- '<i>' . $this->get_plugin_name() . '</i>'
17647
- ) . $this->get_complete_upgrade_instructions( $trial_plan->title ),
17648
- 'trial_started',
17649
- $this->get_text_x_inline( 'Yee-haw', 'interjection expressing joy or exuberance', 'yee-haw' ) . '!'
17650
- );
17651
- }
17652
- }
17653
-
17654
- $this->_admin_notices->remove_sticky( array(
17655
- 'trial_promotion',
17656
- ) );
17657
- }
17658
-
17659
- $plugin_id = fs_request_get( 'plugin_id', false );
17660
-
17661
- // Store activation time ONLY for plugins & themes (not add-ons).
17662
- if ( ! is_numeric( $plugin_id ) || ( $plugin_id == $this->_plugin->id ) ) {
17663
- if ( empty( $this->_storage->activation_timestamp ) ) {
17664
- $this->_storage->activation_timestamp = WP_FS__SCRIPT_START_TIME;
17665
- }
17666
- }
17667
-
17668
- $next_page = '';
17669
-
17670
- $extra = array();
17671
- if ( $auto_install ) {
17672
- $extra['auto_install'] = 'true';
17673
- }
17674
-
17675
- if ( is_numeric( $plugin_id ) ) {
17676
- /**
17677
- * @author Leo Fajardo (@leorw)
17678
- * @since 1.2.1.6
17679
- *
17680
- * Also sync the license after an anonymous user subscribes.
17681
- */
17682
- if ( $this->is_anonymous() || $plugin_id != $this->_plugin->id ) {
17683
- // Add-on was installed - sync license right after install.
17684
- $next_page = $this->_get_sync_license_url( $plugin_id, true, $extra );
17685
- }
17686
- } else {
17687
- /**
17688
- * @author Vova Feldman (@svovaf)
17689
- * @since 1.1.9 If site installed with a valid license, sync license.
17690
- */
17691
- if ( $this->is_paying() ) {
17692
- $this->_sync_plugin_license(
17693
- true,
17694
- // Installs data is already synced in the beginning of this method directly or via _set_account().
17695
- false
17696
- );
17697
- }
17698
-
17699
- // Reload the page with the keys.
17700
- $next_page = $this->is_anonymous() ?
17701
- // If user previously skipped, redirect to account page.
17702
- $this->get_account_url( false, $extra ) :
17703
- $this->get_after_activation_url( 'after_connect_url', array(), $is_network_level_opt_in );
17704
- }
17705
-
17706
- if ( ! empty( $next_page ) && $redirect ) {
17707
- fs_redirect( $next_page );
17708
- }
17709
-
17710
- return $next_page;
17711
- }
17712
-
17713
- /**
17714
- * Install plugin with new user information after approval.
17715
- *
17716
- * @author Vova Feldman (@svovaf)
17717
- * @since 1.0.7
17718
- */
17719
- function _install_with_new_user() {
17720
- $this->_logger->entrance();
17721
-
17722
- if ( $this->is_registered() ) {
17723
- return;
17724
- }
17725
-
17726
- if ( ( $this->is_plugin() && fs_request_is_action( $this->get_unique_affix() . '_activate_new' ) ) ||
17727
- // @todo This logic should be improved because it's executed on every load of a theme.
17728
- $this->is_theme()
17729
- ) {
17730
- // check_admin_referer( $this->_slug . '_activate_new' );
17731
-
17732
- if ( fs_request_has( 'user_secret_key' ) ) {
17733
- if ( fs_is_network_admin() && isset( $this->_storage->pending_sites_info ) ) {
17734
- $pending_sites_info = $this->_storage->pending_sites_info;
17735
-
17736
- $this->install_many_pending_with_user(
17737
- fs_request_get( 'user_id' ),
17738
- fs_request_get( 'user_public_key' ),
17739
- fs_request_get( 'user_secret_key' ),
17740
- fs_request_get_bool( 'is_marketing_allowed', null ),
17741
- fs_request_get_bool( 'is_extensions_tracking_allowed', null ),
17742
- $pending_sites_info['blog_ids'],
17743
- $pending_sites_info['license_key'],
17744
- $pending_sites_info['trial_plan_id']
17745
- );
17746
- } else {
17747
- $this->install_with_new_user(
17748
- fs_request_get( 'user_id' ),
17749
- fs_request_get( 'user_public_key' ),
17750
- fs_request_get( 'user_secret_key' ),
17751
- fs_request_get_bool( 'is_marketing_allowed', null ),
17752
- fs_request_get_bool( 'is_extensions_tracking_allowed', null ),
17753
- fs_request_get( 'install_id' ),
17754
- fs_request_get( 'install_public_key' ),
17755
- fs_request_get( 'install_secret_key' ),
17756
- true,
17757
- fs_request_get_bool( 'auto_install' )
17758
- );
17759
- }
17760
- } else if ( fs_request_has( 'pending_activation' ) ) {
17761
- $this->set_pending_confirmation(
17762
- fs_request_get( 'user_email' ),
17763
- true,
17764
- false,
17765
- false,
17766
- fs_request_get_bool( 'is_suspicious_email' )
17767
- );
17768
- }
17769
- }
17770
- }
17771
-
17772
- /**
17773
- * @author Vova Feldman (@svovaf)
17774
- * @since 2.0.0
17775
- *
17776
- * @param number $id
17777
- * @param string $public_key
17778
- * @param string $secret_key
17779
- *
17780
- * @return \FS_User
17781
- */
17782
- private function setup_user( $id, $public_key, $secret_key ) {
17783
- $user = self::_get_user_by_id( $id );
17784
-
17785
- if ( is_object( $user ) ) {
17786
- $this->_user = $user;
17787
- } else {
17788
- $user = new FS_User();
17789
- $user->id = $id;
17790
- $user->public_key = $public_key;
17791
- $user->secret_key = $secret_key;
17792
-
17793
- $this->_user = $user;
17794
- $user_result = $this->get_api_user_scope()->get();
17795
- $user = new FS_User( $user_result );
17796
-
17797
- $this->_user = $user;
17798
- $this->_store_user();
17799
- }
17800
-
17801
- return $user;
17802
- }
17803
-
17804
- /**
17805
- * Install plugin with new user.
17806
- *
17807
- * @author Vova Feldman (@svovaf)
17808
- * @since 1.1.7.4
17809
- *
17810
- * @param number $user_id
17811
- * @param string $user_public_key
17812
- * @param string $user_secret_key
17813
- * @param bool|null $is_marketing_allowed
17814
- * @param bool|null $is_extensions_tracking_allowed Since 2.3.2
17815
- * @param number $install_id
17816
- * @param string $install_public_key
17817
- * @param string $install_secret_key
17818
- * @param bool $redirect
17819
- * @param bool $auto_install Since 1.2.1.7 If `true` and setting up an account with a valid license, will redirect (or return a URL) to the account page with a special parameter to trigger the auto installation processes.
17820
- *
17821
- * @return string If redirect is `false`, returns the next page the user should be redirected to.
17822
- */
17823
- private function install_with_new_user(
17824
- $user_id,
17825
- $user_public_key,
17826
- $user_secret_key,
17827
- $is_marketing_allowed,
17828
- $is_extensions_tracking_allowed,
17829
- $install_id,
17830
- $install_public_key,
17831
- $install_secret_key,
17832
- $redirect = true,
17833
- $auto_install = false
17834
- ) {
17835
- /**
17836
- * This method is also executed after opting in with a license key since the
17837
- * license can be potentially associated with a different owner.
17838
- *
17839
- * @since 2.0.0
17840
- */
17841
- $user = self::_get_user_by_id( $user_id );
17842
-
17843
- if ( ! is_object( $user ) ) {
17844
- $user = new FS_User();
17845
- $user->id = $user_id;
17846
- $user->public_key = $user_public_key;
17847
- $user->secret_key = $user_secret_key;
17848
-
17849
- $this->_user = $user;
17850
- $user_result = $this->get_api_user_scope()->get();
17851
- $user = new FS_User( $user_result );
17852
- }
17853
-
17854
- $this->_user = $user;
17855
-
17856
- $site = new FS_Site();
17857
- $site->id = $install_id;
17858
- $site->public_key = $install_public_key;
17859
- $site->secret_key = $install_secret_key;
17860
-
17861
- $this->_site = $site;
17862
- $site_result = $this->get_api_site_scope( true )->get();
17863
- $site = new FS_Site( $site_result );
17864
- $this->_site = $site;
17865
-
17866
- if ( ! is_null( $is_marketing_allowed ) ) {
17867
- $this->disable_opt_in_notice_and_lock_user();
17868
- }
17869
-
17870
- $this->update_extensions_tracking_flag( $is_extensions_tracking_allowed );
17871
-
17872
- return $this->setup_account(
17873
- $this->_user,
17874
- $this->_site,
17875
- $redirect,
17876
- $auto_install
17877
- );
17878
- }
17879
-
17880
- /**
17881
- * Install plugin with user.
17882
- *
17883
- * @author Leo Fajardo (@leorw)
17884
- * @since 2.0.0
17885
- *
17886
- * @param number $user_id
17887
- * @param string $user_public_key
17888
- * @param string $user_secret_key
17889
- * @param bool|null $is_marketing_allowed
17890
- * @param bool|null $is_extensions_tracking_allowed Since 2.3.2
17891
- * @param array $site_ids
17892
- * @param bool $license_key
17893
- * @param bool $trial_plan_id
17894
- * @param bool $redirect
17895
- *
17896
- * @return string If redirect is `false`, returns the next page the user should be redirected to.
17897
- */
17898
- private function install_many_pending_with_user(
17899
- $user_id,
17900
- $user_public_key,
17901
- $user_secret_key,
17902
- $is_marketing_allowed,
17903
- $is_extensions_tracking_allowed,
17904
- $site_ids,
17905
- $license_key = false,
17906
- $trial_plan_id = false,
17907
- $redirect = true
17908
- ) {
17909
- $user = $this->setup_user( $user_id, $user_public_key, $user_secret_key );
17910
-
17911
- if ( ! is_null( $is_marketing_allowed ) ) {
17912
- $this->disable_opt_in_notice_and_lock_user();
17913
- }
17914
-
17915
- $this->update_extensions_tracking_flag( $is_extensions_tracking_allowed );
17916
-
17917
- $sites = array();
17918
- foreach ( $site_ids as $site_id ) {
17919
- $sites[] = $this->get_site_info( array( 'blog_id' => $site_id ) );
17920
- }
17921
-
17922
- $this->install_with_user( $user, $license_key, $trial_plan_id, $redirect, true, $sites );
17923
- }
17924
-
17925
- /**
17926
- * Multi-site install with a new user.
17927
- *
17928
- * @author Vova Feldman (@svovaf)
17929
- * @since 2.0.0
17930
- *
17931
- * @param number $user_id
17932
- * @param string $user_public_key
17933
- * @param string $user_secret_key
17934
- * @param bool|null $is_marketing_allowed
17935
- * @param bool|null $is_extensions_tracking_allowed Since 2.3.2
17936
- * @param object[] $installs
17937
- * @param bool $redirect
17938
- * @param bool $auto_install Since 1.2.1.7 If `true` and setting up an account with a valid license, will redirect (or return a URL) to the account page with a special parameter to trigger the auto installation processes.
17939
- *
17940
- * @return string If redirect is `false`, returns the next page the user should be redirected to.
17941
- */
17942
- private function install_many_with_new_user(
17943
- $user_id,
17944
- $user_public_key,
17945
- $user_secret_key,
17946
- $is_marketing_allowed,
17947
- $is_extensions_tracking_allowed,
17948
- array $installs,
17949
- $redirect = true,
17950
- $auto_install = false
17951
- ) {
17952
- $this->setup_user( $user_id, $user_public_key, $user_secret_key );
17953
-
17954
- if ( ! is_null( $is_marketing_allowed ) ) {
17955
- $this->disable_opt_in_notice_and_lock_user();
17956
- }
17957
-
17958
- $this->update_extensions_tracking_flag( $is_extensions_tracking_allowed );
17959
-
17960
- $install_ids = array();
17961
-
17962
- foreach ( $installs as $install ) {
17963
- $install_ids[] = $install->id;
17964
- }
17965
-
17966
- $left = count( $install_ids );
17967
- $offset = 0;
17968
-
17969
- $installs = array();
17970
- while ( $left > 0 ) {
17971
- $result = $this->get_api_user_scope()->get( "/plugins/{$this->_module_id}/installs.json?ids=" . implode( ',', array_slice( $install_ids, $offset, 25 ) ) );
17972
-
17973
- if ( ! $this->is_api_result_object( $result, 'installs' ) ) {
17974
- // @todo Handle API error.
17975
- }
17976
-
17977
- $installs = array_merge( $installs, $result->installs );
17978
-
17979
- $left -= 25;
17980
- }
17981
-
17982
- foreach ( $installs as &$install ) {
17983
- $install = new FS_Site( $install );
17984
- }
17985
-
17986
- return $this->setup_network_account(
17987
- $this->_user,
17988
- $installs,
17989
- $redirect,
17990
- $auto_install
17991
- );
17992
- }
17993
-
17994
- /**
17995
- * @author Vova Feldman (@svovaf)
17996
- * @since 1.1.7.4
17997
- *
17998
- * @param string|bool $email
17999
- * @param bool $redirect
18000
- * @param string|bool $license_key Since 1.2.1.5
18001
- * @param bool $is_pending_trial Since 1.2.1.5
18002
- *
18003
- * @return string Since 1.2.1.5 if $redirect is `false`, return the pending activation page.
18004
- */
18005
- private function set_pending_confirmation(
18006
- $email = false,
18007
- $redirect = true,
18008
- $license_key = false,
18009
- $is_pending_trial = false,
18010
- $is_suspicious_email = false
18011
- ) {
18012
- if ( $this->_ignore_pending_mode ) {
18013
- /**
18014
- * If explicitly asked to ignore pending mode, set to anonymous mode
18015
- * if require confirmation before finalizing the opt-in.
18016
- *
18017
- * @author Vova Feldman
18018
- * @since 1.2.1.6
18019
- */
18020
- $this->skip_connection( null, fs_is_network_admin() );
18021
- } else {
18022
- // Install must be activated via email since
18023
- // user with the same email already exist.
18024
- $this->_storage->is_pending_activation = true;
18025
- $this->_add_pending_activation_notice( $email, $is_pending_trial, $is_suspicious_email );
18026
- }
18027
-
18028
- if ( ! empty( $license_key ) ) {
18029
- $this->_storage->pending_license_key = $license_key;
18030
- }
18031
-
18032
- // Remove the opt-in sticky notice.
18033
- $this->_admin_notices->remove_sticky( array(
18034
- 'connect_account',
18035
- 'trial_promotion',
18036
- ) );
18037
-
18038
- $next_page = $this->get_after_activation_url( 'after_pending_connect_url' );
18039
-
18040
- // Reload the page with with pending activation message.
18041
- if ( $redirect ) {
18042
- fs_redirect( $next_page );
18043
- }
18044
-
18045
- return $next_page;
18046
- }
18047
-
18048
- /**
18049
- * Install plugin with current logged WP user info.
18050
- *
18051
- * @author Vova Feldman (@svovaf)
18052
- * @since 1.0.7
18053
- */
18054
- function _install_with_current_user() {
18055
- $this->_logger->entrance();
18056
-
18057
- if ( $this->is_registered() ) {
18058
- return;
18059
- }
18060
-
18061
- if ( fs_request_is_action( $this->get_unique_affix() . '_activate_existing' ) && fs_request_is_post() ) {
18062
- // check_admin_referer( 'activate_existing_' . $this->_plugin->public_key );
18063
-
18064
- /**
18065
- * @author Vova Feldman (@svovaf)
18066
- * @since 1.1.9 Add license key if given.
18067
- */
18068
- $license_key = fs_request_get( 'license_secret_key' );
18069
-
18070
- $this->update_extensions_tracking_flag( fs_request_get_bool( 'is_extensions_tracking_allowed', null ) );
18071
-
18072
- $this->install_with_current_user( $license_key );
18073
- }
18074
- }
18075
-
18076
-
18077
- /**
18078
- * @author Vova Feldman (@svovaf)
18079
- * @since 1.1.7.4
18080
- *
18081
- * @param string|bool $license_key
18082
- * @param number|bool $trial_plan_id
18083
- * @param array $sites Since 2.0.0
18084
- * @param bool $redirect
18085
- *
18086
- * @return object|string If redirect is `false`, returns the next page the user should be redirected to, or the API error object if failed to install.
18087
- */
18088
- function install_with_current_user(
18089
- $license_key = false,
18090
- $trial_plan_id = false,
18091
- $sites = array(),
18092
- $redirect = true
18093
- ) {
18094
- // Get current logged WP user.
18095
- $current_user = self::_get_current_wp_user();
18096
-
18097
- // Find the relevant FS user by the email.
18098
- $user = self::_get_user_by_email( $current_user->user_email );
18099
-
18100
- return $this->install_with_user( $user, $license_key, $trial_plan_id, $redirect, true, $sites );
18101
- }
18102
-
18103
- /**
18104
- * @author Vova Feldman (@svovaf)
18105
- * @since 2.0.0
18106
- *
18107
- * @param \FS_User $user
18108
- * @param string|bool $license_key
18109
- * @param number|bool $trial_plan_id
18110
- * @param bool $redirect
18111
- * @param bool $setup_account Since 2.0.0. When set to FALSE, executes a light installation without setting up the account as if it's the first opt-in.
18112
- * @param array $sites Since 2.0.0. If not empty, should be a collection of site details for the bulk install API request.
18113
- *
18114
- * @return \FS_Site|object|string If redirect is `false`, returns the next page the user should be redirected to, or the API error object if failed to install. If $setup_account is set to `false`, return the newly created install.
18115
- */
18116
- function install_with_user(
18117
- FS_User $user,
18118
- $license_key = false,
18119
- $trial_plan_id = false,
18120
- $redirect = true,
18121
- $setup_account = true,
18122
- $sites = array()
18123
- ) {
18124
- // We have to set the user before getting user scope API handler.
18125
- $this->_user = $user;
18126
-
18127
- // Install the plugin.
18128
- $result = $this->create_installs_with_user(
18129
- $user,
18130
- $license_key,
18131
- $trial_plan_id,
18132
- $sites,
18133
- $redirect
18134
- );
18135
-
18136
- if ( ! $this->is_api_result_entity( $result ) &&
18137
- ! $this->is_api_result_object( $result, 'installs' )
18138
- ) {
18139
- // @todo Handler potential API error of the $result
18140
- }
18141
-
18142
- if ( empty( $sites ) ) {
18143
- $site = new FS_Site( $result );
18144
- $this->_site = $site;
18145
-
18146
- if ( ! $setup_account ) {
18147
- $this->_store_site();
18148
-
18149
- $this->sync_plan_if_not_exist( $site->plan_id );
18150
-
18151
- if ( ! empty( $license_key ) && FS_Plugin_License::is_valid_id( $site->license_id ) ) {
18152
- $this->sync_license_if_not_exist( $site->license_id, $license_key );
18153
- }
18154
-
18155
- $this->_admin_notices->remove_sticky( 'connect_account', false );
18156
-
18157
- return $site;
18158
- }
18159
-
18160
- return $this->setup_account( $this->_user, $this->_site, $redirect );
18161
- } else {
18162
- $installs = array();
18163
- foreach ( $result->installs as $install ) {
18164
- $installs[] = new FS_Site( $install );
18165
- }
18166
-
18167
- return $this->setup_network_account(
18168
- $user,
18169
- $installs,
18170
- $redirect
18171
- );
18172
- }
18173
- }
18174
-
18175
- /**
18176
- * Initiate an API request to create a collection of installs.
18177
- *
18178
- * @author Vova Feldman (@svovaf)
18179
- * @since 2.0.0
18180
- *
18181
- * @param \FS_User $user
18182
- * @param bool $license_key
18183
- * @param bool $trial_plan_id
18184
- * @param array $sites
18185
- * @param bool $redirect
18186
- * @param bool $silent
18187
- *
18188
- * @return object|mixed
18189
- */
18190
- private function create_installs_with_user(
18191
- FS_User $user,
18192
- $license_key = false,
18193
- $trial_plan_id = false,
18194
- $sites = array(),
18195
- $redirect = false,
18196
- $silent = false
18197
- ) {
18198
- $extra_install_params = array(
18199
- 'uid' => $this->get_anonymous_id(),
18200
- 'is_disconnected' => false,
18201
- );
18202
-
18203
- if ( ! empty( $license_key ) ) {
18204
- $extra_install_params['license_key'] = $this->apply_filters( 'license_key', $license_key );
18205
-
18206
- if ( $silent ) {
18207
- $extra_install_params['ignore_license_owner'] = true;
18208
- }
18209
- } else if ( FS_Plugin_Plan::is_valid_id( $trial_plan_id ) ) {
18210
- $extra_install_params['trial_plan_id'] = $trial_plan_id;
18211
- }
18212
-
18213
- if ( ! empty( $sites ) ) {
18214
- $extra_install_params['sites'] = $sites;
18215
- }
18216
-
18217
- $args = $this->get_install_data_for_api( $extra_install_params, false, false );
18218
-
18219
- // Install the plugin.
18220
- $result = $this->get_api_user_scope_by_user( $user )->call(
18221
- "/plugins/{$this->get_id()}/installs.json",
18222
- 'post',
18223
- $args
18224
- );
18225
-
18226
- if ( ! $this->is_api_result_entity( $result ) &&
18227
- ! $this->is_api_result_object( $result, 'installs' )
18228
- ) {
18229
- if ( ! empty( $args['license_key'] ) ) {
18230
- // Pass the fully entered license key to the failure handler.
18231
- $args['license_key'] = $license_key;
18232
- }
18233
-
18234
- $result = $this->apply_filters( 'after_install_failure', $result, $args );
18235
-
18236
- if ( ! $silent ) {
18237
- $this->_admin_notices->add(
18238
- sprintf( $this->get_text_inline( 'Couldn\'t activate %s.', 'could-not-activate-x' ), $this->get_plugin_name() ) . ' ' .
18239
- $this->get_text_inline( 'Please contact us with the following message:', 'contact-us-with-error-message' ) . ' ' . '<b>' . $result->error->message . '</b>',
18240
- $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
18241
- 'error'
18242
- );
18243
- }
18244
-
18245
- if ( $redirect ) {
18246
- /**
18247
- * We set the user before getting the user scope API handler, so the user became temporarily
18248
- * registered (`is_registered() = true`). Since the API returned an error and we will redirect,
18249
- * we have to set the user to `null`, otherwise, the user will be redirected to the wrong
18250
- * activation page based on the return value of `is_registered()`. In addition, in case the
18251
- * context plugin doesn't have a settings menu and the default page is the `Plugins` page,
18252
- * misleading plugin activation errors will be shown on the `Plugins` page.
18253
- *
18254
- * @author Leo Fajardo (@leorw)
18255
- */
18256
- $this->_user = null;
18257
-
18258
- fs_redirect( $this->get_activation_url( array( 'error' => $result->error->message ) ) );
18259
- }
18260
- }
18261
-
18262
- return $result;
18263
- }
18264
-
18265
- /**
18266
- * Tries to activate add-on account based on parent plugin info.
18267
- *
18268
- * @author Vova Feldman (@svovaf)
18269
- * @since 1.0.6
18270
- *
18271
- * @param Freemius $parent_fs
18272
- * @param bool|int|null $network_level_or_blog_id True for network level opt-in and integer for opt-in for specified blog in the network.
18273
- * @param FS_Plugin_License $bundle_license Since 2.4.0. If provided, this license will be activated for the add-on.
18274
- */
18275
- private function _activate_addon_account(
18276
- Freemius $parent_fs,
18277
- $network_level_or_blog_id = null,
18278
- FS_Plugin_License $bundle_license = null
18279
- ) {
18280
- if ( $this->is_registered() ) {
18281
- // Already activated.
18282
- return;
18283
- }
18284
-
18285
- /**
18286
- * Do not override the `uid` if network-level opt-in since the call to `get_sites_for_network_level_optin()`
18287
- * already returns the data for the current blog.
18288
- *
18289
- * @author Leo Fajardo (@leorw)
18290
- * @since 2.3.0
18291
- */
18292
- $uid_param_to_override = ( true === $network_level_or_blog_id ) ?
18293
- array() :
18294
- array( 'uid' => $this->get_anonymous_id() );
18295
-
18296
- $params = $this->get_install_data_for_api(
18297
- $uid_param_to_override,
18298
- false,
18299
- false,
18300
- /**
18301
- * Do not include the data for the current blog if network-level opt-in since the call to `get_sites_for_network_level_optin`
18302
- * already includes the data for it.
18303
- *
18304
- * @author Leo Fajardo (@leorw)
18305
- * @since 2.3.0
18306
- */
18307
- ( true !== $network_level_or_blog_id )
18308
- );
18309
-
18310
- if ( true === $network_level_or_blog_id ) {
18311
- $params['sites'] = $this->get_sites_for_network_level_optin();
18312
-
18313
- if ( empty( $params['sites'] ) ) {
18314
- return;
18315
- }
18316
- }
18317
-
18318
- if ( is_object( $bundle_license ) ) {
18319
- $params['license_key'] = $bundle_license->secret_key;
18320
- }
18321
-
18322
- // Activate add-on with parent plugin credentials.
18323
- $result = $parent_fs->get_api_site_scope()->call(
18324
- "/addons/{$this->_plugin->id}/installs.json",
18325
- 'post',
18326
- $params
18327
- );
18328
-
18329
- if ( ! $this->is_api_result_object( $result, 'installs' ) ) {
18330
- if ( is_object( $bundle_license ) ) {
18331
- /**
18332
- * When a license object is provided, it's an attempt by the SDK to activate a bundle license and not a user-initiated action, therefore, do not show any admin notice to avoid confusion (e.g.: the notice will show up just above the opt-in link). If the license activation fails, the admin will see an opt-in link instead.
18333
- *
18334
- * @author Leo Fajardo (@leorw)
18335
- * @since 2.4.0
18336
- */
18337
- } else {
18338
- $error_message = FS_Api::is_api_error_object( $result ) ?
18339
- $result->error->message :
18340
- $this->get_text_inline( 'An unknown error has occurred.', 'unknown-error' );
18341
-
18342
- $this->_admin_notices->add(
18343
- sprintf( $this->get_text_inline( 'Couldn\'t activate %s.', 'could-not-activate-x' ), $this->get_plugin_name() ) . ' ' .
18344
- $this->get_text_inline( 'Please contact us with the following message:', 'contact-us-with-error-message' ) . ' ' . '<b>' . $error_message . '</b>',
18345
- $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
18346
- 'error'
18347
- );
18348
- }
18349
-
18350
- return;
18351
- }
18352
-
18353
- $addon_installs = $result->installs;
18354
- foreach ( $addon_installs as $key => $addon_install ) {
18355
- $addon_installs[ $key ] = new FS_Site( $addon_install );
18356
- }
18357
-
18358
- $first_install = $addon_installs[0];
18359
-
18360
- // Get user information based on parent's plugin.
18361
- $user = $parent_fs->get_user();
18362
-
18363
- // First of all, set site and user info - otherwise we won't
18364
- // be able to invoke API calls.
18365
- $this->_site = $first_install;
18366
- $this->_user = $user;
18367
-
18368
- // Sync add-on plans.
18369
- $this->_sync_plans();
18370
-
18371
- $this->handle_account_connection( $addon_installs, ! fs_is_network_admin() );
18372
-
18373
- // Get site's current plan.
18374
- //$this->_site->plan = $this->_get_plan_by_id( $this->_site->plan->id );
18375
-
18376
- // Sync licenses.
18377
- $this->_sync_licenses();
18378
-
18379
- if ( ! fs_is_network_admin() ) {
18380
- // Try to activate premium license.
18381
- $this->_activate_license( true, $bundle_license );
18382
-
18383
- if ( is_object( $bundle_license ) ) {
18384
- $this->maybe_activate_bundle_license( $bundle_license );
18385
- }
18386
- } else {
18387
- if ( is_object( $bundle_license ) ) {
18388
- $premium_license = $bundle_license;
18389
- } else {
18390
- $license_id = fs_request_get( 'license_id' );
18391
-
18392
- if ( is_object( $this->_site ) &&
18393
- FS_Plugin_License::is_valid_id( $license_id ) &&
18394
- $license_id == $this->_site->license_id
18395
- ) {
18396
- // License is already activated.
18397
- return;
18398
- }
18399
-
18400
- $premium_license = FS_Plugin_License::is_valid_id( $license_id ) ?
18401
- $this->_get_license_by_id( $license_id ) :
18402
- $this->_get_available_premium_license();
18403
- }
18404
-
18405
- if ( is_object( $premium_license ) ) {
18406
- $this->maybe_network_activate_addon_license( $premium_license );
18407
- }
18408
- }
18409
- }
18410
-
18411
- /**
18412
- * @author Leo Fajardo (@leorw)
18413
- * @since 2.3.0
18414
- *
18415
- * @param FS_Site[] $installs
18416
- * @param bool $is_site_level
18417
- */
18418
- private function handle_account_connection( $installs, $is_site_level ) {
18419
- $first_install = $installs[0];
18420
-
18421
- if ( $is_site_level ) {
18422
- $this->_set_account( $this->_user, $first_install );
18423
-
18424
- $this->do_action( 'after_account_connection', $this->_user, $first_install );
18425
- } else {
18426
- $this->_store_user();
18427
-
18428
- // Map site addresses to their blog IDs.
18429
- $address_to_blog_map = $this->get_address_to_blog_map();
18430
-
18431
- $first_blog_id = null;
18432
- $blog_2_install_map = array();
18433
- foreach ( $installs as $install ) {
18434
- $address = trailingslashit( fs_strip_url_protocol( $install->url ) );
18435
- $blog_id = $address_to_blog_map[ $address ];
18436
-
18437
- $this->_store_site( true, $blog_id, $install );
18438
-
18439
- if ( is_null( $first_blog_id ) ) {
18440
- $first_blog_id = $blog_id;
18441
- }
18442
-
18443
- $blog_2_install_map[ $blog_id ] = $install;
18444
- }
18445
-
18446
- if ( ! FS_User::is_valid_id( $this->_storage->network_user_id ) ||
18447
- ! is_object( self::_get_user_by_id( $this->_storage->network_user_id ) )
18448
- ) {
18449
- // Store network user.
18450
- $this->_storage->network_user_id = $this->_user->id;
18451
- }
18452
-
18453
- if ( ! FS_Site::is_valid_id( $this->_storage->network_install_blog_id ) ) {
18454
- $this->_storage->network_install_blog_id = $first_blog_id;
18455
- }
18456
-
18457
- if ( count( $installs ) === count( $address_to_blog_map ) ) {
18458
- // Super admin opted in for all sites in the network.
18459
- $this->_storage->is_network_connected = true;
18460
- }
18461
-
18462
- $this->_store_licenses( false );
18463
-
18464
- self::$_accounts->store();
18465
-
18466
- // Don't sync the installs data on network upgrade
18467
- if ( ! $this->network_upgrade_mode_completed() ) {
18468
- $this->send_installs_update();
18469
- }
18470
-
18471
- $current_blog = get_current_blog_id();
18472
-
18473
- foreach ( $blog_2_install_map as $blog_id => $install ) {
18474
- $this->switch_to_blog( $blog_id );
18475
-
18476
- $this->do_action( 'after_account_connection', $this->_user, $install );
18477
- }
18478
-
18479
- // Switch install context back to the first install.
18480
- $this->switch_to_blog(
18481
- $current_blog,
18482
- $first_install,
18483
- ( $this->_site->id != $first_install->id )
18484
- );
18485
-
18486
- $this->do_action( 'after_network_account_connection', $this->_user, $blog_2_install_map );
18487
- }
18488
- }
18489
-
18490
- /**
18491
- * Tries to activate parent account based on add-on's info.
18492
- *
18493
- * @author Vova Feldman (@svovaf)
18494
- * @since 1.2.2.7
18495
- *
18496
- * @param Freemius $parent_fs
18497
- */
18498
- private function activate_parent_account( Freemius $parent_fs ) {
18499
- if ( ! $this->is_addon() ) {
18500
- // This is not an add-on.
18501
- return;
18502
- }
18503
-
18504
- if ( $parent_fs->is_registered() ) {
18505
- // Already activated.
18506
- return;
18507
- }
18508
-
18509
- // Activate parent with add-on's user credentials.
18510
- $parent_install = $this->get_api_user_scope()->call(
18511
- "/plugins/{$parent_fs->_plugin->id}/installs.json",
18512
- 'post',
18513
- $parent_fs->get_install_data_for_api( array(
18514
- 'uid' => $parent_fs->get_anonymous_id(),
18515
- ), false, false )
18516
- );
18517
-
18518
- if ( isset( $parent_install->error ) ) {
18519
- $this->_admin_notices->add(
18520
- sprintf( $this->get_text_inline( 'Couldn\'t activate %s.', 'could-not-activate-x' ), $this->get_plugin_name() ) . ' ' .
18521
- $this->get_text_inline( 'Please contact us with the following message:', 'contact-us-with-error-message' ) . ' ' . '<b>' . $parent_install->error->message . '</b>',
18522
- $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
18523
- 'error'
18524
- );
18525
-
18526
- return;
18527
- }
18528
-
18529
- $parent_fs->_admin_notices->remove_sticky( 'connect_account' );
18530
-
18531
- if ( $parent_fs->is_pending_activation() ) {
18532
- $parent_fs->_admin_notices->remove_sticky( 'activation_pending' );
18533
-
18534
- unset( $parent_fs->_storage->is_pending_activation );
18535
- }
18536
-
18537
- // Get user information based on parent's plugin.
18538
- $user = $this->get_user();
18539
-
18540
- // First of all, set site info - otherwise we won't
18541
- // be able to invoke API calls.
18542
- $parent_fs->_site = new FS_Site( $parent_install );
18543
- $parent_fs->_user = $user;
18544
-
18545
- // Sync add-on plans.
18546
- $parent_fs->_sync_plans();
18547
-
18548
- $parent_fs->_set_account( $user, $parent_fs->_site );
18549
- }
18550
-
18551
- #endregion
18552
-
18553
- #----------------------------------------------------------------------------------
18554
- #region Admin Menu Items
18555
- #----------------------------------------------------------------------------------
18556
-
18557
- private $_menu_items = array();
18558
-
18559
- /**
18560
- * @author Vova Feldman (@svovaf)
18561
- * @since 1.2.1.8
18562
- *
18563
- * @return array
18564
- */
18565
- function get_menu_items() {
18566
- return $this->_menu_items;
18567
- }
18568
-
18569
- /**
18570
- * @author Vova Feldman (@svovaf)
18571
- * @since 1.0.7
18572
- *
18573
- * @return string
18574
- */
18575
- function get_menu_slug() {
18576
- return $this->_menu->get_slug();
18577
- }
18578
-
18579
- /**
18580
- * @author Vova Feldman (@svovaf)
18581
- * @since 1.0.9
18582
- */
18583
- function _prepare_admin_menu() {
18584
- // if ( ! $this->is_on() ) {
18585
- // return;
18586
- // }
18587
-
18588
- if ( is_object( $this->_site ) && ! $this->is_registered() ) {
18589
- return;
18590
- }
18591
-
18592
- /**
18593
- * When running from a site admin with a network activated module and the connection
18594
- * was NOT delegated and the user still haven't skipped or opted-in, then hide the
18595
- * site level settings.
18596
- *
18597
- * @author Vova Feldman (@svovaf)
18598
- * @since 2.0.0
18599
- */
18600
- $should_hide_site_admin_settings = (
18601
- $this->_is_network_active &&
18602
- ! fs_is_network_admin() &&
18603
- ! $this->is_delegated_connection() &&
18604
- ! $this->is_anonymous() &&
18605
- ! $this->is_registered()
18606
- );
18607
-
18608
- $should_hide_site_admin_settings = $this->apply_filters( 'should_hide_site_admin_settings_on_network_activation_mode', $should_hide_site_admin_settings );
18609
-
18610
- if ( ( ! $this->has_api_connectivity() && ! $this->is_enable_anonymous() ) ||
18611
- $should_hide_site_admin_settings
18612
- ) {
18613
- $this->_menu->remove_menu_item( $should_hide_site_admin_settings );
18614
- } else {
18615
- $this->do_action( fs_is_network_admin() ?
18616
- 'before_network_admin_menu_init' :
18617
- 'before_admin_menu_init'
18618
- );
18619
-
18620
- $this->add_menu_action();
18621
-
18622
- $this->add_network_menu_when_missing();
18623
-
18624
- $this->add_submenu_items();
18625
- }
18626
- }
18627
-
18628
- /**
18629
- * Admin dashboard menu items modifications.
18630
- *
18631
- * NOTE: admin_menu action executed before admin_init.
18632
- *
18633
- * @author Vova Feldman (@svovaf)
18634
- * @since 1.0.7
18635
- *
18636
- */
18637
- private function add_menu_action() {
18638
- if ( $this->is_activation_mode() ) {
18639
- if ( $this->show_opt_in_on_setting_page() ) {
18640
- $this->override_plugin_menu_with_activation();
18641
- } else {
18642
- /**
18643
- * Handle theme opt-in when the opt-in form shows as a dialog box in the themes page.
18644
- */
18645
- if ( fs_request_is_action( $this->get_unique_affix() . '_activate_existing' ) ) {
18646
- add_action( 'load-themes.php', array( &$this, '_install_with_current_user' ) );
18647
- } else if ( fs_request_is_action( $this->get_unique_affix() . '_activate_new' ) ||
18648
- fs_request_get_bool( 'pending_activation' )
18649
- ) {
18650
- add_action( 'load-themes.php', array( &$this, '_install_with_new_user' ) );
18651
- }
18652
- }
18653
- } else {
18654
- if ( ! $this->is_registered() ) {
18655
- // If not registered try to install user.
18656
- if ( fs_request_is_action( $this->get_unique_affix() . '_activate_new' ) ) {
18657
- $this->_install_with_new_user();
18658
- }
18659
- } else if (
18660
- fs_request_is_action( 'sync_user' ) &&
18661
- ( ! $this->has_settings_menu() || $this->show_opt_in_on_themes_page() )
18662
- ) {
18663
- $this->_handle_account_user_sync();
18664
- }
18665
- }
18666
- }
18667
-
18668
- /**
18669
- * @author Vova Feldman (@svovaf)
18670
- * @since 1.0.1
18671
- */
18672
- function _redirect_on_clicked_menu_link() {
18673
- $this->_logger->entrance();
18674
-
18675
- $page = fs_request_get('page');
18676
- $page = is_string($page) ? strtolower($page) : '';
18677
-
18678
- $this->_logger->log( 'page = ' . $page );
18679
-
18680
- foreach ( $this->_menu_items as $priority => $items ) {
18681
- foreach ( $items as $item ) {
18682
- if ( isset( $item['url'] ) ) {
18683
- if ( $page === $this->_menu->get_slug( strtolower( $item['menu_slug'] ) ) ) {
18684
- $this->_logger->log( 'Redirecting to ' . $item['url'] );
18685
-
18686
- fs_redirect( $item['url'] );
18687
- }
18688
- }
18689
- }
18690
- }
18691
- }
18692
-
18693
- /**
18694
- * Remove plugin's all admin menu items & pages, and replace with activation page.
18695
- *
18696
- * @author Vova Feldman (@svovaf)
18697
- * @since 1.0.1
18698
- */
18699
- private function override_plugin_menu_with_activation() {
18700
- $this->_logger->entrance();
18701
-
18702
- $hook = false;
18703
-
18704
- if ( ! $this->has_settings_menu() ) {
18705
- // Add the opt-in page without a menu item.
18706
- $hook = FS_Admin_Menu_Manager::add_subpage(
18707
- null,
18708
- $this->get_plugin_name(),
18709
- $this->get_plugin_name(),
18710
- 'manage_options',
18711
- $this->_slug,
18712
- array( &$this, '_connect_page_render' )
18713
- );
18714
- } else if ( $this->_menu->is_top_level() ) {
18715
- if ( $this->_menu->is_override_exact() ) {
18716
- // Make sure the current page is matching the activation page.
18717
- if ( ! $this->is_matching_url( $this->get_activation_url() ) ) {
18718
- return;
18719
- }
18720
- }
18721
-
18722
- $hook = $this->_menu->override_menu_item( array( &$this, '_connect_page_render' ) );
18723
-
18724
- if ( false === $hook ) {
18725
- // Create new menu item just for the opt-in.
18726
- $hook = FS_Admin_Menu_Manager::add_page(
18727
- $this->get_plugin_name(),
18728
- $this->get_plugin_name(),
18729
- 'manage_options',
18730
- $this->_menu->get_slug(),
18731
- array( &$this, '_connect_page_render' )
18732
- );
18733
- }
18734
- } else {
18735
- $menus = array( $this->_menu->get_parent_slug() );
18736
-
18737
- if ( $this->_menu->is_override_exact() ) {
18738
- // Make sure the current page is matching the activation page.
18739
- if ( ! $this->is_matching_url( $this->get_activation_url() ) ) {
18740
- return;
18741
- }
18742
- }
18743
-
18744
- foreach ( $menus as $parent_slug ) {
18745
- $hook = $this->_menu->override_submenu_action(
18746
- $parent_slug,
18747
- $this->_menu->get_raw_slug(),
18748
- array( &$this, '_connect_page_render' )
18749
- );
18750
-
18751
- if ( false !== $hook ) {
18752
- // Found plugin's submenu item.
18753
- break;
18754
- }
18755
- }
18756
- }
18757
-
18758
- if ( $this->is_activation_page() ) {
18759
- // Clean admin page from distracting content.
18760
- self::_clean_admin_content_section();
18761
- }
18762
-
18763
- if ( false !== $hook ) {
18764
- if ( fs_request_is_action( $this->get_unique_affix() . '_activate_existing' ) ) {
18765
- $this->_install_with_current_user();
18766
- } else if ( fs_request_is_action( $this->get_unique_affix() . '_activate_new' ) ) {
18767
- $this->_install_with_new_user();
18768
- }
18769
- }
18770
- }
18771
-
18772
- /**
18773
- * If a plugin was network activated and connected but don't have a network
18774
- * level settings, then add an artificial menu item for the Account and other
18775
- * Freemius settings.
18776
- *
18777
- * @author Vova Feldman (@svovaf)
18778
- * @since 2.0.0
18779
- */
18780
- private function add_network_menu_when_missing() {
18781
- $this->_logger->entrance();
18782
-
18783
- if ( ! $this->_is_network_active ) {
18784
- // Plugin wasn't activated on the network level.
18785
- return;
18786
- }
18787
-
18788
- if ( ! fs_is_network_admin() ) {
18789
- // The context is not the network admin.
18790
- return;
18791
- }
18792
-
18793
- if ( $this->_menu->has_network_menu() ) {
18794
- // Plugin already has a network level menu.
18795
- return;
18796
- }
18797
-
18798
- if ( $this->is_network_activation_mode() ) {
18799
- /**
18800
- * Do not add during activation mode, otherwise, there will be duplicate menus while the opt-in
18801
- * screen is being shown.
18802
- *
18803
- * @author Leo Fajardo (@leorw)
18804
- */
18805
- return;
18806
- }
18807
-
18808
- if ( ! WP_FS__SHOW_NETWORK_EVEN_WHEN_DELEGATED ) {
18809
- if ( $this->is_network_delegated_connection() ) {
18810
- // Super-admin delegated the connection to the site admins.
18811
- return;
18812
- }
18813
- }
18814
-
18815
- if ( ! $this->_menu->has_menu() || $this->_menu->is_top_level() ) {
18816
-
18817
- if ( $this->_menu->has_menu() ||
18818
- ! $this->is_addon() ||
18819
- $this->is_activation_mode()
18820
- ) {
18821
- $this->_dynamically_added_top_level_page_hook_name = $this->_menu->add_page_and_update(
18822
- $this->get_plugin_name(),
18823
- $this->get_plugin_name(),
18824
- 'manage_options',
18825
- $this->_menu->has_menu() ? $this->_menu->get_slug() : $this->_slug
18826
- );
18827
- }
18828
- } else {
18829
- $this->_menu->add_subpage_and_update(
18830
- $this->_menu->get_parent_slug(),
18831
- $this->get_plugin_name(),
18832
- $this->get_plugin_name(),
18833
- 'manage_options',
18834
- $this->_menu->get_slug()
18835
- );
18836
- }
18837
- }
18838
-
18839
- /**
18840
- * @author Leo Fajardo (@leorw)
18841
- * @since 1.2.1
18842
- *
18843
- * return string
18844
- */
18845
- function get_top_level_menu_capability() {
18846
- global $menu;
18847
-
18848
- $top_level_menu_slug = $this->get_top_level_menu_slug();
18849
-
18850
- foreach ( $menu as $menu_info ) {
18851
- /**
18852
- * The second element in the menu info array is the capability/role that has access to the menu and the
18853
- * third element is the menu slug.
18854
- */
18855
- if ( $menu_info[2] === $top_level_menu_slug ) {
18856
- return $menu_info[1];
18857
- }
18858
- }
18859
-
18860
- return 'read';
18861
- }
18862
-
18863
- /**
18864
- * @author Vova Feldman (@svovaf)
18865
- * @since 1.0.0
18866
- *
18867
- * @return string
18868
- */
18869
- private function get_top_level_menu_slug() {
18870
- return ( $this->is_addon() ?
18871
- $this->get_parent_instance()->_menu->get_top_level_menu_slug() :
18872
- $this->_menu->get_top_level_menu_slug() );
18873
- }
18874
-
18875
- /**
18876
- * @author Vova Feldman (@svovaf)
18877
- * @since 1.2.2.7
18878
- *
18879
- * @return string
18880
- */
18881
- function get_pricing_cta_label() {
18882
- $label = $this->get_text_inline( 'Upgrade', 'upgrade' );
18883
-
18884
- if ( $this->is_in_trial_promotion() &&
18885
- ! $this->is_paying_or_trial()
18886
- ) {
18887
- // If running a trial promotion, modify the pricing to load the trial.
18888
- $label = $this->get_text_inline( 'Start Trial', 'start-trial' );
18889
- } else if ( $this->is_paying() ) {
18890
- $label = $this->get_text_inline( 'Pricing', 'pricing' );
18891
- }
18892
-
18893
- return $label;
18894
- }
18895
-
18896
- /**
18897
- * @author Vova Feldman (@svovaf)
18898
- * @since 1.2.2.7
18899
- *
18900
- * @return bool
18901
- */
18902
- function is_pricing_page_visible() {
18903
- return (
18904
- // Has at least one paid plan.
18905
- $this->has_paid_plan() &&
18906
- // Didn't ask to hide the pricing page.
18907
- $this->is_page_visible( 'pricing' ) &&
18908
- // Don't have a valid active license or has more than one plan.
18909
- ( ! $this->is_paying() || ! $this->is_single_plan( true ) )
18910
- );
18911
- }
18912
-
18913
- /**
18914
- * @author Leo Fajardo (@leorw)
18915
- * @since 2.3.0
18916
- *
18917
- * @param bool $is_activation_mode
18918
- *
18919
- * @return bool
18920
- */
18921
- private function should_add_submenu_or_action_links( $is_activation_mode ) {
18922
- if ( $this->is_addon() ) {
18923
- // No submenu items or action links for add-ons.
18924
- return false;
18925
- }
18926
-
18927
- if ( $this->show_opt_in_on_themes_page() ) {
18928
- if ( ! fs_is_network_admin() ) {
18929
- // Also add action links or submenu items when running in a free .org theme so the tabs will be visible.
18930
- return true;
18931
- }
18932
- } else if ( $is_activation_mode ) {
18933
- // Don't show submenu-items/tabs in activation mode, unless it's a wp.org theme.
18934
- return false;
18935
- }
18936
-
18937
- if ( fs_is_network_admin() ) {
18938
- /**
18939
- * Add submenu items or action links to network level when plugin was network activated and the super
18940
- * admin did NOT delegate the connection of all sites to site admins.
18941
- */
18942
- return (
18943
- $this->_is_network_active &&
18944
- ( WP_FS__SHOW_NETWORK_EVEN_WHEN_DELEGATED ||
18945
- ! $this->is_network_delegated_connection() )
18946
- );
18947
- }
18948
-
18949
- return ( ! $this->_is_network_active || $this->is_delegated_connection() );
18950
- }
18951
-
18952
- /**
18953
- * Add default Freemius menu items.
18954
- *
18955
- * @author Vova Feldman (@svovaf)
18956
- * @since 1.0.0
18957
- * @since 1.2.2.7 Also add submenu items when running in a free .org theme so the tabs will be visible.
18958
- */
18959
- private function add_submenu_items() {
18960
- $this->_logger->entrance();
18961
-
18962
- $is_activation_mode = $this->is_activation_mode();
18963
-
18964
- $add_submenu_items = $this->should_add_submenu_or_action_links( $is_activation_mode );
18965
-
18966
- if ( $add_submenu_items ) {
18967
- if ( $this->has_affiliate_program() ) {
18968
- // Add affiliation page.
18969
- $this->add_submenu_item(
18970
- $this->get_text_inline( 'Affiliation', 'affiliation' ),
18971
- array( &$this, '_affiliation_page_render' ),
18972
- $this->get_plugin_name() . ' &ndash; ' . $this->get_text_inline( 'Affiliation', 'affiliation' ),
18973
- 'manage_options',
18974
- 'affiliation',
18975
- 'Freemius::_clean_admin_content_section',
18976
- WP_FS__DEFAULT_PRIORITY,
18977
- $this->is_submenu_item_visible( 'affiliation' )
18978
- );
18979
- }
18980
- }
18981
-
18982
- if ( $add_submenu_items ||
18983
- ( $is_activation_mode &&
18984
- $this->is_only_premium() &&
18985
- $this->is_admin_page( 'account' ) &&
18986
- fs_request_is_action( $this->get_unique_affix() . '_sync_license' )
18987
- )
18988
- ) {
18989
- if ( ! WP_FS__DEMO_MODE && $this->is_registered() ) {
18990
- $show_account = (
18991
- $this->is_submenu_item_visible( 'account' ) &&
18992
- /**
18993
- * @since 1.2.2.7 Don't show the Account for free WP.org themes without any paid plans.
18994
- */
18995
- ( ! $this->is_free_wp_org_theme() || $this->has_paid_plan() )
18996
- );
18997
-
18998
- // Add user account page.
18999
- $this->add_submenu_item(
19000
- $this->get_text_inline( 'Account', 'account' ),
19001
- array( &$this, '_account_page_render' ),
19002
- $this->get_plugin_name() . ' &ndash; ' . $this->get_text_inline( 'Account', 'account' ),
19003
- 'manage_options',
19004
- 'account',
19005
- array( &$this, '_account_page_load' ),
19006
- WP_FS__DEFAULT_PRIORITY,
19007
- ( $add_submenu_items && $show_account )
19008
- );
19009
- }
19010
- }
19011
-
19012
- if ( $add_submenu_items ) {
19013
- if (! WP_FS__DEMO_MODE && ! $this->is_whitelabeled() ) {
19014
- // Add contact page.
19015
- $this->add_submenu_item(
19016
- $this->get_text_inline( 'Contact Us', 'contact-us' ),
19017
- array( &$this, '_contact_page_render' ),
19018
- $this->get_plugin_name() . ' &ndash; ' . $this->get_text_inline( 'Contact Us', 'contact-us' ),
19019
- 'manage_options',
19020
- 'contact',
19021
- 'Freemius::_clean_admin_content_section',
19022
- WP_FS__DEFAULT_PRIORITY,
19023
- $this->is_submenu_item_visible( 'contact' )
19024
- );
19025
- }
19026
-
19027
- if ( $this->has_addons() ) {
19028
- $this->add_submenu_item(
19029
- $this->get_text_inline( 'Add-Ons', 'add-ons' ),
19030
- array( &$this, '_addons_page_render' ),
19031
- $this->get_plugin_name() . ' &ndash; ' . $this->get_text_inline( 'Add-Ons', 'add-ons' ),
19032
- 'manage_options',
19033
- 'addons',
19034
- array( &$this, '_addons_page_load' ),
19035
- WP_FS__LOWEST_PRIORITY - 1,
19036
- $this->is_submenu_item_visible( 'addons' )
19037
- );
19038
- }
19039
- }
19040
-
19041
- if ( $add_submenu_items ||
19042
- ( $is_activation_mode && $this->is_only_premium() && $this->is_admin_page( 'pricing' ) )
19043
- ) {
19044
- if (! WP_FS__DEMO_MODE && ! $this->is_whitelabeled() ) {
19045
- $show_pricing = (
19046
- $this->is_submenu_item_visible( 'pricing' ) &&
19047
- $this->is_pricing_page_visible()
19048
- );
19049
-
19050
- $pricing_cta_text = $this->get_pricing_cta_label();
19051
- $pricing_class = 'upgrade-mode';
19052
- if ( $show_pricing ) {
19053
- if ( $this->is_in_trial_promotion() &&
19054
- ! $this->is_paying_or_trial()
19055
- ) {
19056
- // If running a trial promotion, modify the pricing to load the trial.
19057
- $pricing_class = 'trial-mode';
19058
- } else if ( $this->is_paying() ) {
19059
- $pricing_class = '';
19060
- }
19061
- }
19062
-
19063
- // Add upgrade/pricing page.
19064
- $this->add_submenu_item(
19065
- $pricing_cta_text . '&nbsp;&nbsp;' . ( is_rtl() ? $this->get_text_x_inline( '&#x2190;', 'ASCII arrow left icon', 'symbol_arrow-left' ) : $this->get_text_x_inline( '&#x27a4;', 'ASCII arrow right icon', 'symbol_arrow-right' ) ),
19066
- array( &$this, '_pricing_page_render' ),
19067
- $this->get_plugin_name() . ' &ndash; ' . $this->get_text_x_inline( 'Pricing', 'noun', 'pricing' ),
19068
- 'manage_options',
19069
- 'pricing',
19070
- 'Freemius::_clean_admin_content_section',
19071
- WP_FS__LOWEST_PRIORITY,
19072
- ( $add_submenu_items && $show_pricing ),
19073
- $pricing_class
19074
- );
19075
- }
19076
- }
19077
-
19078
- if ( ! $is_activation_mode || ( true !== $this->_storage->require_license_activation ) ) {
19079
- /**
19080
- * Add the other menu items if there are any when not in activation mode or license activation is not
19081
- * required (license activation is required for registered or anonymous users after activating the
19082
- * premium version when the site is not in trial mode or there's no active valid license).
19083
- *
19084
- * @author Leo Fajardo (@leorw)
19085
- * @since 2.2.1
19086
- */
19087
- if ( 0 < count( $this->_menu_items ) ) {
19088
- if ( ! $this->_menu->is_top_level() ) {
19089
- fs_enqueue_local_style( 'fs_common', '/admin/common.css' );
19090
-
19091
- // Append submenu items right after the plugin's submenu item.
19092
- $this->order_sub_submenu_items();
19093
- } else {
19094
- // Append submenu items.
19095
- $this->embed_submenu_items();
19096
- }
19097
- }
19098
- }
19099
- }
19100
-
19101
- /**
19102
- * Moved the actual submenu item additions to a separated function,
19103
- * in order to support sub-submenu items when the plugin's settings
19104
- * only have a submenu and not top-level menu item.
19105
- *
19106
- * @author Vova Feldman (@svovaf)
19107
- * @since 1.1.4
19108
- */
19109
- private function embed_submenu_items() {
19110
- $item_template = $this->_menu->is_top_level() ?
19111
- '<span class="fs-submenu-item %s %s %s">%s</span>' :
19112
- '<span class="fs-submenu-item fs-sub %s %s %s">%s</span>';
19113
-
19114
- $top_level_menu_capability = $this->get_top_level_menu_capability();
19115
-
19116
- ksort( $this->_menu_items );
19117
-
19118
- $is_first_submenu_item = true;
19119
-
19120
- foreach ( $this->_menu_items as $priority => $items ) {
19121
- foreach ( $items as $item ) {
19122
- $capability = ( ! empty( $item['capability'] ) ? $item['capability'] : $top_level_menu_capability );
19123
-
19124
- $menu_item = sprintf(
19125
- $item_template,
19126
- $this->get_unique_affix(),
19127
- $item['menu_slug'],
19128
- ! empty( $item['class'] ) ? $item['class'] : '',
19129
- $item['menu_title']
19130
- );
19131
-
19132
- $top_level_menu_slug = $this->get_top_level_menu_slug();
19133
- $menu_slug = $this->_menu->get_slug( $item['menu_slug'] );
19134
-
19135
- if ( ! isset( $item['url'] ) ) {
19136
- $hook = FS_Admin_Menu_Manager::add_subpage(
19137
- $item['show_submenu'] ?
19138
- $top_level_menu_slug :
19139
- null,
19140
- $item['page_title'],
19141
- $menu_item,
19142
- $capability,
19143
- $menu_slug,
19144
- $item['render_function']
19145
- );
19146
-
19147
- if ( false !== $item['before_render_function'] ) {
19148
- add_action( "load-$hook", $item['before_render_function'] );
19149
- }
19150
- } else {
19151
- FS_Admin_Menu_Manager::add_subpage(
19152
- $item['show_submenu'] ?
19153
- $top_level_menu_slug :
19154
- null,
19155
- $item['page_title'],
19156
- $menu_item,
19157
- $capability,
19158
- $menu_slug,
19159
- array( $this, '' )
19160
- );
19161
- }
19162
-
19163
- if ( $item['show_submenu'] && $is_first_submenu_item ) {
19164
- if ( $this->_is_network_active && ! empty( $this->_dynamically_added_top_level_page_hook_name ) ) {
19165
- /**
19166
- * If the top-level menu has been dynamically created, remove the first submenu item that
19167
- * WordPress automatically creates when there's no submenu item whose slug matches the
19168
- * parent's. In the following example, the `Awesome Plugin` submenu item will be removed.
19169
- *
19170
- * Awesome Plugin
19171
- * - Awesome Plugin <-- we want to remove this since there's no real setting page for the top-level
19172
- *
19173
- * @author Leo Fajardo (@leorw)
19174
- */
19175
- remove_submenu_page( $top_level_menu_slug, $top_level_menu_slug );
19176
- }
19177
-
19178
- $is_first_submenu_item = false;
19179
- }
19180
- }
19181
- }
19182
- }
19183
-
19184
- /**
19185
- * Re-order the submenu items so all Freemius added new submenu items
19186
- * are added right after the plugin's settings submenu item.
19187
- *
19188
- * @author Vova Feldman (@svovaf)
19189
- * @since 1.1.4
19190
- */
19191
- private function order_sub_submenu_items() {
19192
- global $submenu;
19193
-
19194
- $menu_slug = $this->_menu->get_top_level_menu_slug();
19195
-
19196
- /**
19197
- * Before "admin_menu" fires, WordPress will loop over the default submenus and remove pages for which the user
19198
- * does not have permissions. So in case a plugin does not have top-level menu but does have submenus under any
19199
- * of the default menus, only users that have the right role can access its sub-submenus (Account, Contact Us,
19200
- * Support Forum, etc.) since $submenu[ $menu_slug ] will be empty if the user doesn't have permission.
19201
- *
19202
- * In case a plugin does not have submenus under any of the default menus but does have submenus under the menu
19203
- * of another plugin, only users that have the right role can access its sub-submenus since we will use the
19204
- * capability needed to access the parent menu as the capability for the submenus that we will add.
19205
- */
19206
- if ( empty( $submenu[ $menu_slug ] ) ) {
19207
- return;
19208
- }
19209
-
19210
- $top_level_menu = &$submenu[ $menu_slug ];
19211
-
19212
- $all_submenu_items_after = array();
19213
-
19214
- $found_submenu_item = false;
19215
-
19216
- foreach ( $top_level_menu as $submenu_id => $meta ) {
19217
- if ( $found_submenu_item ) {
19218
- // Remove all submenu items after the plugin's submenu item.
19219
- $all_submenu_items_after[] = $meta;
19220
- unset( $top_level_menu[ $submenu_id ] );
19221
- }
19222
-
19223
- if ( $this->_menu->get_raw_slug() === $meta[2] ) {
19224
- // Found the submenu item, put all below.
19225
- $found_submenu_item = true;
19226
- continue;
19227
- }
19228
- }
19229
-
19230
- // Embed all plugin's new submenu items.
19231
- $this->embed_submenu_items();
19232
-
19233
- // Start with specially high number to make sure it's appended.
19234
- $i = max( 10000, max( array_keys( $top_level_menu ) ) + 1 );
19235
- foreach ( $all_submenu_items_after as $meta ) {
19236
- $top_level_menu[ $i ] = $meta;
19237
- $i ++;
19238
- }
19239
-
19240
- // Sort submenu items.
19241
- ksort( $top_level_menu );
19242
- }
19243
-
19244
- /**
19245
- * Helper method to return the module's support forum URL.
19246
- *
19247
- * @author Vova Feldman (@svovaf)
19248
- * @since 1.2.2.7
19249
- *
19250
- * @return string
19251
- */
19252
- function get_support_forum_url() {
19253
- return $this->apply_filters( 'support_forum_url', "https://wordpress.org/support/{$this->_module_type}/{$this->_slug}" );
19254
- }
19255
-
19256
- /**
19257
- * Displays the Support Forum link when enabled.
19258
- *
19259
- * Can be filtered like so:
19260
- *
19261
- * function _fs_show_support_menu( $is_visible, $menu_id ) {
19262
- * if ( 'support' === $menu_id ) {
19263
- * return _fs->is_registered();
19264
- * }
19265
- * return $is_visible;
19266
- * }
19267
- * _fs()->add_filter('is_submenu_visible', '_fs_show_support_menu', 10, 2);
19268
- *
19269
- */
19270
- function _add_default_submenu_items() {
19271
- if ( ! $this->is_on() ) {
19272
- return;
19273
- }
19274
-
19275
- if ( ! $this->is_activation_mode() &&
19276
- ( ( $this->_is_network_active && fs_is_network_admin() ) ||
19277
- ( ! $this->_is_network_active && is_admin() ) )
19278
- ) {
19279
- $this->add_submenu_link_item(
19280
- $this->apply_filters( 'support_forum_submenu', $this->get_text_inline( 'Support Forum', 'support-forum' ) ),
19281
- $this->get_support_forum_url(),
19282
- 'wp-support-forum',
19283
- null,
19284
- 50,
19285
- $this->is_submenu_item_visible( 'support' )
19286
- );
19287
- }
19288
- }
19289
-
19290
- /**
19291
- * @author Vova Feldman (@svovaf)
19292
- * @since 1.0.1
19293
- *
19294
- * @param string $menu_title
19295
- * @param callable $render_function
19296
- * @param bool|string $page_title
19297
- * @param string $capability
19298
- * @param bool|string $menu_slug
19299
- * @param bool|callable $before_render_function
19300
- * @param int $priority
19301
- * @param bool $show_submenu
19302
- * @param string $class Since 1.2.1.5 can add custom classes to menu items.
19303
- */
19304
- function add_submenu_item(
19305
- $menu_title,
19306
- $render_function,
19307
- $page_title = false,
19308
- $capability = 'manage_options',
19309
- $menu_slug = false,
19310
- $before_render_function = false,
19311
- $priority = WP_FS__DEFAULT_PRIORITY,
19312
- $show_submenu = true,
19313
- $class = ''
19314
- ) {
19315
- $this->_logger->entrance( 'Title = ' . $menu_title );
19316
-
19317
- if ( $this->is_addon() ) {
19318
- $parent_fs = $this->get_parent_instance();
19319
-
19320
- if ( is_object( $parent_fs ) ) {
19321
- $parent_fs->add_submenu_item(
19322
- $menu_title,
19323
- $render_function,
19324
- $page_title,
19325
- $capability,
19326
- $menu_slug,
19327
- $before_render_function,
19328
- $priority,
19329
- $show_submenu,
19330
- $class
19331
- );
19332
-
19333
- return;
19334
- }
19335
- }
19336
-
19337
- if ( ! isset( $this->_menu_items[ $priority ] ) ) {
19338
- $this->_menu_items[ $priority ] = array();
19339
- }
19340
-
19341
- $this->_menu_items[ $priority ][] = array(
19342
- 'page_title' => is_string( $page_title ) ? $page_title : $menu_title,
19343
- 'menu_title' => $menu_title,
19344
- 'capability' => $capability,
19345
- 'menu_slug' => is_string( $menu_slug ) ? $menu_slug : strtolower( $menu_title ),
19346
- 'render_function' => $render_function,
19347
- 'before_render_function' => $before_render_function,
19348
- 'show_submenu' => $show_submenu,
19349
- 'class' => $class,
19350
- );
19351
- }
19352
-
19353
- /**
19354
- * @author Vova Feldman (@svovaf)
19355
- * @since 1.0.1
19356
- *
19357
- * @param string $menu_title
19358
- * @param string $url
19359
- * @param bool $menu_slug
19360
- * @param string $capability
19361
- * @param int $priority
19362
- * @param bool $show_submenu
19363
- */
19364
- function add_submenu_link_item(
19365
- $menu_title,
19366
- $url,
19367
- $menu_slug = false,
19368
- $capability = 'read',
19369
- $priority = WP_FS__DEFAULT_PRIORITY,
19370
- $show_submenu = true
19371
- ) {
19372
- $this->_logger->entrance( 'Title = ' . $menu_title . '; Url = ' . $url );
19373
-
19374
- if ( $this->is_addon() ) {
19375
- $parent_fs = $this->get_parent_instance();
19376
-
19377
- if ( is_object( $parent_fs ) ) {
19378
- $parent_fs->add_submenu_link_item(
19379
- $menu_title,
19380
- $url,
19381
- $menu_slug,
19382
- $capability,
19383
- $priority,
19384
- $show_submenu
19385
- );
19386
-
19387
- return;
19388
- }
19389
- }
19390
-
19391
- if ( ! isset( $this->_menu_items[ $priority ] ) ) {
19392
- $this->_menu_items[ $priority ] = array();
19393
- }
19394
-
19395
- $this->_menu_items[ $priority ][] = array(
19396
- 'menu_title' => $menu_title,
19397
- 'capability' => $capability,
19398
- 'menu_slug' => is_string( $menu_slug ) ? $menu_slug : strtolower( $menu_title ),
19399
- 'url' => $url,
19400
- 'page_title' => $menu_title,
19401
- 'render_function' => 'fs_dummy',
19402
- 'before_render_function' => '',
19403
- 'show_submenu' => $show_submenu,
19404
- );
19405
- }
19406
-
19407
- #endregion ------------------------------------------------------------------
19408
-
19409
- #--------------------------------------------------------------------------------
19410
- #region Admin Notices
19411
- #--------------------------------------------------------------------------------
19412
-
19413
- /**
19414
- * @author Vova Feldman (@svovaf)
19415
- * @since 2.3.1
19416
- *
19417
- * @param string|string[] $ids
19418
- * @param int|null $network_level_or_blog_id
19419
- *
19420
- * @uses FS_Admin_Notices::remove_sticky()
19421
- */
19422
- function remove_sticky( $ids, $network_level_or_blog_id = null ) {
19423
- $this->_admin_notices->remove_sticky( $ids, $network_level_or_blog_id );
19424
- }
19425
-
19426
- #endregion
19427
-
19428
- #--------------------------------------------------------------------------------
19429
- #region Actions / Hooks / Filters
19430
- #--------------------------------------------------------------------------------
19431
-
19432
- /**
19433
- * @author Vova Feldman (@svovaf)
19434
- * @since 1.1.7
19435
- *
19436
- * @param string $tag
19437
- *
19438
- * @return string
19439
- */
19440
- public function get_action_tag( $tag ) {
19441
- return self::get_action_tag_static( $tag, $this->_slug, $this->is_plugin() );
19442
- }
19443
-
19444
- /**
19445
- * @author Vova Feldman (@svovaf)
19446
- * @since 1.2.1.6
19447
- *
19448
- * @param string $tag
19449
- * @param string $slug
19450
- * @param bool $is_plugin
19451
- *
19452
- * @return string
19453
- */
19454
- static function get_action_tag_static( $tag, $slug = '', $is_plugin = true ) {
19455
- $action = "fs_{$tag}";
19456
-
19457
- if ( ! empty( $slug ) ) {
19458
- $action .= '_' . self::get_module_unique_affix( $slug, $is_plugin );
19459
- }
19460
-
19461
- return $action;
19462
- }
19463
-
19464
- /**
19465
- * Returns a string that can be used to generate a unique action name,
19466
- * option name, HTML element ID, or HTML element class.
19467
- *
19468
- * @author Leo Fajardo (@leorw)
19469
- * @since 1.2.2
19470
- *
19471
- * @return string
19472
- */
19473
- public function get_unique_affix() {
19474
- return self::get_module_unique_affix( $this->_slug, $this->is_plugin() );
19475
- }
19476
-
19477
- /**
19478
- * Returns a string that can be used to generate a unique action name,
19479
- * option name, HTML element ID, or HTML element class.
19480
- *
19481
- * @author Vova Feldman (@svovaf)
19482
- * @since 1.2.2.5
19483
- *
19484
- * @param string $slug
19485
- * @param bool $is_plugin
19486
- *
19487
- * @return string
19488
- */
19489
- static function get_module_unique_affix( $slug, $is_plugin = true ) {
19490
- $affix = $slug;
19491
-
19492
- if ( ! $is_plugin ) {
19493
- $affix .= '-' . WP_FS__MODULE_TYPE_THEME;
19494
- }
19495
-
19496
- return $affix;
19497
- }
19498
-
19499
- /**
19500
- * @author Vova Feldman (@svovaf)
19501
- * @since 1.2.1
19502
- * @since 1.2.2.5 The AJAX action names are based on the module ID, not like the non-AJAX actions that are
19503
- * based on the slug for backward compatibility.
19504
- *
19505
- * @param string $tag
19506
- *
19507
- * @return string
19508
- */
19509
- function get_ajax_action( $tag ) {
19510
- return self::get_ajax_action_static( $tag, $this->_module_id );
19511
- }
19512
-
19513
- /**
19514
- * @author Vova Feldman (@svovaf)
19515
- * @since 1.2.1.7
19516
- *
19517
- * @param string $tag
19518
- *
19519
- * @return string
19520
- */
19521
- function get_ajax_security( $tag ) {
19522
- return wp_create_nonce( $this->get_ajax_action( $tag ) );
19523
- }
19524
-
19525
- /**
19526
- * @author Vova Feldman (@svovaf)
19527
- * @since 1.2.1.7
19528
- *
19529
- * @param string $tag
19530
- */
19531
- function check_ajax_referer( $tag ) {
19532
- check_ajax_referer( $this->get_ajax_action( $tag ), 'security' );
19533
- }
19534
-
19535
- /**
19536
- * @author Vova Feldman (@svovaf)
19537
- * @since 1.2.1.6
19538
- * @since 1.2.2.5 The AJAX action names are based on the module ID, not like the non-AJAX actions that are
19539
- * based on the slug for backward compatibility.
19540
- *
19541
- * @param string $tag
19542
- * @param number|null $module_id
19543
- *
19544
- * @return string
19545
- */
19546
- static function get_ajax_action_static( $tag, $module_id = null ) {
19547
- $action = "fs_{$tag}";
19548
-
19549
- if ( ! empty( $module_id ) ) {
19550
- $action .= "_{$module_id}";
19551
- }
19552
-
19553
- return $action;
19554
- }
19555
-
19556
- /**
19557
- * Do action, specific for the current context plugin.
19558
- *
19559
- * @author Vova Feldman (@svovaf)
19560
- * @since 1.0.1
19561
- *
19562
- * @param string $tag The name of the action to be executed.
19563
- * @param mixed $arg,... Optional. Additional arguments which are passed on to the
19564
- * functions hooked to the action. Default empty.
19565
- *
19566
- * @uses do_action()
19567
- */
19568
- function do_action( $tag, $arg = '' ) {
19569
- $this->_logger->entrance( $tag );
19570
-
19571
- $args = func_get_args();
19572
-
19573
- call_user_func_array( 'do_action', array_merge(
19574
- array( $this->get_action_tag( $tag ) ),
19575
- array_slice( $args, 1 ) )
19576
- );
19577
- }
19578
-
19579
- /**
19580
- * Add action, specific for the current context plugin.
19581
- *
19582
- * @author Vova Feldman (@svovaf)
19583
- * @since 1.0.1
19584
- *
19585
- * @param string $tag
19586
- * @param callable $function_to_add
19587
- * @param int $priority
19588
- * @param int $accepted_args
19589
- *
19590
- * @uses add_action()
19591
- */
19592
- function add_action(
19593
- $tag,
19594
- $function_to_add,
19595
- $priority = WP_FS__DEFAULT_PRIORITY,
19596
- $accepted_args = 1
19597
- ) {
19598
- $this->_logger->entrance( $tag );
19599
-
19600
- add_action( $this->get_action_tag( $tag ), $function_to_add, $priority, $accepted_args );
19601
- }
19602
-
19603
- /**
19604
- * Add AJAX action, specific for the current context plugin.
19605
- *
19606
- * @author Vova Feldman (@svovaf)
19607
- * @since 1.2.1
19608
- *
19609
- * @param string $tag
19610
- * @param callable $function_to_add
19611
- * @param int $priority
19612
- *
19613
- * @uses add_action()
19614
- *
19615
- * @return bool True if action added, false if no need to add the action since the AJAX call isn't matching.
19616
- */
19617
- function add_ajax_action(
19618
- $tag,
19619
- $function_to_add,
19620
- $priority = WP_FS__DEFAULT_PRIORITY
19621
- ) {
19622
- $this->_logger->entrance( $tag );
19623
-
19624
- return self::add_ajax_action_static(
19625
- $tag,
19626
- $function_to_add,
19627
- $priority,
19628
- $this->_module_id
19629
- );
19630
- }
19631
-
19632
- /**
19633
- * Add AJAX action.
19634
- *
19635
- * @author Vova Feldman (@svovaf)
19636
- * @since 1.2.1.6
19637
- *
19638
- * @param string $tag
19639
- * @param callable $function_to_add
19640
- * @param int $priority
19641
- * @param number|null $module_id
19642
- *
19643
- * @return bool True if action added, false if no need to add the action since the AJAX call isn't matching.
19644
- * @uses add_action()
19645
- *
19646
- */
19647
- static function add_ajax_action_static(
19648
- $tag,
19649
- $function_to_add,
19650
- $priority = WP_FS__DEFAULT_PRIORITY,
19651
- $module_id = null
19652
- ) {
19653
- self::$_static_logger->entrance( $tag );
19654
-
19655
- if ( ! self::is_ajax_action_static( $tag, $module_id ) ) {
19656
- return false;
19657
- }
19658
-
19659
- add_action(
19660
- 'wp_ajax_' . self::get_ajax_action_static( $tag, $module_id ),
19661
- $function_to_add,
19662
- $priority,
19663
- 0
19664
- );
19665
-
19666
- self::$_static_logger->info( "$tag AJAX callback action added." );
19667
-
19668
- return true;
19669
- }
19670
-
19671
- /**
19672
- * Send a JSON response back to an Ajax request.
19673
- *
19674
- * @author Vova Feldman (@svovaf)
19675
- * @since 1.2.1.5
19676
- *
19677
- * @param mixed $response
19678
- */
19679
- static function shoot_ajax_response( $response ) {
19680
- wp_send_json( $response );
19681
- }
19682
-
19683
- /**
19684
- * Send a JSON response back to an Ajax request, indicating success.
19685
- *
19686
- * @author Vova Feldman (@svovaf)
19687
- * @since 1.2.1.5
19688
- *
19689
- * @param mixed $data Data to encode as JSON, then print and exit.
19690
- */
19691
- static function shoot_ajax_success( $data = null ) {
19692
- wp_send_json_success( $data );
19693
- }
19694
-
19695
- /**
19696
- * Send a JSON response back to an Ajax request, indicating failure.
19697
- *
19698
- * @author Vova Feldman (@svovaf)
19699
- * @since 1.2.1.5
19700
- *
19701
- * @param mixed $error Optional error message.
19702
- */
19703
- static function shoot_ajax_failure( $error = '' ) {
19704
- $result = array( 'success' => false );
19705
- if ( ! empty( $error ) ) {
19706
- $result['error'] = $error;
19707
- }
19708
-
19709
- wp_send_json( $result );
19710
- }
19711
-
19712
- /**
19713
- * Apply filter, specific for the current context plugin.
19714
- *
19715
- * @author Vova Feldman (@svovaf)
19716
- * @since 1.0.9
19717
- *
19718
- * @param string $tag The name of the filter hook.
19719
- * @param mixed $value The value on which the filters hooked to `$tag` are applied on.
19720
- *
19721
- * @return mixed The filtered value after all hooked functions are applied to it.
19722
- *
19723
- * @uses apply_filters()
19724
- */
19725
- function apply_filters( $tag, $value ) {
19726
- $this->_logger->entrance( $tag );
19727
-
19728
- $args = func_get_args();
19729
- array_unshift( $args, $this->get_unique_affix() );
19730
-
19731
- return call_user_func_array( 'fs_apply_filter', $args );
19732
- }
19733
-
19734
- /**
19735
- * Add filter, specific for the current context plugin.
19736
- *
19737
- * @author Vova Feldman (@svovaf)
19738
- * @since 1.0.9
19739
- *
19740
- * @param string $tag
19741
- * @param callable $function_to_add
19742
- * @param int $priority
19743
- * @param int $accepted_args
19744
- *
19745
- * @uses add_filter()
19746
- */
19747
- function add_filter( $tag, $function_to_add, $priority = WP_FS__DEFAULT_PRIORITY, $accepted_args = 1 ) {
19748
- $this->_logger->entrance( $tag );
19749
-
19750
- add_filter( $this->get_action_tag( $tag ), $function_to_add, $priority, $accepted_args );
19751
- }
19752
-
19753
- /**
19754
- * Check if has filter.
19755
- *
19756
- * @author Vova Feldman (@svovaf)
19757
- * @since 1.1.4
19758
- *
19759
- * @param string $tag
19760
- * @param callable|bool $function_to_check Optional. The callback to check for. Default false.
19761
- *
19762
- * @return false|int
19763
- *
19764
- * @uses has_filter()
19765
- */
19766
- function has_filter( $tag, $function_to_check = false ) {
19767
- $this->_logger->entrance( $tag );
19768
-
19769
- return has_filter( $this->get_action_tag( $tag ), $function_to_check );
19770
- }
19771
-
19772
- #endregion
19773
-
19774
- /**
19775
- * Override default i18n text phrases.
19776
- *
19777
- * @author Vova Feldman (@svovaf)
19778
- * @since 1.1.6
19779
- *
19780
- * @param string[] string $key_value
19781
- *
19782
- * @uses fs_override_i18n()
19783
- */
19784
- function override_i18n( $key_value ) {
19785
- fs_override_i18n( $key_value, $this->_slug );
19786
- }
19787
-
19788
- /* Account Page
19789
- ------------------------------------------------------------------------------------------------------------------*/
19790
- /**
19791
- * Update site information.
19792
- *
19793
- * @author Vova Feldman (@svovaf)
19794
- * @since 1.0.1
19795
- *
19796
- * @param bool $store Flush to Database if true.
19797
- * @param null|int $network_level_or_blog_id Since 2.0.0
19798
- * @param \FS_Site $site Since 2.0.0
19799
- */
19800
- private function _store_site( $store = true, $network_level_or_blog_id = null, FS_Site $site = null, $is_backup = false ) {
19801
- $this->_logger->entrance();
19802
-
19803
- if ( is_null( $site ) ) {
19804
- $site = $this->_site;
19805
- }
19806
-
19807
- if ( !isset( $site ) || !is_object($site) || empty( $site->id ) ) {
19808
- $this->_logger->error( "Empty install ID, can't store site." );
19809
-
19810
- return;
19811
- }
19812
-
19813
- $site_clone = clone $site;
19814
-
19815
- $sites = self::get_all_sites( $this->_module_type, $network_level_or_blog_id, $is_backup );
19816
-
19817
- if (
19818
- ! $is_backup &&
19819
- is_object( $this->_user ) && $this->_user->id != $site->user_id
19820
- ) {
19821
- $this->sync_user_by_current_install( $site->user_id );
19822
-
19823
- $prev_stored_user_id = $this->_storage->get( 'prev_user_id', false, $network_level_or_blog_id );
19824
-
19825
- if ( empty( $prev_stored_user_id ) &&
19826
- is_object($this->_user) && $this->_user->id != $site->user_id
19827
- ) {
19828
- /**
19829
- * Store the current user ID as the previous user ID so that the previous user can be used
19830
- * as the install's owner while the new owner's details are not yet available.
19831
- *
19832
- * This will be executed only in the `replica` site. For example, there are 2 sites, namely `original`
19833
- * and `replica`, then an ownership change was initiated and completed in the `original`, the `replica`
19834
- * will be using the previous user until it is updated again (e.g.: until the next clone of `original`
19835
- * into `replica`.
19836
- *
19837
- * @author Leo Fajardo (@leorw)
19838
- */
19839
- $this->_storage->store( 'prev_user_id', $sites[ $this->_slug ]->user_id, $network_level_or_blog_id );
19840
- }
19841
- }
19842
-
19843
- $sites[ $this->_slug ] = $site_clone;
19844
-
19845
- $this->set_account_option(
19846
- ( $is_backup ? 'prev_' : '' ) . 'sites',
19847
- $sites,
19848
- $store,
19849
- $network_level_or_blog_id
19850
- );
19851
- }
19852
-
19853
- /**
19854
- * Stores the context site in the sites backup storage. This logic is used before deleting the site info so that it can be restored later on if necessary (e.g., if the automatic clone resolution attempt fails).
19855
- *
19856
- * @author Leo Fajardo (@leorw)
19857
- * @since 2.5.0
19858
- */
19859
- private function back_up_site() {
19860
- $this->_logger->entrance();
19861
-
19862
- $site_clone = clone $this->_site;
19863
-
19864
- $this->_store_site( true, null, $site_clone, true );
19865
- }
19866
-
19867
- /**
19868
- * Update plugin's plans information.
19869
- *
19870
- * @author Vova Feldman (@svovaf)
19871
- * @since 1.0.2
19872
- *
19873
- * @param bool $store Flush to Database if true.
19874
- */
19875
- private function _store_plans( $store = true ) {
19876
- $this->_logger->entrance();
19877
-
19878
- $plans = self::get_all_plans( $this->_module_type );
19879
-
19880
- // Copy plans.
19881
- $encrypted_plans = array();
19882
- for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
19883
- $encrypted_plans[] = self::_encrypt_entity( $this->_plans[ $i ] );
19884
- }
19885
-
19886
- $plans[ $this->_slug ] = $encrypted_plans;
19887
-
19888
- $this->set_account_option( 'plans', $plans, $store );
19889
- }
19890
-
19891
- /**
19892
- * Update user's plugin licenses.
19893
- *
19894
- * @author Vova Feldman (@svovaf)
19895
- * @since 1.0.5
19896
- *
19897
- * @param bool $store
19898
- * @param number|bool $module_id
19899
- * @param FS_Plugin_License[] $licenses
19900
- */
19901
- private function _store_licenses( $store = true, $module_id = false, $licenses = array() ) {
19902
- $this->_logger->entrance();
19903
-
19904
- $all_licenses = self::get_all_licenses();
19905
-
19906
- if ( ! FS_Plugin::is_valid_id( $module_id ) ) {
19907
- $module_id = $this->_module_id;
19908
-
19909
- $user_licenses = is_array( $this->_licenses ) ?
19910
- $this->_licenses :
19911
- array();
19912
-
19913
- if ( empty( $user_licenses ) ) {
19914
- // If the context user doesn't have any license, don't update the licenses collection.
19915
- return;
19916
- }
19917
-
19918
- $new_user_licenses_map = array();
19919
- foreach ( $user_licenses as $user_license ) {
19920
- $new_user_licenses_map[ $user_license->id ] = $user_license;
19921
- }
19922
-
19923
- self::store_user_id_license_ids_map( array_keys( $new_user_licenses_map ), $this->_module_id, $this->_user->id );
19924
-
19925
- // Update user licenses.
19926
- $licenses_to_update_count = count( $new_user_licenses_map );
19927
- foreach ( $all_licenses[ $module_id ] as $key => $license ) {
19928
- if ( 0 === $licenses_to_update_count ) {
19929
- break;
19930
- }
19931
-
19932
- if ( isset( $new_user_licenses_map[ $license->id ] ) ) {
19933
- // Update license.
19934
- $all_licenses[ $module_id ][ $key ] = $new_user_licenses_map[ $license->id ];
19935
- unset( $new_user_licenses_map[ $license->id ] );
19936
-
19937
- $licenses_to_update_count --;
19938
- }
19939
- }
19940
-
19941
- if ( ! empty( $new_user_licenses_map ) ) {
19942
- // Add new licenses.
19943
- $all_licenses[ $module_id ] = array_merge( array_values( $new_user_licenses_map ), $all_licenses[ $module_id ] );
19944
- }
19945
-
19946
- $licenses = $all_licenses[ $module_id ];
19947
- }
19948
-
19949
- if ( ! isset( $all_licenses[ $module_id ] ) ) {
19950
- $all_licenses[ $module_id ] = array();
19951
- }
19952
-
19953
- $all_licenses[ $module_id ] = $licenses;
19954
-
19955
- self::$_accounts->set_option( 'all_licenses', $all_licenses, $store );
19956
- }
19957
-
19958
- /**
19959
- * Update user information.
19960
- *
19961
- * @author Vova Feldman (@svovaf)
19962
- * @since 1.0.1
19963
- *
19964
- * @param bool $store Flush to Database if true.
19965
- */
19966
- private function _store_user( $store = true ) {
19967
- $this->_logger->entrance();
19968
-
19969
- if ( empty( $this->_user->id ) ) {
19970
- $this->_logger->error( "Empty user ID, can't store user." );
19971
-
19972
- return;
19973
- }
19974
-
19975
- $users = self::get_all_users();
19976
- $users[ $this->_user->id ] = $this->_user;
19977
- self::$_accounts->set_option( 'users', $users, $store );
19978
- }
19979
-
19980
- /**
19981
- * Update new updates information.
19982
- *
19983
- * @author Vova Feldman (@svovaf)
19984
- * @since 1.0.4
19985
- *
19986
- * @param FS_Plugin_Tag|null $update
19987
- * @param bool $store Flush to Database if true.
19988
- * @param bool|number $plugin_id
19989
- */
19990
- private function _store_update( $update, $store = true, $plugin_id = false ) {
19991
- $this->_logger->entrance();
19992
-
19993
- if ( $update instanceof FS_Plugin_Tag ) {
19994
- $update->updated = time();
19995
- }
19996
-
19997
- if ( ! is_numeric( $plugin_id ) ) {
19998
- $plugin_id = $this->_plugin->id;
19999
- }
20000
-
20001
- $updates = self::get_all_updates();
20002
- $updates[ $plugin_id ] = $update;
20003
- self::$_accounts->set_option( 'updates', $updates, $store );
20004
- }
20005
-
20006
- /**
20007
- * Update new updates information.
20008
- *
20009
- * @author Vova Feldman (@svovaf)
20010
- * @since 1.0.6
20011
- *
20012
- * @param FS_Plugin[] $plugin_addons
20013
- * @param bool $store Flush to Database if true.
20014
- */
20015
- private function _store_addons( $plugin_addons, $store = true ) {
20016
- $this->_logger->entrance();
20017
-
20018
- $addons = self::get_all_addons();
20019
- $addons[ $this->_plugin->id ] = $plugin_addons;
20020
- self::$_accounts->set_option( 'addons', $addons, $store );
20021
- }
20022
-
20023
- /**
20024
- * Delete plugin's associated add-ons.
20025
- *
20026
- * @author Vova Feldman (@svovaf)
20027
- * @since 1.0.8
20028
- *
20029
- * @param bool $store
20030
- *
20031
- * @return bool
20032
- */
20033
- private function _delete_account_addons( $store = true ) {
20034
- $all_addons = self::get_all_account_addons();
20035
-
20036
- if ( ! isset( $all_addons[ $this->_plugin->id ] ) ) {
20037
- return false;
20038
- }
20039
-
20040
- unset( $all_addons[ $this->_plugin->id ] );
20041
-
20042
- self::$_accounts->set_option( 'account_addons', $all_addons, $store );
20043
-
20044
- return true;
20045
- }
20046
-
20047
- /**
20048
- * Update account add-ons list.
20049
- *
20050
- * @author Vova Feldman (@svovaf)
20051
- * @since 1.0.6
20052
- *
20053
- * @param FS_Plugin[] $addons
20054
- * @param bool $store Flush to Database if true.
20055
- */
20056
- private function _store_account_addons( $addons, $store = true ) {
20057
- $this->_logger->entrance();
20058
-
20059
- $all_addons = self::get_all_account_addons();
20060
- $all_addons[ $this->_plugin->id ] = $addons;
20061
- self::$_accounts->set_option( 'account_addons', $all_addons, $store );
20062
- }
20063
-
20064
- /**
20065
- * Purges the cache for the valid user licenses API call so that when the `Account` or `Add-Ons` page is loaded,
20066
- * the valid user licenses will be fetched again and the account add-ons may be updated.
20067
- *
20068
- * @author Leo Fajardo (@leorw)
20069
- * @since 2.2.4
20070
- */
20071
- private function purge_valid_user_licenses_cache() {
20072
- if ( ! $this->is_registered() ) {
20073
- return;
20074
- }
20075
-
20076
- $this->get_api_user_scope()->purge_cache( $this->get_valid_user_licenses_endpoint() );
20077
- }
20078
-
20079
- /**
20080
- * @author Leo Fajardo (@leorw)
20081
- * @since 2.3.0
20082
- *
20083
- * @param array $all_licenses
20084
- * @param number|null $site_license_id
20085
- * @param bool $include_parent_licenses
20086
- *
20087
- * @return array
20088
- */
20089
- private function get_foreign_licenses_info( $all_licenses, $site_license_id = null, $include_parent_licenses = false ) {
20090
- $foreign_licenses = array(
20091
- 'ids' => array(),
20092
- 'license_keys' => array()
20093
- );
20094
-
20095
- $parent_license_ids_map = array();
20096
-
20097
- foreach ( $all_licenses as $license ) {
20098
- if ( $license->user_id == $this->_user->id || $license->id == $site_license_id ) {
20099
- continue;
20100
- }
20101
-
20102
- $foreign_licenses['ids'][] = $license->id;
20103
- $foreign_licenses['license_keys'][] = $license->secret_key;
20104
-
20105
- if (
20106
- $include_parent_licenses &&
20107
- is_object( $this->_license ) &&
20108
- FS_Plugin_License::is_valid_id( $this->_license->parent_license_id ) &&
20109
- ! isset( $parent_license_ids_map[ $this->_license->parent_license_id ] )
20110
- ) {
20111
- /**
20112
- * Include the parent license's info only if it has not been included before since child licenses
20113
- * can have the same parent license.
20114
- */
20115
- $foreign_licenses['ids'][] = $this->_license->parent_license_id;
20116
- $foreign_licenses['license_keys'][] = $license->secret_key;
20117
-
20118
- $parent_license_ids_map[ $this->_license->parent_license_id ] = true;
20119
- }
20120
- }
20121
-
20122
- if ( empty( $foreign_licenses['ids'] ) ) {
20123
- $foreign_licenses = array();
20124
- }
20125
-
20126
- return $foreign_licenses;
20127
- }
20128
-
20129
- /**
20130
- * @author Leo Fajardo (@leorw)
20131
- * @since 2.3.0
20132
- *
20133
- * @return string
20134
- */
20135
- private function get_valid_user_licenses_endpoint() {
20136
- $user_licenses_endpoint = '/licenses.json?type=active' .
20137
- ( FS_Plugin::is_valid_id( $this->get_bundle_id() ) ? '&is_enriched=true' : '' );
20138
-
20139
- $foreign_licenses = $this->get_foreign_licenses_info( self::get_all_licenses( $this->_module_id ), null, true );
20140
-
20141
- if ( ! empty ( $foreign_licenses ) ) {
20142
- $foreign_licenses = array(
20143
- // Prefix with `+` to tell the server to include foreign licenses in the licenses collection.
20144
- 'ids' => ( urlencode( '+' ) . implode( ',', $foreign_licenses['ids'] ) ),
20145
- 'license_keys' => implode( ',', array_map( 'urlencode', $foreign_licenses['license_keys'] ) )
20146
- );
20147
-
20148
- $user_licenses_endpoint = add_query_arg( $foreign_licenses, $user_licenses_endpoint );
20149
- }
20150
-
20151
- return $user_licenses_endpoint;
20152
- }
20153
-
20154
- /**
20155
- * Fetches active licenses that are enriched with product type if there's a context `bundle_id` and bundle
20156
- * licenses enriched with product IDs if there are any. From the licenses, the `get_updated_account_addons`
20157
- * method filters out non–add-on product IDs and stores the add-on IDs.
20158
- *
20159
- * @author Leo Fajardo (@leorw)
20160
- * @since 2.2.4
20161
- *
20162
- * @return stdClass[] array
20163
- */
20164
- private function fetch_valid_user_licenses() {
20165
- $this->_logger->entrance();
20166
-
20167
- $result = $this->get_api_user_scope()->get( $this->get_valid_user_licenses_endpoint() );
20168
-
20169
- if ( ! $this->is_api_result_object( $result, 'licenses' ) ||
20170
- ! is_array( $result->licenses )
20171
- ) {
20172
- return array();
20173
- }
20174
-
20175
- return $result->licenses;
20176
- }
20177
-
20178
- /**
20179
- * @author Leo Fajardo (@leorw)
20180
- * @since 2.2.4
20181
- *
20182
- * @return number[] Account add-on IDs.
20183
- */
20184
- function get_updated_account_addons() {
20185
- $addons = $this->get_addons();
20186
- if ( empty( $addons ) ) {
20187
- return array();
20188
- }
20189
-
20190
- $account_addons = $this->get_account_addons();
20191
- if ( ! is_array( $account_addons ) ) {
20192
- $account_addons = array();
20193
- }
20194
-
20195
- $user_licenses = $this->is_registered() ?
20196
- $this->fetch_valid_user_licenses() :
20197
- array();
20198
-
20199
- if ( empty( $user_licenses ) ) {
20200
- return $account_addons;
20201
- }
20202
-
20203
- $addon_ids = array();
20204
- foreach ( $addons as $addon ) {
20205
- $addon_ids[] = $addon->id;
20206
- }
20207
-
20208
- $license_product_ids = array();
20209
-
20210
- foreach ( $user_licenses as $license ) {
20211
- if ( isset( $license->plugin_type ) && 'bundle' === $license->plugin_type ) {
20212
- $license_product_ids = array_merge( $license_product_ids, $license->products );
20213
- } else {
20214
- $license_product_ids[] = $license->plugin_id;
20215
- }
20216
- }
20217
-
20218
- // Filter out non–add-on IDs.
20219
- $new_account_addons = array_intersect( $addon_ids, $license_product_ids );
20220
- if ( count( $new_account_addons ) !== count( $account_addons ) ) {
20221
- $this->_store_account_addons( array_unique( $new_account_addons ) );
20222
- }
20223
-
20224
- return $new_account_addons;
20225
- }
20226
-
20227
- /**
20228
- * Store account params in the Database.
20229
- *
20230
- * @author Vova Feldman (@svovaf)
20231
- * @since 1.0.1
20232
- *
20233
- * @param null|int $blog_id Since 2.0.0
20234
- */
20235
- private function _store_account( $blog_id = null ) {
20236
- $this->_logger->entrance();
20237
-
20238
- $this->_store_site( false, $blog_id );
20239
- $this->_store_user( false );
20240
- $this->_store_plans( false );
20241
- $this->_store_licenses( false );
20242
-
20243
- self::$_accounts->store( $blog_id );
20244
- }
20245
-
20246
- /**
20247
- * Sync user's information.
20248
- *
20249
- * @author Vova Feldman (@svovaf)
20250
- * @since 1.0.3
20251
- * @uses FS_Api
20252
- */
20253
- private function _handle_account_user_sync() {
20254
- $this->_logger->entrance();
20255
-
20256
- $api = $this->get_api_user_scope();
20257
-
20258
- // Get user's information.
20259
- $user = $api->get( '/', true );
20260
-
20261
- if ( isset( $user->id ) ) {
20262
- $this->_user->first = $user->first;
20263
- $this->_user->last = $user->last;
20264
- $this->_user->email = $user->email;
20265
-
20266
- $is_menu_item_account_visible = $this->is_submenu_item_visible( 'account' );
20267
-
20268
- if ( $user->is_verified &&
20269
- ( ! isset( $this->_user->is_verified ) || false === $this->_user->is_verified )
20270
- ) {
20271
- $this->_user->is_verified = true;
20272
-
20273
- $this->do_action( 'account_email_verified', $user->email );
20274
-
20275
- $this->_admin_notices->add(
20276
- $this->get_text_inline( 'Your email has been successfully verified - you are AWESOME!', 'email-verified-message' ),
20277
- $this->get_text_x_inline( 'Right on', 'a positive response', 'right-on' ) . '!',
20278
- 'success',
20279
- // Make admin sticky if account menu item is invisible,
20280
- // since the page will be auto redirected to the plugin's
20281
- // main settings page, and the non-sticky message
20282
- // will disappear.
20283
- ! $is_menu_item_account_visible,
20284
- 'email_verified'
20285
- );
20286
- }
20287
-
20288
- // Flush user details to DB.
20289
- $this->_store_user();
20290
-
20291
- $this->do_action( 'after_account_user_sync', $user );
20292
-
20293
- /**
20294
- * If account menu item is hidden, redirect to plugin's main settings page.
20295
- *
20296
- * @author Vova Feldman (@svovaf)
20297
- * @since 1.1.6
20298
- *
20299
- * @link https://github.com/Freemius/wordpress-sdk/issues/6
20300
- */
20301
- if ( ! $is_menu_item_account_visible ) {
20302
- fs_redirect( $this->_get_admin_page_url() );
20303
- }
20304
- }
20305
- }
20306
-
20307
- /**
20308
- * @author Vova Feldman (@svovaf)
20309
- * @since 1.0.9
20310
- * @uses FS_Api
20311
- *
20312
- * @param number|bool $license_id
20313
- *
20314
- * @return FS_Subscription|object|bool
20315
- */
20316
- private function _fetch_site_license_subscription( $license_id = false ) {
20317
- $this->_logger->entrance();
20318
- $api = $this->get_api_site_scope();
20319
-
20320
- if ( ! is_numeric( $license_id ) ) {
20321
- $license_id = FS_Plugin_License::is_valid_id( $this->_license->parent_license_id ) ?
20322
- $this->_license->parent_license_id :
20323
- $this->_license->id;
20324
- }
20325
-
20326
- $result = $api->get( "/licenses/{$license_id}/subscriptions.json", true );
20327
-
20328
- return ! isset( $result->error ) ?
20329
- ( ( is_array( $result->subscriptions ) && 0 < count( $result->subscriptions ) ) ?
20330
- new FS_Subscription( $result->subscriptions[0] ) :
20331
- false
20332
- ) :
20333
- $result;
20334
- }
20335
-
20336
- /**
20337
- * @author Vova Feldman (@svovaf)
20338
- * @since 1.0.4
20339
- * @uses FS_Api
20340
- *
20341
- * @param number|bool $plan_id
20342
- *
20343
- * @return FS_Plugin_Plan|object
20344
- */
20345
- private function _fetch_site_plan( $plan_id = false ) {
20346
- $this->_logger->entrance();
20347
- $api = $this->get_api_site_scope();
20348
-
20349
- if ( ! is_numeric( $plan_id ) ) {
20350
- $plan_id = $this->_site->plan_id;
20351
- }
20352
-
20353
- $plan = $api->get( "/plans/{$plan_id}.json", true );
20354
-
20355
- return ! isset( $plan->error ) ? new FS_Plugin_Plan( $plan ) : $plan;
20356
- }
20357
-
20358
- /**
20359
- * @author Vova Feldman (@svovaf)
20360
- * @since 1.0.5
20361
- * @uses FS_Api
20362
- *
20363
- * @return FS_Plugin_Plan[]|object
20364
- */
20365
- private function _fetch_plugin_plans() {
20366
- $this->_logger->entrance();
20367
- $api = $this->get_current_or_network_user_api_scope();
20368
-
20369
- /**
20370
- * @since 1.2.3 When running in DEV mode, retrieve pending plans as well.
20371
- */
20372
- $result = $api->get( $this->add_show_pending( "/plugins/{$this->_module_id}/plans.json" ), true );
20373
-
20374
- if ( $this->is_api_result_object( $result, 'plans' ) && is_array( $result->plans ) ) {
20375
- for ( $i = 0, $len = count( $result->plans ); $i < $len; $i ++ ) {
20376
- $result->plans[ $i ] = new FS_Plugin_Plan( $result->plans[ $i ] );
20377
- }
20378
-
20379
- $result = $result->plans;
20380
- }
20381
-
20382
- return $result;
20383
- }
20384
-
20385
- /**
20386
- * @author Vova Feldman (@svovaf)
20387
- * @since 2.0.0
20388
- *
20389
- * @param number $plan_id
20390
- *
20391
- * @return \FS_Plugin_Plan|object
20392
- */
20393
- private function fetch_plan_by_id( $plan_id ) {
20394
- $this->_logger->entrance();
20395
- $api = $this->get_current_or_network_user_api_scope();
20396
-
20397
- $result = $api->get( "/plugins/{$this->_module_id}/plans/{$plan_id}.json", true );
20398
-
20399
- return $this->is_api_result_entity( $result ) ?
20400
- new FS_Plugin_Plan( $result ) :
20401
- $result;
20402
- }
20403
-
20404
- /**
20405
- * @author Vova Feldman (@svovaf)
20406
- * @since 1.0.5
20407
- * @uses FS_Api
20408
- *
20409
- * @param number|bool $plugin_id
20410
- * @param number|bool $site_license_id
20411
- * @param array $foreign_licenses @since 2.0.0. This is used by network-activated plugins.
20412
- * @param number|null $blog_id
20413
- *
20414
- * @return FS_Plugin_License[]|object
20415
- */
20416
- private function _fetch_licenses(
20417
- $plugin_id = false,
20418
- $site_license_id = false,
20419
- $foreign_licenses = array(),
20420
- $blog_id = null
20421
- ) {
20422
- $this->_logger->entrance();
20423
-
20424
- $api = $this->get_api_user_scope();
20425
-
20426
- if ( ! is_numeric( $plugin_id ) ) {
20427
- $plugin_id = $this->_plugin->id;
20428
- }
20429
-
20430
- $user_licenses_endpoint = "/plugins/{$plugin_id}/licenses.json?is_enriched=true";
20431
- if ( ! empty ( $foreign_licenses ) ) {
20432
- $foreign_licenses = array(
20433
- // Prefix with `+` to tell the server to include foreign licenses in the licenses collection.
20434
- 'ids' => ( urlencode( '+' ) . implode( ',', $foreign_licenses['ids'] ) ),
20435
- 'license_keys' => implode( ',', array_map( 'urlencode', $foreign_licenses['license_keys'] ) )
20436
- );
20437
-
20438
- $user_licenses_endpoint = add_query_arg( $foreign_licenses, $user_licenses_endpoint );
20439
- }
20440
-
20441
- $result = $api->get( $user_licenses_endpoint, true );
20442
-
20443
- $is_site_license_synced = false;
20444
-
20445
- $api_errors = array();
20446
-
20447
- if ( $this->is_api_result_object( $result, 'licenses' ) &&
20448
- is_array( $result->licenses )
20449
- ) {
20450
- for ( $i = 0, $len = count( $result->licenses ); $i < $len; $i ++ ) {
20451
- $result->licenses[ $i ] = new FS_Plugin_License( $result->licenses[ $i ] );
20452
-
20453
- if ( ( ! $is_site_license_synced ) && is_numeric( $site_license_id ) ) {
20454
- $is_site_license_synced = ( $site_license_id == $result->licenses[ $i ]->id );
20455
- }
20456
- }
20457
-
20458
- $result = $result->licenses;
20459
- } else {
20460
- $api_errors[] = $result;
20461
- $result = array();
20462
- }
20463
-
20464
- if ( ! $is_site_license_synced ) {
20465
- if ( ! is_null( $blog_id ) ) {
20466
- /**
20467
- * If blog ID is not null, the request is for syncing of the license of a single site via the
20468
- * network-level "Account" page.
20469
- *
20470
- * @author Leo Fajardo (@leorw)
20471
- */
20472
- $this->switch_to_blog( $blog_id );
20473
- }
20474
-
20475
- $api = $this->get_api_site_scope();
20476
-
20477
- if ( is_numeric( $site_license_id ) ) {
20478
- // Try to retrieve a foreign license that is linked to the install.
20479
- $api_result = $api->call( '/licenses.json?is_enriched=true' );
20480
-
20481
- if ( $this->is_api_result_object( $api_result, 'licenses' ) &&
20482
- is_array( $api_result->licenses )
20483
- ) {
20484
- $licenses = $api_result->licenses;
20485
-
20486
- if ( ! empty( $licenses ) ) {
20487
- $result[] = new FS_Plugin_License( $licenses[0] );
20488
- }
20489
- } else {
20490
- $api_errors[] = $api_result;
20491
- }
20492
- } else if (
20493
- is_object( $this->_license ) &&
20494
- /**
20495
- * Sync only if the license belongs to the context plugin. `$plugin_id` can be an add-on ID while
20496
- * the FS instance that does the syncing is the parent FS instance.
20497
- *
20498
- * @author Leo Fajardo (@leorw)
20499
- * @since 2.3.0
20500
- */
20501
- $this->_license->plugin_id == $plugin_id
20502
- ) {
20503
- $is_license_in_result = false;
20504
- if ( ! empty( $result ) ) {
20505
- foreach ( $result as $license ) {
20506
- if ( $license->id == $this->_license->id ) {
20507
- $is_license_in_result = true;
20508
- break;
20509
- }
20510
- }
20511
- }
20512
-
20513
- if ( ! $is_license_in_result ) {
20514
- // Fetch foreign license by ID and license key.
20515
- $license = $api->get( "/licenses/{$this->_license->id}.json?license_key=" .
20516
- urlencode( $this->_license->secret_key ) . '&is_enriched=true' );
20517
-
20518
- if ( $this->is_api_result_entity( $license ) ) {
20519
- $result[] = new FS_Plugin_License( $license );
20520
- } else {
20521
- $api_errors[] = $license;
20522
- }
20523
- }
20524
- }
20525
-
20526
- if ( ! is_null( $blog_id ) ) {
20527
- $this->switch_to_blog( $this->_storage->network_install_blog_id );
20528
- }
20529
- }
20530
-
20531
- if ( is_array( $result ) && 0 < count( $result ) ) {
20532
- // If found at least one license, return license collection even if there are errors.
20533
- return $result;
20534
- }
20535
-
20536
- if ( ! empty( $api_errors ) ) {
20537
- // If found any errors and no licenses, return first error.
20538
- return $api_errors[0];
20539
- }
20540
-
20541
- // Fallback to empty licenses list.
20542
- return $result;
20543
- }
20544
-
20545
- /**
20546
- * @author Vova Feldman (@svovaf)
20547
- * @since 2.0.0
20548
- *
20549
- * @param number $license_id
20550
- * @param string $license_key
20551
- *
20552
- * @return \FS_Plugin_License|object
20553
- */
20554
- private function fetch_license_by_key( $license_id, $license_key ) {
20555
- $this->_logger->entrance();
20556
-
20557
- $api = $this->get_current_or_network_user_api_scope();
20558
-
20559
- $result = $api->get( "/licenses/{$license_id}.json?license_key=" . urlencode( $license_key ) );
20560
-
20561
- return $this->is_api_result_entity( $result ) ?
20562
- new FS_Plugin_License( $result ) :
20563
- $result;
20564
- }
20565
-
20566
- /**
20567
- * @author Vova Feldman (@svovaf)
20568
- * @since 1.2.0
20569
- * @uses FS_Api
20570
- *
20571
- * @param number|bool $plugin_id
20572
- * @param bool $flush
20573
- *
20574
- * @return FS_Payment[]|object
20575
- */
20576
- function _fetch_payments( $plugin_id = false, $flush = false ) {
20577
- $this->_logger->entrance();
20578
-
20579
- $api = $this->get_api_user_scope();
20580
-
20581
- if ( ! is_numeric( $plugin_id ) ) {
20582
- $plugin_id = $this->_plugin->id;
20583
- }
20584
-
20585
- $include_bundles = (
20586
- is_object( $this->_plugin ) &&
20587
- FS_Plugin::is_valid_id( $this->_plugin->bundle_id )
20588
- );
20589
-
20590
- $result = $api->get(
20591
- "/plugins/{$plugin_id}/payments.json?include_addons=true" . ($include_bundles ? '&include_bundles=true' : ''),
20592
- $flush
20593
- );
20594
-
20595
- if ( ! isset( $result->error ) ) {
20596
- for ( $i = 0, $len = count( $result->payments ); $i < $len; $i ++ ) {
20597
- $result->payments[ $i ] = new FS_Payment( $result->payments[ $i ] );
20598
- }
20599
- $result = $result->payments;
20600
- }
20601
-
20602
- return $result;
20603
- }
20604
-
20605
- /**
20606
- * @author Vova Feldman (@svovaf)
20607
- * @since 1.2.1.5
20608
- * @uses FS_Api
20609
- *
20610
- * @param bool $flush
20611
- *
20612
- * @return \FS_Billing|mixed
20613
- */
20614
- function _fetch_billing( $flush = false ) {
20615
- require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-billing.php';
20616
-
20617
- $billing = $this->get_api_user_scope()->get( 'billing.json', $flush );
20618
-
20619
- if ( $this->is_api_result_entity( $billing ) ) {
20620
- $billing = new FS_Billing( $billing );
20621
- }
20622
-
20623
- return $billing;
20624
- }
20625
-
20626
- /**
20627
- * @author Vova Feldman (@svovaf)
20628
- * @since 1.0.5
20629
- *
20630
- * @param FS_Plugin_License[] $licenses
20631
- * @param number $module_id
20632
- */
20633
- private function _update_licenses( $licenses, $module_id ) {
20634
- $this->_logger->entrance();
20635
-
20636
- if ( is_array( $licenses ) ) {
20637
- for ( $i = 0, $len = count( $licenses ); $i < $len; $i ++ ) {
20638
- $licenses[ $i ]->updated = time();
20639
- }
20640
- }
20641
-
20642
- $this->_store_licenses( true, $module_id, $licenses );
20643
- }
20644
-
20645
- /**
20646
- * @author Vova Feldman (@svovaf)
20647
- * @since 1.0.4
20648
- *
20649
- * @param bool|number $plugin_id
20650
- * @param bool $flush Since 1.1.7.3
20651
- * @param int $expiration Since 1.2.2.7
20652
- * @param bool|string $newer_than Since 2.2.1
20653
- *
20654
- * @return object|false New plugin tag info if exist.
20655
- */
20656
- private function _fetch_newer_version( $plugin_id = false, $flush = true, $expiration = WP_FS__TIME_24_HOURS_IN_SEC, $newer_than = false ) {
20657
- $latest_tag = $this->_fetch_latest_version( $plugin_id, $flush, $expiration, $newer_than );
20658
-
20659
- if ( ! is_object( $latest_tag ) ) {
20660
- return false;
20661
- }
20662
-
20663
- $plugin_version = $this->get_plugin_version();
20664
-
20665
- // Check if version is actually newer.
20666
- $has_new_version =
20667
- // If it's an non-installed add-on then always return latest.
20668
- ( $this->_is_addon_id( $plugin_id ) && ! $this->is_addon_activated( $plugin_id ) ) ||
20669
- // Compare versions.
20670
- version_compare( $plugin_version, $latest_tag->version, '<' );
20671
-
20672
- $this->_logger->departure( $has_new_version ? 'Found newer plugin version ' . $latest_tag->version : 'No new version' );
20673
-
20674
- $is_latest_version_beta = ( 'beta' === $latest_tag->release_mode );
20675
-
20676
- $this->_storage->beta_data = array(
20677
- 'is_beta' => $is_latest_version_beta,
20678
- 'version' => $latest_tag->version
20679
- );
20680
-
20681
- return $has_new_version ? $latest_tag : false;
20682
- }
20683
-
20684
- /**
20685
- * @author Vova Feldman (@svovaf)
20686
- * @since 1.0.5
20687
- *
20688
- * @param bool|number $plugin_id
20689
- * @param bool $flush Since 1.1.7.3
20690
- * @param int $expiration Since 1.2.2.7
20691
- * @param bool|string $newer_than Since 2.2.1
20692
- *
20693
- * @return bool|FS_Plugin_Tag
20694
- */
20695
- function get_update( $plugin_id = false, $flush = true, $expiration = WP_FS__TIME_24_HOURS_IN_SEC, $newer_than = false ) {
20696
- $this->_logger->entrance();
20697
-
20698
- if ( ! is_numeric( $plugin_id ) ) {
20699
- $plugin_id = $this->_plugin->id;
20700
- }
20701
-
20702
- $this->check_updates( true, $plugin_id, $flush, $expiration, $newer_than );
20703
- $updates = $this->get_all_updates();
20704
-
20705
- return isset( $updates[ $plugin_id ] ) && is_object( $updates[ $plugin_id ] ) ? $updates[ $plugin_id ] : false;
20706
- }
20707
-
20708
- /**
20709
- * Check if site assigned with active license.
20710
- *
20711
- * @author Vova Feldman (@svovaf)
20712
- * @since 1.0.6
20713
- *
20714
- * @deprecated Please use has_active_valid_license() instead because license can be cancelled.
20715
- */
20716
- function has_active_license() {
20717
- return (
20718
- is_object( $this->_license ) &&
20719
- is_numeric( $this->_license->id ) &&
20720
- ! $this->_license->is_expired()
20721
- );
20722
- }
20723
-
20724
- /**
20725
- * Check if site assigned with active & valid (not expired) license.
20726
- *
20727
- * @author Vova Feldman (@svovaf)
20728
- * @since 1.2.1
20729
- *
20730
- * @param bool $check_expiration
20731
- */
20732
- function has_active_valid_license( $check_expiration = true ) {
20733
- return self::is_active_valid_license( $this->_license, $check_expiration );
20734
- }
20735
-
20736
- /**
20737
- * @author Leo Fajardo (@leorw)
20738
- * @since 2.3.1
20739
- */
20740
- function is_data_debug_mode() {
20741
- if ( is_null( $this->is_whitelabeled ) || ! $this->is_whitelabeled ) {
20742
- return false;
20743
- }
20744
-
20745
- $fs = $this->is_addon() ?
20746
- $this->get_parent_instance() :
20747
- $this;
20748
-
20749
- if ( $fs->is_network_active() && fs_is_network_admin() ) {
20750
- $is_developer_license_debug_mode = get_site_transient( "fs_{$this->get_id()}_data_debug_mode" );
20751
- } else {
20752
- $is_developer_license_debug_mode = get_transient( "fs_{$this->get_id()}_data_debug_mode" );
20753
- }
20754
-
20755
- return ( 'true' === $is_developer_license_debug_mode );
20756
- }
20757
-
20758
- /**
20759
- * @author Leo Fajardo (@leorw)
20760
- * @since 2.3.1
20761
- */
20762
- function _set_data_debug_mode() {
20763
- if ( ! $this->is_whitelabeled( true ) ) {
20764
- return;
20765
- }
20766
-
20767
- $license_or_user_key = fs_request_get( 'license_or_user_key' );
20768
-
20769
- $transient_value = ( ! empty( $license_or_user_key ) ) ?
20770
- 'true' :
20771
- 'false';
20772
-
20773
- if ( 'true' === $transient_value ) {
20774
- $stored_key = $this->_storage->get( ! FS_User::is_valid_id( $this->_storage->last_license_user_id ) ?
20775
- 'last_license_key' :
20776
- 'last_license_user_key'
20777
- );
20778
-
20779
- if ( md5( $license_or_user_key ) !== $stored_key ) {
20780
- $this->shoot_ajax_failure( sprintf(
20781
- '%s... %s',
20782
- $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ),
20783
- $this->get_text_inline(
20784
- 'seems like the key you entered doesn\'t match our records.',
20785
- 'developer-or-license-not-found'
20786
- )
20787
- ) );
20788
- }
20789
- }
20790
-
20791
- if ( $this->is_network_active() && fs_is_network_admin() ) {
20792
- set_site_transient(
20793
- "fs_{$this->get_id()}_data_debug_mode",
20794
- $transient_value,
20795
- WP_FS__TIME_24_HOURS_IN_SEC / 24
20796
- );
20797
- } else {
20798
- set_transient(
20799
- "fs_{$this->get_id()}_data_debug_mode",
20800
- $transient_value,
20801
- WP_FS__TIME_24_HOURS_IN_SEC / 24
20802
- );
20803
- }
20804
-
20805
- if ( 'true' === $transient_value ) {
20806
- $this->_admin_notices->add_sticky(
20807
- $this->get_text_inline(
20808
- 'Debug mode was successfully enabled and will be automatically disabled in 60 min. You can also disable it earlier by clicking the "Stop Debug" link.',
20809
- 'data_debug_mode_enabled'
20810
- ),
20811
- 'data_debug_mode_enabled'
20812
- );
20813
- }
20814
-
20815
- $this->shoot_ajax_success();
20816
- }
20817
-
20818
- /**
20819
- * Check if a given license is active & valid (not expired).
20820
- *
20821
- * @author Vova Feldman (@svovaf)
20822
- * @since 2.1.3
20823
- *
20824
- * @param FS_Plugin_License $license
20825
- * @param bool $check_expiration
20826
- *
20827
- * @return bool
20828
- */
20829
- private static function is_active_valid_license( $license, $check_expiration = true ) {
20830
- return (
20831
- is_object( $license ) &&
20832
- FS_Plugin_License::is_valid_id( $license->id ) &&
20833
- $license->is_active() &&
20834
- ( ! $check_expiration || $license->is_valid() )
20835
- );
20836
- }
20837
-
20838
- /**
20839
- * Checks if there's any site that is associated with an active & valid license.
20840
- * This logic is used to determine if the admin can download the premium code base from a network level admin.
20841
- *
20842
- * @author Vova Feldman (@svovaf)
20843
- * @since 2.1.3
20844
- *
20845
- * @return bool
20846
- */
20847
- function has_any_active_valid_license() {
20848
- if ( ! fs_is_network_admin() ) {
20849
- return $this->has_active_valid_license();
20850
- }
20851
-
20852
- $installs = $this->get_blog_install_map();
20853
- $all_plugin_licenses = self::get_all_licenses( $this->_module_id );
20854
-
20855
- foreach ( $installs as $blog_id => $install ) {
20856
- if ( ! FS_Plugin_License::is_valid_id( $install->license_id ) ) {
20857
- continue;
20858
- }
20859
-
20860
- foreach ( $all_plugin_licenses as $license ) {
20861
- if ( $license->id == $install->license_id ) {
20862
- if ( self::is_active_valid_license( $license ) ) {
20863
- return true;
20864
- }
20865
- }
20866
- }
20867
- }
20868
-
20869
- return false;
20870
- }
20871
-
20872
- /**
20873
- * Check if site assigned with license with enabled features.
20874
- *
20875
- * @author Vova Feldman (@svovaf)
20876
- * @since 1.0.6
20877
- *
20878
- * @return bool
20879
- */
20880
- function has_features_enabled_license() {
20881
- return (
20882
- is_object( $this->_license ) &&
20883
- is_numeric( $this->_license->id ) &&
20884
- $this->_license->is_features_enabled()
20885
- );
20886
- }
20887
-
20888
- /**
20889
- * Checks if the product is activated with a bundle license.
20890
- *
20891
- * @author Leo Fajardo (@leorw)
20892
- * @since 2.4.0
20893
- *
20894
- * @return bool
20895
- */
20896
- function is_activated_with_bundle_license() {
20897
- if ( ! $this->has_features_enabled_license() ) {
20898
- return false;
20899
- }
20900
-
20901
- return FS_Plugin_License::is_valid_id( $this->_license->parent_license_id );
20902
- }
20903
-
20904
- /**
20905
- * Check if user is a trial or have feature enabled license.
20906
- *
20907
- * @author Vova Feldman (@svovaf)
20908
- * @since 1.1.7
20909
- *
20910
- * @return bool
20911
- */
20912
- function can_use_premium_code() {
20913
- return $this->is_trial() || $this->has_features_enabled_license();
20914
- }
20915
-
20916
- /**
20917
- * Checks if the current user can activate plugins or switch themes. Note that this method should only be used
20918
- * after the `init` action is triggered because it is using `current_user_can()` which is only functional after
20919
- * the context user is authenticated.
20920
- *
20921
- * @author Leo Fajardo (@leorw)
20922
- * @since 1.2.2
20923
- *
20924
- * @return bool
20925
- */
20926
- function is_user_admin() {
20927
- /**
20928
- * Require a super-admin when network activated, running from the network level OR if
20929
- * running from the site level but not delegated the opt-in.
20930
- *
20931
- * @author Vova Feldman (@svovaf)
20932
- * @since 2.0.0
20933
- */
20934
- if ( $this->_is_network_active &&
20935
- ( fs_is_network_admin() || ! $this->is_delegated_connection() )
20936
- ) {
20937
- return is_super_admin();
20938
- }
20939
-
20940
- return ( $this->is_plugin() && current_user_can( is_multisite() ? 'manage_options' : 'activate_plugins' ) )
20941
- || ( $this->is_theme() && current_user_can( 'switch_themes' ) );
20942
- }
20943
-
20944
- /**
20945
- * Sync site's plan.
20946
- *
20947
- * @author Vova Feldman (@svovaf)
20948
- * @since 1.0.3
20949
- *
20950
- * @uses FS_Api
20951
- *
20952
- * @param bool $background Hints the method if it's a background sync. If false, it means that was initiated by
20953
- * the admin.
20954
- * @param bool $is_context_single_site @since 2.0.0. This is used when syncing a license for a single install from the
20955
- * network-level "Account" page.
20956
- * @param int|null $current_blog_id @since 2.2.3. This is passed from the `execute_cron` method and used by the
20957
- * `_sync_plugin_license` method in order to switch to the previous blog when sending
20958
- * updates for a single site in case `execute_cron` has switched to a different blog.
20959
- */
20960
- private function _sync_license( $background = false, $is_context_single_site = false, $current_blog_id = null ) {
20961
- $this->_logger->entrance();
20962
-
20963
- $plugin_id = fs_request_get( 'plugin_id', $this->get_id() );
20964
-
20965
- $is_addon_sync = ( ! $this->_plugin->is_addon() && $plugin_id != $this->get_id() );
20966
-
20967
- if ( $is_addon_sync ) {
20968
- $this->_sync_addon_license( $plugin_id, $background );
20969
- } else {
20970
- $this->_sync_plugin_license( $background, true, $is_context_single_site, $current_blog_id );
20971
- }
20972
-
20973
- $this->do_action( 'after_account_plan_sync', $this->get_plan_name() );
20974
- }
20975
-
20976
- /**
20977
- * Sync plugin's add-on license.
20978
- *
20979
- * @author Vova Feldman (@svovaf)
20980
- * @since 1.0.6
20981
- * @uses FS_Api
20982
- *
20983
- * @param number $addon_id
20984
- * @param bool $background
20985
- */
20986
- private function _sync_addon_license( $addon_id, $background ) {
20987
- $this->_logger->entrance();
20988
-
20989
- if ( $this->is_addon_activated( $addon_id ) ) {
20990
- // If already installed, use add-on sync.
20991
- $fs_addon = self::get_instance_by_id( $addon_id );
20992
-
20993
- if (
20994
- // Add-on is network activated and network integrated.
20995
- $fs_addon->is_network_active() ||
20996
- // Background sync cron.
20997
- self::is_cron() ||
20998
- // Add-on is not network activated or not network integrated.
20999
- ! fs_is_network_admin()
21000
- ) {
21001
- $fs_addon->_sync_license( $background );
21002
-
21003
- return;
21004
- }
21005
- }
21006
-
21007
- // Validate add-on exists.
21008
- $addon = $this->get_addon( $addon_id );
21009
-
21010
- if ( ! is_object( $addon ) ) {
21011
- return;
21012
- }
21013
-
21014
- // Add add-on into account add-ons.
21015
- $account_addons = $this->get_account_addons();
21016
- if ( ! is_array( $account_addons ) ) {
21017
- $account_addons = array();
21018
- }
21019
- $account_addons[] = $addon->id;
21020
- $account_addons = array_unique( $account_addons );
21021
- $this->_store_account_addons( $account_addons );
21022
-
21023
- // Load add-on licenses.
21024
- $licenses = $this->_fetch_licenses( $addon->id );
21025
-
21026
- // Sync add-on licenses.
21027
- if ( $this->is_array_instanceof( $licenses, 'FS_Plugin_License' ) ) {
21028
- $this->_update_licenses( $licenses, $addon->id );
21029
-
21030
- if ( ! $this->is_addon_installed( $addon->id ) && FS_License_Manager::has_premium_license( $licenses ) ) {
21031
- $plans_result = $this->get_api_site_or_plugin_scope()->get( $this->add_show_pending( "/addons/{$addon_id}/plans.json" ) );
21032
-
21033
- if ( ! isset( $plans_result->error ) ) {
21034
- $plans = array();
21035
- foreach ( $plans_result->plans as $plan ) {
21036
- $plans[] = new FS_Plugin_Plan( $plan );
21037
- }
21038
-
21039
- $this->_admin_notices->add_sticky(
21040
- sprintf(
21041
- ( FS_Plan_Manager::instance()->has_free_plan( $plans ) ?
21042
- $this->get_text_inline( 'Your %s Add-on plan was successfully upgraded.', 'addon-successfully-upgraded-message' ) :
21043
- /* translators: %s:product name, e.g. Facebook add-on was successfully... */
21044
- $this->get_text_inline( '%s Add-on was successfully purchased.', 'addon-successfully-purchased-message' ) ),
21045
- $addon->title
21046
- ) . ' ' . $this->get_latest_download_link(
21047
- $this->get_text_inline( 'Download the latest version', 'download-latest-version' ),
21048
- $addon_id
21049
- ),
21050
- 'addon_plan_upgraded_' . $addon->slug,
21051
- $this->get_text_x_inline( 'Yee-haw', 'interjection expressing joy or exuberance', 'yee-haw' ) . '!'
21052
- );
21053
- }
21054
- }
21055
- }
21056
- }
21057
-
21058
- /**
21059
- * Sync site's plugin plan.
21060
- *
21061
- * @author Vova Feldman (@svovaf)
21062
- * @since 1.0.6
21063
- * @uses FS_Api
21064
- *
21065
- * @param bool $background Hints the method if it's a background sync. If false, it means that was initiated by the admin.
21066
- * @param bool $send_installs_update Since 2.0.0
21067
- * @param bool $is_context_single_site Since 2.0.0. This is used when sending an update for a single install and
21068
- * syncing its license from the network-level "Account" page (e.g.: after
21069
- * activating a license only for the single install).
21070
- * @param int|null $current_blog_id Since 2.2.3. This is passed from the `execute_cron` method so that it
21071
- * can be used here to switch to the previous blog in case `execute_cron`
21072
- * has switched to a different blog.
21073
- */
21074
- private function _sync_plugin_license(
21075
- $background = false,
21076
- $send_installs_update = true,
21077
- $is_context_single_site = false,
21078
- $current_blog_id = null
21079
- ) {
21080
- $this->_logger->entrance();
21081
-
21082
- $plan_change = 'none';
21083
-
21084
- $is_site_level_sync = ( $is_context_single_site || fs_is_blog_admin() || ! $this->_is_network_active );
21085
-
21086
- if ( ! $send_installs_update ) {
21087
- $site = $this->_site;
21088
- } else {
21089
- /**
21090
- * Sync site info.
21091
- *
21092
- * @todo This line will execute install sync on a daily basis, even if running the free version (for opted-in users). The reason we want to keep it that way is for cases when the user was a paying customer, then there was a failure in subscription payment, and then after some time the payment was successful. This could be heavily optimized. For example, we can skip the $flush if the current install was never associated with a paid version.
21093
- */
21094
- if ( $is_site_level_sync ) {
21095
- /**
21096
- * Switch to the previous blog since `execute_cron` may have switched to a different blog.
21097
- *
21098
- * @author Leo Fajardo (@leorw)
21099
- * @since 2.2.3
21100
- */
21101
- if ( is_numeric( $current_blog_id ) ) {
21102
- $this->switch_to_blog( $current_blog_id );
21103
- }
21104
-
21105
- $result = $this->send_install_update( array(), true, true );
21106
- $is_valid = $this->is_api_result_entity( $result );
21107
- } else {
21108
- $result = $this->send_installs_update( array(), true, true );
21109
- $is_valid = $this->is_api_result_object( $result, 'installs' );
21110
- }
21111
-
21112
- if ( ! $is_valid ) {
21113
- if ( $is_context_single_site ) {
21114
- // Switch back to the main blog so that the following logic will have the right entities.
21115
- $this->switch_to_blog( $this->_storage->network_install_blog_id );
21116
- }
21117
-
21118
- // Show API message only if not background sync or if paying customer.
21119
- if ( ! $background || $this->is_paying() ) {
21120
- // Try to ping API to see if not blocked.
21121
- if ( ! FS_Api::test() ) {
21122
- /**
21123
- * Failed to ping API - blocked!
21124
- *
21125
- * @author Vova Feldman (@svovaf)
21126
- * @since 1.1.6 Only show message related to one of the Freemius powered plugins. Once it will be resolved it will fix the issue for all plugins anyways. There's no point to scare users with multiple error messages.
21127
- */
21128
-
21129
- if ( ! self::$_global_admin_notices->has_sticky( 'api_blocked' ) ) {
21130
- // Add notice immediately if not a background sync.
21131
- $add_notice = ( ! $background );
21132
-
21133
- if ( ! $add_notice ) {
21134
- $counter = (int) get_transient( '_fs_api_connection_retry_counter' );
21135
-
21136
- // We only want to add the notice after 3 consecutive failures.
21137
- $add_notice = ( 3 <= $counter );
21138
-
21139
- if ( ! $add_notice ) {
21140
- /**
21141
- * Update counter transient only if notice shouldn't be added. If it is added the transient will be reset anyway, because the retries mechanism should only start counting if the admin isn't aware of the connectivity issue.
21142
- *
21143
- * Also, since the background sync happens once a day, setting the transient expiration for a week should be enough to count 3 failures, if there's an actual connectivity issue.
21144
- */
21145
- set_transient( '_fs_api_connection_retry_counter', $counter + 1, WP_FS__TIME_WEEK_IN_SEC );
21146
- }
21147
- }
21148
-
21149
- // Add notice instantly for not-background sync and only after 3 failed attempts for background sync.
21150
- if ( $add_notice ) {
21151
- self::$_global_admin_notices->add(
21152
- sprintf(
21153
- $this->get_text_inline( 'Your server is blocking the access to Freemius\' API, which is crucial for %1$s synchronization. Please contact your host to whitelist %2$s', 'server-blocking-access' ),
21154
- $this->get_plugin_name(),
21155
- '<b>' . implode( ', ', $this->apply_filters( 'api_domains', array(
21156
- 'api.freemius.com',
21157
- 'wp.freemius.com'
21158
- ) ) ) . '</b>'
21159
- ) . '<br> ' . $this->get_text_inline( 'Error received from the server:', 'server-error-message' ) . var_export( $result->error, true ),
21160
- $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
21161
- 'error',
21162
- $background,
21163
- 'api_blocked'
21164
- );
21165
-
21166
- // Notice was just shown, reset connectivity counter.
21167
- delete_transient( '_fs_api_connection_retry_counter' );
21168
- }
21169
- }
21170
- } else if ( is_object( $result ) ) {
21171
- // Authentication params are broken.
21172
- $this->_admin_notices->add(
21173
- $this->get_text_inline( 'It seems like one of the authentication parameters is wrong. Update your Public Key, Secret Key & User ID, and try again.', 'wrong-authentication-param-message' ) . '<br> ' . $this->get_text_inline( 'Error received from the server:', 'server-error-message' ) . var_export( $result->error, true ),
21174
- $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
21175
- 'error'
21176
- );
21177
- }
21178
- }
21179
-
21180
- // No reason to continue with license sync while there are API issues.
21181
- return;
21182
- }
21183
-
21184
- // API is working now. Delete the transient and start afresh.
21185
- delete_transient('_fs_api_connection_retry_counter');
21186
-
21187
- if ( $is_site_level_sync ) {
21188
- $site = new FS_Site( $result );
21189
- } else {
21190
- // Map site addresses to their blog IDs.
21191
- $address_to_blog_map = $this->get_address_to_blog_map();
21192
-
21193
- // Find the current context install.
21194
- $site = null;
21195
- foreach ( $result->installs as $install ) {
21196
- if ( $install->id == $this->_site->id ) {
21197
- $site = new FS_Site( $install );
21198
- } else {
21199
- $address = trailingslashit( fs_strip_url_protocol( $install->url ) );
21200
- $blog_id = $address_to_blog_map[ $address ];
21201
-
21202
- $this->_store_site( true, $blog_id, new FS_Site( $install ) );
21203
- }
21204
- }
21205
- }
21206
-
21207
- // Sync plans.
21208
- $this->_sync_plans();
21209
- }
21210
-
21211
- // Remove sticky API connectivity message.
21212
- self::$_global_admin_notices->remove_sticky( 'api_blocked' );
21213
-
21214
- if ( ! $this->has_paid_plan() ) {
21215
- $this->_site = $site;
21216
- $this->_store_site(
21217
- true,
21218
- $is_site_level_sync ?
21219
- null :
21220
- $this->get_network_install_blog_id()
21221
- );
21222
- } else {
21223
- $context_blog_id = 0;
21224
-
21225
- if ( $is_context_single_site ) {
21226
- $context_blog_id = get_current_blog_id();
21227
-
21228
- // Switch back to the main blog in order to properly sync the license.
21229
- $this->switch_to_blog( $this->_storage->network_install_blog_id );
21230
- }
21231
-
21232
- /**
21233
- * Sync licenses. Pass the site's license ID so that the foreign licenses will be fetched if the license
21234
- * associated with that ID is not included in the user's licenses collection.
21235
- */
21236
- $this->_sync_licenses(
21237
- $site->license_id,
21238
- ( $is_context_single_site ?
21239
- $context_blog_id :
21240
- null
21241
- )
21242
- );
21243
-
21244
- if ( $is_context_single_site ) {
21245
- $this->switch_to_blog( $context_blog_id );
21246
- }
21247
-
21248
- // Check if plan / license changed.
21249
- if ( $site->plan_id != $this->_site->plan_id ||
21250
- // Check if trial started.
21251
- $site->trial_plan_id != $this->_site->trial_plan_id ||
21252
- $site->trial_ends != $this->_site->trial_ends ||
21253
- // Check if license changed.
21254
- $site->license_id != $this->_site->license_id
21255
- ) {
21256
- if ( $site->is_trial() && ( ! $this->_site->is_trial() || $site->trial_ends != $this->_site->trial_ends ) ) {
21257
- // New trial started.
21258
- $this->_site = $site;
21259
- $plan_change = 'trial_started';
21260
-
21261
- // For trial with subscription use-case.
21262
- $new_license = is_null( $site->license_id ) ? null : $this->_get_license_by_id( $site->license_id );
21263
-
21264
- if ( is_object( $new_license ) && $new_license->is_valid() ) {
21265
- $this->_site = $site;
21266
- $this->_update_site_license( $new_license );
21267
- $this->_store_licenses();
21268
-
21269
- $this->_sync_site_subscription( $this->_license );
21270
- }
21271
- } else if ( $this->_site->is_trial() && ! $site->is_trial() && ! is_numeric( $site->license_id ) ) {
21272
- // Was in trial, but now trial expired and no license ID.
21273
- // New trial started.
21274
- $this->_site = $site;
21275
- $plan_change = 'trial_expired';
21276
- } else {
21277
- $is_free = $this->is_free_plan();
21278
-
21279
- // Make sure license exist and not expired.
21280
- $new_license = is_null( $site->license_id ) ?
21281
- null :
21282
- $this->_get_license_by_id( $site->license_id );
21283
-
21284
- if ( $is_free && is_null( $new_license ) && $this->has_any_license() && $this->_license->is_cancelled ) {
21285
- // License cancelled.
21286
- $this->_site = $site;
21287
- $this->_update_site_license( $new_license );
21288
- $this->_store_licenses();
21289
-
21290
- $plan_change = 'cancelled';
21291
- } else if ( $is_free && ( ( ! is_object( $new_license ) || $new_license->is_expired() ) ) ) {
21292
- // The license is expired, so ignore upgrade method.
21293
- $this->_site = $site;
21294
- } else {
21295
- // License changed.
21296
- $this->_site = $site;
21297
-
21298
- /**
21299
- * IMPORTANT:
21300
- * The line below should be executed before trying to activate the license on the rest of the network, otherwise, the license' activation counters may be out of sync + there's no need to activate the license on the context site since it's already activated on it.
21301
- *
21302
- * @author Vova Feldman (@svovaf)
21303
- * @since 2.0.0
21304
- */
21305
- $this->_update_site_license( $new_license );
21306
-
21307
- if ( ! $is_context_single_site &&
21308
- fs_is_network_admin() &&
21309
- $this->_is_network_active &&
21310
- $new_license->quota > 1 &&
21311
- get_blog_count() > 1
21312
- ) {
21313
- // See if license can activated on all sites.
21314
- if ( ! $this->try_activate_license_on_network( $this->_user, $new_license ) ) {
21315
- if ( ! fs_request_get_bool( 'auto_install' ) ) {
21316
- // Open the license activation dialog box on the account page.
21317
- add_action( 'admin_footer', array(
21318
- &$this,
21319
- '_open_license_activation_dialog_box'
21320
- ) );
21321
- }
21322
- }
21323
- }
21324
-
21325
- $this->_store_licenses();
21326
-
21327
- $plan_change = $is_free ?
21328
- ( $this->is_only_premium() ? 'activated' : 'upgraded' ) :
21329
- ( is_object( $new_license ) ?
21330
- 'changed' :
21331
- 'downgraded' );
21332
- }
21333
- }
21334
-
21335
- // Store updated site info.
21336
- $this->_store_site(
21337
- true,
21338
- $is_site_level_sync ?
21339
- null :
21340
- $this->get_network_install_blog_id()
21341
- );
21342
- } else {
21343
- if ( ! is_object( $this->_license ) ) {
21344
- $this->maybe_update_whitelabel_flag(
21345
- FS_Plugin_License::is_valid_id( $site->license_id ) ?
21346
- $this->get_license_by_id( $site->license_id ) :
21347
- null
21348
- );
21349
- } else {
21350
- $this->maybe_update_whitelabel_flag( $this->_license );
21351
-
21352
- if ( $this->_license->is_expired() ) {
21353
- if ( ! $this->has_features_enabled_license() ) {
21354
- $this->_deactivate_license();
21355
- $plan_change = 'downgraded';
21356
- } else {
21357
- $last_time_expired_license_notice_was_shown = $this->_storage->get( 'expired_license_notice_shown', 0 );
21358
-
21359
- if ( time() - ( 14 * WP_FS__TIME_24_HOURS_IN_SEC ) >= $last_time_expired_license_notice_was_shown ) {
21360
- /**
21361
- * Show the expired license notice every 14 days.
21362
- *
21363
- * @author Leo Fajardo (@leorw)
21364
- * @since 2.3.1
21365
- */
21366
- $plan_change = 'expired';
21367
- }
21368
- }
21369
- }
21370
- }
21371
-
21372
- if ( is_numeric( $site->license_id ) && is_object( $this->_license ) ) {
21373
- $this->_sync_site_subscription( $this->_license );
21374
- }
21375
- }
21376
-
21377
- if ( ! $this->is_addon() &&
21378
- $this->_site->is_beta() !== $site->is_beta()
21379
- ) {
21380
- // Beta flag updated.
21381
- $this->_site = $site;
21382
-
21383
- $this->_store_site(
21384
- true,
21385
- $is_site_level_sync ?
21386
- null :
21387
- $this->get_network_install_blog_id()
21388
- );
21389
- }
21390
-
21391
- if ( $this->is_addon() || $this->has_addons() ) {
21392
- /**
21393
- * Purge the valid user licenses cache so that when the "Account" or the "Add-Ons" page is loaded,
21394
- * an updated valid user licenses collection will be fetched from the server which is used to also
21395
- * update the account add-ons (add-ons the user has licenses for).
21396
- *
21397
- * @author Leo Fajardo (@leorw)
21398
- * @since 2.2.4
21399
- */
21400
- $this->purge_valid_user_licenses_cache();
21401
- }
21402
- }
21403
-
21404
- $hmm_text = $this->get_text_x_inline( 'Hmm', 'something somebody says when they are thinking about what you have just said.', 'hmm' ) . '...';
21405
-
21406
- if ( $this->apply_filters( 'has_paid_plan_account', $this->has_paid_plan() ) ) {
21407
- switch ( $plan_change ) {
21408
- case 'none':
21409
- if ( ! $background && is_admin() ) {
21410
- $plan = $this->is_trial() ?
21411
- $this->get_trial_plan() :
21412
- $this->get_plan();
21413
-
21414
- if ( $plan->is_free() ) {
21415
- $this->_admin_notices->add(
21416
- sprintf(
21417
- $this->get_text_inline( 'It looks like you are still on the %s plan. If you did upgrade or change your plan, it\'s probably an issue on our side - sorry.', 'plan-did-not-change-message' ),
21418
- '<i><b>' . $plan->title . ( $this->is_trial() ? ' ' . $this->get_text_x_inline( 'Trial', 'trial period', 'trial' ) : '' ) . '</b></i>'
21419
- ) . ' ' . sprintf(
21420
- '<a href="%s">%s</a>',
21421
- $this->contact_url(
21422
- 'bug',
21423
- sprintf( $this->get_text_inline( 'I have upgraded my account but when I try to Sync the License, the plan remains %s.', 'plan-did-not-change-email-message' ),
21424
- strtoupper( $plan->name )
21425
- )
21426
- ),
21427
- $this->get_text_inline( 'Please contact us here', 'contact-us-here' )
21428
- ),
21429
- $hmm_text
21430
- );
21431
- }
21432
- }
21433
- break;
21434
- case 'upgraded':
21435
- case 'activated':
21436
- $this->_admin_notices->add_sticky(
21437
- ( 'activated' === $plan_change ) ?
21438
- $this->get_text_inline( 'Your plan was successfully activated.', 'plan-activated-message' ) :
21439
- $this->get_text_inline( 'Your plan was successfully upgraded.', 'plan-upgraded-message' ) .
21440
- $this->get_complete_upgrade_instructions(),
21441
- 'plan_upgraded',
21442
- $this->get_text_x_inline( 'Yee-haw', 'interjection expressing joy or exuberance', 'yee-haw' ) . '!'
21443
- );
21444
-
21445
- $this->_admin_notices->remove_sticky( array(
21446
- 'trial_started',
21447
- 'trial_promotion',
21448
- 'trial_expired',
21449
- 'activation_complete',
21450
- 'license_expired',
21451
- ) );
21452
- break;
21453
- case 'changed':
21454
- $this->_admin_notices->add_sticky(
21455
- sprintf(
21456
- $this->get_text_inline( 'Your plan was successfully changed to %s.', 'plan-changed-to-x-message' ),
21457
- $this->get_plan_title()
21458
- ),
21459
- 'plan_changed'
21460
- );
21461
-
21462
- $this->_admin_notices->remove_sticky( array(
21463
- 'trial_started',
21464
- 'trial_promotion',
21465
- 'trial_expired',
21466
- 'activation_complete',
21467
- ) );
21468
- break;
21469
- case 'downgraded':
21470
- $this->_admin_notices->add_sticky(
21471
- ($this->has_free_plan() ?
21472
- sprintf( $this->get_text_inline( 'Your license has expired. You can still continue using the free %s forever.', 'license-expired-blocking-message' ), $this->_module_type ) :
21473
- /* translators: %1$s: product title; %2$s, %3$s: wrapping HTML anchor element; %4$s: 'plugin', 'theme', or 'add-on'. */
21474
- sprintf( $this->get_text_inline( 'Your license has expired. %1$sUpgrade now%2$s to continue using the %3$s without interruptions.', 'license-expired-blocking-message_premium-only' ), sprintf('<a href="%s">', $this->pricing_url()), '</a>', $this->get_module_label(true) ) ),
21475
- 'license_expired',
21476
- $hmm_text
21477
- );
21478
- $this->_admin_notices->remove_sticky( 'plan_upgraded' );
21479
- break;
21480
- case 'cancelled':
21481
- $this->_admin_notices->add(
21482
- $this->get_text_inline( 'Your license has been cancelled. If you think it\'s a mistake, please contact support.', 'license-cancelled' ) . ' ' .
21483
- sprintf(
21484
- '<a href="%s">%s</a>',
21485
- $this->contact_url( 'bug' ),
21486
- $this->get_text_inline( 'Please contact us here', 'contact-us-here' )
21487
- ),
21488
- $hmm_text,
21489
- 'error'
21490
- );
21491
- $this->_admin_notices->remove_sticky( 'plan_upgraded' );
21492
- break;
21493
- case 'expired':
21494
- $this->_admin_notices->add_sticky(
21495
- sprintf( $this->get_text_inline( 'Your license has expired. You can still continue using all the %s features, but you\'ll need to renew your license to continue getting updates and support.', 'license-expired-non-blocking-message' ), $this->get_plan()->title ),
21496
- 'license_expired',
21497
- $hmm_text
21498
- );
21499
-
21500
- $this->_storage->expired_license_notice_shown = WP_FS__SCRIPT_START_TIME;
21501
-
21502
- $this->_admin_notices->remove_sticky( 'plan_upgraded' );
21503
- break;
21504
- case 'trial_started':
21505
- $this->_admin_notices->add_sticky(
21506
- sprintf(
21507
- $this->get_text_inline( 'Your trial has been successfully started.', 'trial-started-message' ),
21508
- '<i>' . $this->get_plugin_name() . '</i>'
21509
- ) . $this->get_complete_upgrade_instructions( $this->get_trial_plan()->title ),
21510
- 'trial_started',
21511
- $this->get_text_x_inline( 'Yee-haw', 'interjection expressing joy or exuberance', 'yee-haw' ) . '!'
21512
- );
21513
-
21514
- $this->_admin_notices->remove_sticky( array(
21515
- 'trial_promotion',
21516
- ) );
21517
- break;
21518
- case 'trial_expired':
21519
- $this->_admin_notices->add_sticky(
21520
- ($this->has_free_plan() ?
21521
- $this->get_text_inline( 'Your free trial has expired. You can still continue using all our free features.', 'trial-expired-message' ) :
21522
- /* translators: %1$s: product title; %2$s, %3$s: wrapping HTML anchor element; %4$s: 'plugin', 'theme', or 'add-on'. */
21523
- sprintf( $this->get_text_inline( 'Your free trial has expired. %1$sUpgrade now%2$s to continue using the %3$s without interruptions.', 'trial-expired-message_premium-only' ), sprintf('<a href="%s">', $this->pricing_url()), '</a>', $this->get_module_label(true))),
21524
- 'trial_expired',
21525
- $hmm_text
21526
- );
21527
- $this->_admin_notices->remove_sticky( array(
21528
- 'trial_started',
21529
- 'trial_promotion',
21530
- 'plan_upgraded',
21531
- ) );
21532
- break;
21533
- }
21534
- }
21535
-
21536
- if ( 'none' !== $plan_change ) {
21537
- if (
21538
- ! is_object( $this->_license ) ||
21539
- ! $this->_license->is_whitelabeled
21540
- ) {
21541
- $this->_admin_notices->remove_sticky( 'license_whitelabeled' );
21542
- }
21543
-
21544
- $this->do_action( 'after_license_change', $plan_change, $this->get_plan() );
21545
- }
21546
- }
21547
-
21548
- /**
21549
- * Include the required JS at the footer of the admin to trigger the license activation dialog box.
21550
- *
21551
- * @author Vova Feldman (@svovaf)
21552
- * @since 2.0.0
21553
- */
21554
- public function _open_license_activation_dialog_box() {
21555
- $vars = array( 'license_id' => $this->_site->license_id );
21556
- fs_require_once_template( 'js/open-license-activation.php', $vars );
21557
- }
21558
-
21559
- /**
21560
- * @author Vova Feldman (@svovaf)
21561
- * @since 1.0.5
21562
- *
21563
- * @param bool $background
21564
- * @param FS_Plugin_License|null $premium_license
21565
- */
21566
- protected function _activate_license( $background = false, $premium_license = null ) {
21567
- $this->_logger->entrance();
21568
-
21569
- if ( is_null( $premium_license ) ) {
21570
- $license_id = fs_request_get( 'license_id' );
21571
-
21572
- if ( is_object( $this->_site ) &&
21573
- FS_Plugin_License::is_valid_id( $license_id ) &&
21574
- $license_id == $this->_site->license_id
21575
- ) {
21576
- // License is already activated.
21577
- return;
21578
- }
21579
-
21580
- $premium_license = FS_Plugin_License::is_valid_id( $license_id ) ?
21581
- $this->_get_license_by_id( $license_id ) :
21582
- $this->_get_available_premium_license();
21583
- }
21584
-
21585
- if ( ! is_object( $premium_license ) ) {
21586
- return;
21587
- }
21588
-
21589
- if ( ! is_object( $this->_site ) ) {
21590
- // Not yet opted-in.
21591
- $user = $this->get_current_or_network_user();
21592
- if ( ! is_object( $user ) ) {
21593
- $user = self::_get_user_by_id( $premium_license->user_id );
21594
- }
21595
-
21596
- if ( is_object( $user ) ) {
21597
- $this->install_with_user( $user, $premium_license->secret_key, false, false, false );
21598
- } else {
21599
- $this->opt_in(
21600
- false,
21601
- false,
21602
- false,
21603
- $premium_license->secret_key
21604
- );
21605
-
21606
- return;
21607
- }
21608
- }
21609
-
21610
-
21611
- /**
21612
- * If the premium license is already associated with the install, just
21613
- * update the license reference (activation is not required).
21614
- *
21615
- * @since 1.1.9
21616
- */
21617
- if ( $premium_license->id == $this->_site->license_id ) {
21618
- // License is already activated.
21619
- $this->_update_site_license( $premium_license );
21620
- $this->_store_account();
21621
-
21622
- return;
21623
- }
21624
-
21625
- if ( $this->_site->user_id != $premium_license->user_id ) {
21626
- $api_request_params = array( 'license_key' => $premium_license->secret_key );
21627
- } else {
21628
- $api_request_params = array();
21629
- }
21630
-
21631
- $api = $this->get_api_site_scope();
21632
- $license = $api->call( "/licenses/{$premium_license->id}.json?is_enriched=true", 'put', $api_request_params );
21633
-
21634
- if ( ! $this->is_api_result_entity( $license ) ) {
21635
- if ( ! $background ) {
21636
- $this->_admin_notices->add( sprintf(
21637
- '%s %s',
21638
- $this->get_text_inline( 'It looks like the license could not be activated.', 'license-activation-failed-message' ),
21639
- ( is_object( $license ) && isset( $license->error ) ?
21640
- $license->error->message :
21641
- sprintf( '%s<br><code>%s</code>',
21642
- $this->get_text_inline( 'Error received from the server:', 'server-error-message' ),
21643
- var_export( $license, true )
21644
- )
21645
- )
21646
- ),
21647
- $this->get_text_x_inline( 'Hmm', 'something somebody says when they are thinking about what you have just said.', 'hmm' ) . '...',
21648
- 'error'
21649
- );
21650
- }
21651
-
21652
- return;
21653
- }
21654
-
21655
- $premium_license = new FS_Plugin_License( $license );
21656
-
21657
- // Updated site plan.
21658
- $site = $this->get_api_site_scope()->get( '/', true );
21659
- if ( $this->is_api_result_entity( $site ) ) {
21660
- $this->_site = new FS_Site( $site );
21661
- }
21662
- $this->_update_site_license( $premium_license );
21663
-
21664
- $this->_store_account();
21665
-
21666
- if ( $this->is_addon() || $this->has_addons() ) {
21667
- /**
21668
- * Purge the valid user licenses cache so that when the "Account" or the "Add-Ons" page is loaded,
21669
- * an updated valid user licenses collection will be fetched from the server which is used to also
21670
- * update the account add-ons (add-ons the user has licenses for).
21671
- *
21672
- * @author Leo Fajardo (@leorw)
21673
- * @since 2.2.4
21674
- */
21675
- $this->purge_valid_user_licenses_cache();
21676
- }
21677
-
21678
- if ( ! $background ) {
21679
- $this->_admin_notices->add_sticky(
21680
- $this->get_text_inline( 'Your license was successfully activated.', 'license-activated-message' ) .
21681
- $this->get_complete_upgrade_instructions(),
21682
- 'license_activated',
21683
- $this->get_text_x_inline( 'Yee-haw', 'interjection expressing joy or exuberance', 'yee-haw' ) . '!'
21684
- );
21685
- }
21686
-
21687
- $this->_admin_notices->remove_sticky( array(
21688
- 'trial_promotion',
21689
- 'license_expired',
21690
- ) );
21691
- }
21692
-
21693
- /**
21694
- * @author Vova Feldman (@svovaf)
21695
- * @since 1.0.5
21696
- *
21697
- * @param bool $show_notice
21698
- */
21699
- protected function _deactivate_license( $show_notice = true ) {
21700
- $this->_logger->entrance();
21701
-
21702
- $hmm_text = $this->get_text_x_inline( 'Hmm', 'something somebody says when they are thinking about what you have just said.', 'hmm' ) . '...';
21703
-
21704
- if ( ! FS_Plugin_License::is_valid_id( $this->_site->license_id ) ) {
21705
- $this->_admin_notices->add(
21706
- sprintf( $this->get_text_inline( 'It looks like your site currently doesn\'t have an active license.', 'no-active-license-message' ), $this->get_plan_title() ),
21707
- $hmm_text
21708
- );
21709
-
21710
- return;
21711
- }
21712
-
21713
- $api = $this->get_api_site_scope();
21714
- $license = $api->call( "/licenses/{$this->_site->license_id}.json", 'delete' );
21715
-
21716
- $this->handle_license_deactivation_result( $license, $hmm_text, $show_notice );
21717
- }
21718
-
21719
- /**
21720
- * @author Leo Fajardo (@leorw)
21721
- * @since 2.2.1
21722
- *
21723
- * @param FS_Plugin_License $license
21724
- * @param bool|string $hmm_text
21725
- * @param bool $show_notice
21726
- */
21727
- private function handle_license_deactivation_result( $license, $hmm_text = false, $show_notice = true ) {
21728
- if ( isset( $license->error ) ) {
21729
- $this->_admin_notices->add(
21730
- $this->get_text_inline( 'It looks like the license deactivation failed.', 'license-deactivation-failed-message' ) . '<br> ' .
21731
- $this->get_text_inline( 'Error received from the server:', 'server-error-message' ) . ' ' . var_export( $license->error, true ),
21732
- $hmm_text,
21733
- 'error'
21734
- );
21735
-
21736
- return;
21737
- }
21738
-
21739
- // Update license cache.
21740
- if ( is_array( $this->_licenses ) ) {
21741
- for ( $i = 0, $len = count( $this->_licenses ); $i < $len; $i ++ ) {
21742
- if ( $license->id == $this->_licenses[ $i ]->id ) {
21743
- $this->_licenses[ $i ] = new FS_Plugin_License( $license );
21744
- }
21745
- }
21746
- }
21747
-
21748
- // Update site plan to default.
21749
- $this->_sync_plans();
21750
- $this->_site->plan_id = $this->_plans[0]->id;
21751
- // Unlink license from site.
21752
- $this->_update_site_license( null );
21753
-
21754
- $this->_store_account();
21755
-
21756
- if ( $show_notice ) {
21757
- $this->_admin_notices->add(
21758
- sprintf( $this->is_only_premium() ?
21759
- $this->get_text_inline( 'Your %s license was successfully deactivated.', 'license-deactivation-message_premium-only' ) :
21760
- $this->get_text_inline( 'Your license was successfully deactivated, you are back to the %s plan.', 'license-deactivation-message' ),
21761
- $this->get_plan_title()
21762
- ),
21763
- $this->get_text_inline( 'O.K', 'ok' )
21764
- );
21765
- }
21766
-
21767
- $this->_admin_notices->remove_sticky( array(
21768
- 'plan_upgraded',
21769
- 'license_activated',
21770
- ) );
21771
- }
21772
-
21773
- /**
21774
- * Site plan downgrade.
21775
- *
21776
- * @author Vova Feldman (@svovaf)
21777
- * @since 1.0.4
21778
- *
21779
- * @return object
21780
- *
21781
- * @uses FS_Api
21782
- */
21783
- private function _downgrade_site() {
21784
- $this->_logger->entrance();
21785
-
21786
- $deactivate_license = fs_request_get_bool( 'deactivate_license' );
21787
-
21788
- $api = $this->get_api_site_scope();
21789
- $site = $api->call( 'downgrade.json', 'put', array( 'deactivate_license' => $deactivate_license ) );
21790
-
21791
- $plan_downgraded = false;
21792
- $plan = false;
21793
- if ( $this->is_api_result_entity( $site ) ) {
21794
- $prev_plan_id = $this->_site->plan_id;
21795
-
21796
- // Update new site plan id.
21797
- $this->_site->plan_id = $site->plan_id;
21798
-
21799
- $plan = $this->get_plan();
21800
- $subscription = $this->_sync_site_subscription( $this->_license );
21801
-
21802
- // Plan downgraded if plan was changed or subscription was cancelled.
21803
- $plan_downgraded = ( $plan instanceof FS_Plugin_Plan && $prev_plan_id != $plan->id ) ||
21804
- ( is_object( $subscription ) && ! isset( $subscription->error ) && ! $subscription->is_active() );
21805
- } else {
21806
- // handle different error cases.
21807
- $this->handle_license_deactivation_result(
21808
- $site,
21809
- $this->get_text_x_inline( 'Hmm', 'something somebody says when they are thinking about what you have just said.', 'hmm' ) . '...'
21810
- );
21811
- }
21812
-
21813
- if ( ! $plan_downgraded ) {
21814
- return (object) array(
21815
- 'error' => (object) array(
21816
- 'message' => $this->get_text_inline( 'Seems like we are having some temporary issue with your subscription cancellation. Please try again in few minutes.', 'subscription-cancellation-failure-message' )
21817
- )
21818
- );
21819
- }
21820
-
21821
- // Remove previous sticky message about upgrade (if exist).
21822
- $this->_admin_notices->remove_sticky( 'plan_upgraded' );
21823
-
21824
- $this->_admin_notices->add(
21825
- sprintf( $this->get_text_inline( 'Your subscription was successfully cancelled. Your %s plan license will expire in %s.', 'plan-x-downgraded-message' ),
21826
- $plan->title,
21827
- human_time_diff( time(), strtotime( $this->_license->expiration ) )
21828
- )
21829
- );
21830
-
21831
- // Store site updates.
21832
- $this->_store_site();
21833
-
21834
- if ( $deactivate_license &&
21835
- ! FS_Plugin_License::is_valid_id( $site->license_id )
21836
- ) {
21837
- if ( $this->_site->is_localhost() ) {
21838
- $this->_license->activated_local = max( 0, $this->_license->activated_local - 1 );
21839
- } else {
21840
- $this->_license->activated = max( 0, $this->_license->activated - 1 );
21841
- }
21842
-
21843
- // Handle successful license deactivation result.
21844
- $this->handle_license_deactivation_result( $this->_license );
21845
- }
21846
-
21847
- return $site;
21848
- }
21849
-
21850
- /**
21851
- * @author Vova Feldman (@svovaf)
21852
- * @since 1.1.8.1
21853
- *
21854
- * @param bool|string $plan_name
21855
- *
21856
- * @return bool If trial was successfully started.
21857
- */
21858
- function start_trial( $plan_name = false ) {
21859
- $this->_logger->entrance();
21860
-
21861
- // Alias.
21862
- $oops_text = $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...';
21863
-
21864
- if ( $this->is_trial() ) {
21865
- // Already in trial mode.
21866
- $this->_admin_notices->add(
21867
- sprintf( $this->get_text_inline( 'You are already running the %s in a trial mode.', 'in-trial-mode' ), $this->_module_type ),
21868
- $oops_text,
21869
- 'error'
21870
- );
21871
-
21872
- return false;
21873
- }
21874
-
21875
- if ( $this->_site->is_trial_utilized() ) {
21876
- // Trial was already utilized.
21877
- $this->_admin_notices->add(
21878
- $this->get_text_inline( 'You already utilized a trial before.', 'trial-utilized' ),
21879
- $oops_text,
21880
- 'error'
21881
- );
21882
-
21883
- return false;
21884
- }
21885
-
21886
- if ( false !== $plan_name ) {
21887
- $plan = $this->get_plan_by_name( $plan_name );
21888
-
21889
- if ( false === $plan ) {
21890
- // Plan doesn't exist.
21891
- $this->_admin_notices->add(
21892
- sprintf( $this->get_text_inline( 'Plan %s do not exist, therefore, can\'t start a trial.', 'trial-plan-x-not-exist' ), $plan_name ),
21893
- $oops_text,
21894
- 'error'
21895
- );
21896
-
21897
- return false;
21898
- }
21899
-
21900
- if ( ! $plan->has_trial() ) {
21901
- // Plan doesn't exist.
21902
- $this->_admin_notices->add(
21903
- sprintf( $this->get_text_inline( 'Plan %s does not support a trial period.', 'plan-x-no-trial' ), $plan_name ),
21904
- $oops_text,
21905
- 'error'
21906
- );
21907
-
21908
- return false;
21909
- }
21910
- } else {
21911
- if ( ! $this->has_trial_plan() ) {
21912
- // None of the plans have a trial.
21913
- $this->_admin_notices->add(
21914
- sprintf( $this->get_text_inline( 'None of the %s\'s plans supports a trial period.', 'no-trials' ), $this->_module_type ),
21915
- $oops_text,
21916
- 'error'
21917
- );
21918
-
21919
- return false;
21920
- }
21921
-
21922
- $plans_with_trial = FS_Plan_Manager::instance()->get_trial_plans( $this->_plans );
21923
-
21924
- $plan = $plans_with_trial[0];
21925
- }
21926
-
21927
- $api = $this->get_api_site_scope();
21928
- $plan = $api->call( "plans/{$plan->id}/trials.json", 'post' );
21929
-
21930
- if ( ! $this->is_api_result_entity( $plan ) ) {
21931
- // Some API error while trying to start the trial.
21932
- $this->_admin_notices->add(
21933
- sprintf( $this->get_text_inline( 'Unexpected API error. Please contact the %s\'s author with the following error.', 'unexpected-api-error' ), $this->_module_type )
21934
- . ' ' . var_export( $plan, true ),
21935
- $oops_text,
21936
- 'error'
21937
- );
21938
-
21939
- return false;
21940
- }
21941
-
21942
- // Sync license.
21943
- $this->_sync_license();
21944
-
21945
- return $this->is_trial();
21946
- }
21947
-
21948
- /**
21949
- * Cancel site trial.
21950
- *
21951
- * @author Vova Feldman (@svovaf)
21952
- * @since 1.0.9
21953
- *
21954
- * @return object
21955
- *
21956
- * @uses FS_Api
21957
- */
21958
- private function _cancel_trial() {
21959
- $this->_logger->entrance();
21960
-
21961
- if ( ! $this->is_trial() ) {
21962
- return (object) array(
21963
- 'error' => (object) array(
21964
- 'message' => $this->get_text_inline( 'It looks like you are not in trial mode anymore so there\'s nothing to cancel :)', 'trial-cancel-no-trial-message' )
21965
- )
21966
- );
21967
- }
21968
-
21969
- $trial_plan = $this->get_trial_plan();
21970
-
21971
- $api = $this->get_api_site_scope();
21972
- $site = $api->call( 'trials.json', 'delete' );
21973
-
21974
- $trial_cancelled = false;
21975
-
21976
- if ( $this->is_api_result_entity( $site ) ) {
21977
- $prev_trial_ends = $this->_site->trial_ends;
21978
-
21979
- if ( $this->is_paid_trial() ) {
21980
- $this->_license->expiration = $site->trial_ends;
21981
- $this->_license->is_cancelled = true;
21982
- $this->_update_site_license( $this->_license );
21983
- $this->_store_licenses();
21984
-
21985
- // Clear subscription reference.
21986
- $this->_sync_site_subscription( null );
21987
- }
21988
-
21989
- // Update site info.
21990
- $this->_site = new FS_Site( $site );
21991
-
21992
- $trial_cancelled = ( $prev_trial_ends != $site->trial_ends );
21993
- } else {
21994
- // @todo handle different error cases.
21995
- }
21996
-
21997
- if ( ! $trial_cancelled ) {
21998
- return (object) array(
21999
- 'error' => (object) array(
22000
- 'message' => $this->get_text_inline( 'Seems like we are having some temporary issue with your trial cancellation. Please try again in few minutes.', 'trial-cancel-failure-message' )
22001
- )
22002
- );
22003
- }
22004
-
22005
- // Remove previous sticky messages about upgrade or trial (if exist).
22006
- $this->_admin_notices->remove_sticky( array(
22007
- 'trial_started',
22008
- 'trial_promotion',
22009
- 'plan_upgraded',
22010
- ) );
22011
-
22012
- // Store site updates.
22013
- $this->_store_site();
22014
-
22015
- if ( ! $this->is_addon() ||
22016
- ! $this->deactivate_premium_only_addon_without_license( true )
22017
- ) {
22018
- $this->_admin_notices->add(
22019
- sprintf( $this->get_text_inline( 'Your %s free trial was successfully cancelled.', 'trial-cancel-message' ), $trial_plan->title )
22020
- );
22021
- }
22022
-
22023
- return $site;
22024
- }
22025
-
22026
- /**
22027
- * @author Vova Feldman (@svovaf)
22028
- * @since 1.0.6
22029
- *
22030
- * @param bool|number $plugin_id
22031
- *
22032
- * @return bool
22033
- */
22034
- private function _is_addon_id( $plugin_id ) {
22035
- return is_numeric( $plugin_id ) && ( $this->get_id() != $plugin_id );
22036
- }
22037
-
22038
- /**
22039
- * Check if user eligible to download premium version updates.
22040
- *
22041
- * @author Vova Feldman (@svovaf)
22042
- * @since 1.0.6
22043
- *
22044
- * @return bool
22045
- */
22046
- private function _can_download_premium() {
22047
- return $this->has_any_active_valid_license() ||
22048
- ( $this->is_trial() && ! $this->get_trial_plan()->is_free() );
22049
- }
22050
-
22051
- /**
22052
- *
22053
- * @author Vova Feldman (@svovaf)
22054
- * @since 1.0.6
22055
- *
22056
- * @param bool|number $addon_id
22057
- * @param string $type "json" or "zip"
22058
- *
22059
- * @return string
22060
- */
22061
- private function _get_latest_version_endpoint( $addon_id = false, $type = 'json' ) {
22062
-
22063
- $is_addon = $this->_is_addon_id( $addon_id );
22064
-
22065
- $is_premium = null;
22066
- if ( ! $is_addon ) {
22067
- $is_premium = ( $this->is_premium() || $this->_can_download_premium() );
22068
- } else if ( $this->is_addon_activated( $addon_id ) ) {
22069
- $fs_addon = self::get_instance_by_id( $addon_id );
22070
- $is_premium = ( $fs_addon->is_premium() || $fs_addon->_can_download_premium() );
22071
- }
22072
-
22073
- // If add-on, then append add-on ID.
22074
- $endpoint = ( $is_addon ? "/addons/$addon_id" : '' ) .
22075
- '/updates/latest.' . $type;
22076
-
22077
- // If add-on and not yet activated, try to fetch based on server licensing.
22078
- if ( is_bool( $is_premium ) ) {
22079
- $endpoint = add_query_arg( 'is_premium', json_encode( $is_premium ), $endpoint );
22080
- }
22081
-
22082
- if ( $this->has_secret_key() ) {
22083
- $endpoint = add_query_arg( 'type', 'all', $endpoint );
22084
- } else if ( is_object( $this->_site ) && $this->_site->is_beta() ) {
22085
- $endpoint = add_query_arg( 'type', 'beta', $endpoint );
22086
- }
22087
-
22088
- return $endpoint;
22089
- }
22090
-
22091
- /**
22092
- * @author Vova Feldman (@svovaf)
22093
- * @since 1.0.4
22094
- *
22095
- * @param bool|number $addon_id
22096
- * @param bool $flush Since 1.1.7.3
22097
- * @param int $expiration Since 1.2.2.7
22098
- * @param bool|string $newer_than Since 2.2.1
22099
- * @param bool|string $fetch_readme Since 2.2.1
22100
- *
22101
- * @return object|false Plugin latest tag info.
22102
- */
22103
- function _fetch_latest_version(
22104
- $addon_id = false,
22105
- $flush = true,
22106
- $expiration = WP_FS__TIME_24_HOURS_IN_SEC,
22107
- $newer_than = false,
22108
- $fetch_readme = true
22109
- ) {
22110
- $this->_logger->entrance();
22111
-
22112
- if ( $this->is_unresolved_clone() ) {
22113
- return false;
22114
- }
22115
-
22116
- $switch_to_blog_id = null;
22117
-
22118
- /**
22119
- * @since 1.1.7.3 Check for plugin updates from Freemius only if opted-in.
22120
- * @since 1.1.7.4 Also check updates for add-ons.
22121
- */
22122
- if ( ! $this->is_registered() &&
22123
- ! $this->_is_addon_id( $addon_id )
22124
- ) {
22125
- if ( ! is_multisite() ) {
22126
- return false;
22127
- }
22128
-
22129
- $installs_map = $this->get_blog_install_map();
22130
-
22131
- foreach ( $installs_map as $blog_id => $install ) {
22132
- /**
22133
- * @var FS_Site $install
22134
- */
22135
- if ( $install->is_trial() ) {
22136
- $switch_to_blog_id = $blog_id;
22137
- break;
22138
- }
22139
-
22140
- if ( FS_Plugin_License::is_valid_id( $install->license_id ) ) {
22141
- $license = $this->get_license_by_id( $install->license_id );
22142
-
22143
- if ( is_object( $license ) && $license->is_features_enabled() ) {
22144
- $switch_to_blog_id = $blog_id;
22145
- break;
22146
- }
22147
- }
22148
- }
22149
-
22150
- if ( is_null( $switch_to_blog_id ) ) {
22151
- return false;
22152
- }
22153
- }
22154
-
22155
- $current_blog_id = is_numeric( $switch_to_blog_id ) ?
22156
- get_current_blog_id() :
22157
- 0;
22158
-
22159
- if ( is_numeric( $switch_to_blog_id ) ) {
22160
- $this->switch_to_blog( $switch_to_blog_id );
22161
- }
22162
-
22163
- $latest_version_endpoint = $this->_get_latest_version_endpoint( $addon_id, 'json' );
22164
-
22165
- if ( ! empty( $newer_than ) ) {
22166
- $latest_version_endpoint = add_query_arg( 'newer_than', $newer_than, $latest_version_endpoint );
22167
- }
22168
-
22169
- if ( true === $fetch_readme ) {
22170
- $latest_version_endpoint = add_query_arg( 'readme', 'true', $latest_version_endpoint );
22171
- }
22172
-
22173
- $tag = $this->get_api_site_or_plugin_scope()->get(
22174
- $latest_version_endpoint,
22175
- $flush,
22176
- $expiration
22177
- );
22178
-
22179
- if ( is_numeric( $switch_to_blog_id ) ) {
22180
- $this->switch_to_blog( $current_blog_id );
22181
- }
22182
-
22183
- $latest_version = ( is_object( $tag ) && isset( $tag->version ) ) ? $tag->version : 'couldn\'t get';
22184
-
22185
- $this->_logger->departure( 'Latest version ' . $latest_version );
22186
-
22187
- return ( is_object( $tag ) && isset( $tag->version ) ) ? $tag : false;
22188
- }
22189
-
22190
- #----------------------------------------------------------------------------------
22191
- #region Download Plugin
22192
- #----------------------------------------------------------------------------------
22193
-
22194
- /**
22195
- * Download latest plugin version, based on plan.
22196
- *
22197
- * Not like _download_latest(), this will redirect the page
22198
- * to secure download url to prevent dual download (from FS to WP server,
22199
- * and then from WP server to the client / browser).
22200
- *
22201
- * @author Vova Feldman (@svovaf)
22202
- * @since 1.0.9
22203
- *
22204
- * @param bool|number $plugin_id
22205
- *
22206
- * @uses FS_Api
22207
- * @uses wp_redirect()
22208
- */
22209
- private function download_latest_directly( $plugin_id = false ) {
22210
- $this->_logger->entrance();
22211
-
22212
- wp_redirect( $this->get_latest_download_api_url( $plugin_id ) );
22213
- }
22214
-
22215
- /**
22216
- * Get latest plugin FS API download URL.
22217
- *
22218
- * @author Vova Feldman (@svovaf)
22219
- * @since 1.0.9
22220
- *
22221
- * @param bool|number $plugin_id
22222
- *
22223
- * @return string
22224
- */
22225
- private function get_latest_download_api_url( $plugin_id = false ) {
22226
- $this->_logger->entrance();
22227
-
22228
- $download_api_url = $this->get_api_site_scope()->get_signed_url(
22229
- $this->_get_latest_version_endpoint( $plugin_id, 'zip' )
22230
- );
22231
-
22232
- return str_replace( 'http:', 'https:', $download_api_url );
22233
- }
22234
-
22235
- /**
22236
- * Get payment invoice URL.
22237
- *
22238
- * @author Vova Feldman (@svovaf)
22239
- * @since 1.2.0
22240
- *
22241
- * @param bool|number $payment_id
22242
- *
22243
- * @return string
22244
- */
22245
- function _get_invoice_api_url( $payment_id = false ) {
22246
- $this->_logger->entrance();
22247
-
22248
- $url = $this->get_api_user_scope()->get_signed_url(
22249
- "/payments/{$payment_id}/invoice.pdf"
22250
- );
22251
-
22252
- if ( ! fs_starts_with( $url, 'https://' ) ) {
22253
- // Always use HTTPS for invoices.
22254
- $url = 'https' . substr( $url, 4 );
22255
- }
22256
-
22257
- return $url;
22258
- }
22259
-
22260
- /**
22261
- * Get latest plugin download link.
22262
- *
22263
- * @author Vova Feldman (@svovaf)
22264
- * @since 1.0.9
22265
- *
22266
- * @param string $label
22267
- * @param bool|number $plugin_id
22268
- *
22269
- * @return string
22270
- */
22271
- private function get_latest_download_link( $label, $plugin_id = false ) {
22272
- return sprintf(
22273
- '<a target="_blank" rel="noopener" href="%s">%s</a>',
22274
- $this->_get_latest_download_local_url( $plugin_id ),
22275
- $label
22276
- );
22277
- }
22278
-
22279
- /**
22280
- * Get latest plugin download local URL.
22281
- *
22282
- * @author Vova Feldman (@svovaf)
22283
- * @since 1.0.9
22284
- *
22285
- * @param bool|number $plugin_id
22286
- *
22287
- * @return string
22288
- */
22289
- function _get_latest_download_local_url( $plugin_id = false ) {
22290
- // Add timestamp to protect from caching.
22291
- $params = array( 'ts' => WP_FS__SCRIPT_START_TIME );
22292
-
22293
- if ( ! empty( $plugin_id ) ) {
22294
- $params['plugin_id'] = $plugin_id;
22295
- } else if ( $this->is_addon() ) {
22296
- $params['plugin_id'] = $this->get_id();
22297
- }
22298
-
22299
- $fs = $this->is_addon() ?
22300
- $this->get_parent_instance() :
22301
- $this;
22302
-
22303
- return $this->apply_filters( 'download_latest_url', $fs->get_account_url( 'download_latest', $params ) );
22304
- }
22305
-
22306
- #endregion Download Plugin ------------------------------------------------------------------
22307
-
22308
- /**
22309
- * @author Vova Feldman (@svovaf)
22310
- * @since 1.0.4
22311
- *
22312
- * @uses FS_Api
22313
- *
22314
- * @param bool $background Hints the method if it's a background updates check. If false, it means that
22315
- * was initiated by the admin.
22316
- * @param bool|number $plugin_id
22317
- * @param bool $flush Since 1.1.7.3
22318
- * @param int $expiration Since 1.2.2.7
22319
- * @param bool|string $newer_than Since 2.2.1
22320
- */
22321
- private function check_updates(
22322
- $background = false,
22323
- $plugin_id = false,
22324
- $flush = true,
22325
- $expiration = WP_FS__TIME_24_HOURS_IN_SEC,
22326
- $newer_than = false
22327
- ) {
22328
- $this->_logger->entrance();
22329
-
22330
- // Check if there's a newer version for download.
22331
- $new_version = $this->_fetch_newer_version( $plugin_id, $flush, $expiration, $newer_than );
22332
-
22333
- $update = null;
22334
- if ( is_object( $new_version ) ) {
22335
- $update = new FS_Plugin_Tag( $new_version );
22336
-
22337
- if ( ! $background ) {
22338
- $this->_admin_notices->add(
22339
- sprintf(
22340
- /* translators: %s: Numeric version number (e.g. '2.1.9' */
22341
- $this->get_text_inline( 'Version %s was released.', 'version-x-released' ) . ' ' . $this->get_text_inline( 'Please download %s.', 'please-download-x' ),
22342
- $update->version,
22343
- sprintf(
22344
- '<a href="%s" target="_blank" rel="noopener">%s</a>',
22345
- $this->get_account_url( 'download_latest' ),
22346
- sprintf(
22347
- /* translators: %s: plan name (e.g. latest "Professional" version) */
22348
- $this->get_text_inline( 'the latest %s version here', 'latest-x-version' ),
22349
- $this->get_plan_title()
22350
- )
22351
- )
22352
- ),
22353
- $this->get_text_inline( 'New', 'new' ) . '!'
22354
- );
22355
- }
22356
- } else if ( false === $new_version && ! $background ) {
22357
- $this->_admin_notices->add(
22358
- $this->get_text_inline( 'Seems like you got the latest release.', 'you-have-latest' ),
22359
- $this->get_text_inline( 'You are all good!', 'you-are-good' )
22360
- );
22361
- }
22362
-
22363
- $this->_store_update( $update, true, $plugin_id );
22364
- }
22365
-
22366
- /**
22367
- * @author Vova Feldman (@svovaf)
22368
- * @since 1.0.4
22369
- *
22370
- * @param bool $flush Since 1.1.7.3 add 24 hour cache by default.
22371
- *
22372
- * @return FS_Plugin[]
22373
- *
22374
- * @uses FS_Api
22375
- */
22376
- private function sync_addons( $flush = false ) {
22377
- $this->_logger->entrance();
22378
-
22379
- $api = $this->get_api_site_or_plugin_scope();
22380
-
22381
- $path = $this->add_show_pending( '/addons.json?enriched=true&count=50' );
22382
-
22383
- /**
22384
- * @since 1.2.1
22385
- *
22386
- * If there's a cached version of the add-ons and not asking
22387
- * for a flush, just use the currently stored add-ons.
22388
- */
22389
- if ( ! $flush && $api->is_cached( $path ) ) {
22390
- $addons = self::get_all_addons();
22391
-
22392
- return isset( $addons[ $this->_plugin->id ] ) ?
22393
- $addons[ $this->_plugin->id ] :
22394
- array();
22395
- }
22396
-
22397
- $result = $api->get( $path, $flush );
22398
-
22399
- $addons = array();
22400
- if ( $this->is_api_result_object( $result, 'plugins' ) &&
22401
- is_array( $result->plugins )
22402
- ) {
22403
- for ( $i = 0, $len = count( $result->plugins ); $i < $len; $i ++ ) {
22404
- $addons[ $i ] = new FS_Plugin( $result->plugins[ $i ] );
22405
- }
22406
-
22407
- $this->_store_addons( $addons, true );
22408
- }
22409
-
22410
- return $addons;
22411
- }
22412
-
22413
- /**
22414
- * Handle user email update.
22415
- *
22416
- * @author Vova Feldman (@svovaf)
22417
- * @since 1.0.3
22418
- * @uses FS_Api
22419
- *
22420
- * @param string $new_email
22421
- *
22422
- * @return object
22423
- */
22424
- private function update_email( $new_email ) {
22425
- $this->_logger->entrance();
22426
-
22427
- $api = $this->get_api_user_scope();
22428
- $user = $api->call( "?plugin_id={$this->_plugin->id}&fields=id,email,is_verified", 'put', array(
22429
- 'email' => $new_email,
22430
- 'after_email_confirm_url' => $this->_get_admin_page_url(
22431
- 'account',
22432
- array( 'fs_action' => 'sync_user' )
22433
- ),
22434
- ) );
22435
-
22436
- if ( ! isset( $user->error ) ) {
22437
- $this->_user->email = $user->email;
22438
- $this->_user->is_verified = $user->is_verified;
22439
- $this->_store_user();
22440
- } else {
22441
- // handle different error cases.
22442
- }
22443
-
22444
- return $user;
22445
- }
22446
-
22447
- #----------------------------------------------------------------------------------
22448
- #region API Error Handling
22449
- #----------------------------------------------------------------------------------
22450
-
22451
- /**
22452
- * @author Vova Feldman (@svovaf)
22453
- * @since 1.1.1
22454
- *
22455
- * @param mixed $result
22456
- *
22457
- * @return bool Is API result contains an error.
22458
- */
22459
- private function is_api_error( $result ) {
22460
- return FS_Api::is_api_error( $result );
22461
- }
22462
-
22463
- /**
22464
- * Checks if given API result is a non-empty and not an error object.
22465
- *
22466
- * @author Vova Feldman (@svovaf)
22467
- * @since 1.2.1.5
22468
- *
22469
- * @param mixed $result
22470
- * @param string|null $required_property Optional property we want to verify that is set.
22471
- *
22472
- * @return bool
22473
- */
22474
- function is_api_result_object( $result, $required_property = null ) {
22475
- return FS_Api::is_api_result_object( $result, $required_property );
22476
- }
22477
-
22478
- /**
22479
- * Checks if given API result is a non-empty entity object with non-empty ID.
22480
- *
22481
- * @author Vova Feldman (@svovaf)
22482
- * @since 1.2.1.5
22483
- *
22484
- * @param mixed $result
22485
- *
22486
- * @return bool
22487
- */
22488
- private function is_api_result_entity( $result ) {
22489
- return FS_Api::is_api_result_entity( $result );
22490
- }
22491
-
22492
- #endregion
22493
-
22494
- /**
22495
- * Make sure a given argument is an array of a specific type.
22496
- *
22497
- * @author Vova Feldman (@svovaf)
22498
- * @since 1.2.1.5
22499
- *
22500
- * @param mixed $array
22501
- * @param string $class
22502
- *
22503
- * @return bool
22504
- */
22505
- private function is_array_instanceof( $array, $class ) {
22506
- return ( is_array( $array ) && ( empty( $array ) || $array[0] instanceof $class ) );
22507
- }
22508
-
22509
- /**
22510
- * Start install ownership change.
22511
- *
22512
- * @author Vova Feldman (@svovaf)
22513
- * @since 1.1.1
22514
- * @uses FS_Api
22515
- *
22516
- * @param string $candidate_email
22517
- * @param string $transfer_type
22518
- *
22519
- * @return bool Is ownership change successfully initiated.
22520
- */
22521
- private function init_change_owner( $candidate_email, $transfer_type ) {
22522
- $this->_logger->entrance();
22523
-
22524
- $installs_info_by_slug_map = $this->get_parent_and_addons_installs_info();
22525
- $install_ids = array();
22526
-
22527
- foreach ( $installs_info_by_slug_map as $slug => $install_info ) {
22528
- $install = $install_info['install'];
22529
-
22530
- if ( $this->_user->id != $install->user_id ) {
22531
- // Skip add-on installs that are not owned by the parent product's install's owner.
22532
- continue;
22533
- }
22534
-
22535
- $install_ids[ $slug ] = $install->id;
22536
- }
22537
-
22538
- $api = $this->get_api_site_scope();
22539
- $result = $api->call( "/users/{$this->_user->id}.json", 'put', array(
22540
- 'email' => $candidate_email,
22541
- 'transfer_type' => $transfer_type,
22542
- 'install_ids' => implode( ',', array_values( $install_ids ) ),
22543
- 'after_confirm_url' => $this->_get_admin_page_url(
22544
- 'account',
22545
- array( 'fs_action' => 'change_owner' )
22546
- ),
22547
- ) );
22548
-
22549
- return ! $this->is_api_error( $result );
22550
- }
22551
-
22552
- /**
22553
- * Handle install ownership change.
22554
- *
22555
- * @author Vova Feldman (@svovaf)
22556
- * @since 1.1.1
22557
- * @uses FS_Api
22558
- *
22559
- * @return bool Was ownership change successfully complete.
22560
- */
22561
- private function complete_change_owner() {
22562
- $this->_logger->entrance();
22563
-
22564
- $install_ids = fs_request_get( 'install_ids' );
22565
-
22566
- if ( ! empty( $install_ids ) ) {
22567
- $install_ids = explode( ',', $install_ids );
22568
-
22569
- foreach ( $install_ids as $key => $install_id ) {
22570
- if ( ! FS_Site::is_valid_id( $install_id ) ) {
22571
- unset( $install_ids[ $key ] );
22572
- }
22573
- }
22574
- }
22575
-
22576
- if ( ! is_array( $install_ids ) ) {
22577
- $install_ids = array();
22578
- }
22579
-
22580
- $user = new FS_User();
22581
- $user->id = fs_request_get( 'user_id' );
22582
- $user->public_key = fs_request_get( 'user_public_key' );
22583
- $user->secret_key = fs_request_get( 'user_secret_key' );
22584
-
22585
- $prev_user = $this->_user;
22586
- $this->_user = $user;
22587
-
22588
- $result = $this->get_api_user_scope( true )->get(
22589
- "/installs.json?install_ids=" . implode( ',', $install_ids )
22590
- );
22591
-
22592
- $current_blog_sites = self::get_all_sites( $this->get_module_type() );
22593
-
22594
- if ( $this->is_api_result_object( $result, 'installs' ) ) {
22595
- $site_id_slug_map = array();
22596
-
22597
- foreach ( $current_blog_sites as $slug => $site ) {
22598
- $site_id_slug_map[ $site->id ] = $slug;
22599
- }
22600
-
22601
- foreach ( $result->installs as $install ) {
22602
- $site = new FS_Site( $install );
22603
-
22604
- if ( ! isset( $site_id_slug_map[ $install->id ] ) ) {
22605
- continue;
22606
- }
22607
-
22608
- $current_blog_sites[ $site_id_slug_map[ $install->id ] ] = clone $site;
22609
-
22610
- if ( $this->_site->id == $site->id ) {
22611
- $this->_site = $site;
22612
- }
22613
- }
22614
- }
22615
-
22616
- // Validate install's user and given user.
22617
- if ( $user->id != $this->_site->user_id ) {
22618
- $this->_user = $prev_user;
22619
-
22620
- return false;
22621
- }
22622
-
22623
- $this->set_account_option( 'sites', $current_blog_sites, true );
22624
-
22625
- // Fetch new user information.
22626
- $user_result = $this->get_api_user_scope( true )->get();
22627
- $user = new FS_User( $user_result );
22628
- $this->_user = $user;
22629
-
22630
- $this->_set_account( $user, $this->_site );
22631
-
22632
- $remove_user = true;
22633
- $all_modules_sites = self::get_all_modules_sites();
22634
-
22635
- foreach ( $all_modules_sites as $sites_by_module_type ) {
22636
- foreach ( $sites_by_module_type as $sites_by_slug ) {
22637
- foreach ( $sites_by_slug as $site ) {
22638
- if ( $prev_user->id == $site->user_id ) {
22639
- $remove_user = false;
22640
- break;
22641
- }
22642
- }
22643
-
22644
- if ( ! $remove_user ) {
22645
- break;
22646
- }
22647
- }
22648
-
22649
- if ( ! $remove_user ) {
22650
- break;
22651
- }
22652
- }
22653
-
22654
- if ( $remove_user ) {
22655
- $users = self::get_all_users();
22656
-
22657
- if ( isset( $users[ $prev_user->id ] ) ) {
22658
- unset( $users[ $prev_user->id ] );
22659
- } else {
22660
- // If the prev user wasn't found by the key, iterate over the users collection.
22661
- foreach ( $users as $key => $user ) {
22662
- if ( $user->id == $prev_user->id ) {
22663
- unset( $users[ $key ] );
22664
- break;
22665
- }
22666
- }
22667
- }
22668
-
22669
- $this->set_account_option( 'users', $users, true );
22670
- }
22671
-
22672
- return true;
22673
- }
22674
-
22675
- /**
22676
- * Completes ownership change by license.
22677
- *
22678
- * @author Leo Fajardo (@leorw)
22679
- * @since 2.3.2
22680
- *
22681
- * @param number $user_id
22682
- * @param array[string]number $install_ids_by_slug_map
22683
- *
22684
- */
22685
- private function complete_ownership_change_by_license( $user_id, $install_ids_by_slug_map ) {
22686
- $this->_logger->entrance();
22687
-
22688
- $this->sync_user_by_current_install( $user_id );
22689
-
22690
- $result = $this->get_api_user_scope( true )->get(
22691
- "/installs.json?install_ids=" . implode( ',', $install_ids_by_slug_map )
22692
- );
22693
-
22694
- if ( $this->is_api_result_object( $result, 'installs' ) ) {
22695
- $sites = self::get_all_sites( $this->get_module_type() );
22696
- $install_ids_by_slug_map = array_flip( $install_ids_by_slug_map );
22697
-
22698
- foreach ( $result->installs as $install ) {
22699
- $site = new FS_Site( $install );
22700
-
22701
- $sites[ $install_ids_by_slug_map[ $site->id ] ] = clone $site;
22702
- }
22703
-
22704
- $this->set_account_option( 'sites', $sites, true );
22705
- }
22706
- }
22707
-
22708
- /**
22709
- * Handle user name update.
22710
- *
22711
- * @author Vova Feldman (@svovaf)
22712
- * @since 1.0.9
22713
- * @uses FS_Api
22714
- *
22715
- * @return object
22716
- */
22717
- private function update_user_name() {
22718
- $this->_logger->entrance();
22719
- $name = fs_request_get( 'fs_user_name_' . $this->get_unique_affix(), '' );
22720
-
22721
- $api = $this->get_api_user_scope();
22722
- $user = $api->call( "?plugin_id={$this->_plugin->id}&fields=id,first,last", 'put', array(
22723
- 'name' => $name,
22724
- ) );
22725
-
22726
- if ( ! isset( $user->error ) ) {
22727
- $this->_user->first = $user->first;
22728
- $this->_user->last = $user->last;
22729
- $this->_store_user();
22730
- } else {
22731
- // handle different error cases.
22732
-
22733
- }
22734
-
22735
- return $user;
22736
- }
22737
-
22738
- /**
22739
- * Verify user email.
22740
- *
22741
- * @author Vova Feldman (@svovaf)
22742
- * @since 1.0.3
22743
- * @uses FS_Api
22744
- */
22745
- private function verify_email() {
22746
- $this->_handle_account_user_sync();
22747
-
22748
- if ( $this->_user->is_verified() ) {
22749
- return;
22750
- }
22751
-
22752
- $api = $this->get_api_site_scope();
22753
- $result = $api->call( "/users/{$this->_user->id}/verify.json", 'put', array(
22754
- 'after_email_confirm_url' => $this->_get_admin_page_url(
22755
- 'account',
22756
- array( 'fs_action' => 'sync_user' )
22757
- )
22758
- ) );
22759
-
22760
- if ( ! isset( $result->error ) ) {
22761
- $this->_admin_notices->add( sprintf(
22762
- $this->get_text_inline( 'Verification mail was just sent to %s. If you can\'t find it after 5 min, please check your spam box.', 'verification-email-sent-message' ),
22763
- sprintf( '<a href="mailto:%1$s">%2$s</a>', esc_url( $this->_user->email ), $this->_user->email )
22764
- ) );
22765
- } else {
22766
- // handle different error cases.
22767
-
22768
- }
22769
- }
22770
-
22771
- /**
22772
- * @author Vova Feldman (@svovaf)
22773
- * @since 1.1.2
22774
- *
22775
- * @param array $params
22776
- * @param bool|null $network
22777
- *
22778
- * @return string
22779
- */
22780
- function get_activation_url( $params = array(), $network = null ) {
22781
- if ( $this->is_addon() && $this->has_free_plan() ) {
22782
- /**
22783
- * @author Vova Feldman (@svovaf)
22784
- * @since 1.2.1.7 Add-on's activation is the parent's module activation.
22785
- */
22786
- return $this->get_parent_instance()->get_activation_url( $params );
22787
- }
22788
-
22789
- return $this->apply_filters( 'connect_url', $this->_get_admin_page_url( '', $params, $network ) );
22790
- }
22791
-
22792
- /**
22793
- * @author Vova Feldman (@svovaf)
22794
- * @since 1.2.1.5
22795
- *
22796
- * @param array $params
22797
- *
22798
- * @return string
22799
- */
22800
- function get_reconnect_url( $params = array() ) {
22801
- $params['fs_action'] = 'reset_anonymous_mode';
22802
- $params['fs_unique_affix'] = $this->get_unique_affix();
22803
-
22804
- return $this->get_activation_url( $params );
22805
- }
22806
-
22807
- /**
22808
- * Get the URL of the page that should be loaded after the user connect
22809
- * or skip in the opt-in screen.
22810
- *
22811
- * @author Vova Feldman (@svovaf)
22812
- * @since 1.1.3
22813
- *
22814
- * @param string $filter Filter name.
22815
- * @param array $params Since 1.2.2.7
22816
- * @param bool|null $network
22817
- *
22818
- * @return string
22819
- */
22820
- function get_after_activation_url( $filter, $params = array(), $network = null ) {
22821
- if ( $this->show_opt_in_on_themes_page() &&
22822
- ( fs_request_has( 'pending_activation' ) ||
22823
- // For cases when the first time path is set, even though it's a WP.org theme.
22824
- fs_request_get_bool( $this->get_unique_affix() . '_show_optin' ) )
22825
- ) {
22826
- $first_time_path = '';
22827
- } else {
22828
- $first_time_path = $this->_menu->get_first_time_path(
22829
- fs_is_network_admin() && $this->_is_network_active
22830
- );
22831
- }
22832
-
22833
- if ( $this->_is_network_active &&
22834
- fs_is_network_admin() &&
22835
- ! $this->_menu->has_network_menu() &&
22836
- $this->is_network_registered()
22837
- ) {
22838
- $target_url = $this->get_account_url();
22839
- } else {
22840
- // Default plugin's page.
22841
- $target_url = $this->_get_admin_page_url( '', array(), $network );
22842
- }
22843
-
22844
- return add_query_arg( $params, $this->apply_filters(
22845
- $filter,
22846
- empty( $first_time_path ) ?
22847
- $target_url :
22848
- $first_time_path
22849
- ) );
22850
- }
22851
-
22852
- /**
22853
- * Handle account page updates / edits / actions.
22854
- *
22855
- * @author Vova Feldman (@svovaf)
22856
- * @since 1.0.2
22857
- *
22858
- */
22859
- private function _handle_account_edits() {
22860
- if ( ! $this->is_user_admin() ) {
22861
- return;
22862
- }
22863
-
22864
- $action = fs_get_action();
22865
-
22866
- if ( empty( $action ) ) {
22867
- return;
22868
- }
22869
-
22870
- $plugin_id = fs_request_get( 'plugin_id', $this->get_id() );
22871
- $install_id = fs_request_get( 'install_id', '' );
22872
-
22873
- // Alias.
22874
- $oops_text = $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...';
22875
-
22876
- $is_network_action = $this->is_network_level_action();
22877
- $blog_id = $this->is_network_level_site_specific_action();
22878
- $is_parent_plugin_action = ( $plugin_id == $this->get_id() );
22879
-
22880
- if ( is_numeric( $blog_id ) ) {
22881
- $this->switch_to_blog( $blog_id );
22882
- } else {
22883
- $blog_id = '';
22884
- }
22885
-
22886
- switch ( $action ) {
22887
- case 'opt_in':
22888
- check_admin_referer( trim( "{$action}:{$blog_id}:{$install_id}", ':' ) );
22889
-
22890
- if ( $is_parent_plugin_action ) {
22891
- if ( $is_network_action && ! empty( $blog_id ) ) {
22892
- if ( ! $this->is_registered() ) {
22893
- $this->install_with_user(
22894
- $this->get_network_user(),
22895
- false,
22896
- false,
22897
- false,
22898
- false
22899
- );
22900
-
22901
- $this->_admin_notices->add(
22902
- $this->get_text_inline( 'Site successfully opted in.', 'successful-opt-in' ),
22903
- $this->get_text_inline( 'Awesome', 'awesome' )
22904
- );
22905
- }
22906
- }
22907
- }
22908
- break;
22909
-
22910
- case 'toggle_tracking':
22911
- check_admin_referer( trim( "{$action}:{$blog_id}:{$install_id}", ':' ) );
22912
-
22913
- if ( $is_parent_plugin_action ) {
22914
- if ( $is_network_action && ! empty( $blog_id ) ) {
22915
- if ( $this->is_registered() ) {
22916
- if ( $this->is_tracking_prohibited() ) {
22917
- if ( $this->allow_site_tracking() ) {
22918
- $this->_admin_notices->add(
22919
- sprintf( $this->get_text_inline( 'We appreciate your help in making the %s better by letting us track some usage data.', 'opt-out-message-appreciation' ), $this->_module_type ),
22920
- $this->get_text_inline( 'Thank you!', 'thank-you' )
22921
- );
22922
- }
22923
- } else {
22924
- if ( $this->stop_site_tracking() ) {
22925
- $this->_admin_notices->add(
22926
- sprintf(
22927
- $this->get_text_inline( 'We will no longer be sending any usage data of %s on %s to %s.', 'opted-out-successfully' ),
22928
- $this->get_plugin_title(),
22929
- fs_strip_url_protocol( self::get_site_url( $blog_id ) ),
22930
- sprintf(
22931
- '<a href="%s" target="_blank" rel="noopener">%s</a>',
22932
- 'https://freemius.com',
22933
- 'freemius.com'
22934
- )
22935
- )
22936
- );
22937
- }
22938
- }
22939
- }
22940
- }
22941
- }
22942
-
22943
- break;
22944
-
22945
- case 'delete_account':
22946
- check_admin_referer( trim( "{$action}:{$blog_id}:{$install_id}", ':' ) );
22947
-
22948
- $is_network_deletion = $is_network_action && empty( $blog_id );
22949
-
22950
- if ( $is_parent_plugin_action ) {
22951
- // Delete add-on installs if have any.
22952
- $installed_addons = $this->get_installed_addons();
22953
- foreach ( $installed_addons as $fs_addon ) {
22954
- if ( $is_network_deletion ) {
22955
- $fs_addon->delete_network_account_event();
22956
- } else {
22957
- $fs_addon->delete_account_event();
22958
- }
22959
- }
22960
-
22961
- if ( $is_network_deletion ) {
22962
- $this->delete_network_account_event();
22963
- } else {
22964
- $this->delete_account_event();
22965
- }
22966
-
22967
- // Clear user and site.
22968
- $this->_site = null;
22969
- $this->_user = null;
22970
-
22971
- $this->maybe_set_slug_and_network_menu_exists_flag();
22972
-
22973
- fs_redirect( $this->get_activation_url() );
22974
- } else {
22975
- if ( $this->is_addon_activated( $plugin_id ) ) {
22976
- $fs_addon = self::get_instance_by_id( $plugin_id );
22977
-
22978
- if ( $is_network_deletion ) {
22979
- $fs_addon->delete_network_account_event();
22980
- } else {
22981
- $fs_addon->delete_account_event();
22982
- }
22983
-
22984
- fs_redirect( $this->_get_admin_page_url( 'account' ) );
22985
- }
22986
- }
22987
-
22988
- return;
22989
-
22990
- case 'downgrade_account':
22991
- if ( is_numeric( $blog_id ) ) {
22992
- check_admin_referer( trim( "{$action}:{$blog_id}:{$install_id}", ':' ) );
22993
- } else {
22994
- check_admin_referer( $action );
22995
- }
22996
-
22997
- $switch_to_network_install_blog_after_cancellation = (
22998
- is_numeric( $blog_id ) &&
22999
- $plugin_id == $this->get_id() &&
23000
- ! $this->is_trial()
23001
- );
23002
-
23003
- $result = $this->cancel_subscription_or_trial( $plugin_id );
23004
- if ( $this->is_api_error( $result ) ) {
23005
- $this->_admin_notices->add(
23006
- $result->error->message,
23007
- $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
23008
- 'error'
23009
- );
23010
- }
23011
-
23012
- if ( $switch_to_network_install_blog_after_cancellation ) {
23013
- $this->switch_to_blog( $this->_storage->network_install_blog_id );
23014
- }
23015
-
23016
- return;
23017
-
23018
- case 'activate_license':
23019
- check_admin_referer( trim( "{$action}:{$blog_id}:{$install_id}", ':' ) );
23020
-
23021
- $fs = $this;
23022
- if ( $plugin_id != $this->get_id() ) {
23023
- $fs = $this->is_addon_activated( $plugin_id ) ?
23024
- self::get_instance_by_id( $plugin_id ) :
23025
- null;
23026
- }
23027
-
23028
- if ( is_object( $fs ) ) {
23029
- $fs->_activate_license();
23030
-
23031
- /**
23032
- * Remove the product ID from `$_REQUEST` so that the syncing of the license for the other products will work properly.
23033
- *
23034
- * @author Leo Fajardo (@leorw)
23035
- * @since 2.4.0
23036
- */
23037
- unset( $_REQUEST['plugin_id'] );
23038
-
23039
- if ( $this->is_bundle_license_auto_activation_enabled() ) {
23040
- $fs->maybe_activate_bundle_license( null, array(), is_numeric( $blog_id ) ? $blog_id : 0 );
23041
- }
23042
- }
23043
-
23044
- return;
23045
-
23046
- case 'deactivate_license':
23047
- check_admin_referer( trim( "{$action}:{$blog_id}:{$install_id}", ':' ) );
23048
-
23049
- if ( $plugin_id == $this->get_id() ) {
23050
- $this->_deactivate_license();
23051
-
23052
- if ( $this->is_only_premium() ) {
23053
- // Clear user and site.
23054
- $this->_site = null;
23055
- $this->_user = null;
23056
-
23057
- if ( ! $is_network_action ) {
23058
- fs_redirect( $this->get_activation_url() );
23059
- } else if ( is_numeric( $blog_id ) ) {
23060
- $this->switch_to_blog( $this->_storage->network_install_blog_id );
23061
- }
23062
- }
23063
- } else {
23064
- if ( $this->is_addon_activated( $plugin_id ) ) {
23065
- $fs_addon = self::get_instance_by_id( $plugin_id );
23066
- $fs_addon->_deactivate_license();
23067
- }
23068
- }
23069
-
23070
- return;
23071
-
23072
- case 'check_updates':
23073
- check_admin_referer( $action );
23074
- $this->check_updates();
23075
-
23076
- return;
23077
-
23078
- case 'change_owner':
23079
- $state = fs_request_get( 'state', 'init' );
23080
- switch ( $state ) {
23081
- case 'init':
23082
- $candidate_email = fs_request_get( 'candidate_email' );
23083
- $transfer_type = fs_request_get( 'transfer_