WP fail2ban - Version 4.0.1

Version Description

  • Add extra features via Freemius. This is entirely optional. WPf2b works as before, including new features listed here.
  • Add settings summary page (Settings -> WP fail2ban).
  • Add WP_FAIL2BAN_PASSWORD_REQUEST_LOG.
  • Add WP_FAIL2BAN_SPAM_LOG.
  • Add WP_FAIL2BAN_LOG_COMMENTS_EXTRA - enable logging for attempted comments on posts which are:
    • not found,
    • closed for commenting,
    • in the trash,
    • drafts,
    • password protected
  • Block user enumeration via REST API.
Download this release

Release Info

Developer invisnet
Plugin Icon 128x128 WP fail2ban
Version 4.0.1
Comparing to
See all releases

Code changes from version 3.6.0 to 4.0.1

Files changed (76) hide show
  1. admin/img/docs.svg +6 -0
  2. admin/summary.php +252 -0
  3. feature/comments.php +152 -0
  4. feature/lib.php +135 -0
  5. feature/password.php +30 -0
  6. feature/spam.php +53 -0
  7. feature/user-enum.php +80 -0
  8. feature/user.php +54 -0
  9. feature/xmlrpc.php +92 -0
  10. feature/xmlrpc/log.php +35 -0
  11. feature/xmlrpc/pingback.php +33 -0
  12. filters.d/wordpress-extra.conf +27 -0
  13. filters.d/wordpress-hard.conf +29 -27
  14. filters.d/wordpress-soft.conf +22 -22
  15. readme.txt +199 -189
  16. vendor/freemius/wordpress-sdk/.codeclimate.yml +19 -0
  17. vendor/freemius/wordpress-sdk/.github/ISSUE_TEMPLATE.md +29 -0
  18. vendor/freemius/wordpress-sdk/.travis.yml +11 -0
  19. vendor/freemius/wordpress-sdk/LICENSE.txt +674 -0
  20. vendor/freemius/wordpress-sdk/README.md +253 -0
  21. vendor/freemius/wordpress-sdk/assets/css/admin/account.css +1 -0
  22. vendor/freemius/wordpress-sdk/assets/css/admin/add-ons.css +2 -0
  23. vendor/freemius/wordpress-sdk/assets/css/admin/affiliation.css +1 -0
  24. vendor/freemius/wordpress-sdk/assets/css/admin/checkout.css +1 -0
  25. vendor/freemius/wordpress-sdk/assets/css/admin/common.css +2 -0
  26. vendor/freemius/wordpress-sdk/assets/css/admin/connect.css +1 -0
  27. vendor/freemius/wordpress-sdk/assets/css/admin/debug.css +1 -0
  28. vendor/freemius/wordpress-sdk/assets/css/admin/dialog-boxes.css +2 -0
  29. vendor/freemius/wordpress-sdk/assets/css/admin/gdpr-optin-notice.css +1 -0
  30. vendor/freemius/wordpress-sdk/assets/css/admin/index.php +3 -0
  31. vendor/freemius/wordpress-sdk/assets/css/customizer.css +1 -0
  32. vendor/freemius/wordpress-sdk/assets/css/index.php +3 -0
  33. vendor/freemius/wordpress-sdk/assets/img/index.php +3 -0
  34. vendor/freemius/wordpress-sdk/assets/img/plugin-icon.png +0 -0
  35. vendor/freemius/wordpress-sdk/assets/img/theme-icon.png +0 -0
  36. vendor/freemius/wordpress-sdk/assets/index.php +3 -0
  37. vendor/freemius/wordpress-sdk/assets/js/index.php +3 -0
  38. vendor/freemius/wordpress-sdk/assets/js/nojquery.ba-postmessage.js +140 -0
  39. vendor/freemius/wordpress-sdk/assets/js/nojquery.ba-postmessage.min.js +12 -0
  40. vendor/freemius/wordpress-sdk/assets/js/postmessage.js +135 -0
  41. vendor/freemius/wordpress-sdk/assets/scss/_colors.scss +79 -0
  42. vendor/freemius/wordpress-sdk/assets/scss/_functions.scss +0 -0
  43. vendor/freemius/wordpress-sdk/assets/scss/_load.scss +4 -0
  44. vendor/freemius/wordpress-sdk/assets/scss/_mixins.scss +270 -0
  45. vendor/freemius/wordpress-sdk/assets/scss/_start.scss +4 -0
  46. vendor/freemius/wordpress-sdk/assets/scss/_vars.scss +6 -0
  47. vendor/freemius/wordpress-sdk/assets/scss/admin/_ajax-loader.scss +49 -0
  48. vendor/freemius/wordpress-sdk/assets/scss/admin/_auto-install.scss +33 -0
  49. vendor/freemius/wordpress-sdk/assets/scss/admin/_buttons.scss +28 -0
  50. vendor/freemius/wordpress-sdk/assets/scss/admin/_deactivation-feedback.scss +55 -0
  51. vendor/freemius/wordpress-sdk/assets/scss/admin/_gdpr-consent.scss +81 -0
  52. vendor/freemius/wordpress-sdk/assets/scss/admin/_license-activation.scss +47 -0
  53. vendor/freemius/wordpress-sdk/assets/scss/admin/_license-key-resend.scss +68 -0
  54. vendor/freemius/wordpress-sdk/assets/scss/admin/_modal-common.scss +194 -0
  55. vendor/freemius/wordpress-sdk/assets/scss/admin/_multisite-options.scss +40 -0
  56. vendor/freemius/wordpress-sdk/assets/scss/admin/_plugin-upgrade-notice.scss +8 -0
  57. vendor/freemius/wordpress-sdk/assets/scss/admin/_subscription-cancellation.scss +30 -0
  58. vendor/freemius/wordpress-sdk/assets/scss/admin/_themes.scss +21 -0
  59. vendor/freemius/wordpress-sdk/assets/scss/admin/_tooltip.scss +66 -0
  60. vendor/freemius/wordpress-sdk/assets/scss/admin/account.scss +302 -0
  61. vendor/freemius/wordpress-sdk/assets/scss/admin/add-ons.scss +449 -0
  62. vendor/freemius/wordpress-sdk/assets/scss/admin/affiliation.scss +97 -0
  63. vendor/freemius/wordpress-sdk/assets/scss/admin/checkout.scss +5 -0
  64. vendor/freemius/wordpress-sdk/assets/scss/admin/common.scss +220 -0
  65. vendor/freemius/wordpress-sdk/assets/scss/admin/connect.scss +548 -0
  66. vendor/freemius/wordpress-sdk/assets/scss/admin/debug.scss +135 -0
  67. vendor/freemius/wordpress-sdk/assets/scss/admin/dialog-boxes.scss +10 -0
  68. vendor/freemius/wordpress-sdk/assets/scss/admin/gdpr-optin-notice.scss +17 -0
  69. vendor/freemius/wordpress-sdk/assets/scss/admin/index.php +3 -0
  70. vendor/freemius/wordpress-sdk/assets/scss/customizer.scss +125 -0
  71. vendor/freemius/wordpress-sdk/assets/scss/index.php +3 -0
  72. vendor/freemius/wordpress-sdk/composer.json +10 -0
  73. vendor/freemius/wordpress-sdk/config.php +388 -0
  74. vendor/freemius/wordpress-sdk/gulpfile.js +167 -0
  75. vendor/freemius/wordpress-sdk/includes/class-freemius-abstract.php +597 -0
  76. vendor/freemius/wordpress-sdk/includes/class-freemius.php +19831 -0
admin/img/docs.svg ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 26 26" version="1.1" width="16px" height="16px">
3
+ <g id="surface1">
4
+ <path style=" " d="M 7 0 C 4.796875 0 3 1.796875 3 4 L 3 22 C 3 24.203125 4.796875 26 7 26 L 19 26 C 21.203125 26 23 24.203125 23 22 L 23 8 C 23 6.9375 22.027344 5.929688 20.28125 4.21875 C 20.039063 3.980469 19.777344 3.714844 19.53125 3.46875 C 19.285156 3.222656 19.019531 2.992188 18.78125 2.75 C 17.070313 1.003906 16.0625 0 15 0 Z M 7 2 L 14.28125 2 C 15.003906 2.183594 15 3.050781 15 3.9375 L 15 7 C 15 7.550781 15.449219 8 16 8 L 19 8 C 19.996094 8 21 8.003906 21 9 L 21 22 C 21 23.105469 20.105469 24 19 24 L 7 24 C 5.894531 24 5 23.105469 5 22 L 5 4 C 5 2.894531 5.894531 2 7 2 Z M 7.8125 10 C 7.261719 10.050781 6.855469 10.542969 6.90625 11.09375 C 6.957031 11.644531 7.449219 12.050781 8 12 L 18 12 C 18.359375 12.003906 18.695313 11.816406 18.878906 11.503906 C 19.058594 11.191406 19.058594 10.808594 18.878906 10.496094 C 18.695313 10.183594 18.359375 9.996094 18 10 L 8 10 C 7.96875 10 7.9375 10 7.90625 10 C 7.875 10 7.84375 10 7.8125 10 Z M 7.8125 14 C 7.261719 14.050781 6.855469 14.542969 6.90625 15.09375 C 6.957031 15.644531 7.449219 16.050781 8 16 L 16 16 C 16.359375 16.003906 16.695313 15.816406 16.878906 15.503906 C 17.058594 15.191406 17.058594 14.808594 16.878906 14.496094 C 16.695313 14.183594 16.359375 13.996094 16 14 L 8 14 C 7.96875 14 7.9375 14 7.90625 14 C 7.875 14 7.84375 14 7.8125 14 Z M 7.8125 18 C 7.261719 18.050781 6.855469 18.542969 6.90625 19.09375 C 6.957031 19.644531 7.449219 20.050781 8 20 L 18 20 C 18.359375 20.003906 18.695313 19.816406 18.878906 19.503906 C 19.058594 19.191406 19.058594 18.808594 18.878906 18.496094 C 18.695313 18.183594 18.359375 17.996094 18 18 L 8 18 C 7.96875 18 7.9375 18 7.90625 18 C 7.875 18 7.84375 18 7.8125 18 Z "/>
5
+ </g>
6
+ </svg>
admin/summary.php ADDED
@@ -0,0 +1,252 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Configuration summary
4
+ *
5
+ * @package wp-fail2ban
6
+ * @since 4.0.0
7
+ */
8
+ namespace org\lecklider\charles\wordpress\wp_fail2ban;
9
+
10
+ /**
11
+ * Add options page
12
+ *
13
+ * @since 4.0.0
14
+ */
15
+ function admin_menu()
16
+ {
17
+ add_options_page(
18
+ 'WP fail2ban - Summary',
19
+ 'WP fail2ban',
20
+ 'manage_options',
21
+ 'wp-fail2ban',
22
+ __NAMESPACE__.'\summary'
23
+ );
24
+ }
25
+ add_action('admin_menu', __NAMESPACE__.'\admin_menu');
26
+
27
+
28
+ /**
29
+ * Link to documentation
30
+ *
31
+ * @since 4.0.0
32
+ *
33
+ * @param string $define
34
+ * @param string $name
35
+ *
36
+ * @return string
37
+ */
38
+ function _doc_link($define, $name)
39
+ {
40
+ static $wp_f2b_ver;
41
+
42
+ if (empty($wp_f2b_ver)) {
43
+ $wp_f2b_ver = substr(WP_FAIL2BAN, 0, strrpos(WP_FAIL2BAN, '.'));
44
+ }
45
+
46
+ return sprintf('<a href="https://wp-fail2ban.readthedocs.io/en/%s/defines.html#%s" target="_blank">%s <span class="dashicons dashicons-external"></span></a>', $wp_f2b_ver, str_replace('_', '-', strtolower($define)), $name);
47
+ }
48
+
49
+
50
+ /**
51
+ * List log facilities
52
+ *
53
+ * @param int $facility
54
+ *
55
+ * @since 4.0.0
56
+ */
57
+ function _get_log_facility($facility)
58
+ {
59
+ $facilities = [
60
+ LOG_AUTH => 'LOG_AUTH',
61
+ LOG_AUTHPRIV => 'LOG_AUTHPRIV',
62
+ LOG_CRON => 'LOG_CRON',
63
+ LOG_DAEMON => 'LOG_DAEMON',
64
+ LOG_KERN => 'LOG_KERN',
65
+ LOG_LOCAL0 => 'LOG_LOCAL0',
66
+ LOG_LOCAL1 => 'LOG_LOCAL1',
67
+ LOG_LOCAL2 => 'LOG_LOCAL2',
68
+ LOG_LOCAL3 => 'LOG_LOCAL3',
69
+ LOG_LOCAL4 => 'LOG_LOCAL4',
70
+ LOG_LOCAL5 => 'LOG_LOCAL5',
71
+ LOG_LOCAL6 => 'LOG_LOCAL6',
72
+ LOG_LOCAL7 => 'LOG_LOCAL7',
73
+ LOG_LPR => 'LOG_LPR',
74
+ LOG_MAIL => 'LOG_MAIL',
75
+ LOG_NEWS => 'LOG_NEWS',
76
+ LOG_SYSLOG => 'LOG_SYSLOG',
77
+ LOG_USER => 'LOG_USER',
78
+ LOG_UUCP => 'LOG_UUCP',
79
+ ];
80
+
81
+ return (array_key_exists($facility, $facilities))
82
+ ? $facilities[$facility]
83
+ : '(unknown)';
84
+ }
85
+
86
+
87
+ /**
88
+ *
89
+ *
90
+ * @since 4.0.0
91
+ *
92
+ * @param string $name
93
+ * @param string $enabled
94
+ * @param string $location
95
+ */
96
+ function _log($name, $enabled, $location)
97
+ {
98
+ ?>
99
+ <tr>
100
+ <th><?=_doc_link($enabled, $name)?></th>
101
+ <?php if (defined($enabled) && true === constant($enabled)) : ?>
102
+ <td><?=__('Yes')?></td>
103
+ <th><?=__('Facility')?></th>
104
+ <td><?=_get_log_facility(constant($location))?> <?=(constant($location) == constant("DEFAULT_$location")) ? ' <em>('.__('default').')</em>' : ''?></td>
105
+ <?php else : ?>
106
+ <td><?=__('No')?></td>
107
+ <?php endif; ?>
108
+ </tr>
109
+ <?php
110
+ }
111
+
112
+
113
+ /**
114
+ * Display syslog connection options
115
+ *
116
+ * @since 4.0.0
117
+ */
118
+ function _log_options()
119
+ {
120
+ $options = (defined('WP_FAIL2BAN_OPENLOG_OPTIONS'))
121
+ ? WP_FAIL2BAN_OPENLOG_OPTIONS
122
+ : DEFAULT_WP_FAIL2BAN_OPENLOG_OPTIONS;
123
+
124
+ $opts = [];
125
+ (LOG_CONS == ($options & LOG_CONS)) and $opts[] = 'LOG_CONS';
126
+ (LOG_PERROR == ($options & LOG_PERROR)) and $opts[] = 'LOG_PERROR';
127
+ (LOG_PID == ($options & LOG_PID)) and $opts[] = 'LOG_PID';
128
+ (LOG_NDELAY == ($options & LOG_NDELAY)) and $opts[] = 'LOG_NDELAY';
129
+ (LOG_ODELAY == ($options & LOG_ODELAY)) and $opts[] = 'LOG_ODELAY';
130
+ ?>
131
+ <tr>
132
+ <th><?=_doc_link('WP_FAIL2BAN_OPENLOG_OPTIONS', __('Connection'))?></th>
133
+ <td colspan="3"><?=sprintf((DEFAULT_WP_FAIL2BAN_OPENLOG_OPTIONS == $options)
134
+ ? '%s <em>(%s)</em>'
135
+ : '%s', join(', ', $opts), __('default'))?></td>
136
+ </tr>
137
+ <?php
138
+ }
139
+
140
+
141
+ /**
142
+ * Display Yes/No/array values
143
+ *
144
+ * @param string $name
145
+ * @param string|array $option
146
+ * @param bool|null $ary
147
+ *
148
+ * @since 4.0.0
149
+ */
150
+ function _yes_no_array($name, $option, $ary = false)
151
+ {
152
+ $th = _doc_link($option, $name);
153
+
154
+ if ($ary) {
155
+ if (defined($option)) {
156
+ $items = (is_array(constant($option)))
157
+ ? constant($option)
158
+ : trim(' "', explode(',', constant($option)));
159
+ } else {
160
+ $items = ['-'];
161
+ }
162
+ $td = join(', ', $items);
163
+ } elseif (is_null($ary)) {
164
+ if (defined($option)) {
165
+ $td = (is_array(constant($option)))
166
+ ? join(' ,', constant($option))
167
+ : constant($option);
168
+ } else {
169
+ $td = '-';
170
+ }
171
+ } else {
172
+ $td = (defined($option) && true === constant($option))
173
+ ? __('Yes')
174
+ : __('No');
175
+ }
176
+
177
+ echo <<<___YNA___
178
+ <tr>
179
+ <th>$th</th>
180
+ <td>$td</td>
181
+ </tr>
182
+ ___YNA___;
183
+ }
184
+
185
+
186
+ /**
187
+ * Display configuration summary
188
+ *
189
+ * @since 4.0.0
190
+ */
191
+ function summary()
192
+ {
193
+ ?>
194
+ <div class="wrap">
195
+ <style>
196
+ table.form-table a {
197
+ text-decoration: none;
198
+ }
199
+ </style>
200
+ <h1>WP fail2ban - Summary</h1>
201
+ <?php if (wf_fs()->is_not_paying()) : ?>
202
+ <p>Do you want a simple GUI to change these settings?</p>
203
+ <p>Do you want reports on where and when attacks are happening?</p>
204
+ <p><a href="<?=wf_fs()->get_upgrade_url()?>">Upgrade now!</a></p>
205
+ <hr>
206
+ <?php endif; ?>
207
+ <h2><?=__('Logging')?></h2>
208
+ <table class="form-table">
209
+ <tbody>
210
+ <?php
211
+ _log(__('Comments'), 'WP_FAIL2BAN_LOG_COMMENTS', 'WP_FAIL2BAN_COMMENT_LOG');
212
+ _log(__('Password Requests'), 'WP_FAIL2BAN_LOG_PASSWORD_REQUEST', 'WP_FAIL2BAN_PASSWORD_REQUEST_LOG');
213
+ _log(__('Pingbacks'), 'WP_FAIL2BAN_LOG_PINGBACKS', 'WP_FAIL2BAN_PINGBACK_LOG');
214
+ _log(__('Spam'), 'WP_FAIL2BAN_LOG_SPAM', 'WP_FAIL2BAN_SPAM_LOG');
215
+ _log_options();
216
+ ?>
217
+ </tbody>
218
+ </table>
219
+ <h3><?=__('Workarounds')?></h3>
220
+ <table class="form-table">
221
+ <tbody>
222
+ <?php
223
+ _yes_no_array(__('Short Tag'), 'WP_FAIL2BAN_SYSLOG_SHORT_TAG');
224
+ _yes_no_array(__('Specify Host'), 'WP_FAIL2BAN_HTTP_HOST');
225
+ _yes_no_array(__('Truncate Host'), 'WP_FAIL2BAN_TRUNCATE_HOST');
226
+ ?>
227
+ </tbody>
228
+ </table>
229
+ <hr>
230
+ <h2><?=__('Block')?></h2>
231
+ <table class="form-table">
232
+ <tbody>
233
+ <?php
234
+ _yes_no_array(__('User Enumeration'), 'WP_FAIL2BAN_BLOCK_USER_ENUMERATION');
235
+ _yes_no_array(__('Usernames'), 'WP_FAIL2BAN_BLOCKED_USERS', null);
236
+ ?>
237
+ </tbody>
238
+ </table>
239
+ <hr>
240
+ <h2><?=__('Misc')?></h2>
241
+ <table class="form-table">
242
+ <tbody>
243
+ <?php
244
+ _yes_no_array(__('Proxies'), 'WP_FAIL2BAN_PROXIES', true);
245
+ _yes_no_array(__('Remote Address'), 'WP_FAIL2BAN_REMOTE_ADDR');
246
+ ?>
247
+ </tbody>
248
+ </table>
249
+ </div>
250
+ <?php
251
+ }
252
+
feature/comments.php ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Comment logging
5
+ *
6
+ * @package wp-fail2ban
7
+ * @since 4.0.0
8
+ */
9
+ namespace org\lecklider\charles\wordpress\wp_fail2ban;
10
+
11
+ if ( !defined( 'ABSPATH' ) ) {
12
+ exit;
13
+ }
14
+ /**
15
+ * Log new comment
16
+ *
17
+ * @since 3.5.0
18
+ *
19
+ * @param bool $maybe_notify
20
+ * @param int $comment_ID
21
+ *
22
+ * @return bool
23
+ *
24
+ * @wp-f2b-extra Comment \d+
25
+ */
26
+ function notify_post_author( $maybe_notify, $comment_ID )
27
+ {
28
+ openlog( 'WP_FAIL2BAN_COMMENT_LOG' );
29
+ syslog( LOG_INFO, "Comment {$comment_ID}" );
30
+ // @codeCoverageIgnoreEnd
31
+ return $maybe_notify;
32
+ }
33
+
34
+ add_filter(
35
+ 'notify_post_author',
36
+ __NAMESPACE__ . '\\notify_post_author',
37
+ 10,
38
+ 2
39
+ );
40
+
41
+ if ( defined( 'WP_FAIL2BAN_LOG_COMMENTS_EXTRA' ) ) {
42
+ /** WPF2B_ACTION_COMMENT_NOT_FOUND */
43
+
44
+ if ( WP_FAIL2BAN_LOG_COMMENTS_EXTRA & 0x20002 ) {
45
+ /**
46
+ * Log attempted comment on non-existent post
47
+ *
48
+ * @since 4.0.0
49
+ *
50
+ * @param int $comment_post_ID
51
+ *
52
+ * @wp-f2b-extra Comment post not found \d+
53
+ */
54
+ function comment_id_not_found( $comment_post_ID )
55
+ {
56
+ openlog( 'WP_FAIL2BAN_COMMENT_LOG' );
57
+ syslog( LOG_INFO, "Comment post not found {$comment_post_ID}" );
58
+ // @codeCoverageIgnoreEnd
59
+ }
60
+
61
+ add_action( 'comment_id_not_found', __NAMESPACE__ . '\\comment_id_not_found' );
62
+ }
63
+
64
+ /** LOG_ACTION_LOG_COMMENT_CLOSED */
65
+
66
+ if ( WP_FAIL2BAN_LOG_COMMENTS_EXTRA & 0x20004 ) {
67
+ /**
68
+ * Log attempted comment on closed post
69
+ *
70
+ * @since 4.0.0
71
+ *
72
+ * @param int $comment_post_ID
73
+ *
74
+ * @wp-f2b-extra Comments closed on post \d+
75
+ */
76
+ function comment_closed( $comment_post_ID )
77
+ {
78
+ openlog( 'WP_FAIL2BAN_COMMENT_LOG' );
79
+ syslog( LOG_INFO, "Comments closed on post {$comment_post_ID}" );
80
+ // @codeCoverageIgnoreEnd
81
+ }
82
+
83
+ add_action( 'comment_closed', __NAMESPACE__ . '\\comment_closed' );
84
+ }
85
+
86
+ /** LOG_ACTION_LOG_COMMENT_TRASH */
87
+
88
+ if ( WP_FAIL2BAN_LOG_COMMENTS_EXTRA & 0x20008 ) {
89
+ /**
90
+ * Log attempted comment on trashed post
91
+ *
92
+ * @since 4.0.0
93
+ *
94
+ * @param int $comment_post_ID
95
+ *
96
+ * @wp-f2b-extra Comment attempt on trash post \d+
97
+ */
98
+ function comment_on_trash( $comment_post_ID )
99
+ {
100
+ openlog( 'WP_FAIL2BAN_COMMENT_LOG' );
101
+ syslog( LOG_INFO, "Comment on trash post {$comment_post_ID}" );
102
+ // @codeCoverageIgnoreEnd
103
+ }
104
+
105
+ add_action( 'comment_on_trash', __NAMESPACE__ . '\\comment_on_trash' );
106
+ }
107
+
108
+ /** LOG_ACTION_LOG_COMMENT_DRAFT */
109
+
110
+ if ( WP_FAIL2BAN_LOG_COMMENTS_EXTRA & 0x20010 ) {
111
+ /**
112
+ * Log attempted comment on draft post
113
+ *
114
+ * @since 4.0.0
115
+ *
116
+ * @param int $comment_post_ID
117
+ *
118
+ * @wp-f2b-extra Comment attempt on draft post \d+
119
+ */
120
+ function comment_on_draft( $comment_post_ID )
121
+ {
122
+ openlog( 'WP_FAIL2BAN_COMMENT_LOG' );
123
+ syslog( LOG_INFO, "Comment on draft post {$comment_post_ID}" );
124
+ // @codeCoverageIgnoreEnd
125
+ }
126
+
127
+ add_action( 'comment_on_draft', __NAMESPACE__ . '\\comment_on_draft' );
128
+ }
129
+
130
+ /** LOG_ACTION_LOG_COMMENT_PASSWORD */
131
+
132
+ if ( WP_FAIL2BAN_LOG_COMMENTS_EXTRA & 0x20020 ) {
133
+ /**
134
+ * Log attempted comment on password-protected post
135
+ *
136
+ * @since 4.0.0
137
+ *
138
+ * @param int $comment_post_ID
139
+ *
140
+ * @wp-f2b-extra Comment attempt on password-protected post \d+
141
+ */
142
+ function comment_on_password_protected( $comment_post_ID )
143
+ {
144
+ openlog( 'WP_FAIL2BAN_COMMENT_LOG' );
145
+ syslog( LOG_INFO, "Comment on password-protected post {$comment_post_ID}" );
146
+ // @codeCoverageIgnoreEnd
147
+ }
148
+
149
+ add_action( 'comment_on_password_protected', __NAMESPACE__ . '\\comment_on_password_protected' );
150
+ }
151
+
152
+ }
feature/lib.php ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Library functions
5
+ *
6
+ * @package wp-fail2ban
7
+ * @since 4.0.0
8
+ */
9
+ namespace org\lecklider\charles\wordpress\wp_fail2ban;
10
+
11
+ if ( !defined( 'ABSPATH' ) ) {
12
+ exit;
13
+ }
14
+ /**
15
+ * Wrapper for \openlog
16
+ *
17
+ * @since 3.5.0 Refactored for unit testing
18
+ *
19
+ * @param string $log
20
+ */
21
+ function openlog( $log = 'WP_FAIL2BAN_AUTH_LOG' )
22
+ {
23
+ $tag = ( defined( 'WP_FAIL2BAN_SYSLOG_SHORT_TAG' ) && true === WP_FAIL2BAN_SYSLOG_SHORT_TAG ? 'wp' : 'wordpress' );
24
+ $host = ( array_key_exists( 'WP_FAIL2BAN_HTTP_HOST', $_ENV ) ? $_ENV['WP_FAIL2BAN_HTTP_HOST'] : $_SERVER['HTTP_HOST'] );
25
+ /**
26
+ * Some varieties of syslogd have difficulty if $host is too long
27
+ * @since 3.5.0
28
+ */
29
+ if ( defined( 'WP_FAIL2BAN_TRUNCATE_HOST' ) && 1 < intval( WP_FAIL2BAN_TRUNCATE_HOST ) ) {
30
+ $host = substr( $host, 0, intval( WP_FAIL2BAN_TRUNCATE_HOST ) );
31
+ }
32
+
33
+ if ( false === \openlog( "{$tag}({$host})", WP_FAIL2BAN_OPENLOG_OPTIONS, constant( $log ) ) ) {
34
+ error_log( 'WPf2b: Cannot open syslog', 0 );
35
+ // @codeCoverageIgnore
36
+ } elseif ( defined( 'WP_FAIL2BAN_TRACE' ) ) {
37
+ error_log( 'WPf2b: Opened syslog', 0 );
38
+ // @codeCoverageIgnore
39
+ }
40
+
41
+ }
42
+
43
+ /**
44
+ * Wrapper for \syslog
45
+ *
46
+ * @since 3.5.0
47
+ *
48
+ * @param int $level
49
+ * @param string $msg
50
+ * @param string|null $remote_addr
51
+ */
52
+ function syslog( $level, $msg, $remote_addr = null )
53
+ {
54
+ $msg .= ' from ';
55
+ $msg .= ( is_null( $remote_addr ) ? remote_addr() : $remote_addr );
56
+
57
+ if ( false === \syslog( $level, $msg ) ) {
58
+ error_log( "WPf2b: Cannot write to syslog: '{$msg}'", 0 );
59
+ // @codeCoverageIgnore
60
+ } elseif ( defined( 'WP_FAIL2BAN_TRACE' ) ) {
61
+ error_log( "WPf2b: Wrote to syslog: '{$msg}'", 0 );
62
+ // @codeCoverageIgnore
63
+ }
64
+
65
+ \closelog();
66
+ if ( defined( 'PHPUNIT_COMPOSER_INSTALL' ) ) {
67
+ echo "{$level}|{$msg}" ;
68
+ }
69
+ }
70
+
71
+ /**
72
+ * Graceful immediate exit
73
+ *
74
+ * @since 3.5.0 Refactored for unit testing
75
+ */
76
+ function bail()
77
+ {
78
+ wp_die( 'Forbidden', 'Forbidden', array(
79
+ 'response' => 403,
80
+ ) );
81
+ }
82
+
83
+ /**
84
+ * Compute remote IP address
85
+ *
86
+ * @return string
87
+ *
88
+ * @todo Test me!
89
+ * @codeCoverageIgnore
90
+ */
91
+ function remote_addr()
92
+ {
93
+ static $remote_addr = null ;
94
+ /**
95
+ * @since 4.0.0
96
+ */
97
+
98
+ if ( is_null( $remote_addr ) ) {
99
+ if ( defined( 'WP_FAIL2BAN_PROXIES' ) ) {
100
+
101
+ if ( array_key_exists( 'HTTP_X_FORWARDED_FOR', $_SERVER ) ) {
102
+ $ip = ip2long( $_SERVER['REMOTE_ADDR'] );
103
+ /**
104
+ * PHP 7 lets you define an array
105
+ * @since 3.5.4
106
+ */
107
+ $proxies = ( is_array( WP_FAIL2BAN_PROXIES ) ? WP_FAIL2BAN_PROXIES : explode( ',', WP_FAIL2BAN_PROXIES ) );
108
+ foreach ( $proxies as $proxy ) {
109
+
110
+ if ( '#' == $proxy[0] ) {
111
+ continue;
112
+ } elseif ( 2 == count( $cidr = explode( '/', $proxy ) ) ) {
113
+ $net = ip2long( $cidr[0] );
114
+ $mask = ~(pow( 2, 32 - $cidr[1] ) - 1);
115
+ } else {
116
+ $net = ip2long( $proxy );
117
+ $mask = -1;
118
+ }
119
+
120
+ if ( $net == ($ip & $mask) ) {
121
+ return ( false === ($len = strpos( $_SERVER['HTTP_X_FORWARDED_FOR'], ',' )) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : substr( $_SERVER['HTTP_X_FORWARDED_FOR'], 0, $len ) );
122
+ }
123
+ }
124
+ }
125
+
126
+ }
127
+ /**
128
+ * For plugins and themes that anonymise requests
129
+ * @since 3.6.0
130
+ */
131
+ $remote_addr = ( defined( 'WP_FAIL2BAN_REMOTE_ADDR' ) ? WP_FAIL2BAN_REMOTE_ADDR : $_SERVER['REMOTE_ADDR'] );
132
+ }
133
+
134
+ return $remote_addr;
135
+ }
feature/password.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Password-related functionality
5
+ *
6
+ * @package wp-fail2ban
7
+ * @since 4.0.0
8
+ */
9
+ namespace org\lecklider\charles\wordpress\wp_fail2ban;
10
+
11
+ if ( !defined( 'ABSPATH' ) ) {
12
+ exit;
13
+ }
14
+ /**
15
+ * Log password reset requests
16
+ *
17
+ * @since 3.5.0
18
+ *
19
+ * @param string $user_login
20
+ *
21
+ * @wp-f2b-extra Password reset requested for .*
22
+ */
23
+ function retrieve_password( $user_login )
24
+ {
25
+ openlog( 'WP_FAIL2BAN_PASSWORD_REQUEST_LOG' );
26
+ syslog( LOG_NOTICE, "Password reset requested for {$user_login}" );
27
+ // @codeCoverageIgnoreEnd
28
+ }
29
+
30
+ add_action( 'retrieve_password', __NAMESPACE__ . '\\retrieve_password' );
feature/spam.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Spam comments
5
+ *
6
+ * @package wp-fail2ban
7
+ * @since 4.0.0
8
+ */
9
+ namespace org\lecklider\charles\wordpress\wp_fail2ban;
10
+
11
+ if ( !defined( 'ABSPATH' ) ) {
12
+ exit;
13
+ }
14
+ /**
15
+ * Catch comments marked as spam
16
+ *
17
+ * @since 3.5.0
18
+ *
19
+ * @param int $comment_id
20
+ * @param string $comment_status
21
+ *
22
+ * @wp-f2b-hard Spam comment \d+
23
+ */
24
+ function log_spam_comment( $comment_id, $comment_status )
25
+ {
26
+ if ( 'spam' === $comment_status ) {
27
+
28
+ if ( is_null( $comment = get_comment( $comment_id, ARRAY_A ) ) ) {
29
+ /**
30
+ * @todo: decide what to do about this
31
+ */
32
+ } else {
33
+ $remote_addr = ( empty($comment['comment_author_IP']) ? 'unknown' : $comment['comment_author_IP'] );
34
+ openlog( 'WP_FAIL2BAN_SPAM_LOG' );
35
+ syslog( LOG_INFO, "Spam comment {$comment_id}", $remote_addr );
36
+ // @codeCoverageIgnoreEnd
37
+ }
38
+
39
+ }
40
+ }
41
+
42
+ add_action(
43
+ 'comment_post',
44
+ __NAMESPACE__ . '\\log_spam_comment',
45
+ 10,
46
+ 2
47
+ );
48
+ add_action(
49
+ 'wp_set_comment_status',
50
+ __NAMESPACE__ . '\\log_spam_comment',
51
+ 10,
52
+ 2
53
+ );
feature/user-enum.php ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * User enumeration
5
+ *
6
+ * @package wp-fail2ban
7
+ * @since 4.0.0
8
+ */
9
+ namespace org\lecklider\charles\wordpress\wp_fail2ban;
10
+
11
+ if ( !defined( 'ABSPATH' ) ) {
12
+ exit;
13
+ }
14
+ /**
15
+ * Common enumeration handling
16
+ *
17
+ * @since 4.0.0
18
+ *
19
+ * @wp-f2b-hard Blocked user enumeration attempt
20
+ */
21
+ function _log_bail_user_enum()
22
+ {
23
+ openlog();
24
+ syslog( LOG_NOTICE, 'Blocked user enumeration attempt' );
25
+ // @codeCoverageIgnoreEnd
26
+ bail();
27
+ }
28
+
29
+ /**
30
+ * Catch traditional user enum
31
+ *
32
+ * @see \WP::parse_request()
33
+ *
34
+ * @since 3.5.0 Refactored for unit testing
35
+ * @since 2.1.0
36
+ *
37
+ * @param \WP $query
38
+ *
39
+ * @return \WP
40
+ */
41
+ function parse_request( $query )
42
+ {
43
+ if ( !current_user_can( 'list_users' ) && intval( @$query->query_vars['author'] ) ) {
44
+ _log_bail_user_enum();
45
+ }
46
+ return $query;
47
+ }
48
+
49
+ add_filter(
50
+ 'parse_request',
51
+ __NAMESPACE__ . '\\parse_request',
52
+ 1,
53
+ 2
54
+ );
55
+ /**
56
+ * Catch RESTful user enum
57
+ *
58
+ * @see \WP_REST_Users_Controller::get_items()
59
+ *
60
+ * @since 4.0.0
61
+ *
62
+ * @param array $prepared_args
63
+ * @param \WP_REST_Request $request
64
+ *
65
+ * @return array
66
+ */
67
+ function rest_user_query( $prepared_args, $request )
68
+ {
69
+ if ( !current_user_can( 'list_users' ) ) {
70
+ _log_bail_user_enum();
71
+ }
72
+ return $prepared_args;
73
+ }
74
+
75
+ add_filter(
76
+ 'rest_user_query',
77
+ __NAMESPACE__ . '\\rest_user_query',
78
+ 10,
79
+ 2
80
+ );
feature/user.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Blocked user functionality
5
+ *
6
+ * @package wp-fail2ban
7
+ * @since 4.0.0
8
+ */
9
+ namespace org\lecklider\charles\wordpress\wp_fail2ban;
10
+
11
+ if ( !defined( 'ABSPATH' ) ) {
12
+ exit;
13
+ }
14
+ /**
15
+ * Catched blocked users
16
+ *
17
+ * @since 3.5.0 Refactored for unit testing
18
+ * @since 2.0.0
19
+ *
20
+ * @param mixed|null $user
21
+ * @param string $username
22
+ * @param string $password
23
+ *
24
+ * @return mixed|null
25
+ *
26
+ * @wp-f2b-hard Blocked authentication attempt for .*
27
+ */
28
+ function authenticate( $user, $username, $password )
29
+ {
30
+
31
+ if ( !empty($username) ) {
32
+ /**
33
+ * @since 3.5.0 Arrays allowed in PHP 7
34
+ */
35
+ $matched = ( is_array( WP_FAIL2BAN_BLOCKED_USERS ) ? in_array( $username, WP_FAIL2BAN_BLOCKED_USERS ) : preg_match( '/' . WP_FAIL2BAN_BLOCKED_USERS . '/i', $username ) );
36
+
37
+ if ( $matched ) {
38
+ openlog();
39
+ syslog( LOG_NOTICE, "Blocked authentication attempt for {$username}" );
40
+ // @codeCoverageIgnoreEnd
41
+ bail();
42
+ }
43
+
44
+ }
45
+
46
+ return $user;
47
+ }
48
+
49
+ add_filter(
50
+ 'authenticate',
51
+ __NAMESPACE__ . '\\authenticate',
52
+ 1,
53
+ 3
54
+ );
feature/xmlrpc.php ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * XML-RPC functionality
5
+ *
6
+ * @package wp-fail2ban
7
+ * @since 4.0.0
8
+ */
9
+ namespace org\lecklider\charles\wordpress\wp_fail2ban;
10
+
11
+ if ( !defined( 'ABSPATH' ) ) {
12
+ exit;
13
+ }
14
+ /**
15
+ * Catch multiple XML-RPC authentication failures
16
+ *
17
+ * @see \wp_xmlrpc_server::login()
18
+ *
19
+ * @since 4.0.0 Return $error
20
+ * @since 3.5.0 Refactored for unit testing
21
+ * @since 3.0.0
22
+ *
23
+ * @param \IXR_Error $error
24
+ * @param \WP_Error $user
25
+ *
26
+ * @return \IXR_Error
27
+ *
28
+ * @wp-f2b-hard XML-RPC multicall authentication failure
29
+ */
30
+ function xmlrpc_login_error( $error, $user )
31
+ {
32
+ static $attempts = 0 ;
33
+
34
+ if ( ++$attempts > 1 ) {
35
+ openlog();
36
+ syslog( LOG_NOTICE, 'XML-RPC multicall authentication failure' );
37
+ // @codeCoverageIgnoreEnd
38
+ bail();
39
+ } else {
40
+ return $error;
41
+ }
42
+
43
+ }
44
+
45
+ add_action(
46
+ 'xmlrpc_login_error',
47
+ __NAMESPACE__ . '\\xmlrpc_login_error',
48
+ 10,
49
+ 2
50
+ );
51
+ /**
52
+ * Catch failed pingbacks
53
+ *
54
+ * @see \wp_xmlrpc_server::pingback_error()
55
+ *
56
+ * @since 4.0.0 Return $ixr_error
57
+ * @since 3.5.0 Refactored for unit testing
58
+ * @since 3.0.0
59
+ *
60
+ * @param \IXR_Error $ixr_error
61
+ *
62
+ * @return \IXR_Error
63
+ *
64
+ * @wp-f2b-hard Pingback error .* generated
65
+ */
66
+ function xmlrpc_pingback_error( $ixr_error )
67
+ {
68
+
69
+ if ( 48 !== $ixr_error->code ) {
70
+ openlog();
71
+ syslog( LOG_NOTICE, 'Pingback error ' . $ixr_error->code . ' generated' );
72
+ // @codeCoverageIgnoreEnd
73
+ }
74
+
75
+ return $ixr_error;
76
+ }
77
+
78
+ add_filter( 'xmlrpc_pingback_error', __NAMESPACE__ . '\\xmlrpc_pingback_error', 5 );
79
+ /**
80
+ * @since 4.0.0 Refactored
81
+ * @since 2.2.0
82
+ */
83
+ if ( defined( 'WP_FAIL2BAN_LOG_PINGBACKS' ) && true === WP_FAIL2BAN_LOG_PINGBACKS ) {
84
+ require_once 'xmlrpc/pingback.php';
85
+ }
86
+ /**
87
+ * @since 4.0.0 Refactored
88
+ * @since 3.6.0
89
+ */
90
+ if ( defined( 'WP_FAIL2BAN_XMLRPC_LOG' ) && '' < WP_FAIL2BAN_XMLRPC_LOG ) {
91
+ require_once 'xmlrpc/log.php';
92
+ }
feature/xmlrpc/log.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * XML-RPC Request logging
4
+ *
5
+ * @package wp-fail2ban
6
+ * @since 4.0.0
7
+ */
8
+ namespace org\lecklider\charles\wordpress\wp_fail2ban;
9
+
10
+ if (!defined('ABSPATH')) {
11
+ exit;
12
+ }
13
+
14
+ /**
15
+ * Log XML-RPC requests
16
+ *
17
+ * It seems attackers are doing weird things with XML-RPC. This makes it easy to
18
+ * log them for analysis and future blocking.
19
+ *
20
+ * @since 4.0.0 Fix: Removed HTTP_RAW_POST_DATA
21
+ * https://wordpress.org/support/?p=10971843
22
+ * @since 3.6.0
23
+ *
24
+ * @codeCoverageIgnore
25
+ */
26
+ if (false === ($fp = fopen(WP_FAIL2BAN_XMLRPC_LOG, 'a+'))) {
27
+ // TODO: decided whether to log this
28
+ } else {
29
+ $raw_data = (version_compare(PHP_VERSION, '7.0.0') >= 0)
30
+ ? file_get_contents('php://input')
31
+ : $HTTP_RAW_POST_DATA;
32
+
33
+ fprintf($fp, "# ---\n# Date: %s\n# IP: %s\n\n%s\n", date(DATE_ATOM), remote_addr(), $raw_data);
34
+ fclose($fp);
35
+ }
feature/xmlrpc/pingback.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * pingback logging
5
+ *
6
+ * @package wp-fail2ban
7
+ * @since 4.0.0
8
+ */
9
+ namespace org\lecklider\charles\wordpress\wp_fail2ban;
10
+
11
+ if ( !defined( 'ABSPATH' ) ) {
12
+ exit;
13
+ }
14
+ /**
15
+ * Log pingbacks
16
+ *
17
+ * @since 3.5.0 Refactored for unit testing
18
+ * @since 2.2.0
19
+ *
20
+ * @param string $call
21
+ */
22
+ function xmlrpc_call( $call )
23
+ {
24
+
25
+ if ( 'pingback.ping' == $call ) {
26
+ openlog( 'WP_FAIL2BAN_PINGBACK_LOG' );
27
+ syslog( LOG_INFO, 'Pingback requested' );
28
+ // @codeCoverageIgnoreEnd
29
+ }
30
+
31
+ }
32
+
33
+ add_action( 'xmlrpc_call', __NAMESPACE__ . '\\xmlrpc_call' );
filters.d/wordpress-extra.conf ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Fail2Ban filter for WordPress extra failures
2
+ # Auto-generated: 2019-01-24T14:41:41+00:00
3
+ #
4
+
5
+ [INCLUDES]
6
+
7
+ before = common.conf
8
+
9
+ [Definition]
10
+
11
+ _daemon = (?:wordpress|wp)
12
+
13
+ failregex = ^%(__prefix_line)sComment \d+ from <HOST>$
14
+ ^%(__prefix_line)sComment post not found \d+ from <HOST>$
15
+ ^%(__prefix_line)sComments closed on post \d+ from <HOST>$
16
+ ^%(__prefix_line)sComment attempt on trash post \d+ from <HOST>$
17
+ ^%(__prefix_line)sComment attempt on draft post \d+ from <HOST>$
18
+ ^%(__prefix_line)sComment attempt on password-protected post \d+ from <HOST>$
19
+ ^%(__prefix_line)sPassword reset requested for .* from <HOST>$
20
+
21
+ ignoreregex =
22
+
23
+ # DEV Notes:
24
+ # Requires the 'WP fail2ban' plugin:
25
+ # https://wp-fail2ban.com/
26
+ #
27
+ # Author: Charles Lecklider
filters.d/wordpress-hard.conf CHANGED
@@ -1,27 +1,29 @@
1
- # Fail2Ban filter for WordPress hard failures
2
- # Auto-generated: 2018-11-04T16:40:53+00:00
3
- #
4
-
5
- [INCLUDES]
6
-
7
- before = common.conf
8
-
9
- [Definition]
10
-
11
- _daemon = (?:wordpress|wp)
12
-
13
- failregex = ^%(__prefix_line)sBlocked authentication attempt for .* from <HOST>$
14
- ^%(__prefix_line)sBlocked user enumeration attempt from <HOST>$
15
- ^%(__prefix_line)sSpam comment \d+ from <HOST>$
16
- ^%(__prefix_line)sXML-RPC multicall authentication failure from <HOST>$
17
- ^%(__prefix_line)sPingback error .* generated from <HOST>$
18
- ^%(__prefix_line)sAuthentication attempt for unknown user .* from <HOST>$
19
- ^%(__prefix_line)sXML-RPC authentication attempt for unknown user .* from <HOST>$
20
-
21
- ignoreregex =
22
-
23
- # DEV Notes:
24
- # Requires the 'WP fail2ban' plugin:
25
- # https://github.com/invisnet/wp-fail2ban/
26
- #
27
- # Author: Charles Lecklider
 
 
1
+ # Fail2Ban filter for WordPress hard failures
2
+ # Auto-generated: 2019-01-24T14:41:41+00:00
3
+ #
4
+
5
+ [INCLUDES]
6
+
7
+ before = common.conf
8
+
9
+ [Definition]
10
+
11
+ _daemon = (?:wordpress|wp)
12
+
13
+ failregex = ^%(__prefix_line)sAuthentication attempt for unknown user .* from <HOST>$
14
+ ^%(__prefix_line)sXML-RPC authentication attempt for unknown user .* from <HOST>$
15
+ ^%(__prefix_line)sSpam comment \d+ from <HOST>$
16
+ ^%(__prefix_line)sBlocked user enumeration attempt from <HOST>$
17
+ ^%(__prefix_line)sBlocked authentication attempt for .* from <HOST>$
18
+ ^%(__prefix_line)sXML-RPC multicall authentication failure from <HOST>$
19
+ ^%(__prefix_line)sPingback error .* generated from <HOST>$
20
+ ^%(__prefix_line)sXML-RPC multicall authentication failure from <HOST>$
21
+ ^%(__prefix_line)sPingback error .* generated from <HOST>$
22
+
23
+ ignoreregex =
24
+
25
+ # DEV Notes:
26
+ # Requires the 'WP fail2ban' plugin:
27
+ # https://wp-fail2ban.com/
28
+ #
29
+ # Author: Charles Lecklider
filters.d/wordpress-soft.conf CHANGED
@@ -1,22 +1,22 @@
1
- # Fail2Ban filter for WordPress soft failures
2
- # Auto-generated: 2018-11-04T16:40:53+00:00
3
- #
4
-
5
- [INCLUDES]
6
-
7
- before = common.conf
8
-
9
- [Definition]
10
-
11
- _daemon = (?:wordpress|wp)
12
-
13
- failregex = ^%(__prefix_line)sAuthentication failure for .* from <HOST>$
14
- ^%(__prefix_line)sXML-RPC authentication failure for .* from <HOST>$
15
-
16
- ignoreregex =
17
-
18
- # DEV Notes:
19
- # Requires the 'WP fail2ban' plugin:
20
- # https://github.com/invisnet/wp-fail2ban/
21
- #
22
- # Author: Charles Lecklider
1
+ # Fail2Ban filter for WordPress soft failures
2
+ # Auto-generated: 2019-01-24T14:41:41+00:00
3
+ #
4
+
5
+ [INCLUDES]
6
+
7
+ before = common.conf
8
+
9
+ [Definition]
10
+
11
+ _daemon = (?:wordpress|wp)
12
+
13
+ failregex = ^%(__prefix_line)sAuthentication failure for .* from <HOST>$
14
+ ^%(__prefix_line)sXML-RPC authentication failure for .* from <HOST>$
15
+
16
+ ignoreregex =
17
+
18
+ # DEV Notes:
19
+ # Requires the 'WP fail2ban' plugin:
20
+ # https://wp-fail2ban.com/
21
+ #
22
+ # Author: Charles Lecklider
readme.txt CHANGED
@@ -1,189 +1,199 @@
1
- === WP fail2ban ===
2
- Contributors: invisnet
3
- Author URI: https://charles.lecklider.org/
4
- Plugin URI: https://github.com/invisnet/wp-fail2ban
5
- Tags: fail2ban, login, security, syslog
6
- Requires at least: 3.4
7
- Tested up to: 4.9
8
- Stable tag: 3.6.0
9
- Requires PHP: 5.3
10
- License: GPLv2 or later
11
- License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
- Provides: FAIL2BAN
13
-
14
- Write a myriad of WordPress events to syslog for integration with fail2ban.
15
-
16
- == Description ==
17
-
18
- [fail2ban](http://www.fail2ban.org/) is one of the simplest and most effective security measures you can implement to prevent brute-force password-guessing attacks.
19
-
20
- *WP fail2ban* logs all login attempts - including via XML-RPC, whether successful or not, to syslog using LOG_AUTH. For example:
21
-
22
- Oct 17 20:59:54 foobar wordpress(www.example.com)[1234]: Authentication failure for admin from 192.168.0.1
23
- Oct 17 21:00:00 foobar wordpress(www.example.com)[2345]: Accepted password for admin from 192.168.0.1
24
-
25
- *WPf2b* comes with two `fail2ban` filters, `wordpress-hard.conf` and `wordpress-soft.conf`, designed to allow a split between immediate banning and the traditional more graceful approach.
26
-
27
- = Features =
28
-
29
- **CloudFlare and Proxy Servers**
30
-
31
- *WPf2b* can be configured to work with CloudFlare and other proxy servers. For an overview see [`WP_FAIL2BAN_PROXIES`](https://wp-fail2ban.readthedocs.io/en/3.6/defines.html#wp-fail2ban-proxies).
32
-
33
- **Comments**
34
-
35
- *WPf2b* can log comments. See [`WP_FAIL2BAN_LOG_COMMENTS`](https://wp-fail2ban.readthedocs.io/en/3.6/defines.html#wp-fail2ban-log-comments).
36
-
37
- **Pingbacks**
38
-
39
- *WPf2b* logs failed pingbacks, and can log all pingbacks. For an overview see [`WP_FAIL2BAN_LOG_PINGBACKS`](https://wp-fail2ban.readthedocs.io/en/3.6/defines.html#wp-fail2ban-log-pingbacks).
40
-
41
- **Spam**
42
-
43
- *WPf2b* can log comments marked as spam. See [`WP_FAIL2BAN_LOG_SPAM`](https://wp-fail2ban.readthedocs.io/en/3.6/defines.html#wp-fail2ban-log-spam).
44
-
45
- **User Enumeration**
46
-
47
- *WPf2b* can block user enumeration. See [`WP_FAIL2BAN_BLOCK_USER_ENUMERATION`](https://wp-fail2ban.readthedocs.io/en/3.6/defines.html#wp-fail2ban-block-user-enumeration).
48
-
49
- **Work-Arounds for Broken syslogd**
50
-
51
- *WPf2b* can be configured to work around most syslogd weirdness. For an overview see [`WP_FAIL2BAN_SYSLOG_SHORT_TAG`](https://wp-fail2ban.readthedocs.io/en/3.6/defines.html#wp-fail2ban-syslog-short-tag) and [`WP_FAIL2BAN_HTTP_HOST`](https://wp-fail2ban.readthedocs.io/en/3.6/defines.html#wp-fail2ban-http-host).
52
-
53
- **Blocking Users**
54
-
55
- *WPf2b* can be configured to short-cut the login process when the username matches a regex. For an overview see [`WP_FAIL2BAN_BLOCKED_USERS`](https://wp-fail2ban.readthedocs.io/en/3.6/defines.html#wp-fail2ban-blocked-users).
56
-
57
- **`mu-plugins` Support**
58
-
59
- *WPf2b* can easily be configured as a must-use plugin - see [Configuration](https://wp-fail2ban.readthedocs.io/en/3.6/configuration.html#mu-plugins-support).
60
-
61
-
62
-
63
- == Installation ==
64
-
65
- 1. Install via the Plugin Directory, or upload to your plugins directory.
66
- 1. Activate the plugin through the 'Plugins' menu in WordPress.
67
- 1. Edit `wp-config.php` to suit your needs - see [Configuration](https://wp-fail2ban.readthedocs.io/en/3.6/configuration.html).
68
-
69
- == Changelog ==
70
-
71
- = 3.6.0 =
72
- * The [filter files](https://wp-fail2ban.readthedocs.io/en/3.6/filters.html) are now generated from PHPDoc in the code. There were too many times when the filters were out of sync with the code (programmer error) - this should resolve that by bringing the patterns closer to the code that emits them.
73
- * Added [PHPUnit tests](https://wp-fail2ban.readthedocs.io/en/3.6/tests.html). Almost 100% code coverage, with the exception of [`WP_FAIL2BAN_PROXIES`](https://wp-fail2ban.readthedocs.io/en/3.6/defines.html#wp-fail2ban-proxies) which is quite hard to test properly.
74
- * Bugfix for [`wordpress-soft.conf`](https://wp-fail2ban.readthedocs.io/en/3.6/filters.html#wordpress-soft-conf).
75
- * Add [`WP_FAIL2BAN_XMLRPC_LOG`](https://wp-fail2ban.readthedocs.io/en/3.6/defines.html#wp-fail2ban-xmlrpc-log).
76
- * Add [`WP_FAIL2BAN_REMOTE_ADDR`](https://wp-fail2ban.readthedocs.io/en/3.6/defines.html#wp-fail2ban-remote-addr).
77
- * [`WP_FAIL2BAN_PROXIES`](https://wp-fail2ban.readthedocs.io/en/3.6/defines.html#wp-fail2ban-proxies) now supports an array of IPs with PHP 7.
78
- * Moved all documentation to [https://wp-fail2ban.readthedocs.io/](https://wp-fail2ban.readthedocs.io/).
79
-
80
- = 3.5.3 =
81
- * Bugfix for [`wordpress-hard.conf`](https://wp-fail2ban.readthedocs.io/en/3.6/filters.html#wordpress-hard-conf).
82
-
83
- = 3.5.1 =
84
- * Bugfix for [`WP_FAIL2BAN_BLOCK_USER_ENUMERATION`](https://wp-fail2ban.readthedocs.io/en/3.6/defines.html#wp-fail2ban-block-user-enumeration).
85
-
86
- = 3.5.0 =
87
- * Add [`WP_FAIL2BAN_OPENLOG_OPTIONS`](https://wp-fail2ban.readthedocs.io/en/3.6/defines.html#wp-fail2ban-openlog-options).
88
- * Add [`WP_FAIL2BAN_LOG_COMMENTS`](https://wp-fail2ban.readthedocs.io/en/3.6/defines.html#wp-fail2ban-log-comments) and [`WP_FAIL2BAN_COMMENT_LOG`](https://wp-fail2ban.readthedocs.io/en/3.6/defines.html#wp-fail2ban-comment-log).
89
- * Add [`WP_FAIL2BAN_LOG_PASSWORD_REQUEST`](https://wp-fail2ban.readthedocs.io/en/3.6/defines.html#wp-fail2ban-log-password-request).
90
- * Add [`WP_FAIL2BAN_LOG_SPAM`](https://wp-fail2ban.readthedocs.io/en/3.6/defines.html#wp-fail2ban-log-spam).
91
- * Add [`WP_FAIL2BAN_TRUNCATE_HOST`](https://wp-fail2ban.readthedocs.io/en/3.6/defines.html#wp-fail2ban-truncate-host).
92
- * [`WP_FAIL2BAN_BLOCKED_USERS`](https://wp-fail2ban.readthedocs.io/en/3.6/defines.html#wp-fail2ban-blocked-users) now supports an array of users with PHP 7.
93
-
94
- = 3.0.3 =
95
- * Fix regex in [`wordpress-hard.conf`](https://wp-fail2ban.readthedocs.io/en/3.6/filters.html#wordpress-hard-conf).
96
-
97
- = 3.0.2 =
98
- * Prevent double logging in WP 4.5.x for XML-RPC authentication failure
99
-
100
- = 3.0.1 =
101
- * Fix regex in [`wordpress-hard.conf`](https://wp-fail2ban.readthedocs.io/en/3.6/filters.html#wordpress-hard-conf).
102
-
103
- = 3.0.0 =
104
- * Add [`WP_FAIL2BAN_SYSLOG_SHORT_TAG`](https://wp-fail2ban.readthedocs.io/en/3.6/defines.html#wp-fail2ban-syslog-short-tag).
105
- * Add [`WP_FAIL2BAN_HTTP_HOST`](https://wp-fail2ban.readthedocs.io/en/3.6/defines.html#wp-fail2ban-http-host).
106
- * Log XML-RPC authentication failure.
107
- * Add better support for MU deployment.
108
-
109
- = 2.3.2 =
110
- * Bugfix [`WP_FAIL2BAN_BLOCKED_USERS`](https://wp-fail2ban.readthedocs.io/en/3.6/defines.html#wp-fail2ban-blocked-users).
111
-
112
- = 2.3.0 =
113
- * Bugfix in *experimental* [`WP_FAIL2BAN_PROXIES`](https://wp-fail2ban.readthedocs.io/en/3.6/defines.html#wp-fail2ban-proxies) code (thanks to KyleCartmell).
114
-
115
- = 2.2.1 =
116
- * Fix stupid mistake with [`WP_FAIL2BAN_BLOCKED_USERS`](https://wp-fail2ban.readthedocs.io/en/3.6/defines.html#wp-fail2ban-blocked-users).
117
-
118
- = 2.2.0 =
119
- * Custom authentication log is now called [`WP_FAIL2BAN_AUTH_LOG`](https://wp-fail2ban.readthedocs.io/en/3.6/defines.html#wp-fail2ban-auth-log).
120
- * Add logging for pingbacks; see [`WP_FAIL2BAN_LOG_PINGBACKS`](https://wp-fail2ban.readthedocs.io/en/3.6/defines.html#wp-fail2ban-log-pingbacks).
121
- * Custom pingback log is called [`WP_FAIL2BAN_PINGBACK_LOG`](https://wp-fail2ban.readthedocs.io/en/3.6/defines.html#wp-fail2ban-pingback-log).
122
-
123
- = 2.1.1 =
124
- * Minor bugfix.
125
-
126
- = 2.1.0 =
127
- * Add support for blocking user enumeration; see [`WP_FAIL2BAN_BLOCK_USER_ENUMERATION`](https://wp-fail2ban.readthedocs.io/en/3.6/defines.html#wp-fail2ban-block-user-enumeration).
128
- * Add support for CIDR notation in [`WP_FAIL2BAN_PROXIES`](https://wp-fail2ban.readthedocs.io/en/3.6/defines.html#wp-fail2ban-proxies).
129
-
130
- = 2.0.1 =
131
- * Bugfix in *experimental* [`WP_FAIL2BAN_PROXIES`](https://wp-fail2ban.readthedocs.io/en/3.6/defines.html#wp-fail2ban-proxies) code.
132
-
133
- = 2.0.0 =
134
- * Add *experimental* support for X-Forwarded-For header; see [`WP_FAIL2BAN_PROXIES`](https://wp-fail2ban.readthedocs.io/en/3.6/defines.html#wp-fail2ban-proxies).
135
- * Add *experimental* support for regex-based login blocking; see [`WP_FAIL2BAN_BLOCKED_USERS`](https://wp-fail2ban.readthedocs.io/en/3.6/defines.html#wp-fail2ban-blocked-users).
136
-
137
- = 1.2.1 =
138
- * Update FAQ.
139
-
140
- = 1.2 =
141
- * Fix harmless warning.
142
-
143
- = 1.1 =
144
- * Minor cosmetic updates.
145
-
146
- = 1.0 =
147
- * Initial release.
148
-
149
- == Upgrade Notice ==
150
-
151
- = 3.6.0 =
152
- You will need up update your `fail2ban` filters.
153
-
154
- = 3.5.3 =
155
- You will need up update your `fail2ban` filters.
156
-
157
- = 3.5.1 =
158
- Bugfix: disable [`WP_FAIL2BAN_BLOCK_USER_ENUMERATION`](https://wp-fail2ban.readthedocs.io/en/3.6/defines.html#wp-fail2ban-block-user-enumeration) in admin area....
159
-
160
- = 3.5.0 =
161
- You will need up update your `fail2ban` filters.
162
-
163
- = 3.0.3 =
164
- You will need up update your `fail2ban` filters.
165
-
166
- = 3.0.0 =
167
- BREAKING CHANGE: The `fail2ban` filters have been split into two files. You will need up update your `fail2ban` configuration.
168
-
169
- = 2.3.0 =
170
- Fix for [`WP_FAIL2BAN_PROXIES`](https://wp-fail2ban.readthedocs.io/en/3.6/defines.html#wp-fail2ban-proxies); if you're not using it you can safely skip this release.
171
-
172
- = 2.2.1 =
173
- Bugfix.
174
-
175
- = 2.2.0 =
176
- BREAKING CHANGE: `WP_FAIL2BAN_LOG` has been renamed to [`WP_FAIL2BAN_AUTH_LOG`](https://wp-fail2ban.readthedocs.io/en/3.6/defines.html#wp-fail2ban-auth-log).
177
-
178
- Pingbacks are getting a lot of attention recently, so *WPf2b* can now log them.
179
- The `wordpress.conf` filter has been updated; you will need to update your `fail2ban` configuration.
180
-
181
- = 2.1.0 =
182
- The `wordpress.conf` filter has been updated; you will need to update your `fail2ban` configuration.
183
-
184
- = 2.0.1 =
185
- Bugfix in experimental code; still an experimental release.
186
-
187
- = 2.0.0 =
188
- This is an experimental release. If your current version is working and you're not interested in the new features, skip this version - wait for 2.1.0. For those that do want to test this release, note that `wordpress.conf` has changed - you'll need to copy it to `fail2ban/filters.d` again.
189
-
 
 
 
 
 
 
 
 
 
 
1
+ === WP fail2ban ===
2
+ Contributors: invisnet
3
+ Donate link: https://paypal.me/invisnet/
4
+ Author URI: https://charles.lecklider.org/
5
+ Plugin URI: https://wp-fail2ban.com/
6
+ Tags: fail2ban, login, security, syslog
7
+ Requires at least: 3.4
8
+ Tested up to: 5.0
9
+ Stable tag: 4.0.1
10
+ Requires PHP: 5.3
11
+ License: GPLv2 or later
12
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
13
+
14
+ Write a myriad of WordPress events to syslog for integration with fail2ban.
15
+
16
+ == Description ==
17
+
18
+ [fail2ban](http://www.fail2ban.org/) is one of the simplest and most effective security measures you can implement to prevent brute-force attacks.
19
+
20
+ *WP fail2ban* logs all login attempts - including via XML-RPC, whether successful or not, to syslog using LOG_AUTH. For example:
21
+
22
+ Oct 17 20:59:54 foobar wordpress(www.example.com)[1234]: Authentication failure for admin from 192.168.0.1
23
+ Oct 17 21:00:00 foobar wordpress(www.example.com)[2345]: Accepted password for admin from 192.168.0.1
24
+
25
+ *WPf2b* comes with two `fail2ban` filters, `wordpress-hard.conf` and `wordpress-soft.conf`, designed to allow a split between immediate banning and the traditional more graceful approach.
26
+
27
+ = Features =
28
+
29
+
30
+
31
+ * **CloudFlare and Proxy Servers**
32
+ *WPf2b* can be configured to work with CloudFlare and other proxy servers. For an overview see [`WP_FAIL2BAN_PROXIES`](https://docs.wp-fail2ban.com/en/4.0/defines.html#wp-fail2ban-proxies).
33
+
34
+ * **Comments**
35
+ *WPf2b* can log comments (see [`WP_FAIL2BAN_LOG_COMMENTS`](https://docs.wp-fail2ban.com/en/4.0/defines.html#wp-fail2ban-log-comments)) and attempted comments (see [`WP_FAIL2BAN_LOG_COMMENTS_EXTRA`](https://docs.wp-fail2ban.com/en/4.0/defines.html#wp-fail2ban-log-comments-extra)).
36
+
37
+ * **Pingbacks**
38
+ *WPf2b* logs failed pingbacks, and can log all pingbacks. For an overview see [`WP_FAIL2BAN_LOG_PINGBACKS`](https://docs.wp-fail2ban.com/en/4.0/defines.html#wp-fail2ban-log-pingbacks).
39
+
40
+ * **Spam**
41
+ *WPf2b* can log comments marked as spam. See [`WP_FAIL2BAN_LOG_SPAM`](https://docs.wp-fail2ban.com/en/4.0/defines.html#wp-fail2ban-log-spam).
42
+
43
+ * **Block User Enumeration**
44
+ *WPf2b* can block user enumeration. See [`WP_FAIL2BAN_BLOCK_USER_ENUMERATION`](https://docs.wp-fail2ban.com/en/4.0/defines.html#wp-fail2ban-block-user-enumeration).
45
+
46
+ * **Work-Arounds for Broken syslogd**
47
+ *WPf2b* can be configured to work around most syslogd weirdness. For an overview see [`WP_FAIL2BAN_SYSLOG_SHORT_TAG`](https://docs.wp-fail2ban.com/en/4.0/defines.html#wp-fail2ban-syslog-short-tag) and [`WP_FAIL2BAN_HTTP_HOST`](https://docs.wp-fail2ban.com/en/4.0/defines.html#wp-fail2ban-http-host).
48
+
49
+ * **Blocking Users**
50
+ *WPf2b* can be configured to short-cut the login process when the username matches a regex. For an overview see [`WP_FAIL2BAN_BLOCKED_USERS`](https://docs.wp-fail2ban.com/en/4.0/defines.html#wp-fail2ban-blocked-users).
51
+
52
+ * **`mu-plugins` Support**
53
+ *WPf2b* can easily be configured as a must-use plugin - see [Configuration](https://docs.wp-fail2ban.com/en/4.0/configuration.html#mu-plugins-support).
54
+
55
+ == Installation ==
56
+
57
+ 1. Install via the Plugin Directory, or upload to your plugins directory.
58
+ 1. Activate the plugin through the 'Plugins' menu in WordPress.
59
+ 1. Edit `wp-config.php` to suit your needs - see [Configuration](https://docs.wp-fail2ban.com/en/4.0/configuration.html).
60
+
61
+ == Changelog ==
62
+
63
+ = 4.0.1 =
64
+ * Add extra features via Freemius. **This is entirely optional.** *WPf2b* works as before, including new features listed here.
65
+ * Add settings summary page (Settings -> WP fail2ban).
66
+ * Add [`WP_FAIL2BAN_PASSWORD_REQUEST_LOG`](https://docs.wp-fail2ban.com/en/4.0/defines.html#wp-fail2ban-password-request-log).
67
+ * Add [`WP_FAIL2BAN_SPAM_LOG`](https://docs.wp-fail2ban.com/en/4.0/defines.html#wp-fail2ban-spam-log).
68
+ * Add [`WP_FAIL2BAN_LOG_COMMENTS_EXTRA`](https://docs.wp-fail2ban.com/en/4.0/defines.html#wp-fail2ban-log-comments-extra) - enable logging for attempted comments on posts which are:
69
+ * not found,
70
+ * closed for commenting,
71
+ * in the trash,
72
+ * drafts,
73
+ * password protected
74
+ * Block user enumeration via REST API.
75
+
76
+ = 4.0.0 =
77
+ * Not released.
78
+
79
+ = 3.6.0 =
80
+ * The [filter files](https://docs.wp-fail2ban.com/en/4.0/filters.html) are now generated from PHPDoc in the code. There were too many times when the filters were out of sync with the code (programmer error) - this should resolve that by bringing the patterns closer to the code that emits them.
81
+ * Added [PHPUnit tests](https://docs.wp-fail2ban.com/en/4.0/tests.html). Almost 100% code coverage, with the exception of [`WP_FAIL2BAN_PROXIES`](https://docs.wp-fail2ban.com/en/4.0/defines.html#wp-fail2ban-proxies) which is quite hard to test properly.
82
+ * Bugfix for [`wordpress-soft.conf`](https://docs.wp-fail2ban.com/en/4.0/filters.html#wordpress-soft-conf).
83
+ * Add [`WP_FAIL2BAN_XMLRPC_LOG`](https://docs.wp-fail2ban.com/en/4.0/defines.html#wp-fail2ban-xmlrpc-log).
84
+ * Add [`WP_FAIL2BAN_REMOTE_ADDR`](https://docs.wp-fail2ban.com/en/4.0/defines.html#wp-fail2ban-remote-addr).
85
+ * [`WP_FAIL2BAN_PROXIES`](https://docs.wp-fail2ban.com/en/4.0/defines.html#wp-fail2ban-proxies) now supports an array of IPs with PHP 7.
86
+ * Moved all documentation to [https://docs.wp-fail2ban.com/](https://docs.wp-fail2ban.com/).
87
+
88
+ = 3.5.3 =
89
+ * Bugfix for [`wordpress-hard.conf`](https://docs.wp-fail2ban.com/en/4.0/filters.html#wordpress-hard-conf).
90
+
91
+ = 3.5.1 =
92
+ * Bugfix for [`WP_FAIL2BAN_BLOCK_USER_ENUMERATION`](https://docs.wp-fail2ban.com/en/4.0/defines.html#wp-fail2ban-block-user-enumeration).
93
+
94
+ = 3.5.0 =
95
+ * Add [`WP_FAIL2BAN_OPENLOG_OPTIONS`](https://docs.wp-fail2ban.com/en/4.0/defines.html#wp-fail2ban-openlog-options).
96
+ * Add [`WP_FAIL2BAN_LOG_COMMENTS`](https://docs.wp-fail2ban.com/en/4.0/defines.html#wp-fail2ban-log-comments) and [`WP_FAIL2BAN_COMMENT_LOG`](https://docs.wp-fail2ban.com/en/4.0/defines.html#wp-fail2ban-comment-log).
97
+ * Add [`WP_FAIL2BAN_LOG_PASSWORD_REQUEST`](https://docs.wp-fail2ban.com/en/4.0/defines.html#wp-fail2ban-log-password-request).
98
+ * Add [`WP_FAIL2BAN_LOG_SPAM`](https://docs.wp-fail2ban.com/en/4.0/defines.html#wp-fail2ban-log-spam).
99
+ * Add [`WP_FAIL2BAN_TRUNCATE_HOST`](https://docs.wp-fail2ban.com/en/4.0/defines.html#wp-fail2ban-truncate-host).
100
+ * [`WP_FAIL2BAN_BLOCKED_USERS`](https://docs.wp-fail2ban.com/en/4.0/defines.html#wp-fail2ban-blocked-users) now supports an array of users with PHP 7.
101
+
102
+ = 3.0.3 =
103
+ * Fix regex in [`wordpress-hard.conf`](https://docs.wp-fail2ban.com/en/4.0/filters.html#wordpress-hard-conf).
104
+
105
+ = 3.0.2 =
106
+ * Prevent double logging in WP 4.5.x for XML-RPC authentication failure
107
+
108
+ = 3.0.1 =
109
+ * Fix regex in [`wordpress-hard.conf`](https://docs.wp-fail2ban.com/en/4.0/filters.html#wordpress-hard-conf).
110
+
111
+ = 3.0.0 =
112
+ * Add [`WP_FAIL2BAN_SYSLOG_SHORT_TAG`](https://docs.wp-fail2ban.com/en/4.0/defines.html#wp-fail2ban-syslog-short-tag).
113
+ * Add [`WP_FAIL2BAN_HTTP_HOST`](https://docs.wp-fail2ban.com/en/4.0/defines.html#wp-fail2ban-http-host).
114
+ * Log XML-RPC authentication failure.
115
+ * Add better support for MU deployment.
116
+
117
+ = 2.3.2 =
118
+ * Bugfix [`WP_FAIL2BAN_BLOCKED_USERS`](https://docs.wp-fail2ban.com/en/4.0/defines.html#wp-fail2ban-blocked-users).
119
+
120
+ = 2.3.0 =
121
+ * Bugfix in *experimental* [`WP_FAIL2BAN_PROXIES`](https://docs.wp-fail2ban.com/en/4.0/defines.html#wp-fail2ban-proxies) code (thanks to KyleCartmell).
122
+
123
+ = 2.2.1 =
124
+ * Fix stupid mistake with [`WP_FAIL2BAN_BLOCKED_USERS`](https://docs.wp-fail2ban.com/en/4.0/defines.html#wp-fail2ban-blocked-users).
125
+
126
+ = 2.2.0 =
127
+ * Custom authentication log is now called [`WP_FAIL2BAN_AUTH_LOG`](https://docs.wp-fail2ban.com/en/4.0/defines.html#wp-fail2ban-auth-log).
128
+ * Add logging for pingbacks; see [`WP_FAIL2BAN_LOG_PINGBACKS`](https://docs.wp-fail2ban.com/en/4.0/defines.html#wp-fail2ban-log-pingbacks).
129
+ * Custom pingback log is called [`WP_FAIL2BAN_PINGBACK_LOG`](https://docs.wp-fail2ban.com/en/4.0/defines.html#wp-fail2ban-pingback-log).
130
+
131
+ = 2.1.1 =
132
+ * Minor bugfix.
133
+
134
+ = 2.1.0 =
135
+ * Add support for blocking user enumeration; see [`WP_FAIL2BAN_BLOCK_USER_ENUMERATION`](https://docs.wp-fail2ban.com/en/4.0/defines.html#wp-fail2ban-block-user-enumeration).
136
+ * Add support for CIDR notation in [`WP_FAIL2BAN_PROXIES`](https://docs.wp-fail2ban.com/en/4.0/defines.html#wp-fail2ban-proxies).
137
+
138
+ = 2.0.1 =
139
+ * Bugfix in *experimental* [`WP_FAIL2BAN_PROXIES`](https://docs.wp-fail2ban.com/en/4.0/defines.html#wp-fail2ban-proxies) code.
140
+
141
+ = 2.0.0 =
142
+ * Add *experimental* support for X-Forwarded-For header; see [`WP_FAIL2BAN_PROXIES`](https://docs.wp-fail2ban.com/en/4.0/defines.html#wp-fail2ban-proxies).
143
+ * Add *experimental* support for regex-based login blocking; see [`WP_FAIL2BAN_BLOCKED_USERS`](https://docs.wp-fail2ban.com/en/4.0/defines.html#wp-fail2ban-blocked-users).
144
+
145
+ = 1.2.1 =
146
+ * Update FAQ.
147
+
148
+ = 1.2 =
149
+ * Fix harmless warning.
150
+
151
+ = 1.1 =
152
+ * Minor cosmetic updates.
153
+
154
+ = 1.0 =
155
+ * Initial release.
156
+
157
+ == Upgrade Notice ==
158
+
159
+ = 4.0.0 =
160
+ To take advantage of the new features you will need up update your `fail2ban` filters; existing filters will continue to work as before.
161
+
162
+ = 3.6.0 =
163
+ You will need up update your `fail2ban` filters.
164
+
165
+ = 3.5.3 =
166
+ You will need up update your `fail2ban` filters.
167
+
168
+ = 3.5.1 =
169
+ Bugfix: disable [`WP_FAIL2BAN_BLOCK_USER_ENUMERATION`](https://docs.wp-fail2ban.com/en/4.0/defines.html#wp-fail2ban-block-user-enumeration) in admin area....
170
+
171
+ = 3.5.0 =
172
+ You will need up update your `fail2ban` filters.
173
+
174
+ = 3.0.3 =
175
+ You will need up update your `fail2ban` filters.
176
+
177
+ = 3.0.0 =
178
+ BREAKING CHANGE: The `fail2ban` filters have been split into two files. You will need up update your `fail2ban` configuration.
179
+
180
+ = 2.3.0 =
181
+ Fix for [`WP_FAIL2BAN_PROXIES`](https://docs.wp-fail2ban.com/en/4.0/defines.html#wp-fail2ban-proxies); if you're not using it you can safely skip this release.
182
+
183
+ = 2.2.1 =
184
+ Bugfix.
185
+
186
+ = 2.2.0 =
187
+ BREAKING CHANGE: `WP_FAIL2BAN_LOG` has been renamed to [`WP_FAIL2BAN_AUTH_LOG`](https://docs.wp-fail2ban.com/en/4.0/defines.html#wp-fail2ban-auth-log).
188
+
189
+ Pingbacks are getting a lot of attention recently, so *WPf2b* can now log them.
190
+ The `wordpress.conf` filter has been updated; you will need to update your `fail2ban` configuration.
191
+
192
+ = 2.1.0 =
193
+ The `wordpress.conf` filter has been updated; you will need to update your `fail2ban` configuration.
194
+
195
+ = 2.0.1 =
196
+ Bugfix in experimental code; still an experimental release.
197
+
198
+ = 2.0.0 =
199
+ This is an experimental release. If your current version is working and you're not interested in the new features, skip this version - wait for 2.1.0. For those that do want to test this release, note that `wordpress.conf` has changed - you'll need to copy it to `fail2ban/filters.d` again.
vendor/freemius/wordpress-sdk/.codeclimate.yml ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ engines:
2
+ phpcodesniffer:
3
+ enabled: true
4
+ config:
5
+ standard: "WordPress"
6
+ checks:
7
+ Squiz Commenting InlineComment InvalidEndChar:
8
+ enabled: false
9
+ Squiz Commenting InlineComment SpacingBefore:
10
+ enabled: false
11
+ Squiz Commenting InlineComment WrongStyle:
12
+ enabled: false
13
+ Generic Commenting DocComment MissingShort:
14
+ enabled: false
15
+ Generic WhiteSpace ScopeIndent IncorrectExact:
16
+ enabled: false
17
+ ratings:
18
+ paths:
19
+ - "**.php"
vendor/freemius/wordpress-sdk/.github/ISSUE_TEMPLATE.md ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ **Actual Behavior**:
2
+ - `What is the issue? (*)`
3
+ - `What is the expected behavior?`
4
+
5
+ **Versions**: (*)
6
+ - `Freemius SDK Version:`
7
+ - `WordPress Version:`
8
+ - `PHP Version:`
9
+
10
+ **Plugin / Theme**: (*)
11
+ - `Name:`
12
+ - `Slug:`
13
+ - `Freemius ID:`
14
+
15
+ **Additional Information**:
16
+ - `Browser Type: (*)`
17
+ - `Browser Version: (*)`
18
+ - `OS: (*)`
19
+ - `Stack Traces:`
20
+
21
+ ----
22
+ **Note:** `(*)` indicates required information. Without this information, your issue may be auto-closed.
23
+
24
+ > You can find your Freemius SDK version at `/freemius/start.php`
25
+
26
+ > You can find your Freemius product ID in the Freemius dashboard: `SETTINGS -> INTEGRATION`.
27
+
28
+ > Do not modify the titles or questions. Simply add your responses to the ends of the questions.
29
+ Add more lines if needed.
vendor/freemius/wordpress-sdk/.travis.yml ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ sudo: false
2
+
3
+ language: php
4
+
5
+ php:
6
+ - 5.3
7
+ - 5.4
8
+ - 5.5
9
+ - 5.6
10
+ - 7.0
11
+ - hhvm
vendor/freemius/wordpress-sdk/LICENSE.txt ADDED
@@ -0,0 +1,674 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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>.
vendor/freemius/wordpress-sdk/README.md ADDED
@@ -0,0 +1,253 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Freemius WordPress SDK
2
+ ======================
3
+
4
+ [Monetization](https://freemius.com/wordpress/), [analytics](https://freemius.com/wordpress/insights/), and marketing automation platform for plugin & theme developers. Freemius empower developers to create prosperous subscription based businesses.
5
+
6
+ You can see some of the WordPress.org plugins & themes that are utilizing the power of Freemius here:
7
+
8
+ https://includewp.com/freemius/#focus
9
+
10
+ If you are a WordPress plugin or theme developer and you are interested to monetize with Freemius you can [sign-up here for free](https://dashboard.freemius.com/register/):
11
+
12
+ https://dashboard.freemius.com/register/
13
+
14
+ **Below you'll find the integration instructions for our WordPress SDK.**
15
+
16
+ ## Code Documentation
17
+
18
+ You can find the SDK's PHP-Doc documentation here:
19
+ https://codedoc.pub/freemius/wordpress-sdk/master/
20
+
21
+ ## Initializing the SDK
22
+
23
+ Copy the code below and paste it into the top of your main plugin's PHP file, right after the plugin's header comment:
24
+
25
+ ```php
26
+ <?php
27
+ // Create a helper function for easy SDK access.
28
+ function my_prefix_fs() {
29
+ global $my_prefix_fs;
30
+ if ( ! isset( $my_prefix_fs ) ) {
31
+ // Include Freemius SDK.
32
+ require_once dirname(__FILE__) . '/freemius/start.php';
33
+
34
+ $my_prefix_fs = fs_dynamic_init( array(
35
+ 'id' => '1234',
36
+ 'slug' => 'my-plugin-slug',
37
+ 'menu_slug' => 'my_menu_slug', // You can also use __FILE__
38
+ 'public_key' => 'pk_MY_PUBLIC_KEY',
39
+ 'is_live' => true,
40
+ 'is_premium' => true,
41
+ 'has_addons' => false,
42
+ 'has_paid_plans' => false,
43
+ // Set the SDK to work in a sandbox mode (for development & testing).
44
+ // IMPORTANT: MAKE SURE TO REMOVE SECRET KEY BEFORE DEPLOYMENT.
45
+ 'secret_key' => 'sk_MY_SECRET_KEY',
46
+ ) );
47
+ }
48
+
49
+ return $my_prefix_fs;
50
+ }
51
+
52
+ // Init Freemius.
53
+ my_prefix_fs();
54
+ ?>
55
+ ```
56
+
57
+ - **1234** - Replace with your plugin's ID.
58
+ - **pk_MY_PUBLIC_KEY** - Replace with your plugin's public key.
59
+ - **sk_MY_SECRET_KEY** - Replace with your plugin's secret key.
60
+ - **my-plugin-slug** - Replace with your plugin's WordPress.org slug.
61
+ - **my_menu_slug** - Replace with your admin dashboard settings menu slug.
62
+
63
+
64
+ ## Usage example
65
+
66
+ You can call the SDK by using the shortcode function:
67
+
68
+ ```php
69
+ <?php my_prefix_fs()->get_upgrade_url(); ?>
70
+ ```
71
+
72
+ Or when calling Freemius multiple times in a scope, it's recommended to use it with the global variable:
73
+
74
+ ```php
75
+ <?php
76
+ global $my_prefix_fs;
77
+ $my_prefix_fs->get_account_url();
78
+ ?>
79
+ ```
80
+
81
+ ## Adding license based logic examples
82
+
83
+ Add marketing content to encourage your users to upgrade for your paid version:
84
+
85
+ ```php
86
+ <?php
87
+ if ( my_prefix_fs()->is_not_paying() ) {
88
+ echo '<section><h1>' . esc_html__('Awesome Premium Features', 'my-plugin-slug') . '</h1>';
89
+ echo '<a href="' . my_prefix_fs()->get_upgrade_url() . '">' .
90
+ esc_html__('Upgrade Now!', 'my-plugin-slug') .
91
+ '</a>';
92
+ echo '</section>';
93
+ }
94
+ ?>
95
+ ```
96
+
97
+ Add logic which will only be available in your premium plugin version:
98
+
99
+ ```php
100
+ <?php
101
+ // This "if" block will be auto removed from the Free version.
102
+ if ( my_prefix_fs()->is__premium_only() ) {
103
+
104
+ // ... premium only logic ...
105
+
106
+ }
107
+ ?>
108
+ ```
109
+
110
+ To add a function which will only be available in your premium plugin version, simply add __premium_only as the suffix of the function name. Just make sure that all lines that call that method directly or by hooks, are also wrapped in premium only logic:
111
+
112
+ ```php
113
+ <?php
114
+ class My_Plugin {
115
+ function init() {
116
+ ...
117
+
118
+ // This "if" block will be auto removed from the free version.
119
+ if ( my_prefix_fs()->is__premium_only() ) {
120
+ // Init premium version.
121
+ $this->admin_init__premium_only();
122
+
123
+ add_action( 'admin_init', array( &$this, 'admin_init_hook__premium_only' );
124
+ }
125
+
126
+ ...
127
+ }
128
+
129
+ // This method will be only included in the premium version.
130
+ function admin_init__premium_only() {
131
+ ...
132
+ }
133
+
134
+ // This method will be only included in the premium version.
135
+ function admin_init_hook__premium_only() {
136
+ ...
137
+ }
138
+ }
139
+ ?>
140
+ ```
141
+
142
+ Add logic which will only be executed for customers in your 'professional' plan:
143
+
144
+ ```php
145
+ <?php
146
+ if ( my_prefix_fs()->is_plan('professional', true) ) {
147
+ // .. logic related to Professional plan only ...
148
+ }
149
+ ?>
150
+ ```
151
+
152
+ Add logic which will only be executed for customers in your 'professional' plan or higher plans:
153
+
154
+ ```php
155
+ <?php
156
+ if ( my_prefix_fs()->is_plan('professional') ) {
157
+ // ... logic related to Professional plan and higher plans ...
158
+ }
159
+ ?>
160
+ ```
161
+
162
+ Add logic which will only be available in your premium plugin version AND will only be executed for customers in your 'professional' plan (and higher plans):
163
+
164
+ ```php
165
+ <?php
166
+ // This "if" block will be auto removed from the Free version.
167
+ if ( my_prefix_fs()->is_plan__premium_only('professional') ) {
168
+ // ... logic related to Professional plan and higher plans ...
169
+ }
170
+ ?>
171
+ ```
172
+
173
+ Add logic only for users in trial:
174
+
175
+ ```php
176
+ <?php
177
+ if ( my_prefix_fs()->is_trial() ) {
178
+ // ... logic for users in trial ...
179
+ }
180
+ ?>
181
+ ```
182
+
183
+ Add logic for specified paid plan:
184
+
185
+ ```php
186
+ <?php
187
+ // This "if" block will be auto removed from the Free version.
188
+ if ( my_prefix_fs()->is__premium_only() ) {
189
+ if ( my_prefix_fs()->is_plan( 'professional', true ) ) {
190
+
191
+ // ... logic related to Professional plan only ...
192
+
193
+ } else if ( my_prefix_fs()->is_plan( 'business' ) ) {
194
+
195
+ // ... logic related to Business plan and higher plans ...
196
+
197
+ }
198
+ }
199
+ ?>
200
+ ```
201
+
202
+ ## Excluding files and folders from the free plugin version
203
+ There are two ways to exclude files from your free version.
204
+
205
+ 1. Add `__premium_only` just before the file extension. For example, functions__premium_only.php will be only included in the premium plugin version. This works for all type of files, not only PHP.
206
+ 2. Add `@fs_premium_only` a sepcial meta tag to the plugin's main PHP file header. Example:
207
+ ```php
208
+ <?php
209
+ /**
210
+ * Plugin Name: My Very Awesome Plugin
211
+ * Plugin URI: http://my-awesome-plugin.com
212
+ * Description: Create and manage Awesomeness right in WordPress.
213
+ * Version: 1.0.0
214
+ * Author: Awesomattic
215
+ * Author URI: http://my-awesome-plugin.com/me/
216
+ * License: GPLv2
217
+ * Text Domain: myplugin
218
+ * Domain Path: /langs
219
+ *
220
+ * @fs_premium_only /lib/functions.php, /premium-files/
221
+ */
222
+
223
+ if ( ! defined( 'ABSPATH' ) ) {
224
+ exit;
225
+ }
226
+
227
+ // ... my code ...
228
+ ?>
229
+ ```
230
+ The file `/lib/functions.php` and the directory `/premium-files/` will be removed from the free plugin version.
231
+
232
+ # WordPress.org Compliance
233
+ Based on [WordPress.org Guidelines](https://wordpress.org/plugins/about/guidelines/) you are not allowed to submit a plugin that has premium code in it:
234
+ > All code hosted by WordPress.org servers must be free and fully-functional. If you want to sell advanced features for a plugin (such as a "pro" version), then you must sell and serve that code from your own site, we will not host it on our servers.
235
+
236
+ Therefore, if you want to deploy your free plugin's version to WordPress.org, make sure you wrap all your premium code with `if ( my_prefix_fs()->{{ method }}__premium_only() )` or the other methods provided to exclude premium features & files from the free version.
237
+
238
+ ## Deployment
239
+ Zip your plugin's root folder and upload it in the Deployment section in the *Freemius Developer's Dashboard*.
240
+ The plugin will be scanned and processed by a custom developed *PHP Processor* which will auto-generate two versions of your plugin:
241
+
242
+ 1. **Premium version**: Identical to your uploaded version, including all code (except your `secret_key`). Will be enabled for download ONLY for your paying or in trial customers.
243
+ 2. **Free version**: The code stripped from all your paid features (based on the logic added wrapped in `{ method }__premium_only()`).
244
+
245
+ The free version is the one that you should give your users to download. Therefore, download the free generated version and upload to your site. Or, if your plugin was WordPress.org complaint and you made sure to exclude all your premium code with the different provided techniques, you can deploy the downloaded free version to the .org repo.
246
+
247
+ ## Reporting Bugs
248
+ Email dev [at] freemius [dot] com
249
+
250
+ ## FAQ
251
+
252
+ ## Copyright
253
+ Freemius, Inc.
vendor/freemius/wordpress-sdk/assets/css/admin/account.css ADDED
@@ -0,0 +1 @@
 
1
+ #fs_account .postbox,#fs_account .widefat{max-width:700px}#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:0.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}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:grey;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%}
vendor/freemius/wordpress-sdk/assets/css/admin/add-ons.css ADDED
@@ -0,0 +1,2 @@
 
 
1
+ #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,0.15s;-o-transition:all,0.15s;-ms-transition:all,0.15s;-webkit-transition:all,0.15s;transition:all,0.15s;left:0;right:0;top:0;position:absolute}#fs_addons .fs-cards-list .fs-card .fs-inner 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,0.15s;-o-transition:all,0.15s;-ms-transition:all,0.15s;-webkit-transition:all,0.15s;transition:all,0.15s}#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:0.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:greenyellow;display:block;padding:2px 10px;-moz-box-shadow:1px 1px 1px rgba(0,0,0,0.3);-webkit-box-shadow:1px 1px 1px rgba(0,0,0,0.3);box-shadow:1px 1px 1px rgba(0,0,0,0.3);text-transform:uppercase;font-size:0.9em;font-weight:bold}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-cta .button{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}}
2
+ #TB_window,#TB_window iframe{width:772px !important}#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 .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,0.2);-webkit-box-shadow:1px 1px 1px rgba(0,0,0,0.2);box-shadow:1px 1px 1px rgba(0,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:0.9em}#plugin-information .plugin-information-pricing .fs-plan .nav-tab-wrapper .nav-tab label{text-transform:uppercase;color:green;background:greenyellow;position:absolute;left:-1px;right:-1px;bottom:100%;border:1px solid darkgreen;padding:2px;text-align:center;font-size:0.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:greenyellow}#plugin-information .plugin-information-pricing .fs-plan ul.fs-trial-terms{font-size:0.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}@media screen and (max-width: 961px){#fs_addons .fs-cards-list .fs-card{height:265px}}
vendor/freemius/wordpress-sdk/assets/css/admin/affiliation.css ADDED
@@ -0,0 +1 @@
 
1
+ @charset "UTF-8";#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}
vendor/freemius/wordpress-sdk/assets/css/admin/checkout.css ADDED
@@ -0,0 +1 @@
 
1
+ @media screen and (max-width: 782px){#wpbody-content{padding-bottom:0 !important}}
vendor/freemius/wordpress-sdk/assets/css/admin/common.css ADDED
@@ -0,0 +1,2 @@
 
 
1
+ .theme-browser .theme .fs-premium-theme-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,0.3);-webkit-box-shadow:0 2px 1px -1px rgba(0,0,0,0.3);box-shadow:0 2px 1px -1px rgba(0,0,0,0.3);font-size:1.1em}#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}}
2
+ .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,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,0.3);-webkit-box-shadow:0 2px 2px rgba(6,113,6,0.3);box-shadow:0 2px 2px rgba(6,113,6,0.3);opacity:0.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: 500px){#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:'\21B3';padding:0 5px}.rtl span.fs-submenu-item.fs-sub:before{content:'\21B2'}.fs-submenu-item.pricing.upgrade-mode{color:greenyellow}.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}.wrap.fs-section h2{text-align:left}.plugins p.fs-upgrade-notice{border:0;background-color:#d54e21;padding:10px;color:#f9f9f9;margin-top:10px}
vendor/freemius/wordpress-sdk/assets/css/admin/connect.css ADDED
@@ -0,0 +1 @@
 
1
+ #fs_connect{width:480px;-moz-box-shadow:0px 1px 2px rgba(0,0,0,0.3);-webkit-box-shadow:0px 1px 2px rgba(0,0,0,0.3);box-shadow:0px 1px 2px rgba(0,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,0.1);-webkit-box-shadow:0 1px 1px 0 rgba(0,0,0,0.1);box-shadow:0 1px 1px 0 rgba(0,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 #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:' \279C'}#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 0.5s ease;-o-transition:background 0.5s ease;-ms-transition:background 0.5s ease;-webkit-transition:background 0.5s ease;transition:background 0.5s ease}#fs_connect .fs-permissions .fs-license-sync-disclaimer{text-align:center;margin-top:0}#fs_connect .fs-permissions .fs-trigger{font-size:0.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 div{margin-left:55px}#fs_connect .fs-permissions ul li div span{font-weight:bold;text-transform:uppercase;color:#23282d}#fs_connect .fs-permissions ul li div p{margin:2px 0 0 0}#fs_connect .fs-permissions.fs-open{background:#fff}#fs_connect .fs-permissions.fs-open ul{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:0.85em;padding:5px;background:rgba(0,0,0,0.05)}#fs_connect .fs-terms,#fs_connect .fs-terms a{color:#999}#fs_connect .fs-terms a{text-decoration:none}#multisite_options_container{margin-top:10px;border:1px solid #ccc;padding:5px}#multisite_options_container a{text-decoration:none}#multisite_options_container a:focus{box-shadow:none}#multisite_options_container a.selected{font-weight:bold}#multisite_options_container.apply-on-all-sites{border:0 none;padding:0}#multisite_options_container.apply-on-all-sites #all_sites_options{border-spacing:0}#multisite_options_container.apply-on-all-sites #all_sites_options td:not(:first-child){display:none}#multisite_options_container #sites_list_container{display:none;overflow:auto}#multisite_options_container #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 0.3s ease-in-out;-o-transition:opacity 0.3s ease-in-out;-ms-transition:opacity 0.3s ease-in-out;-webkit-transition:opacity 0.3s ease-in-out;transition:opacity 0.3s ease-in-out;position:absolute;background:rgba(0,0,0,0.8);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,0.2);-webkit-box-shadow:1px 1px 1px rgba(0,0,0,0.2);box-shadow:1px 1px 1px rgba(0,0,0,0.2);line-height:1.3em;font-weight:bold;text-align:left}.rtl .fs-tooltip-trigger .fs-tooltip{text-align:right}.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,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:' \000bb'}.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 div{margin-right:55px;margin-left:0}.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,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:white;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,0.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}
vendor/freemius/wordpress-sdk/assets/css/admin/debug.css ADDED
@@ -0,0 +1 @@
 
1
+ .switch{position:relative;display:inline-block;font-size:1.6em;font-weight:bold;color:#ccc;text-shadow:0px 1px 1px rgba(255,255,255,0.8);height:18px;padding:6px 6px 5px 6px;border:1px solid #ccc;border:1px solid rgba(0,0,0,0.2);border-radius:4px;background:#ececec;box-shadow:0px 0px 4px rgba(0,0,0,0.1),inset 0px 1px 3px 0px rgba(0,0,0,0.1);cursor:pointer}.switch span{display:inline-block;width:35px;text-transform:uppercase}.switch span.on{color:#6bc406}.switch .toggle{position:absolute;top:1px;width:37px;height:25px;border:1px solid #ccc;border:1px solid rgba(0,0,0,0.3);border-radius:4px;background:#fff;background:-moz-linear-gradient(top, #ececec 0%, #fff 100%);background:-webkit-gradient(linear, left top, left bottom, color-stop(0%, #ececec), color-stop(100%, #fff));background:-webkit-linear-gradient(top, #ececec 0%, #fff 100%);background:-o-linear-gradient(top, #ececec 0%, #fff 100%);background:-ms-linear-gradient(top, #ececec 0%, #fff 100%);background:linear-gradient(top, #ececec 0%, #fff 100%);box-shadow:inset 0px 1px 0px 0px rgba(255,255,255,0.5);z-index:999;-moz-transition:all 0.15s ease-in-out;-o-transition:all 0.15s ease-in-out;-ms-transition:all 0.15s ease-in-out;-webkit-transition:all 0.15s ease-in-out;transition:all 0.15s ease-in-out}.switch.on .toggle{left:2%}.switch.off .toggle{left:54%}.switch.round{padding:0px 20px;border-radius:40px}.switch.round .toggle{border-radius:40px;width:14px;height:14px}.switch.round.on .toggle{left:3%;background:#6bc406}.switch.round.off .toggle{left:58%}.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}
vendor/freemius/wordpress-sdk/assets/css/admin/dialog-boxes.css ADDED
@@ -0,0 +1,2 @@
 
 
1
+ .fs-modal{position:fixed;overflow:auto;height:100%;width:100%;top:0;z-index:100000;display:none;background:rgba(0,0,0,0.6)}.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:#eeeeee 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:0.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 0.2s ease-in-out;-o-transition:all 0.2s ease-in-out;-ms-transition:all 0.2s ease-in-out;-webkit-transition:all 0.2s ease-in-out;transition:all 0.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:#eeeeee solid 1px;text-align:right}.fs-modal .fs-modal-footer>.button{margin:0 7px}.fs-modal .fs-modal-footer>.button:first-child{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}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{float:left}.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.license_key{width:100%}#license_options_container table,#license_options_container table select,#license_options_container table #available_license_key{width:100%}#license_options_container table td:first-child{width:1%}#license_options_container table #other_license_key_container label{position:relative;top:6px;float:left;margin-right:5px}#license_options_container table #other_license_key_container div{overflow:hidden;width:auto;height:30px;display:block;top:2px;position:relative}#license_options_container table #other_license_key_container div input{margin:0}#sites_list_container td{cursor:pointer}#multisite_options_container{margin-top:10px;border:1px solid #ccc;padding:5px}#multisite_options_container a{text-decoration:none}#multisite_options_container a:focus{box-shadow:none}#multisite_options_container a.selected{font-weight:bold}#multisite_options_container.apply-on-all-sites{border:0 none;padding:0}#multisite_options_container.apply-on-all-sites #all_sites_options{border-spacing:0}#multisite_options_container.apply-on-all-sites #all_sites_options td:not(:first-child){display:none}#multisite_options_container #sites_list_container{display:none;overflow:auto}#multisite_options_container #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}}
2
+ .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-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:0.3;-o-transform:0.3;-ms-transform:0.3;-webkit-transform:0.3;transform:0.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,0.1) !important}
vendor/freemius/wordpress-sdk/assets/css/admin/gdpr-optin-notice.css ADDED
@@ -0,0 +1 @@
 
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}
vendor/freemius/wordpress-sdk/assets/css/admin/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ // Hide file structure from users on unprotected servers.
vendor/freemius/wordpress-sdk/assets/css/customizer.css ADDED
@@ -0,0 +1 @@
 
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 0.3s ease-in-out;-o-transition:opacity 0.3s ease-in-out;-ms-transition:opacity 0.3s ease-in-out;-webkit-transition:opacity 0.3s ease-in-out;transition:opacity 0.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,0.2);-webkit-box-shadow:1px 1px 1px rgba(0,0,0,0.2);box-shadow:1px 1px 1px rgba(0,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}
vendor/freemius/wordpress-sdk/assets/css/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ // Hide file structure from users on unprotected servers.
vendor/freemius/wordpress-sdk/assets/img/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ // Hide file structure from users on unprotected servers.
vendor/freemius/wordpress-sdk/assets/img/plugin-icon.png ADDED
Binary file
vendor/freemius/wordpress-sdk/assets/img/theme-icon.png ADDED
Binary file
vendor/freemius/wordpress-sdk/assets/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ // Hide file structure from users on unprotected servers.
vendor/freemius/wordpress-sdk/assets/js/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ // Hide file structure from users on unprotected servers.
vendor/freemius/wordpress-sdk/assets/js/nojquery.ba-postmessage.js ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ }
vendor/freemius/wordpress-sdk/assets/js/nojquery.ba-postmessage.min.js ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
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};
vendor/freemius/wordpress-sdk/assets/js/postmessage.js ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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);
vendor/freemius/wordpress-sdk/assets/scss/_colors.scss ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ $menu-hover-color: #333;
2
+ $darkest-color: #000;
3
+ $fms-live-color: #71ae00;
4
+ $fms-test-color: #f7941d;
5
+ $fms-link-color: #29abe1;
6
+ $fms-link-hover-color: darken(#29abe1, 10%);
7
+ $body-bkg: #111;
8
+ $special-color: #d3135a;
9
+ $body-color: #f1f1f1;
10
+ $fms-white: #f1f1f1;
11
+ $container-bkg: #222;
12
+ $container-bkg-odd: #262626;
13
+ $container-border-color: #333;
14
+ $table-head-bkg: #333;
15
+ $table-head-color: #999;
16
+ $info-color: #999;
17
+ $error-color: #ff0000;
18
+
19
+ $fs-logo-blue-color: #29abe1;
20
+ $fs-logo-green-color: #71ae00;
21
+ $fs-logo-magenta-color: #d3135a;
22
+
23
+ // WordPress colors.
24
+ $page-header-bkg: #333;
25
+ $page-header-color: $fms-white;
26
+ $text-dark-color: #333;
27
+ $text-light-color: #666;
28
+ $text-lightest-color: #999;
29
+
30
+ // Notices.
31
+ $wp-notice-success-color: #f7fff7;
32
+ $wp-notice-success-dark-color: #46b450;
33
+ $wp-notice-error-color: #ffeaea;
34
+ $wp-notice-error-dark-color: #dc3232;
35
+ $wp-notice-warn-color: #fff8e5;
36
+ $wp-notice-warn-dark-color: #ffb900;
37
+ $fs-notice-promotion-border-color: #00a0d2;
38
+ $fs-notice-promotion-bkg: #f2fcff;
39
+
40
+ // WP Buttons.
41
+ $button-primary-bkg: #6bc406;
42
+ $button-primary-color: $fms-white;
43
+ $button-secondary-bkg: #333;
44
+ $button-secondary-color: $fms-white;
45
+ $featured-color: #6bc406;
46
+ $wp-selected-color: #0074a3;
47
+ $wp-button-alert-border-color: #d2593c;
48
+ $wp-button-alert-border-top-color: #ec6544;
49
+ $wp-button-alert-shadow-color: #d2593c;
50
+ $wp-button-alert-focused-shadow1-color: #dd6041;
51
+ $wp-button-alert-focused-shadow2-color: #e4a796;
52
+ $wp-button-alert-background-color: #f56a48;
53
+ $wp-button-alert-hovered-background-color: #fd6d4a;
54
+ $wp-button-alert-active-background-color: #dd6041;
55
+ $wp-button-alert-disabled-color: #f5b3a1;
56
+ $wp-button-alert-disabled-background-color: #e76444;
57
+ $wp-button-alert-disabled-border-color: #d85e40;
58
+
59
+ $wordpress_color: #01749A;
60
+ $blogger_color: #ff8100;
61
+ $wix_color: #fac102;
62
+ $shopify_color: #80d100;
63
+ $addthis_color: #fe6d4e;
64
+ $tumblr_color: #34506b;
65
+ $zepo_color: #00baf2;
66
+ $jquery_color: #000919;
67
+ $javascript_color: #00baf2;
68
+ $squarespace_color: #000;
69
+
70
+ $blog_color: #ff6600;
71
+ $facebook_color: #3b5998;
72
+ $twitter_color: #4099ff;
73
+ $linkedin_color: #4875b4;
74
+ $youtube_color: #ff3333;
75
+ $gplus_color: #c63d2d;
76
+
77
+ // Tooltip
78
+ $tooltip-color: #fff;
79
+ $tooltip-bkg-color: rgba(0,0,0,0.8);
vendor/freemius/wordpress-sdk/assets/scss/_functions.scss ADDED
File without changes
vendor/freemius/wordpress-sdk/assets/scss/_load.scss ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ @import 'mixins';
2
+ @import "vars";
3
+ @import "functions";
4
+ @import "colors";
vendor/freemius/wordpress-sdk/assets/scss/_mixins.scss ADDED
@@ -0,0 +1,270 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // ---- CSS3 SASS MIXINS ----
2
+ // https://github.com/madr/css3-sass-mixins
3
+ //
4
+ // Copyright (C) 2011 by Anders Ytterström
5
+ //
6
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ // of this software and associated documentation files (the "Software"), to deal
8
+ // in the Software without restriction, including without limitation the rights
9
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ // copies of the Software, and to permit persons to whom the Software is
11
+ // furnished to do so, subject to the following conditions:
12
+ //
13
+ // The above copyright notice and this permission notice shall be included in
14
+ // all copies or substantial portions of the Software.
15
+ //
16
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ // THE SOFTWARE.
23
+ //
24
+
25
+ // ---- LEGACY IE SUPPORT USING FILTERS ----
26
+ // Should IE filters be used or not?
27
+ // PROS: gradients, drop shadows etc will be handled by css.
28
+ // CONS: will harm the site performance badly,
29
+ // especially on sites with heavy rendering and scripting.
30
+ $useIEFilters: 0;
31
+ // might be 0 or 1. disabled by default.
32
+ // ---- /LEGACY IE SUPPORT USING FILTERS ----
33
+
34
+
35
+ @mixin background-size ($value) {
36
+ -webkit-background-size: $value;
37
+ background-size: $value;
38
+ }
39
+
40
+ @mixin border-image ($path, $offsets, $repeats) {
41
+ -moz-border-image: $path $offsets $repeats;
42
+ -o-border-image: $path $offsets $repeats;
43
+ -webkit-border-image: $path $offsets $repeats;
44
+ border-image: $path $offsets $repeats;
45
+ }
46
+
47
+ @mixin border-radius ($values...) {
48
+ -moz-border-radius: $values;
49
+ -webkit-border-radius: $values;
50
+ border-radius: $values;
51
+ /*-moz-background-clip: padding;
52
+ -webkit-background-clip: padding-box;
53
+ background-clip: padding-box;*/
54
+ }
55
+
56
+ @mixin box-shadow ($values...) {
57
+ -moz-box-shadow: $values;
58
+ -webkit-box-shadow: $values;
59
+ box-shadow: $values;
60
+ }
61
+
62
+ //@mixin box-shadow ($x, $y, $offset, $hex, $ie: $useIEFilters, $inset: null, $spread:null) {
63
+ // -moz-box-shadow: $x $y $offset $spread $hex $inset;
64
+ // -webkit-box-shadow: $x $y $offset $spread $hex $inset;
65
+ // box-shadow: $x $y $offset $spread $hex $inset;
66
+ //
67
+ // @if $ie == 1 {
68
+ // $iecolor: '#' + red($hex) + green($hex) + blue($hex);
69
+ // filter: progid:DXImageTransform.Microsoft.dropshadow(OffX=#{$x}, OffY=#{$y}, Color='#{$iecolor}');
70
+ // -ms-filter: quote(progid:DXImageTransform.Microsoft.dropshadow(OffX=#{$x}, OffY=#{$y}, Color='#{$iecolor}'));
71
+ // }
72
+ //}
73
+
74
+ @mixin box-sizing($value) {
75
+ -moz-box-sizing: $value;
76
+ -webkit-box-sizing: $value;
77
+ box-sizing: $value;
78
+ }
79
+
80
+ // requires sass 3.2
81
+ @mixin keyframes($name){
82
+ @-moz-keyframes #{$name} { @content; }
83
+ @-ms-keyframes #{$name} { @content; }
84
+ @-o-keyframes #{$name} { @content; }
85
+ @-webkit-keyframes #{$name} { @content; }
86
+ @keyframes #{$name} { @content; }
87
+ }
88
+
89
+ @mixin linear-gradient($from, $to, $ie: $useIEFilters) {
90
+ @if $ie != 1 { background-color: $to; }
91
+
92
+ background-image: -webkit-gradient(linear,left top,left bottom,color-stop(0, $from),color-stop(1, $to));
93
+ background-image: -webkit-linear-gradient(top, $from, $to);
94
+ background-image: -moz-linear-gradient(top, $from, $to);
95
+ background-image: -ms-linear-gradient(top, $from, $to);
96
+ background-image: -o-linear-gradient(top, $from, $to);
97
+ background-image: linear-gradient(top, bottom, $from, $to);
98
+
99
+ @if $ie == 1 {
100
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#{$from}', endColorstr='#{$to}');
101
+ }
102
+ }
103
+
104
+ @mixin horizontal-gradient($startColor: #555, $endColor: #333, $ie: $useIEFilters) {
105
+ @if $ie != 1 { background-color: $endColor; }
106
+
107
+ background-color: $endColor;
108
+ background-image: -webkit-gradient(linear, 0 0, 100% 0, from($startColor), to($endColor)); // Safari 4+, Chrome 2+
109
+ background-image: -webkit-linear-gradient(left, $startColor, $endColor); // Safari 5.1+, Chrome 10+
110
+ background-image: -moz-linear-gradient(left, $startColor, $endColor); // FF 3.6+
111
+ background-image: -o-linear-gradient(left, $startColor, $endColor); // Opera 11.10
112
+ background-image: linear-gradient(to right, $startColor, $endColor); // Standard, IE10
113
+ background-repeat: repeat-x;
114
+ @if $ie == 1 {
115
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#{$startColor}', endColorstr='#{$endColor}', GradientType=1);
116
+ }
117
+ }
118
+
119
+ @mixin radial-gradient($from, $to, $ie: $useIEFilters) {
120
+ @if $ie != 1 { background-color: $to; }
121
+
122
+ background: -moz-radial-gradient(center, circle cover, $from 0%, $to 100%);
123
+ background: -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(0%, $from), color-stop(100%, $to));
124
+ background: -webkit-radial-gradient(center, circle cover, $from 0%, $to 100%);
125
+ background: -o-radial-gradient(center, circle cover, $from 0%, $to 100%);
126
+ background: -ms-radial-gradient(center, circle cover, $from 0%, $to 100%);
127
+ background: radial-gradient(center, circle cover, $from 0%, $to 100%);
128
+ background-color: $from;
129
+
130
+ @if $ie == 1 {
131
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#{$from}', endColorstr='#{$to}', GradientType=1); /* IE6-9 fallback on horizontal gradient */
132
+ }
133
+ }
134
+
135
+ @mixin perspective($perspective) {
136
+ -moz-perspective: $perspective;
137
+ -ms-perspective: $perspective;
138
+ -webkit-perspective: $perspective;
139
+ perspective: $perspective;
140
+ -moz-transform-style: preserve-3d;
141
+ -ms-transform-style: preserve-3d;
142
+ -webkit-transform-style: preserve-3d;
143
+ transform-style: preserve-3d;
144
+ }
145
+
146
+ @mixin transform ($transforms) {
147
+ -moz-transform: $transforms;
148
+ -o-transform: $transforms;
149
+ -ms-transform: $transforms;
150
+ -webkit-transform: $transforms;
151
+ transform: $transforms;
152
+ }
153
+
154
+ @mixin matrix ($a, $b, $c, $d, $e, $f) {
155
+ -moz-transform: matrix($a, $b, $c, $d, #{$e}px, #{$f}px);
156
+ -o-transform: matrix($a, $b, $c, $d, $e, $f);
157
+ -ms-transform: matrix($a, $b, $c, $d, $e, $f);
158
+ -webkit-transform: matrix($a, $b, $c, $d, $e, $f);
159
+ transform: matrix($a, $b, $c, $d, $e, $f);
160
+ }
161
+
162
+ @mixin rotate ($deg) {
163
+ @include transform(rotate(#{$deg}deg));
164
+ }
165
+
166
+ @mixin scale ($size) {
167
+ @include transform(scale(#{$size}));
168
+ }
169
+
170
+ @mixin translate ($x, $y) {
171
+ @include transform(translate($x, $y));
172
+ }
173
+
174
+ @mixin transition ($value...) {
175
+ -moz-transition: $value;
176
+ -o-transition: $value;
177
+ -ms-transition: $value;
178
+ -webkit-transition: $value;
179
+ transition: $value;
180
+ }
181
+
182
+ @mixin animation($str) {
183
+ -webkit-animation: #{$str};
184
+ -moz-animation: #{$str};
185
+ -ms-animation: #{$str};
186
+ -o-animation: #{$str};
187
+ animation: #{$str};
188
+ }
189
+
190
+ @mixin animation-name($str) {
191
+ -webkit-animation-name: #{$str};
192
+ -moz-animation-name: #{$str};
193
+ -ms-animation-name: #{$str};
194
+ -o-animation-name: #{$str};
195
+ animation-name: #{$str};
196
+ }
197
+
198
+ @mixin animation-duration($str) {
199
+ -webkit-animation-duration: #{$str};
200
+ -moz-animation-duration: #{$str};
201
+ -ms-animation-duration: #{$str};
202
+ -o-animation-duration: #{$str};
203
+ animation-duration: #{$str};
204
+ }
205
+
206
+ @mixin animation-direction($str) {
207
+ -webkit-animation-direction: #{$str};
208
+ -moz-animation-direction: #{$str};
209
+ -ms-animation-direction: #{$str};
210
+ -o-animation-direction: #{$str};
211
+ animation-direction: #{$str};
212
+ }
213
+
214
+ @mixin animation-delay($str) {
215
+ animation-delay:#{$str};
216
+ -o-animation-delay:#{$str};
217
+ -ms-animation-delay:#{$str};
218
+ -webkit-animation-delay:#{$str};
219
+ -moz-animation-delay:#{$str};
220
+ }
221
+
222
+ @mixin animation-iteration-count($str) {
223
+ animation-iteration-count:#{$str};
224
+ -o-animation-iteration-count:#{$str};
225
+ -ms-animation-iteration-count:#{$str};
226
+ -webkit-animation-iteration-count:#{$str};
227
+ -moz-animation-iteration-count:#{$str};
228
+ }
229
+
230
+ @mixin animation-timing-function($str) {
231
+ -webkit-animation-timing-function: #{$str};
232
+ -moz-animation-timing-function: #{$str};
233
+ -ms-animation-timing-function: #{$str};
234
+ -o-animation-timing-function: #{$str};
235
+ animation-timing-function: #{$str};
236
+ }
237
+
238
+ // ==== /CSS3 SASS MIXINS ====
239
+
240
+ @mixin opacity($opacity) {
241
+ opacity: $opacity;
242
+ $opacity-ie: $opacity * 100;
243
+ filter: alpha(opacity=$opacity-ie); //IE8
244
+ }
245
+
246
+ @mixin size($width, $height: $width)
247
+ {
248
+ width: $width;
249
+ height: $height;
250
+ }
251
+
252
+ @mixin clearfix
253
+ {
254
+ &:after {
255
+ content: "";
256
+ display: table;
257
+ clear: both;
258
+ }
259
+ }
260
+
261
+ // Placeholder text
262
+ @mixin placeholder($color: $input-color-placeholder) {
263
+ // Firefox
264
+ &::-moz-placeholder {
265
+ color: $color;
266
+ opacity: 1; // Override Firefox's unusual default opacity; see https://github.com/twbs/bootstrap/pull/11526
267
+ }
268
+ &:-ms-input-placeholder { color: $color; } // Internet Explorer 10+
269
+ &::-webkit-input-placeholder { color: $color; } // Safari and Chrome
270
+ }
vendor/freemius/wordpress-sdk/assets/scss/_start.scss ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ @import "vars";
2
+ @import "colors";
3
+ @import "mixins";
4
+ @import "functions";
vendor/freemius/wordpress-sdk/assets/scss/_vars.scss ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ $is_production: true;
2
+
3
+ $img_common: if($is_production == true, '//img.freemius.com', 'http://img.freemius:8080');
4
+
5
+ $layout_width: 960px;
6
+ $admin_mobile_max_width: 782px;
vendor/freemius/wordpress-sdk/assets/scss/admin/_ajax-loader.scss ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ $color: $wp-selected-color;
2
+ $bkg-color: #fff;
3
+ $size: 20;
4
+
5
+ .fs-ajax-loader
6
+ {
7
+ position: relative;
8
+ width: #{8*$size + 10}px;
9
+ height: #{$size}px;
10
+ margin: auto;
11
+
12
+ .fs-ajax-loader-bar
13
+ {
14
+ position: absolute;
15
+ top: 0;
16
+ background-color: $color;
17
+ width: #{$size}px;
18
+ height: #{$size}px;
19
+ @include animation-name(bounce_ajaxLoader);
20
+ @include animation-duration(1.5s);
21
+ @include animation-iteration-count(infinite);
22
+ @include animation-direction(normal);
23
+ @include transform(.3);
24
+ }
25
+
26
+ @for $i from 0 through 7
27
+ {
28
+ .fs-ajax-loader-bar-#{$i + 1}
29
+ {
30
+ left: #{$i*($size - 1)}px;
31
+ @include animation-delay(#{0.6 + $i*0.15}s);
32
+ }
33
+ }
34
+ }
35
+
36
+ @include keyframes(bounce_ajaxLoader)
37
+ {
38
+ 0%
39
+ {
40
+ @include transform(scale(1));
41
+ background-color: $color;
42
+ }
43
+
44
+ 100%
45
+ {
46
+ @include transform(scale(.3));
47
+ background-color: $bkg-color;
48
+ }
49
+ }
vendor/freemius/wordpress-sdk/assets/scss/admin/_auto-install.scss ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .fs-modal-auto-install
2
+ {
3
+ $max-width: 300px;
4
+
5
+ #request-filesystem-credentials-form
6
+ {
7
+ h2,
8
+ .request-filesystem-credentials-action-buttons
9
+ {
10
+ display: none;
11
+ }
12
+
13
+ input[type=password],
14
+ input[type=email],
15
+ input[type=text]
16
+ {
17
+ -webkit-appearance: none;
18
+ padding: 10px 10px 5px 10px;
19
+ width: $max-width;
20
+ max-width: 100%;
21
+ }
22
+
23
+ > div,
24
+ label,
25
+ fieldset
26
+ {
27
+ width: $max-width;
28
+ max-width: 100%;
29
+ margin: 0 auto;
30
+ display: block;
31
+ }
32
+ }
33
+ }
vendor/freemius/wordpress-sdk/assets/scss/admin/_buttons.scss ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .button-primary.warn {
2
+ box-shadow: 0 1px 0 $wp-button-alert-shadow-color;
3
+ text-shadow: 0 -1px 1px $wp-button-alert-shadow-color, 1px 0 1px $wp-button-alert-shadow-color, 0 1px 1px $wp-button-alert-shadow-color, -1px 0 1px $wp-button-alert-shadow-color;
4
+ background: $wp-button-alert-background-color;
5
+ border-color: $wp-button-alert-border-top-color $wp-button-alert-border-color $wp-button-alert-border-color;
6
+
7
+ &:hover {
8
+ background: $wp-button-alert-hovered-background-color;
9
+ border-color: $wp-button-alert-border-color;
10
+ }
11
+
12
+ &:focus {
13
+ box-shadow: 0 1px 0 $wp-button-alert-focused-shadow1-color, 0 0 2px 1px $wp-button-alert-focused-shadow2-color;
14
+ }
15
+
16
+ &:active {
17
+ background: $wp-button-alert-active-background-color;
18
+ border-color: $wp-button-alert-border-color;
19
+ box-shadow: inset 0 2px 0 $wp-button-alert-shadow-color;
20
+ }
21
+
22
+ &.disabled {
23
+ color: $wp-button-alert-disabled-color !important;
24
+ background: $wp-button-alert-disabled-background-color !important;
25
+ border-color: $wp-button-alert-disabled-border-color !important;
26
+ text-shadow: 0 -1px 0 rgba(0,0,0,.1) !important;
27
+ }
28
+ }
vendor/freemius/wordpress-sdk/assets/scss/admin/_deactivation-feedback.scss ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "../colors";
2
+
3
+ .fs-modal.fs-modal-deactivation-feedback {
4
+ .reason-input, .internal-message {
5
+ margin: 3px 0 3px 22px;
6
+
7
+ input, textarea {
8
+ width: 100%;
9
+ }
10
+ }
11
+
12
+ li.reason {
13
+ &.has-internal-message .internal-message {
14
+ border: 1px solid lighten($darkest-color, 80%);
15
+ padding: 7px;
16
+ display: none;
17
+ }
18
+
19
+ @media (max-width: 650px) {
20
+ li.reason {
21
+ margin-bottom: 10px;
22
+
23
+ .reason-input, .internal-message {
24
+ margin-left: 29px;
25
+ }
26
+
27
+ label {
28
+ display: table;
29
+
30
+ > span {
31
+ display: table-cell;
32
+ font-size: 1.3em;
33
+ }
34
+ }
35
+ }
36
+ }
37
+ }
38
+
39
+ .anonymous-feedback-label {
40
+ float: left;
41
+ }
42
+
43
+ .fs-modal-panel {
44
+ margin-top: 0 !important;
45
+
46
+ h3 {
47
+ margin-top: 0;
48
+ line-height: 1.5em;
49
+ }
50
+ }
51
+ }
52
+
53
+ #the-list .deactivate > .fs-slug {
54
+ display: none;
55
+ }
vendor/freemius/wordpress-sdk/assets/scss/admin/_gdpr-consent.scss ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #fs_marketing_optin
2
+ {
3
+ display: none;
4
+ margin-top: 10px;
5
+ border: 1px solid #ccc;
6
+ padding: 10px;
7
+ line-height: 1.5em;
8
+
9
+ .fs-message
10
+ {
11
+ display: block;
12
+ margin-bottom: 5px;
13
+ font-size: 1.05em;
14
+ font-weight: 600;
15
+ }
16
+
17
+ &.error
18
+ {
19
+ border: 1px solid $fs-logo-magenta-color;
20
+ background: #fee;
21
+
22
+ .fs-message
23
+ {
24
+ color: $fs-logo-magenta-color;
25
+ }
26
+ }
27
+
28
+ .fs-input-container
29
+ {
30
+ margin-top: 5px;
31
+
32
+ label
33
+ {
34
+ margin-top: 5px;
35
+ display: block;
36
+
37
+ input
38
+ {
39
+ float: left;
40
+ margin: 1px 0 0 0;
41
+ }
42
+
43
+ &:first-child
44
+ {
45
+ display: block;
46
+ margin-bottom: 2px;
47
+ }
48
+ }
49
+ }
50
+
51
+ .fs-input-label
52
+ {
53
+ display: block;
54
+ margin-left: 20px;
55
+
56
+ .underlined
57
+ {
58
+ text-decoration: underline;
59
+ }
60
+ }
61
+ }
62
+
63
+ .rtl
64
+ {
65
+ #fs_marketing_optin
66
+ {
67
+ .fs-input-container
68
+ {
69
+ label input
70
+ {
71
+ float: right;
72
+ }
73
+ }
74
+
75
+ .fs-input-label
76
+ {
77
+ margin-left: 0;
78
+ margin-right: 20px;
79
+ }
80
+ }
81
+ }
vendor/freemius/wordpress-sdk/assets/scss/admin/_license-activation.scss ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .fs-modal.fs-modal-license-activation {
2
+ .fs-modal-body {
3
+ input.license_key {
4
+ width: 100%;
5
+ }
6
+ }
7
+ }
8
+
9
+ #license_options_container {
10
+ table {
11
+ &, select, #available_license_key {
12
+ width: 100%;
13
+ }
14
+
15
+ td:first-child {
16
+ width: 1%;
17
+ }
18
+
19
+ #other_license_key_container {
20
+ label {
21
+ position: relative;
22
+ top: 6px;
23
+ float: left;
24
+ margin-right: 5px;
25
+ }
26
+
27
+ div {
28
+ overflow: hidden;
29
+ width: auto;
30
+ height: 30px;
31
+ display: block;
32
+ top: 2px;
33
+ position: relative;
34
+
35
+ input {
36
+ margin: 0;
37
+ }
38
+ }
39
+ }
40
+ }
41
+ }
42
+
43
+ #sites_list_container {
44
+ td {
45
+ cursor: pointer;
46
+ }
47
+ }
vendor/freemius/wordpress-sdk/assets/scss/admin/_license-key-resend.scss ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .fs-modal.fs-modal-license-key-resend
2
+ {
3
+ .email-address-container
4
+ {
5
+ overflow: hidden;
6
+ padding-right: 2px;
7
+ }
8
+
9
+ &.fs-freemium
10
+ {
11
+ input.email-address
12
+ {
13
+ width: 300px;
14
+ }
15
+
16
+ label
17
+ {
18
+ display: block;
19
+ margin-bottom: 10px;
20
+ }
21
+ }
22
+
23
+ &.fs-premium
24
+ {
25
+ input.email-address
26
+ {
27
+ width: 100%;
28
+ }
29
+
30
+ .button-container
31
+ {
32
+ float: right;
33
+ margin-left: 7px;
34
+
35
+ @media (max-width: 650px) {
36
+ margin-top: 2px;
37
+ }
38
+ }
39
+ }
40
+ }
41
+
42
+ .rtl
43
+ {
44
+ .fs-modal.fs-modal-license-key-resend
45
+ {
46
+ .fs-modal-body
47
+ {
48
+ .input-container > .email-address-container
49
+ {
50
+ padding-left: 2px;
51
+ padding-right: 0;
52
+ }
53
+
54
+ .button-container
55
+ {
56
+ float: left;
57
+ margin-right: 7px;
58
+ margin-left: 0;
59
+ }
60
+ }
61
+ }
62
+ }
63
+
64
+ a.show-license-resend-modal
65
+ {
66
+ margin-top: 4px;
67
+ display: inline-block;
68
+ }
vendor/freemius/wordpress-sdk/assets/scss/admin/_modal-common.scss ADDED
@@ -0,0 +1,194 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "../colors";
2
+ @import "../mixins";
3
+
4
+ .fs-modal {
5
+ position: fixed;
6
+ overflow: auto;
7
+ height: 100%;
8
+ width: 100%;
9
+ top: 0;
10
+ z-index: 100000;
11
+ display: none;
12
+ background: rgba(0, 0, 0, 0.6);
13
+
14
+ .fs-modal-dialog {
15
+ background: transparent;
16
+ position: absolute;
17
+ left: 50%;
18
+ margin-left: -298px;
19
+ padding-bottom: 30px;
20
+ top: -100%;
21
+ z-index: 100001;
22
+ width: 596px;
23
+
24
+ @media (max-width: 650px) {
25
+ margin-left: -50%;
26
+ box-sizing: border-box;
27
+ padding-left: 10px;
28
+ padding-right: 10px;
29
+ width: 100%;
30
+
31
+ .fs-modal-panel > h3 > strong {
32
+ font-size: 1.3em;
33
+ }
34
+ }
35
+ }
36
+
37
+ &.active {
38
+ display: block;
39
+
40
+ &:before {
41
+ display: block;
42
+ }
43
+
44
+ .fs-modal-dialog {
45
+ top: 10%;
46
+ }
47
+ }
48
+
49
+ &.fs-success {
50
+ .fs-modal-header {
51
+ border-bottom-color: $wp-notice-success-dark-color;
52
+ }
53
+
54
+ .fs-modal-body {
55
+ background-color: $wp-notice-success-color;
56
+ }
57
+ }
58
+
59
+ &.fs-warn {
60
+ .fs-modal-header {
61
+ border-bottom-color: $wp-notice-warn-dark-color;
62
+ }
63
+
64
+ .fs-modal-body {
65
+ background-color: $wp-notice-warn-color;
66
+ }
67
+ }
68
+
69
+ &.fs-error {
70
+ .fs-modal-header {
71
+ border-bottom-color: $wp-notice-error-dark-color;
72
+ }
73
+
74
+ .fs-modal-body {
75
+ background-color: $wp-notice-error-color;
76
+ }
77
+ }
78
+
79
+
80
+ .fs-modal-body,
81
+ .fs-modal-footer {
82
+ border: 0;
83
+ background: #fefefe;
84
+ padding: 20px;
85
+ }
86
+
87
+ .fs-modal-header {
88
+ border-bottom: #eeeeee solid 1px;
89
+ background: #fbfbfb;
90
+ padding: 15px 20px;
91
+ position: relative;
92
+ margin-bottom: -10px;
93
+ // z-index: 2;
94
+
95
+ h4 {
96
+ margin: 0;
97
+ padding: 0;
98
+ text-transform: uppercase;
99
+ font-size: 1.2em;
100
+ font-weight: bold;
101
+ color: #cacaca;
102
+ text-shadow: 1px 1px 1px #fff;
103
+ letter-spacing: 0.6px;
104
+ -webkit-font-smoothing: antialiased;
105
+ }
106
+
107
+ .fs-close {
108
+ position: absolute;
109
+ right: 10px;
110
+ top: 12px;
111
+ cursor: pointer;
112
+ color: #bbb;
113
+ @include border-radius(20px);
114
+ padding: 3px;
115
+ @include transition(all 0.2s ease-in-out);
116
+
117
+ &:hover {
118
+ color: #fff;
119
+ background: #aaa;
120
+ }
121
+
122
+ &, &:hover
123
+ {
124
+ .dashicons
125
+ {
126
+ text-decoration: none;
127
+ }
128
+ }
129
+ }
130
+ }
131
+
132
+ .fs-modal-body {
133
+ border-bottom: 0;
134
+
135
+ p {
136
+ font-size: 14px;
137
+ }
138
+
139
+ h2 {
140
+ font-size: 20px;
141
+ line-height: 1.5em;
142
+ }
143
+
144
+ > div {
145
+ margin-top: 10px;
146
+
147
+ h2 {
148
+ font-weight: bold;
149
+ font-size: 20px;
150
+ margin-top: 0;
151
+ }
152
+ }
153
+ }
154
+
155
+ .fs-modal-footer {
156
+ border-top: #eeeeee solid 1px;
157
+ text-align: right;
158
+
159
+ > .button {
160
+ margin: 0 7px;
161
+
162
+ &:first-child {
163
+ margin: 0;
164
+ }
165
+ }
166
+ }
167
+
168
+ .fs-modal-panel {
169
+ > .notice.inline {
170
+ margin: 0;
171
+ display: none;
172
+ }
173
+
174
+ &:not(.active) {
175
+ display: none;
176
+ }
177
+ }
178
+ }
179
+
180
+ .rtl
181
+ {
182
+ .fs-modal {
183
+ .fs-modal-header {
184
+ .fs-close {
185
+ right: auto;
186
+ left: 20px;
187
+ }
188
+ }
189
+ }
190
+ }
191
+
192
+ body.has-fs-modal {
193
+ overflow: hidden;
194
+ }
vendor/freemius/wordpress-sdk/assets/scss/admin/_multisite-options.scss ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #multisite_options_container {
2
+ margin-top: 10px;
3
+ border: 1px solid #ccc;
4
+ padding: 5px;
5
+
6
+ a {
7
+ text-decoration: none;
8
+
9
+ &:focus {
10
+ box-shadow: none;
11
+ }
12
+
13
+ &.selected {
14
+ font-weight: bold;
15
+ }
16
+ }
17
+
18
+ &.apply-on-all-sites {
19
+ border: 0 none;
20
+ padding: 0;
21
+
22
+ #all_sites_options {
23
+ border-spacing: 0;
24
+
25
+ td:not(:first-child) {
26
+ display: none;
27
+ }
28
+ }
29
+ }
30
+
31
+ #sites_list_container {
32
+ display: none;
33
+ overflow: auto;
34
+
35
+ table td {
36
+ border-top: 1px solid #ccc;
37
+ padding: 4px 2px;
38
+ }
39
+ }
40
+ }
vendor/freemius/wordpress-sdk/assets/scss/admin/_plugin-upgrade-notice.scss ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ .plugins p.fs-upgrade-notice
2
+ {
3
+ border: 0;
4
+ background-color: #d54e21;
5
+ padding: 10px;
6
+ color: #f9f9f9;
7
+ margin-top: 10px;
8
+ }
vendor/freemius/wordpress-sdk/assets/scss/admin/_subscription-cancellation.scss ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .fs-modal.fs-modal-subscription-cancellation {
2
+ .fs-price-increase-warning {
3
+ color: red;
4
+ font-weight: bold;
5
+ padding: 0 25px;
6
+ margin-bottom: 0;
7
+ }
8
+
9
+ ul.subscription-actions label {
10
+ input {
11
+ float: left;
12
+ top: 5px;
13
+ position: relative;
14
+
15
+ .rtl & {
16
+ float: right;
17
+ }
18
+ }
19
+
20
+ span {
21
+ display: block;
22
+ margin-left: 24px;
23
+
24
+ .rtl & {
25
+ margin-left: 0;
26
+ margin-right: 24px;
27
+ }
28
+ }
29
+ }
30
+ }
vendor/freemius/wordpress-sdk/assets/scss/admin/_themes.scss ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .theme-browser
2
+ {
3
+ .theme
4
+ {
5
+ .fs-premium-theme-badge
6
+ {
7
+ position: absolute;
8
+ top: 10px;
9
+ right: 0;
10
+ background: $fs-logo-green-color;
11
+ color: #fff;
12
+ text-transform: uppercase;
13
+ padding: 5px 10px;
14
+ @include border-radius(3px 0 0 3px);
15
+ font-weight: bold;
16
+ border-right: 0;
17
+ @include box-shadow(0 2px 1px -1px rgba(0, 0, 0, .3));
18
+ font-size: 1.1em;
19
+ }
20
+ }
21
+ }
vendor/freemius/wordpress-sdk/assets/scss/admin/_tooltip.scss ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .fs-tooltip-trigger
2
+ {
3
+ &:not(a)
4
+ {
5
+ cursor: help;
6
+ }
7
+
8
+ position: relative;
9
+
10
+ .fs-tooltip
11
+ {
12
+ opacity: 0;
13
+ visibility: hidden;
14
+ @include transition(opacity 0.3s ease-in-out);
15
+ position: absolute;
16
+ background: $tooltip-bkg-color;
17
+ color: $tooltip-color;
18
+ font-family: 'arial', serif;
19
+ font-size: 12px;
20
+ padding: 10px;
21
+ z-index: 999999;
22
+ bottom: 100%;
23
+ margin-bottom: 5px;
24
+ left: 0;
25
+ right: 0;
26
+ @include border-radius(5px);
27
+ @include box-shadow(1px 1px 1px rgba(0, 0, 0, 0.2));
28
+ line-height: 1.3em;
29
+ font-weight: bold;
30
+ text-align: left;
31
+
32
+ .rtl &
33
+ {
34
+ text-align: right;
35
+ }
36
+
37
+ &::after
38
+ {
39
+ content: ' ';
40
+ display: block;
41
+ width: 0;
42
+ height: 0;
43
+ border-style: solid;
44
+ border-width: 5px 5px 0 5px;
45
+ border-color: $tooltip-bkg-color transparent transparent transparent;
46
+ position: absolute;
47
+ top: 100%;
48
+ left: 21px;
49
+
50
+ .rtl &
51
+ {
52
+ right: 21px;
53
+ left: auto;
54
+ }
55
+ }
56
+ }
57
+
58
+ &:hover
59
+ {
60
+ .fs-tooltip
61
+ {
62
+ visibility: visible;
63
+ opacity: 1;
64
+ }
65
+ }
66
+ }
vendor/freemius/wordpress-sdk/assets/scss/admin/account.scss ADDED
@@ -0,0 +1,302 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "../start";
2
+
3
+ #fs_account
4
+ {
5
+ .postbox,
6
+ .widefat
7
+ {
8
+ max-width: 700px;
9
+ }
10
+
11
+ h3
12
+ {
13
+ font-size: 1.3em;
14
+ padding: 12px 15px;
15
+ margin: 0 0 12px 0;
16
+ line-height: 1.4;
17
+ border-bottom: 1px solid #F1F1F1;
18
+
19
+ .dashicons {
20
+ width: 26px;
21
+ height: 26px;
22
+ font-size: 1.3em;
23
+ }
24
+ }
25
+
26
+ i.dashicons
27
+ {
28
+ font-size: 1.2em;
29
+ height: 1.2em;
30
+ width: 1.2em;
31
+ }
32
+
33
+ .dashicons
34
+ {
35
+ vertical-align: middle;
36
+ }
37
+
38
+ .fs-header-actions
39
+ {
40
+ position: absolute;
41
+ top: 17px;
42
+ right: 15px;
43
+ font-size: 0.9em;
44
+
45
+ ul
46
+ {
47
+ margin: 0;
48
+ }
49
+
50
+ li
51
+ {
52
+ form
53
+ {
54
+ display: inline-block;
55
+ }
56
+
57
+ float: left;
58
+ a
59
+ {
60
+ text-decoration: none;
61
+ }
62
+ }
63
+ }
64
+ }
65
+
66
+ #fs_account_details .button-group {
67
+ float: right;
68
+ }
69
+
70
+ .rtl #fs_account .fs-header-actions
71
+ {
72
+ left: 15px;
73
+ right: auto;
74
+ }
75
+
76
+ .fs-key-value-table
77
+ {
78
+ width: 100%;
79
+
80
+ form
81
+ {
82
+ display: inline-block;
83
+ }
84
+
85
+ tr
86
+ {
87
+ td:first-child
88
+ {
89
+ nobr
90
+ {
91
+ font-weight: bold;
92
+ }
93
+
94
+ text-align: right;
95
+
96
+ form
97
+ {
98
+ display: block;
99
+ }
100
+ }
101
+
102
+ td.fs-right
103
+ {
104
+ text-align: right;
105
+ }
106
+
107
+ &.fs-odd
108
+ {
109
+ background: #ebebeb;
110
+ }
111
+ }
112
+
113
+ td, th
114
+ {
115
+ padding: 10px;
116
+ }
117
+
118
+ code {
119
+ line-height: 28px;
120
+ }
121
+
122
+ var, code, input[type="text"]
123
+ {
124
+ color: #0073AA;
125
+ font-size: 16px;
126
+ background: none;
127
+ }
128
+
129
+ input[type="text"] {
130
+ width: 100%;
131
+ font-weight: bold;
132
+ }
133
+ }
134
+
135
+ label.fs-tag
136
+ {
137
+ background: #ffba00;
138
+ color: #fff;
139
+ display: inline-block;
140
+ border-radius: 3px;
141
+ padding: 5px;
142
+ font-size: 11px;
143
+ line-height: 11px;
144
+ vertical-align: baseline;
145
+
146
+ &.fs-warn
147
+ {
148
+ background: #ffba00;
149
+ }
150
+ &.fs-success
151
+ {
152
+ background: #46b450;
153
+ }
154
+ &.fs-error
155
+ {
156
+ background: #dc3232;
157
+ }
158
+ }
159
+
160
+ #fs_sites
161
+ {
162
+ .fs-scrollable-table
163
+ {
164
+ .fs-table-body {
165
+ max-height: 200px;
166
+ overflow: auto;
167
+ border: 1px solid #e5e5e5;
168
+
169
+ & > table.widefat {
170
+ border: none !important;
171
+ }
172
+ }
173
+
174
+ .fs-main-column {
175
+ width: 100%;
176
+ }
177
+
178
+ .fs-site-details
179
+ {
180
+ td:first-of-type
181
+ {
182
+ text-align: right;
183
+ color: grey;
184
+ width: 1px;
185
+ }
186
+
187
+ td:last-of-type
188
+ {
189
+ text-align: right;
190
+ }
191
+ }
192
+
193
+ .fs-install-details table
194
+ {
195
+ tr td
196
+ {
197
+ width: 1px;
198
+ white-space: nowrap;
199
+
200
+ &:last-of-type
201
+ {
202
+ width: auto;
203
+ }
204
+ }
205
+ }
206
+ }
207
+ }
208
+
209
+ #fs_addons
210
+ {
211
+ h3
212
+ {
213
+ border: none;
214
+ margin-bottom: 0;
215
+ padding: 4px 5px;
216
+ }
217
+
218
+ td
219
+ {
220
+ vertical-align: middle;
221
+ }
222
+
223
+ thead {
224
+ white-space: nowrap;
225
+ }
226
+
227
+ td:first-child,
228
+ th:first-child
229
+ {
230
+ text-align: left;
231
+ font-weight: bold;
232
+ }
233
+ td:last-child,
234
+ th:last-child
235
+ {
236
+ text-align: right;
237
+ }
238
+ th
239
+ {
240
+ font-weight: bold;
241
+ }
242
+ }
243
+
244
+ #fs_billing_address {
245
+ width: 100%;
246
+
247
+ tr {
248
+ td {
249
+ width: 50%;
250
+ padding: 5px;
251
+ }
252
+
253
+ &:first-of-type {
254
+ td {
255
+ padding-top: 0;
256
+ }
257
+ }
258
+ }
259
+
260
+ @mixin read-mode {
261
+ border-color: transparent;
262
+ color: #777;
263
+ border-bottom: 1px dashed #ccc;
264
+ padding-left: 0;
265
+ background: none;
266
+ }
267
+
268
+ span {
269
+ font-weight: bold;
270
+ }
271
+
272
+ input, select {
273
+ @include placeholder(transparent);
274
+
275
+ display: block;
276
+ width: 100%;
277
+ margin-top: 5px;
278
+
279
+ &.fs-read-mode {
280
+ @include read-mode();
281
+ }
282
+ }
283
+
284
+
285
+ &.fs-read-mode {
286
+ td span {
287
+ display: none;
288
+ }
289
+
290
+ input, select
291
+ {
292
+ @include read-mode();
293
+ @include placeholder(#ccc);
294
+ }
295
+ }
296
+
297
+
298
+ button {
299
+ display: block;
300
+ width: 100%;
301
+ }
302
+ }
vendor/freemius/wordpress-sdk/assets/scss/admin/add-ons.scss ADDED
@@ -0,0 +1,449 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "../start";
2
+
3
+ #fs_addons
4
+ {
5
+ .fs-cards-list
6
+ {
7
+ list-style: none;
8
+
9
+ .fs-card
10
+ {
11
+ float: left;
12
+ // height: 185px; // With reviews/ratings
13
+ height: 152px;
14
+ width: 310px;
15
+ padding: 0;
16
+ margin: 0 0 30px 30px;
17
+ font-size: 14px;
18
+ list-style: none;
19
+ border: 1px solid #ddd;
20
+ cursor: pointer;
21
+ position: relative;
22
+
23
+ .fs-overlay
24
+ {
25
+ position: absolute;
26
+ left: 0;
27
+ right: 0;
28
+ bottom: 0;
29
+ top: 0;
30
+ z-index: 9;
31
+ }
32
+
33
+ .fs-inner
34
+ {
35
+ background-color: #fff;
36
+ overflow: hidden;
37
+ height: 100%;
38
+ position: relative;
39
+
40
+ ul
41
+ {
42
+ @include transition(all, 0.15s);
43
+ left: 0;
44
+ right: 0;
45
+ top: 0;
46
+ position: absolute;
47
+ }
48
+
49
+ li
50
+ {
51
+ list-style: none;
52
+ line-height: 18px;
53
+ padding: 0 15px;
54
+ width: 100%;
55
+ display: block;
56
+ @include box-sizing(border-box);
57
+ }
58
+
59
+ .fs-card-banner
60
+ {
61
+ padding: 0;
62
+ margin: 0;
63
+ line-height: 0;
64
+ display: block;
65
+ height: 100px;
66
+ background-repeat: repeat-x;
67
+ background-size: 100% 100%;
68
+ @include transition(all, 0.15s);
69
+ }
70
+
71
+ .fs-title
72
+ {
73
+ margin: 10px 0 0 0;
74
+ height: 18px;
75
+ overflow: hidden;
76
+ color: #000;
77
+ white-space: nowrap;
78
+ text-overflow: ellipsis;
79
+ font-weight: bold;
80
+ }
81
+
82
+ .fs-offer
83
+ {
84
+ font-size: 0.9em;
85
+ }
86
+
87
+ .fs-description
88
+ {
89
+ background-color: #f9f9f9;
90
+ padding: 10px 15px 100px 15px;
91
+ border-top: 1px solid #eee;
92
+ margin: 0 0 10px 0;
93
+ color: #777;
94
+ }
95
+
96
+ .fs-tag
97
+ {
98
+ position: absolute;
99
+ top: 10px;
100
+ right: 0px;
101
+ background: greenyellow;
102
+ display: block;
103
+ padding: 2px 10px;
104
+ @include box-shadow(1px 1px 1px rgba(0,0,0,0.3));
105
+ text-transform: uppercase;
106
+ font-size: 0.9em;
107
+ font-weight: bold;
108
+ }
109
+
110
+ .fs-cta
111
+ {
112
+ .button
113
+ {
114
+ position: absolute;
115
+ top: 112px;
116
+ right: 10px;
117
+ }
118
+ }
119
+ }
120
+
121
+ @media screen and (min-width: 960px) {
122
+ &:hover
123
+ {
124
+ .fs-overlay
125
+ {
126
+ border: 2px solid $fms-link-color;
127
+ margin-left: -1px;
128
+ margin-top: -1px;
129
+ }
130
+
131
+ .fs-inner
132
+ {
133
+ ul
134
+ {
135
+ top: -100px;
136
+ }
137
+
138
+ .fs-card-banner
139
+ {
140
+ // background-position: 50% -100px;
141
+ }
142
+
143
+ .fs-title,
144
+ .fs-offer
145
+ {
146
+ color: $fms-link-color;
147
+ }
148
+ }
149
+ }
150
+ }
151
+ }
152
+ }
153
+ }
154
+
155
+ #TB_window
156
+ {
157
+ &, iframe
158
+ {
159
+ width: 772px !important;
160
+ }
161
+ }
162
+
163
+ #plugin-information
164
+ {
165
+ #section-description
166
+ {
167
+ h2, h3, p, b, i, blockquote, li, ul, ol
168
+ {
169
+ clear: none;
170
+ }
171
+
172
+ .fs-selling-points
173
+ {
174
+ padding-bottom: 10px;
175
+ border-bottom: 1px solid #ddd;
176
+
177
+ ul
178
+ {
179
+ margin: 0;
180
+
181
+ li
182
+ {
183
+ padding: 0;
184
+ list-style: none outside none;
185
+
186
+ i.dashicons
187
+ {
188
+ color: $fs-logo-green-color;
189
+ font-size: 3em;
190
+ vertical-align: middle;
191
+ line-height: 30px;
192
+ float: left;
193
+ margin: 0 0 0 -15px;
194
+ }
195
+
196
+ h3
197
+ {
198
+ margin: 1em 30px !important;
199
+ }
200
+ }
201
+ }
202
+ }
203
+
204
+ .fs-screenshots
205
+ {
206
+ @include clearfix();
207
+ ul
208
+ {
209
+ list-style: none;
210
+ margin: 0;
211
+
212
+ li
213
+ {
214
+ width: 225px;
215
+ height: 225px;
216
+ float: left;
217
+ margin-bottom: 20px;
218
+ @include box-sizing(content-box);
219
+
220
+ a
221
+ {
222
+ display: block;
223
+ width: 100%;
224
+ height: 100%;
225
+ border: 1px solid;
226
+ @include box-shadow(1px 1px 1px rgba(0, 0, 0, 0.2));
227
+ background-size: cover;
228
+ }
229
+
230
+ &.odd
231
+ {
232
+ margin-right: 20px;
233
+ }
234
+ }
235
+ }
236
+ }
237
+ }
238
+
239
+ .plugin-information-pricing
240
+ {
241
+ $pricing_color: #FFFEEC;
242
+ $borders_color: #DDD;
243
+ margin: -16px;
244
+ // padding: 20px;
245
+ border-bottom: 1px solid $borders_color;
246
+
247
+ .fs-plan
248
+ {
249
+
250
+ h3
251
+ {
252
+ margin-top: 0;
253
+ padding: 20px;
254
+ font-size: 16px;
255
+ }
256
+
257
+ .nav-tab-wrapper
258
+ {
259
+ border-bottom: 1px solid $borders_color;
260
+
261
+ .nav-tab
262
+ {
263
+ cursor: pointer;
264
+ position: relative;
265
+ padding: 0 10px;
266
+ font-size: 0.9em;
267
+
268
+ label
269
+ {
270
+ text-transform: uppercase;
271
+ color: green;
272
+ background: greenyellow;
273
+ position: absolute;
274
+ left: -1px;
275
+ right: -1px;
276
+ bottom: 100%;
277
+ border: 1px solid darkgreen;
278
+ padding: 2px;
279
+ text-align: center;
280
+ font-size: 0.9em;
281
+ line-height: 1em;
282
+ }
283
+
284
+ &.nav-tab-active
285
+ {
286
+ cursor: default;
287
+ background: $pricing_color;
288
+ border-bottom-color: $pricing_color;
289
+ }
290
+ }
291
+ }
292
+
293
+ &.fs-single-cycle
294
+ {
295
+ h3
296
+ {
297
+ background: $pricing_color;
298
+ margin: 0;
299
+ padding-bottom: 0;
300
+ color: #0073aa;
301
+ }
302
+
303
+ .nav-tab-wrapper,
304
+ .fs-billing-frequency
305
+ {
306
+ display: none;
307
+ }
308
+ }
309
+
310
+ .fs-pricing-body
311
+ {
312
+ background: $pricing_color;
313
+ padding: 20px;
314
+ }
315
+
316
+ .button
317
+ {
318
+ width: 100%;
319
+ text-align: center;
320
+ font-weight: bold;
321
+ text-transform: uppercase;
322
+ font-size: 1.1em;
323
+ }
324
+
325
+ label
326
+ {
327
+ white-space: nowrap;
328
+ }
329
+
330
+ var {
331
+ font-style: normal;
332
+ }
333
+
334
+ .fs-billing-frequency,
335
+ .fs-annual-discount
336
+ {
337
+ text-align: center;
338
+ display: block;
339
+ font-weight: bold;
340
+ margin-bottom: 10px;
341
+ text-transform: uppercase;
342
+ background: #F3F3F3;
343
+ padding: 2px;
344
+ border: 1px solid #ccc;
345
+ }
346
+
347
+ .fs-annual-discount
348
+ {
349
+ text-transform: none;
350
+ color: green;
351
+ background: greenyellow;
352
+ }
353
+
354
+ ul.fs-trial-terms
355
+ {
356
+ font-size: 0.9em;
357
+
358
+ i
359
+ {
360
+ float: left;
361
+ margin: 0 0 0 -15px;
362
+ }
363
+
364
+ li
365
+ {
366
+ margin: 10px 0 0 0;
367
+ }
368
+ }
369
+ }
370
+ }
371
+
372
+ #section-features
373
+ {
374
+ .fs-features
375
+ {
376
+ margin: -20px -26px;
377
+ }
378
+
379
+ table
380
+ {
381
+ width: 100%;
382
+ border-spacing: 0;
383
+ border-collapse: separate;
384
+
385
+ thead
386
+ {
387
+ th
388
+ {
389
+ padding: 10px 0;
390
+ }
391
+
392
+ .fs-price
393
+ {
394
+ color: $fs-logo-green-color;
395
+ font-weight: normal;
396
+ display: block;
397
+ text-align: center;
398
+ }
399
+ }
400
+
401
+ tbody
402
+ {
403
+ td
404
+ {
405
+ border-top: 1px solid #ccc;
406
+ padding: 10px 0;
407
+ text-align: center;
408
+ width: 100px;
409
+ color: $fs-logo-green-color;
410
+
411
+ &:first-child
412
+ {
413
+ text-align: left;
414
+ width: auto;
415
+ color: inherit;
416
+ padding-left: 26px;
417
+ }
418
+ }
419
+ tr.fs-odd
420
+ {
421
+ td
422
+ {
423
+ background: #fefefe;
424
+ }
425
+ }
426
+ }
427
+ }
428
+
429
+ .dashicons-yes
430
+ {
431
+ width: 30px;
432
+ height: 30px;
433
+ font-size: 30px;
434
+ }
435
+ }
436
+ }
437
+
438
+ @media screen and (max-width: 961px) {
439
+ #fs_addons
440
+ {
441
+ .fs-cards-list
442
+ {
443
+ .fs-card
444
+ {
445
+ height: 265px;
446
+ }
447
+ }
448
+ }
449
+ }
vendor/freemius/wordpress-sdk/assets/scss/admin/affiliation.scss ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "../start";
2
+
3
+ #fs_affiliation_content_wrapper {
4
+ #messages {
5
+ margin-top: 25px;
6
+ }
7
+
8
+ h3 {
9
+ font-size: 24px;
10
+ padding: 0;
11
+ margin-left: 0;
12
+ }
13
+
14
+ ul {
15
+ li {
16
+ @include box-sizing(border-box);
17
+ list-style-type: none;
18
+
19
+ &:before {
20
+ content: '✓';
21
+ margin-right: 10px;
22
+ font-weight: bold;
23
+ }
24
+ }
25
+ }
26
+
27
+ p:not(.description), li, label {
28
+ font-size: 16px !important;
29
+ line-height: 26px !important;
30
+ }
31
+
32
+ .button {
33
+ margin-top: 20px;
34
+ margin-bottom: 7px;
35
+ line-height: 35px;
36
+ height: 40px;
37
+ font-size: 16px;
38
+
39
+ &#cancel_button {
40
+ margin-right: 5px;
41
+ }
42
+ }
43
+
44
+ form {
45
+ .input-container {
46
+ .input-label {
47
+ font-weight: bold;
48
+ display: block;
49
+ width: 100%;
50
+ }
51
+
52
+ &.input-container-text {
53
+ label, input, textarea {
54
+ display: block;
55
+ }
56
+ }
57
+
58
+ margin-bottom: 15px;
59
+
60
+ #add_domain, .remove-domain {
61
+ text-decoration: none;
62
+ display: inline-block;
63
+ margin-top: 3px;
64
+
65
+ &:focus {
66
+ box-shadow: none;
67
+ }
68
+
69
+ &.disabled {
70
+ color: #aaa;
71
+ cursor: default;
72
+ }
73
+ }
74
+ }
75
+
76
+ #extra_domains_container {
77
+ .description {
78
+ margin-top: 0;
79
+ position: relative;
80
+ top: -4px;
81
+ }
82
+
83
+ .extra-domain-input-container {
84
+ margin-bottom: 15px;
85
+
86
+ .domain {
87
+ display: inline-block;
88
+ margin-right: 5px;
89
+
90
+ &:last-of-type {
91
+ margin-bottom: 0;
92
+ }
93
+ }
94
+ }
95
+ }
96
+ }
97
+ }
vendor/freemius/wordpress-sdk/assets/scss/admin/checkout.scss ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ @media screen and (max-width: 782px) {
2
+ #wpbody-content {
3
+ padding-bottom: 0 !important;
4
+ }
5
+ }
vendor/freemius/wordpress-sdk/assets/scss/admin/common.scss ADDED
@@ -0,0 +1,220 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "../start";
2
+ @import "themes";
3
+
4
+ #fs_frame
5
+ {
6
+ line-height: 0;
7
+ font-size: 0;
8
+ }
9
+
10
+ .fs-full-size-wrapper
11
+ {
12
+ margin: 40px 0 -65px -20px;
13
+
14
+ @media (max-width: 600px) {
15
+ margin: 0 0 -65px -10px;
16
+ }
17
+ }
18
+
19
+ .fs-notice
20
+ {
21
+ position: relative;
22
+
23
+ &.fs-has-title
24
+ {
25
+ margin-bottom: 30px !important;
26
+ }
27
+
28
+ &.success
29
+ {
30
+ color: green;
31
+ // font-weight: normal;
32
+ }
33
+
34
+ &.promotion
35
+ {
36
+ border-color: $fs-notice-promotion-border-color !important;
37
+ background-color: $fs-notice-promotion-bkg !important;
38
+ }
39
+
40
+ .fs-notice-body
41
+ {
42
+ margin: .5em 0;
43
+ padding: 2px;
44
+ }
45
+
46
+ .fs-close
47
+ {
48
+ // position: absolute;
49
+ // top: 2px;
50
+ // bottom: 2px;
51
+ // right: 2px;
52
+ // min-width: 100px;
53
+ // text-align: center;
54
+ // padding-right: 2px;
55
+ cursor: pointer;
56
+ color: #aaa;
57
+ float: right;
58
+
59
+ &:hover
60
+ {
61
+ color: #666;
62
+ // background: #A9A9A9;
63
+ }
64
+
65
+ > *
66
+ {
67
+ margin-top: 7px;
68
+ display: inline-block;
69
+ }
70
+ }
71
+
72
+ label.fs-plugin-title
73
+ {
74
+ background: rgba(0, 0, 0, 0.3);
75
+ color: #fff;
76
+ padding: 2px 10px;
77
+ position: absolute;
78
+ top: 100%;
79
+ bottom: auto;
80
+ right: auto;
81
+ @include border-radius(0 0 3px 3px);
82
+ left: 10px;
83
+ font-size: 12px;
84
+ font-weight: bold;
85
+ cursor: auto;
86
+ }
87
+ }
88
+
89
+ div.fs-notice
90
+ {
91
+ &.updated,
92
+ &.success,
93
+ &.promotion
94
+ {
95
+ display: block !important;
96
+ }
97
+ }
98
+
99
+ .rtl .fs-notice
100
+ {
101
+ .fs-close
102
+ {
103
+ // left: 2px;
104
+ // right: auto;
105
+ // padding-right: 0;
106
+ // padding-left: 2px;
107
+ float: left;
108
+ }
109
+ }
110
+
111
+ .fs-secure-notice
112
+ {
113
+ position: fixed;
114
+ top: 32px;
115
+ left: 160px;
116
+ right: 0;
117
+ background: rgb(235, 253, 235);
118
+ padding: 10px 20px;
119
+ color: green;
120
+ z-index: 9999;
121
+ @include box-shadow(0 2px 2px rgba(6, 113, 6, 0.3));
122
+ @include opacity(0.95);
123
+
124
+ &:hover
125
+ {
126
+ @include opacity(1);
127
+ }
128
+
129
+ a.fs-security-proof
130
+ {
131
+ color: green;
132
+ text-decoration: none;
133
+ }
134
+ }
135
+
136
+ @media screen and (max-width: 960px) {
137
+ .fs-secure-notice
138
+ {
139
+ left: 36px;
140
+ }
141
+ }
142
+
143
+ @media screen and (max-width: 600px) {
144
+ .fs-secure-notice
145
+ {
146
+ display: none;
147
+ }
148
+ }
149
+
150
+ @media screen and (max-width: 500px) {
151
+ #fs_promo_tab
152
+ {
153
+ display: none;
154
+ }
155
+ }
156
+
157
+ @media screen and (max-width: 782px) {
158
+ .fs-secure-notice
159
+ {
160
+ left: 0;
161
+ top: 46px;
162
+ text-align: center;
163
+ }
164
+ }
165
+
166
+ span.fs-submenu-item.fs-sub:before
167
+ {
168
+ // Add small arrow.
169
+ content: '\21B3';
170
+ padding: 0 5px;
171
+ }
172
+
173
+ .rtl
174
+ {
175
+ span.fs-submenu-item.fs-sub:before
176
+ {
177
+ // Add small RTL arrow.
178
+ content: '\21B2';
179
+ }
180
+ }
181
+
182
+ .fs-submenu-item
183
+ {
184
+ &.pricing
185
+ {
186
+ &.upgrade-mode
187
+ {
188
+ color: greenyellow;
189
+ }
190
+
191
+ &.trial-mode
192
+ {
193
+ color: #83e2ff;
194
+ }
195
+ }
196
+ }
197
+
198
+ #adminmenu .update-plugins.fs-trial
199
+ {
200
+ background-color: #00b9eb;
201
+ }
202
+ .fs-ajax-spinner
203
+ {
204
+ border: 0;
205
+ width: 20px;
206
+ height: 20px;
207
+ margin-right: 5px;
208
+ vertical-align: sub;
209
+ display: inline-block;
210
+ background: url('/wp-admin/images/wpspin_light-2x.gif');
211
+ background-size: contain;
212
+ }
213
+
214
+ .wrap.fs-section {
215
+ h2 {
216
+ text-align: left;
217
+ }
218
+ }
219
+
220
+ @import "plugin-upgrade-notice";
vendor/freemius/wordpress-sdk/assets/scss/admin/connect.scss ADDED
@@ -0,0 +1,548 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "../start";
2
+
3
+ $form_width: 480px;
4
+
5
+ #fs_connect
6
+ {
7
+ width: $form_width;
8
+ @include box-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));
9
+ margin: 20px 0;
10
+
11
+ @media screen and (max-width: ($form_width - 1)) {
12
+ @include box-shadow(none);
13
+ width: auto;
14
+ margin: 0 0 0 -10px;
15
+ }
16
+
17
+ .fs-content
18
+ {
19
+ background: #fff;
20
+ padding: 15px 20px;
21
+
22
+ .fs-error {
23
+ background: snow;
24
+ color: $fs-logo-magenta-color;
25
+ border: 1px solid $fs-logo-magenta-color;
26
+ @include box-shadow(0 1px 1px 0 rgba(0,0,0,.1));
27
+ text-align: center;
28
+ padding: 5px;
29
+ margin-bottom: 10px;
30
+ }
31
+
32
+ p
33
+ {
34
+ margin: 0;
35
+ padding: 0;
36
+ font-size: 1.2em;
37
+ }
38
+ }
39
+
40
+ .fs-license-key-container {
41
+ position: relative;
42
+ width: 280px;
43
+ margin: 10px auto 0 auto;
44
+
45
+ input {
46
+ width: 100%;
47
+ }
48
+
49
+ .dashicons {
50
+ position: absolute;
51
+ top: 5px;
52
+ right: 5px;
53
+ }
54
+ }
55
+
56
+ &.require-license-key {
57
+ #sites_list_container {
58
+ td {
59
+ cursor: pointer;
60
+ }
61
+ }
62
+ }
63
+
64
+ #delegate_to_site_admins {
65
+ margin-right: 15px;
66
+ float: right;
67
+ height: 26px;
68
+ vertical-align: middle;
69
+ line-height: 37px;
70
+ font-weight: bold;
71
+ border-bottom: 1px dashed;
72
+ text-decoration: none;
73
+
74
+ &.rtl {
75
+ margin-left: 15px;
76
+ margin-right: 0;
77
+ }
78
+ }
79
+
80
+ .fs-actions
81
+ {
82
+ padding: 10px 20px;
83
+ background: #C0C7CA;
84
+
85
+ .button
86
+ {
87
+ padding: 0 10px 1px;
88
+ line-height: 35px;
89
+ height: 37px;
90
+ font-size: 16px;
91
+ margin-bottom: 0;
92
+
93
+ .dashicons
94
+ {
95
+ font-size: 37px;
96
+ margin-left: -8px;
97
+ margin-right: 12px;
98
+ }
99
+
100
+ &.button-primary
101
+ {
102
+ padding-right: 15px;
103
+ padding-left: 15px;
104
+
105
+ &:after
106
+ {
107
+ content: ' \279C';
108
+ }
109
+
110
+ &.fs-loading
111
+ {
112
+ &:after
113
+ {
114
+ content: '';
115
+ }
116
+ }
117
+ }
118
+
119
+ &.button-secondary
120
+ {
121
+ float: right;
122
+ }
123
+ }
124
+
125
+ // .fs-skip
126
+ // {
127
+ // line-height: 38px;
128
+ // vertical-align: middle;
129
+ // text-decoration: none;
130
+ // margin-left: 10px;
131
+ // }
132
+ }
133
+
134
+ &.fs-anonymous-disabled
135
+ {
136
+ .fs-actions
137
+ {
138
+ .button.button-primary
139
+ {
140
+ width: 100%;
141
+ }
142
+ }
143
+ }
144
+
145
+ .fs-permissions
146
+ {
147
+ padding: 10px 20px;
148
+ background: #FEFEFE;
149
+ // background: #F1F1F1;
150
+ @include transition(background 0.5s ease);
151
+
152
+ .fs-license-sync-disclaimer {
153
+ text-align: center;
154
+ margin-top: 0;
155
+ }
156
+
157
+ .fs-trigger
158
+ {
159
+ font-size: 0.9em;
160
+ text-decoration: none;
161
+ text-align: center;
162
+ display: block;
163
+ }
164
+
165
+ ul
166
+ {
167
+ height: 0;
168
+ overflow: hidden;
169
+ margin: 0;
170
+
171
+ li
172
+ {
173
+ margin-bottom: 12px;
174
+
175
+ &:last-child
176
+ {
177
+ margin-bottom: 0;
178
+ }
179
+
180
+ i.dashicons
181
+ {
182
+ float: left;
183
+ font-size: 40px;
184
+ width: 40px;
185
+ height: 40px;
186
+ }
187
+
188
+ div
189
+ {
190
+ margin-left: 55px;
191
+
192
+ span
193
+ {
194
+ font-weight: bold;
195
+ text-transform: uppercase;
196
+ color: #23282d;
197
+ }
198
+
199
+ p
200
+ {
201
+ margin: 2px 0 0 0;
202
+ }
203
+ }
204
+ }
205
+ }
206
+
207
+ &.fs-open
208
+ {
209
+ background: #fff;
210
+
211
+ ul
212
+ {
213
+ height: auto;
214
+ margin: 20px 20px 10px 20px;
215
+ }
216
+ }
217
+
218
+ @media screen and (max-width: ($form_width - 1)) {
219
+ background: #fff;
220
+
221
+ .fs-trigger
222
+ {
223
+ display: none;
224
+ }
225
+
226
+ ul
227
+ {
228
+ height: auto;
229
+ margin: 20px;
230
+ }
231
+ }
232
+ }
233
+
234
+ .fs-freemium-licensing {
235
+ padding: 8px;
236
+ // background: #0085BA;
237
+ background: #777;
238
+ color: #fff;
239
+
240
+ p {
241
+ text-align: center;
242
+ display: block;
243
+ margin: 0;
244
+ padding: 0;
245
+ }
246
+
247
+ a {
248
+ color: #C2EEFF;
249
+ text-decoration: underline;
250
+ }
251
+ }
252
+
253
+ $icon_size: 80px;
254
+ $wp_logo_padding: $icon_size / 10;
255
+ $icons_top: 10px;
256
+
257
+ .fs-visual
258
+ {
259
+ padding: 12px;
260
+ line-height: 0;
261
+ background: #fafafa;
262
+ height: $icon_size;
263
+ position: relative;
264
+
265
+ .fs-site-icon
266
+ {
267
+ position: absolute;
268
+ left: 20px;
269
+ top: $icons_top;
270
+ }
271
+
272
+ .fs-connect-logo
273
+ {
274
+ position: absolute;
275
+ right: 20px;
276
+ top: $icons_top;
277
+ }
278
+
279
+ .fs-plugin-icon
280
+ {
281
+ position: absolute;
282
+ top: $icons_top;
283
+ left: 50%;
284
+ margin-left: - ($icon_size / 2);
285
+ }
286
+
287
+ .fs-plugin-icon,
288
+ .fs-site-icon,
289
+ img,
290
+ object
291
+ {
292
+ width: $icon_size;
293
+ height: $icon_size;
294
+ }
295
+
296
+ .dashicons-wordpress
297
+ {
298
+ font-size: $icon_size - ($wp_logo_padding * 2);
299
+ background: $wordpress_color;
300
+ color: #fff;
301
+ width: $icon_size - ($wp_logo_padding * 2);
302
+ height: $icon_size - ($wp_logo_padding * 2);
303
+ padding: $wp_logo_padding;
304
+ }
305
+
306
+ .dashicons-plus
307
+ {
308
+ position: absolute;
309
+ top: 50%;
310
+ font-size: 30px;
311
+ margin-top: -10px;
312
+ color: #bbb;
313
+
314
+ &.fs-first
315
+ {
316
+ left: 28%;
317
+ }
318
+ &.fs-second
319
+ {
320
+ left: 65%;
321
+ }
322
+ }
323
+
324
+ .fs-plugin-icon,
325
+ .fs-connect-logo,
326
+ .fs-site-icon
327
+ {
328
+ border: 1px solid #ccc;
329
+ padding: 1px;
330
+ background: #fff;
331
+ }
332
+ }
333
+
334
+ .fs-terms
335
+ {
336
+ text-align: center;
337
+ font-size: 0.85em;
338
+ padding: 5px;
339
+ background: rgba(0, 0, 0, 0.05);
340
+
341
+ &, a
342
+ {
343
+ color: #999;
344
+ }
345
+
346
+ a
347
+ {
348
+ text-decoration: none;
349
+ }
350
+ }
351
+ }
352
+
353
+ @import "multisite-options";
354
+ @import "tooltip";
355
+ @import "gdpr-consent";
356
+
357
+ .rtl
358
+ {
359
+ #fs_connect
360
+ {
361
+ .fs-actions
362
+ {
363
+ padding: 10px 20px;
364
+ background: #C0C7CA;
365
+
366
+ .button
367
+ {
368
+ .dashicons
369
+ {
370
+ font-size: 37px;
371
+ margin-left: -8px;
372
+ margin-right: 12px;
373
+ }
374
+
375
+ &.button-primary
376
+ {
377
+ &:after
378
+ {
379
+ content: ' \000bb';
380
+ }
381
+
382
+ &.fs-loading
383
+ {
384
+ &:after
385
+ {
386
+ content: '';
387
+ }
388
+ }
389
+ }
390
+
391
+ &.button-secondary
392
+ {
393
+ float: left;
394
+ }
395
+ }
396
+ }
397
+
398
+ .fs-permissions
399
+ {
400
+ ul
401
+ {
402
+ li
403
+ {
404
+ div
405
+ {
406
+ margin-right: 55px;
407
+ margin-left: 0;
408
+ }
409
+
410
+ i.dashicons
411
+ {
412
+ float: right;
413
+ }
414
+
415
+ }
416
+ }
417
+ }
418
+
419
+ .fs-visual
420
+ {
421
+ .fs-site-icon
422
+ {
423
+ right: 20px;
424
+ left: auto;
425
+ }
426
+
427
+ .fs-connect-logo
428
+ {
429
+ right: auto;
430
+ left: 20px;
431
+ }
432
+ }
433
+ }
434
+ }
435
+
436
+ #fs_theme_connect_wrapper {
437
+ position: fixed;
438
+ top: 0;
439
+ height: 100%;
440
+ width: 100%;
441
+ z-index: 99990;
442
+ background: rgba(0, 0, 0, 0.75);
443
+ text-align: center;
444
+ overflow-y: auto;
445
+
446
+ &:before {
447
+ content: "";
448
+ display: inline-block;
449
+ vertical-align: middle;
450
+ height: 100%;
451
+ }
452
+
453
+ > button.close {
454
+ color: white;
455
+ cursor: pointer;
456
+ height: 40px;
457
+ width: 40px;
458
+ position: absolute;
459
+ right: 0;
460
+ border: 0;
461
+ background-color: transparent;
462
+ top: 32px;
463
+ }
464
+
465
+ #fs_connect {
466
+ top: 0;
467
+ text-align: left;
468
+ display: inline-block;
469
+ vertical-align: middle;
470
+ margin-top: 52px;
471
+ margin-bottom: 20px;
472
+
473
+ .fs-terms
474
+ {
475
+ background: rgba(140, 140, 140, 0.64);
476
+
477
+ &, a
478
+ {
479
+ color: #c5c5c5;
480
+ }
481
+ }
482
+ }
483
+ }
484
+
485
+ .wp-pointer-content
486
+ {
487
+ #fs_connect
488
+ {
489
+ margin: 0;
490
+ @include box-shadow(none);
491
+ }
492
+ }
493
+
494
+ .fs-opt-in-pointer
495
+ {
496
+ .wp-pointer-content
497
+ {
498
+ padding: 0;
499
+ }
500
+
501
+ &.wp-pointer-top
502
+ {
503
+ .wp-pointer-arrow
504
+ {
505
+ border-bottom-color: #dfdfdf;
506
+ }
507
+ .wp-pointer-arrow-inner
508
+ {
509
+ border-bottom-color: #fafafa;
510
+ }
511
+ }
512
+
513
+ &.wp-pointer-bottom
514
+ {
515
+ .wp-pointer-arrow
516
+ {
517
+ border-top-color: #dfdfdf;
518
+ }
519
+ .wp-pointer-arrow-inner
520
+ {
521
+ border-top-color: #fafafa;
522
+ }
523
+ }
524
+
525
+ &.wp-pointer-left
526
+ {
527
+ .wp-pointer-arrow
528
+ {
529
+ border-right-color: #dfdfdf;
530
+ }
531
+ .wp-pointer-arrow-inner
532
+ {
533
+ border-right-color: #fafafa;
534
+ }
535
+ }
536
+
537
+ &.wp-pointer-right
538
+ {
539
+ .wp-pointer-arrow
540
+ {
541
+ border-left-color: #dfdfdf;
542
+ }
543
+ .wp-pointer-arrow-inner
544
+ {
545
+ border-left-color: #fafafa;
546
+ }
547
+ }
548
+ }
vendor/freemius/wordpress-sdk/assets/scss/admin/debug.scss ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "../start";
2
+
3
+ .switch
4
+ {
5
+ position: relative;
6
+ display: inline-block;
7
+ font-size: 1.6em;
8
+ font-weight: bold;
9
+ color: #ccc;
10
+ text-shadow: 0px 1px 1px rgba(255, 255, 255, 0.8);
11
+ height: 18px;
12
+ padding: 6px 6px 5px 6px;
13
+ border: 1px solid #ccc;
14
+ border: 1px solid rgba(0, 0, 0, 0.2);
15
+ border-radius: 4px;
16
+ background: #ececec;
17
+ box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.1), inset 0px 1px 3px 0px rgba(0, 0, 0, 0.1);
18
+ cursor: pointer;
19
+
20
+ span
21
+ {
22
+ display: inline-block; width: 35px;
23
+ text-transform: uppercase;
24
+
25
+ &.on
26
+ {
27
+ color: $button-primary-bkg;
28
+ }
29
+ }
30
+
31
+ .toggle
32
+ {
33
+ position: absolute;
34
+ top: 1px;
35
+ width: 37px;
36
+ height: 25px;
37
+ border: 1px solid #ccc;
38
+ border: 1px solid rgba(0, 0, 0, 0.3);
39
+ border-radius: 4px;
40
+ background: #fff;
41
+ background: -moz-linear-gradient(top, #ececec 0%, #fff 100%);
42
+ background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #ececec), color-stop(100%, #fff));
43
+ background: -webkit-linear-gradient(top, #ececec 0%, #fff 100%);
44
+ background: -o-linear-gradient(top, #ececec 0%, #fff 100%);
45
+ background: -ms-linear-gradient(top, #ececec 0%, #fff 100%);
46
+ background: linear-gradient(top, #ececec 0%, #fff 100%);
47
+ box-shadow: inset 0px 1px 0px 0px rgba(255, 255, 255, 0.5);
48
+ z-index: 999;
49
+ @include transition(all 0.15s ease-in-out);
50
+ }
51
+
52
+ &.on .toggle
53
+ {
54
+ left: 2%;
55
+ }
56
+ &.off .toggle
57
+ {
58
+ left: 54%;
59
+ }
60
+
61
+ /* Round switch */
62
+ &.round
63
+ {
64
+ padding: 0px 20px;
65
+ border-radius: 40px;
66
+
67
+ .toggle
68
+ {
69
+ border-radius: 40px;
70
+ width: 14px;
71
+ height: 14px;
72
+ }
73
+
74
+ &.on .toggle
75
+ {
76
+ left: 3%;
77
+ background: $button-primary-bkg;
78
+ }
79
+ &.off .toggle
80
+ {
81
+ left: 58%;
82
+ }
83
+ }
84
+ }
85
+
86
+ .switch-label
87
+ {
88
+ font-size: 20px;
89
+ line-height: 31px;
90
+ margin: 0 5px;
91
+ }
92
+
93
+ #fs_log_book {
94
+ table {
95
+ font-family: Consolas,Monaco,monospace;
96
+ font-size: 12px;
97
+
98
+ th {
99
+ color: #ccc;
100
+ }
101
+
102
+ tr {
103
+ background: #232525;
104
+
105
+ &.alternate {
106
+ background: #2b2b2b;
107
+ }
108
+
109
+ td {
110
+ &.fs-col--logger {
111
+ color: #5a7435;
112
+ }
113
+ &.fs-col--type {
114
+ color: #ffc861;
115
+ }
116
+ &.fs-col--function {
117
+ color: #a7b7b1;
118
+ font-weight: bold;
119
+ }
120
+ &.fs-col--message {
121
+ &, a
122
+ {
123
+ color: #9a73ac !important;
124
+ }
125
+ }
126
+ &.fs-col--file {
127
+ color: #d07922;
128
+ }
129
+ &.fs-col--timestamp {
130
+ color: #6596be;
131
+ }
132
+ }
133
+ }
134
+ }
135
+ }
vendor/freemius/wordpress-sdk/assets/scss/admin/dialog-boxes.scss ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ @import "../start";
2
+ @import "modal-common";
3
+ @import "deactivation-feedback";
4
+ @import "subscription-cancellation";
5
+ @import "license-activation";
6
+ @import "multisite-options";
7
+ @import "license-key-resend";
8
+ @import "ajax-loader";
9
+ @import "auto-install";
10
+ @import "buttons";
vendor/freemius/wordpress-sdk/assets/scss/admin/gdpr-optin-notice.scss ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .fs-notice[data-id^="gdpr_optin_actions"]
2
+ {
3
+ .underlined {
4
+ text-decoration: underline;
5
+ }
6
+
7
+ ul {
8
+ .button, .action-description {
9
+ vertical-align: middle;
10
+ }
11
+
12
+ .action-description {
13
+ display: inline-block;
14
+ margin-left: 3px;
15
+ }
16
+ }
17
+ }
vendor/freemius/wordpress-sdk/assets/scss/admin/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ // Hide file structure from users on unprotected servers.
vendor/freemius/wordpress-sdk/assets/scss/customizer.scss ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "start";
2
+
3
+ #fs_customizer_upsell {
4
+ .fs-customizer-plan {
5
+ padding: 10px 20px 20px 20px;
6
+ border-radius: 3px;
7
+ background: #fff;
8
+
9
+ h2 {
10
+ position: relative;
11
+ margin: 0;
12
+ line-height: 2em;
13
+ text-transform: uppercase;
14
+
15
+ .button-link {
16
+ top: -2px;
17
+ }
18
+ }
19
+ }
20
+
21
+ .fs-feature {
22
+ position: relative;
23
+ }
24
+
25
+ .dashicons-yes {
26
+ color: #0085ba;
27
+ font-size: 2em;
28
+ vertical-align: bottom;
29
+ margin-left: -7px;
30
+ margin-right: 10px;
31
+
32
+ .rtl & {
33
+ margin-left: 10px;
34
+ margin-right: -7px;
35
+ }
36
+ }
37
+
38
+ .dashicons-editor-help
39
+ {
40
+ color: #bbb;
41
+ cursor: help;
42
+
43
+ $tooltip-color: #000;
44
+
45
+ .fs-feature-desc {
46
+ opacity: 0;
47
+ visibility: hidden;
48
+ @include transition(opacity 0.3s ease-in-out);
49
+
50
+ position: absolute;
51
+ background: $tooltip-color;
52
+ color: #fff;
53
+ font-family: 'arial', serif;
54
+ font-size: 12px;
55
+ padding: 10px;
56
+ z-index: 999999;
57
+ bottom: 100%;
58
+ margin-bottom: 5px;
59
+ left: 0;
60
+ right: 0;
61
+ @include border-radius(5px);
62
+ @include box-shadow(1px 1px 1px rgba(0,0,0,0.2));
63
+ line-height: 1.3em;
64
+ font-weight: bold;
65
+ text-align: left;
66
+
67
+ .rtl &
68
+ {
69
+ text-align: right;
70
+ }
71
+
72
+ &::after {
73
+ content: ' ';
74
+ display: block;
75
+ width: 0;
76
+ height: 0;
77
+ border-style: solid;
78
+ border-width: 5px 5px 0 5px;
79
+ border-color: $tooltip-color transparent transparent transparent;
80
+ position: absolute;
81
+ top: 100%;
82
+ left: 21px;
83
+
84
+ .rtl & {
85
+ right: 21px;
86
+ left: auto;
87
+ }
88
+ }
89
+ }
90
+
91
+ &:hover {
92
+ .fs-feature-desc {
93
+ visibility: visible;
94
+ opacity: 1;
95
+ }
96
+ }
97
+ }
98
+
99
+ .button-primary {
100
+ display: block;
101
+ text-align: center;
102
+ margin-top: 10px;
103
+ }
104
+ }
105
+
106
+ #fs_customizer_support
107
+ {
108
+ display: block !important;
109
+
110
+ .button {
111
+ float: right;
112
+ }
113
+
114
+ .button-group {
115
+ width: 100%;
116
+ display: block;
117
+ margin-top: 10px;
118
+
119
+ .button {
120
+ float: none;
121
+ width: 50%;
122
+ text-align: center;
123
+ }
124
+ }
125
+ }
vendor/freemius/wordpress-sdk/assets/scss/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ // Hide file structure from users on unprotected servers.
vendor/freemius/wordpress-sdk/composer.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "freemius/wordpress-sdk",
3
+ "description": "Freemius WordPress SDK",
4
+ "keywords": ["freemius", "wordpress", "plugin", "sdk"],
5
+ "homepage": "https://freemius.com",
6
+ "license": "GPL-3.0-only",
7
+ "require": {
8
+ "php": ">=5.2"
9
+ }
10
+ }
vendor/freemius/wordpress-sdk/config.php ADDED
@@ -0,0 +1,388 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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: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_network_admin() ||
355
+ ( is_multisite() &&
356
+ ( ( defined( 'DOING_AJAX' ) && DOING_AJAX &&
357
+ ( isset( $_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
+ }
vendor/freemius/wordpress-sdk/gulpfile.js ADDED
@@ -0,0 +1,167 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var gulp = require('gulp');
2
+ var path = require('path');
3
+ var filesystem = require('fs');
4
+ var wpPot = require('gulp-wp-pot');
5
+ var gettext = require('gulp-gettext');
6
+ var sort = require('gulp-sort');
7
+ var pofill = require('gulp-pofill');
8
+ var rename = require('gulp-rename');
9
+ var clean = require('gulp-clean');
10
+
11
+ var languagesFolder = './languages/';
12
+
13
+ var options = require('./transifex-config.json');
14
+
15
+ function getFolders(dir) {
16
+ return filesystem.readdirSync(dir)
17
+ .filter(function (file) {
18
+ return filesystem.statSync(path.join(dir, file)).isDirectory();
19
+ });
20
+ }
21
+
22
+ var transifex = require('gulp-transifex').createClient(options);
23
+
24
+ // Create POT out of i18n.php.
25
+ gulp.task('prepare-source', function () {
26
+ gulp.src('**/*.php')
27
+ .pipe(sort())
28
+ .pipe(wpPot({
29
+ destFile : 'freemius.pot',
30
+ package : 'freemius',
31
+ bugReport : 'https://github.com/Freemius/wordpress-sdk/issues',
32
+ lastTranslator : 'Vova Feldman <vova@freemius.com>',
33
+ team : 'Freemius Team <admin@freemius.com>',
34
+ /*gettextMethods: {
35
+ instances: ['this', '_fs'],
36
+ methods: [
37
+ 'get_text_inline'
38
+ ]
39
+ },*/
40
+ gettextFunctions: [
41
+ {name: 'get_text_inline'},
42
+
43
+ {name: 'fs_text_inline'},
44
+ {name: 'fs_echo_inline'},
45
+ {name: 'fs_esc_js_inline'},
46
+ {name: 'fs_esc_attr_inline'},
47
+ {name: 'fs_esc_attr_echo_inline'},
48
+ {name: 'fs_esc_html_inline'},
49
+ {name: 'fs_esc_html_echo_inline'},
50
+
51
+ {name: 'get_text_x_inline', context: 2},
52
+ {name: 'fs_text_x_inline', context: 2},
53
+ {name: 'fs_echo_x_inline', context: 2},
54
+ {name: 'fs_esc_attr_x_inline', context: 2},
55
+ {name: 'fs_esc_js_x_inline', context: 2},
56
+ {name: 'fs_esc_js_echo_x_inline', context: 2},
57
+ {name: 'fs_esc_html_x_inline', context: 2},
58
+ {name: 'fs_esc_html_echo_x_inline', context: 2}
59
+ /*,
60
+
61
+
62
+ {name: '_fs_text'},
63
+ {name: '_fs_x', context: 2},
64
+ {name: '_fs_echo'},
65
+ {name: '_fs_esc_attr'},
66
+ {name: '_fs_esc_attr_echo'},
67
+ {name: '_fs_esc_html'},
68
+ {name: '_fs_esc_html_echo'},
69
+ {name: '_fs_ex', context: 2},
70
+ {name: '_fs_esc_attr_x', context: 2},
71
+ {name: '_fs_esc_html_x', context: 2},
72
+
73
+ {name: '_fs_n', plural: 2},
74
+ {name: '_fs_n_noop', plural: 2},
75
+ {name: '_fs_nx', plural: 2, context: 4},
76
+ {name: '_fs_nx_noop', plural: 2, context: 3}*/
77
+ ]
78
+ }))
79
+ .pipe(gulp.dest(languagesFolder + 'freemius.pot'));
80
+
81
+ // Create English PO out of the POT.
82
+ return gulp.src(languagesFolder + 'freemius.pot')
83
+ .pipe(pofill({
84
+ items: function (item) {
85
+ // If msgstr is empty, use identity translation
86
+ if (!item.msgstr.length) {
87
+ item.msgstr = [''];
88
+ }
89
+ if (!item.msgstr[0]) {
90
+ item.msgstr[0] = item.msgid;
91
+ }
92
+ return item;
93
+ }
94
+ }))
95
+ .pipe(rename('freemius-en.po'))
96
+ .pipe(gulp.dest(languagesFolder));
97
+ });
98
+
99
+ // Push updated po resource to transifex.
100
+ gulp.task('update-transifex', ['prepare-source'], function () {
101
+ return gulp.src(languagesFolder + 'freemius-en.po')
102
+ .pipe(transifex.pushResource());
103
+ });
104
+
105
+ // Download latest *.po translations.
106
+ gulp.task('download-translations', ['update-transifex'], function () {
107
+ return gulp.src(languagesFolder + 'freemius-en.po')
108
+ .pipe(transifex.pullResource());
109
+ });
110
+
111
+ // Move translations to languages root.
112
+ gulp.task('prepare-translations', ['download-translations'], function () {
113
+ var folders = getFolders(languagesFolder);
114
+
115
+ return folders.map(function (folder) {
116
+ return gulp.src(path.join(languagesFolder, folder, 'freemius-en.po'))
117
+ .pipe(rename('freemius-' + folder + '.po'))
118
+ .pipe(gulp.dest(languagesFolder));
119
+ });
120
+ });
121
+
122
+ // Feel up empty translations with English.
123
+ gulp.task('translations-feelup', ['prepare-translations'], function () {
124
+ return gulp.src(languagesFolder + '*.po')
125
+ .pipe(pofill({
126
+ items: function (item) {
127
+ // If msgstr is empty, use identity translation
128
+ if (0 == item.msgstr.length) {
129
+ item.msgstr = [''];
130
+ }
131
+ if (0 == item.msgstr[0].length) {
132
+ // item.msgid[0] = item.msgid;
133
+ item.msgstr[0] = item.msgid;
134
+ }
135
+ return item;
136
+ }
137
+ }))
138
+ .pipe(gulp.dest(languagesFolder));
139
+ });
140
+
141
+ // Cleanup temporary translation folders.
142
+ gulp.task('cleanup', ['prepare-translations'], function () {
143
+ var folders = getFolders(languagesFolder);
144
+
145
+ return folders.map(function (folder) {
146
+ return gulp.src(path.join(languagesFolder, folder), {read: false})
147
+ .pipe(clean());
148
+ });
149
+ });
150
+
151
+ // Compile *.po to *.mo binaries for usage.
152
+ gulp.task('compile-translations', ['translations-feelup'], function () {
153
+ // Compile POs to MOs.
154
+ return gulp.src(languagesFolder + '*.po')
155
+ .pipe(gettext())
156
+ .pipe(gulp.dest(languagesFolder))
157
+ });
158
+
159
+ gulp.task('default', [], function () {
160
+ gulp.run('prepare-source');
161
+ gulp.run('update-transifex');
162
+ gulp.run('download-translations');
163
+ gulp.run('prepare-translations');
164
+ gulp.run('translations-feelup');
165
+ gulp.run('cleanup');
166
+ gulp.run('compile-translations');
167
+ });
vendor/freemius/wordpress-sdk/includes/class-freemius-abstract.php ADDED
@@ -0,0 +1,597 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ }
vendor/freemius/wordpress-sdk/includes/class-freemius.php ADDED
@@ -0,0 +1,21773 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 1.1.6
169
+ * @var string[]bool.
170
+ */
171
+ private $_permissions;
172
+
173
+ /**
174
+ * @var FS_Storage
175
+ */
176
+ private $_storage;
177
+
178
+ /**
179
+ * @since 1.2.2.7
180
+ * @var FS_Cache_Manager
181
+ */
182
+ private $_cache;
183
+
184
+ /**
185
+ * @since 1.0.0
186
+ *
187
+ * @var FS_Logger
188
+ */
189
+ private $_logger;
190
+ /**
191
+ * @since 1.0.4
192
+ *
193
+ * @var FS_Plugin
194
+ */
195
+ private $_plugin = false;
196
+ /**
197
+ * @since 1.0.4
198
+ *
199
+ * @var FS_Plugin|false
200
+ */
201
+ private $_parent_plugin = false;
202
+ /**
203
+ * @since 1.1.1
204
+ *
205
+ * @var Freemius
206
+ */
207
+ private $_parent = false;
208
+ /**
209
+ * @since 1.0.1
210
+ *
211
+ * @var FS_User
212
+ */
213
+ private $_user = false;
214
+ /**
215
+ * @since 1.0.1
216
+ *
217
+ * @var FS_Site
218
+ */
219
+ private $_site = false;
220
+ /**
221
+ * @since 1.0.1
222
+ *
223
+ * @var FS_Plugin_License
224
+ */
225
+ private $_license;
226
+ /**
227
+ * @since 1.0.2
228
+ *
229
+ * @var FS_Plugin_Plan[]
230
+ */
231
+ private $_plans = false;
232
+ /**
233
+ * @var FS_Plugin_License[]
234
+ * @since 1.0.5
235
+ */
236
+ private $_licenses = false;
237
+
238
+ /**
239
+ * @since 1.0.1
240
+ *
241
+ * @var FS_Admin_Menu_Manager
242
+ */
243
+ private $_menu;
244
+
245
+ /**
246
+ * @var FS_Admin_Notices
247
+ */
248
+ private $_admin_notices;
249
+
250
+ /**
251
+ * @since 1.1.6
252
+ *
253
+ * @var FS_Admin_Notices
254
+ */
255
+ private static $_global_admin_notices;
256
+
257
+ /**
258
+ * @var FS_Logger
259
+ * @since 1.0.0
260
+ */
261
+ private static $_static_logger;
262
+
263
+ /**
264
+ * @var FS_Options
265
+ * @since 1.0.2
266
+ */
267
+ private static $_accounts;
268
+
269
+ /**
270
+ * @since 1.2.2
271
+ *
272
+ * @var number
273
+ */
274
+ private $_module_id;
275
+
276
+ /**
277
+ * @var Freemius[]
278
+ */
279
+ private static $_instances = array();
280
+
281
+ /**
282
+ * @since 1.2.3
283
+ *
284
+ * @var FS_Affiliate
285
+ */
286
+ private $affiliate = null;
287
+
288
+ /**
289
+ * @since 1.2.3
290
+ *
291
+ * @var FS_AffiliateTerms
292
+ */
293
+ private $plugin_affiliate_terms = null;
294
+
295
+ /**
296
+ * @since 1.2.3
297
+ *
298
+ * @var FS_AffiliateTerms
299
+ */
300
+ private $custom_affiliate_terms = null;
301
+
302
+ /**
303
+ * @since 2.0.0
304
+ *
305
+ * @var bool
306
+ */
307
+ private $_is_multisite_integrated;
308
+
309
+ /**
310
+ * @since 2.0.0
311
+ *
312
+ * @var bool True if the current request is for a network admin screen and the plugin is network active.
313
+ */
314
+ private $_is_network_active;
315
+
316
+ /**
317
+ * @since 2.0.0
318
+ *
319
+ * @var int|null The original blog ID the plugin was loaded with.
320
+ */
321
+ private $_blog_id = null;
322
+
323
+ /**
324
+ * @since 2.0.0
325
+ *
326
+ * @var int|null The current execution context. When true, run on network context. When int, run on the specified blog context.
327
+ */
328
+ private $_context_is_network_or_blog_id = null;
329
+
330
+ /**
331
+ * @since 2.0.0
332
+ *
333
+ * @var string
334
+ */
335
+ private $_dynamically_added_top_level_page_hook_name = '';
336
+
337
+ #region Uninstall Reasons IDs
338
+
339
+ const REASON_NO_LONGER_NEEDED = 1;
340
+ const REASON_FOUND_A_BETTER_PLUGIN = 2;
341
+ const REASON_NEEDED_FOR_A_SHORT_PERIOD = 3;
342
+ const REASON_BROKE_MY_SITE = 4;
343
+ const REASON_SUDDENLY_STOPPED_WORKING = 5;
344
+ const REASON_CANT_PAY_ANYMORE = 6;
345
+ const REASON_OTHER = 7;
346
+ const REASON_DIDNT_WORK = 8;
347
+ const REASON_DONT_LIKE_TO_SHARE_MY_INFORMATION = 9;
348
+ const REASON_COULDNT_MAKE_IT_WORK = 10;
349
+ const REASON_GREAT_BUT_NEED_SPECIFIC_FEATURE = 11;
350
+ const REASON_NOT_WORKING = 12;
351
+ const REASON_NOT_WHAT_I_WAS_LOOKING_FOR = 13;
352
+ const REASON_DIDNT_WORK_AS_EXPECTED = 14;
353
+ const REASON_TEMPORARY_DEACTIVATION = 15;
354
+
355
+ #endregion
356
+
357
+ /* Ctor
358
+ ------------------------------------------------------------------------------------------------------------------*/
359
+
360
+ /**
361
+ * Main singleton instance.
362
+ *
363
+ * @author Vova Feldman (@svovaf)
364
+ * @since 1.0.0
365
+ *
366
+ * @param number $module_id
367
+ * @param string|bool $slug
368
+ * @param bool $is_init Since 1.2.1 Is initiation sequence.
369
+ */
370
+ private function __construct( $module_id, $slug = false, $is_init = false ) {
371
+ if ( $is_init && is_numeric( $module_id ) && is_string( $slug ) ) {
372
+ $this->store_id_slug_type_path_map( $module_id, $slug );
373
+ }
374
+
375
+ $this->_module_id = $module_id;
376
+ $this->_slug = $this->get_slug();
377
+ $this->_module_type = $this->get_module_type();
378
+
379
+ $this->_blog_id = is_multisite() ? get_current_blog_id() : null;
380
+
381
+ $this->_storage = FS_Storage::instance( $this->_module_type, $this->_slug );
382
+
383
+ $this->_cache = FS_Cache_Manager::get_manager( WP_FS___OPTION_PREFIX . "cache_{$module_id}" );
384
+
385
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $this->get_unique_affix(), WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
386
+
387
+ $this->_plugin_main_file_path = $this->_find_caller_plugin_file( $is_init );
388
+ $this->_plugin_dir_path = plugin_dir_path( $this->_plugin_main_file_path );
389
+ $this->_plugin_basename = $this->get_plugin_basename();
390
+ $this->_free_plugin_basename = str_replace( '-premium/', '/', $this->_plugin_basename );
391
+
392
+ $this->_is_multisite_integrated = (
393
+ defined( "WP_FS__PRODUCT_{$module_id}_MULTISITE" ) &&
394
+ ( true === constant( "WP_FS__PRODUCT_{$module_id}_MULTISITE" ) )
395
+ );
396
+
397
+ $this->_is_network_active = (
398
+ is_multisite() &&
399
+ $this->_is_multisite_integrated &&
400
+ // Themes are always network activated, but the ACTUAL activation is per site.
401
+ $this->is_plugin() &&
402
+ ( is_plugin_active_for_network( $this->_plugin_basename ) ||
403
+ // Plugin network level activation or uninstall.
404
+ is_plugin_inactive( $this->_plugin_basename ) )
405
+ );
406
+
407
+ $this->_storage->set_network_active(
408
+ $this->_is_network_active,
409
+ $this->is_delegated_connection()
410
+ );
411
+
412
+ #region Migration
413
+
414
+ if ( is_multisite() ) {
415
+ /**
416
+ * If the install_timestamp exists on the site level but doesn't exist on the
417
+ * network level storage, it means that we need to process the storage with migration.
418
+ *
419
+ * 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.
420
+ *
421
+ * @author Vova Feldman (@svovaf)
422
+ * @since 2.0.0
423
+ */
424
+ if ( false === $this->_storage->get( 'install_timestamp', false, true ) &&
425
+ false !== $this->_storage->get( 'install_timestamp', false, false )
426
+ ) {
427
+ // Initiate storage migration.
428
+ $this->_storage->migrate_to_network();
429
+
430
+ // Migrate module cache to network level storage.
431
+ $this->_cache->migrate_to_network();
432
+ }
433
+ }
434
+
435
+ #endregion
436
+
437
+ $base_name_split = explode( '/', $this->_plugin_basename );
438
+ $this->_plugin_dir_name = $base_name_split[0];
439
+
440
+ if ( $this->_logger->is_on() ) {
441
+ $this->_logger->info( 'plugin_main_file_path = ' . $this->_plugin_main_file_path );
442
+ $this->_logger->info( 'plugin_dir_path = ' . $this->_plugin_dir_path );
443
+ $this->_logger->info( 'plugin_basename = ' . $this->_plugin_basename );
444
+ $this->_logger->info( 'free_plugin_basename = ' . $this->_free_plugin_basename );
445
+ $this->_logger->info( 'plugin_dir_name = ' . $this->_plugin_dir_name );
446
+ }
447
+
448
+ // Remember link between file to slug.
449
+ $this->store_file_slug_map();
450
+
451
+ // Store plugin's initial install timestamp.
452
+ if ( ! isset( $this->_storage->install_timestamp ) ) {
453
+ $this->_storage->install_timestamp = WP_FS__SCRIPT_START_TIME;
454
+ }
455
+
456
+ if ( ! is_object( $this->_plugin ) ) {
457
+ $this->_plugin = FS_Plugin_Manager::instance( $this->_module_id )->get();
458
+ }
459
+
460
+ $this->_admin_notices = FS_Admin_Notices::instance(
461
+ $this->_slug . ( $this->is_theme() ? ':theme' : '' ),
462
+ /**
463
+ * Ensure that the admin notice will always have a title by using the stored plugin title if available and
464
+ * retrieving the title via the "get_plugin_name" method if there is no stored plugin title available.
465
+ *
466
+ * @author Leo Fajardo (@leorw)
467
+ * @since 1.2.2
468
+ */
469
+ ( is_object( $this->_plugin ) ? $this->_plugin->title : $this->get_plugin_name() ),
470
+ $this->get_unique_affix()
471
+ );
472
+
473
+ if ( 'true' === fs_request_get( 'fs_clear_api_cache' ) ||
474
+ 'true' === fs_request_is_action( 'restart_freemius' )
475
+ ) {
476
+ FS_Api::clear_cache();
477
+ $this->_cache->clear();
478
+ }
479
+
480
+ $this->_register_hooks();
481
+
482
+ /**
483
+ * Starting from version 2.0.0, `FS_Site` entities no longer have the `plan` property and have `plan_id`
484
+ * instead. This should be called before calling `_load_account()`, otherwise, `$this->_site` will not be
485
+ * loaded in `_load_account` for versions of SDK starting from 2.0.0.
486
+ *
487
+ * @author Leo Fajardo (@leorw)
488
+ */
489
+ self::migrate_install_plan_to_plan_id( $this->_storage );
490
+
491
+ $this->_load_account();
492
+
493
+ $this->_version_updates_handler();
494
+ }
495
+
496
+ /**
497
+ * Checks whether this module has a settings menu.
498
+ *
499
+ * @author Leo Fajardo (@leorw)
500
+ * @since 1.2.2
501
+ *
502
+ * @return bool
503
+ */
504
+ function has_settings_menu() {
505
+ return ( $this->_is_network_active && fs_is_network_admin() ) ?
506
+ $this->_menu->has_network_menu() :
507
+ $this->_menu->has_menu();
508
+ }
509
+
510
+ /**
511
+ * Check if the context module is free wp.org theme.
512
+ *
513
+ * This method is helpful because:
514
+ * 1. wp.org themes are limited to a single submenu item,
515
+ * and sub-submenu items are most likely not allowed (never verified).
516
+ * 2. wp.org themes are not allowed to redirect the user
517
+ * after the theme activation, therefore, the agreed UX
518
+ * is showing the opt-in as a modal dialog box after
519
+ * activation (approved by @otto42, @emiluzelac, @greenshady, @grapplerulrich).
520
+ *
521
+ * @author Vova Feldman (@svovaf)
522
+ * @since 1.2.2.7
523
+ *
524
+ * @return bool
525
+ */
526
+ function is_free_wp_org_theme() {
527
+ return (
528
+ $this->is_theme() &&
529
+ $this->is_org_repo_compliant() &&
530
+ ! $this->is_premium()
531
+ );
532
+ }
533
+
534
+ /**
535
+ * Checks whether this a submenu item is visible.
536
+ *
537
+ * @author Vova Feldman (@svovaf)
538
+ * @since 1.2.2.6
539
+ * @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.
540
+ *
541
+ * @param string $slug
542
+ * @param bool $ignore_free_wp_org_theme_context This is used to decide if the associated tab should be shown
543
+ * or hidden.
544
+ *
545
+ * @return bool
546
+ */
547
+ function is_submenu_item_visible( $slug, $ignore_free_wp_org_theme_context = false ) {
548
+ if ( $this->is_admin_page( $slug ) ) {
549
+ /**
550
+ * It is the current context page, so show the submenu item
551
+ * so the user will have the right context page, even if it
552
+ * was set to hidden.
553
+ */
554
+ return true;
555
+ }
556
+
557
+ if ( ! $this->has_settings_menu() ) {
558
+ // No menu settings at all.
559
+ return false;
560
+ }
561
+
562
+ if ( ! $ignore_free_wp_org_theme_context && $this->is_free_wp_org_theme() ) {
563
+ /**
564
+ * wp.org themes are limited to a single submenu item, and
565
+ * sub-submenu items are most likely not allowed (never verified).
566
+ */
567
+ return false;
568
+ }
569
+
570
+ return $this->_menu->is_submenu_item_visible( $slug );
571
+ }
572
+
573
+ /**
574
+ * Check if a Freemius page should be accessible via the UI.
575
+ *
576
+ * @author Vova Feldman (@svovaf)
577
+ * @since 1.2.2.7
578
+ *
579
+ * @param string $slug
580
+ *
581
+ * @return bool
582
+ */
583
+ function is_page_visible( $slug ) {
584
+ if ( $this->is_admin_page( $slug ) ) {
585
+ return true;
586
+ }
587
+
588
+ return $this->_menu->is_submenu_item_visible( $slug, true, true );
589
+ }
590
+
591
+ /**
592
+ * @author Vova Feldman (@svovaf)
593
+ * @since 1.0.9
594
+ */
595
+ private function _version_updates_handler() {
596
+ if ( ! isset( $this->_storage->sdk_version ) || $this->_storage->sdk_version != $this->version ) {
597
+ // Freemius version upgrade mode.
598
+ $this->_storage->sdk_last_version = $this->_storage->sdk_version;
599
+ $this->_storage->sdk_version = $this->version;
600
+
601
+ if ( empty( $this->_storage->sdk_last_version ) ||
602
+ version_compare( $this->_storage->sdk_last_version, $this->version, '<' )
603
+ ) {
604
+ $this->_storage->sdk_upgrade_mode = true;
605
+ $this->_storage->sdk_downgrade_mode = false;
606
+ } else {
607
+ $this->_storage->sdk_downgrade_mode = true;
608
+ $this->_storage->sdk_upgrade_mode = false;
609
+
610
+ }
611
+
612
+ $this->do_action( 'sdk_version_update', $this->_storage->sdk_last_version, $this->version );
613
+ }
614
+
615
+ $plugin_version = $this->get_plugin_version();
616
+ if ( ! isset( $this->_storage->plugin_version ) || $this->_storage->plugin_version != $plugin_version ) {
617
+ // Plugin version upgrade mode.
618
+ $this->_storage->plugin_last_version = $this->_storage->plugin_version;
619
+ $this->_storage->plugin_version = $plugin_version;
620
+
621
+ if ( empty( $this->_storage->plugin_last_version ) ||
622
+ version_compare( $this->_storage->plugin_last_version, $plugin_version, '<' )
623
+ ) {
624
+ $this->_storage->plugin_upgrade_mode = true;
625
+ $this->_storage->plugin_downgrade_mode = false;
626
+ } else {
627
+ $this->_storage->plugin_downgrade_mode = true;
628
+ $this->_storage->plugin_upgrade_mode = false;
629
+ }
630
+
631
+ if ( ! empty( $this->_storage->plugin_last_version ) ) {
632
+ // Different version of the plugin was installed before, therefore it's an update.
633
+ $this->_storage->is_plugin_new_install = false;
634
+ }
635
+
636
+ $this->do_action( 'plugin_version_update', $this->_storage->plugin_last_version, $plugin_version );
637
+ }
638
+ }
639
+
640
+ #--------------------------------------------------------------------------------
641
+ #region Data Migration on SDK Update
642
+ #--------------------------------------------------------------------------------
643
+
644
+ /**
645
+ * @author Vova Feldman (@svovaf)
646
+ * @since 1.1.5
647
+ *
648
+ * @param string $sdk_prev_version
649
+ * @param string $sdk_version
650
+ */
651
+ function _sdk_version_update( $sdk_prev_version, $sdk_version ) {
652
+ /**
653
+ * @since 1.1.7.3 Fixed unwanted connectivity test cleanup.
654
+ */
655
+ if ( empty( $sdk_prev_version ) ) {
656
+ return;
657
+ }
658
+
659
+ if ( version_compare( $sdk_prev_version, '2.1.0', '<' ) &&
660
+ version_compare( $sdk_version, '2.1.0', '>=' )
661
+ ) {
662
+ $this->_storage->handle_gdpr_admin_notice = true;
663
+ }
664
+
665
+ if ( version_compare( $sdk_prev_version, '2.0.0', '<' ) &&
666
+ version_compare( $sdk_version, '2.0.0', '>=' )
667
+ ) {
668
+ $this->migrate_to_subscriptions_collection();
669
+
670
+ $this->consolidate_licenses();
671
+
672
+ // Clear trial_plan since it's now loaded from the plans collection when needed.
673
+ $this->_storage->remove( 'trial_plan', true, false );
674
+ }
675
+
676
+ if ( version_compare( $sdk_prev_version, '1.2.3', '<' ) &&
677
+ version_compare( $sdk_version, '1.2.3', '>=' )
678
+ ) {
679
+ /**
680
+ * Starting from version 1.2.3, paths are stored as relative instead of absolute and some of them can be
681
+ * invalid.
682
+ *
683
+ * @author Leo Fajardo (@leorw)
684
+ */
685
+ $this->remove_invalid_paths();
686
+ }
687
+
688
+ if ( version_compare( $sdk_prev_version, '1.1.5', '<' ) &&
689
+ version_compare( $sdk_version, '1.1.5', '>=' )
690
+ ) {
691
+ // On version 1.1.5 merged connectivity and is_on data.
692
+ if ( isset( $this->_storage->connectivity_test ) ) {
693
+ if ( ! isset( $this->_storage->is_on ) ) {
694
+ unset( $this->_storage->connectivity_test );
695
+ } else {
696
+ $connectivity_data = $this->_storage->connectivity_test;
697
+ $connectivity_data['is_active'] = $this->_storage->is_on['is_active'];
698
+ $connectivity_data['timestamp'] = $this->_storage->is_on['timestamp'];
699
+
700
+ // Override.
701
+ $this->_storage->connectivity_test = $connectivity_data;
702
+
703
+ // Remove previous structure.
704
+ unset( $this->_storage->is_on );
705
+ }
706
+
707
+ }
708
+ }
709
+
710
+ if (
711
+ version_compare( $sdk_prev_version, '2.2.1', '<' ) &&
712
+ version_compare( $sdk_version, '2.2.1', '>=' )
713
+ ) {
714
+ /**
715
+ * Clear the file cache without storing the previous path since it could be a wrong path. For example,
716
+ * 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
717
+ * as the parent plugin's when the add-on was auto-installed since the relevant method names were not
718
+ * skipped in the logic that determines the right path in the `get_caller_main_file_and_type` method
719
+ * (e.g. `try_activate_plugin`). Since it was an auto-installation, the caller was the parent plugin
720
+ * and so its path was used. In case the stored path is wrong, clearing the cache will resolve issues
721
+ * related to data mix-up between plugins (e.g. titles and versions of an add-on and its parent plugin).
722
+ *
723
+ * @author Leo Fajardo (@leorw)
724
+ * @since 2.2.1
725
+ */
726
+ $this->clear_module_main_file_cache( false );
727
+ }
728
+ }
729
+
730
+ /**
731
+ * @author Leo Fajardo (@leorw)
732
+ * @since 2.0.0
733
+ *
734
+ * @param \FS_Storage $storage
735
+ * @param bool|int|null $blog_id
736
+ */
737
+ private static function migrate_install_plan_to_plan_id( FS_Storage $storage, $blog_id = null ) {
738
+ if ( empty( $storage->sdk_version ) ) {
739
+ // New installation of the plugin, no need to upgrade.
740
+ return;
741
+ }
742
+
743
+ if ( ! version_compare( $storage->sdk_version, '2.0.0', '<' ) ) {
744
+ // Previous version is >= 2.0.0, so no need to migrate.
745
+ return;
746
+ }
747
+
748
+ // Alias.
749
+ $module_type = $storage->get_module_type();
750
+ $module_slug = $storage->get_module_slug();
751
+
752
+ $installs = self::get_all_sites( $module_type, $blog_id );
753
+ $install = isset( $installs[ $module_slug ] ) ? $installs[ $module_slug ] : null;
754
+
755
+ if ( ! is_object( $install ) ) {
756
+ return;
757
+ }
758
+
759
+ if ( isset( $install->plan ) && is_object( $install->plan ) ) {
760
+ if ( isset( $install->plan->id ) && ! empty( $install->plan->id ) ) {
761
+ $install->plan_id = self::_decrypt( $install->plan->id );
762
+ }
763
+
764
+ unset( $install->plan );
765
+
766
+ $installs[ $module_slug ] = clone $install;
767
+
768
+ self::set_account_option_by_module(
769
+ $module_type,
770
+ 'sites',
771
+ $installs,
772
+ true,
773
+ $blog_id
774
+ );
775
+ }
776
+ }
777
+
778
+ /**
779
+ * @author Leo Fajardo (@leorw)
780
+ * @since 2.0.0
781
+ */
782
+ private function migrate_to_subscriptions_collection() {
783
+ if ( ! is_object( $this->_site ) ) {
784
+ return;
785
+ }
786
+
787
+ if ( isset( $this->_storage->subscription ) && is_object( $this->_storage->subscription ) ) {
788
+ $this->_storage->subscriptions = array( $this->_storage->subscription );
789
+ }
790
+ }
791
+
792
+ /**
793
+ * @author Leo Fajardo (@leorw)
794
+ * @since 2.0.0
795
+ */
796
+ private function consolidate_licenses() {
797
+ $plugin_licenses = self::get_account_option( 'licenses', WP_FS__MODULE_TYPE_PLUGIN );
798
+ if ( isset( $plugin_licenses[ $this->_slug ] ) ) {
799
+ $plugin_licenses = $plugin_licenses[ $this->_slug ];
800
+ } else {
801
+ $plugin_licenses = array();
802
+ }
803
+
804
+ $theme_licenses = self::get_account_option( 'licenses', WP_FS__MODULE_TYPE_THEME );
805
+ if ( isset( $theme_licenses[ $this->_slug ] ) ) {
806
+ $theme_licenses = $theme_licenses[ $this->_slug ];
807
+ } else {
808
+ $theme_licenses = array();
809
+ }
810
+
811
+ if ( empty( $plugin_licenses ) && empty( $theme_licenses ) ) {
812
+ return;
813
+ }
814
+
815
+ $all_licenses = array();
816
+ $user_id_license_ids_map = array();
817
+
818
+ foreach ( $plugin_licenses as $user_id => $user_licenses ) {
819
+ if ( is_array( $user_licenses ) ) {
820
+ if ( ! isset( $user_license_ids[ $user_id ] ) ) {
821
+ $user_id_license_ids_map[ $user_id ] = array();
822
+ }
823
+
824
+ foreach ( $user_licenses as $user_license ) {
825
+ $all_licenses[] = $user_license;
826
+ $user_id_license_ids_map[ $user_id ][] = $user_license->id;
827
+ }
828
+ }
829
+ }
830
+
831
+ foreach ( $theme_licenses as $user_id => $user_licenses ) {
832
+ if ( is_array( $user_licenses ) ) {
833
+ if ( ! isset( $user_license_ids[ $user_id ] ) ) {
834
+ $user_id_license_ids_map[ $user_id ] = array();
835
+ }
836
+
837
+ foreach ( $user_licenses as $user_license ) {
838
+ $all_licenses[] = $user_license;
839
+ $user_id_license_ids_map[ $user_id ][] = $user_license->id;
840
+ }
841
+ }
842
+ }
843
+
844
+ self::store_user_id_license_ids_map(
845
+ $user_id_license_ids_map,
846
+ $this->_module_id
847
+ );
848
+
849
+ $this->_store_licenses( true, $this->_module_id, $all_licenses );
850
+ }
851
+
852
+ /**
853
+ * Remove invalid paths.
854
+ *
855
+ * @author Leo Fajardo (@leorw)
856
+ * @since 1.2.3
857
+ */
858
+ private function remove_invalid_paths() {
859
+ // Remove invalid path that is still associated with the current slug if there's any.
860
+ $file_slug_map = self::$_accounts->get_option( 'file_slug_map', array() );
861
+ foreach ( $file_slug_map as $plugin_basename => $slug ) {
862
+ if ( $slug === $this->_slug &&
863
+ $plugin_basename !== $this->_plugin_basename &&
864
+ ! file_exists( $this->get_absolute_path( $plugin_basename ) )
865
+ ) {
866
+ unset( $file_slug_map[ $plugin_basename ] );
867
+ self::$_accounts->set_option( 'file_slug_map', $file_slug_map, true );
868
+
869
+ break;
870
+ }
871
+ }
872
+ }
873
+
874
+ /**
875
+ * @author Vova Feldman (@svovaf)
876
+ * @since 1.2.2.7
877
+ *
878
+ * @param string $plugin_prev_version
879
+ * @param string $plugin_version
880
+ */
881
+ function _after_version_update( $plugin_prev_version, $plugin_version ) {
882
+ if ( $this->is_theme() ) {
883
+ // Expire the cache of the previous tabs since the theme may
884
+ // have setting updates.
885
+ $this->_cache->expire( 'tabs' );
886
+ $this->_cache->expire( 'tabs_stylesheets' );
887
+ }
888
+ }
889
+
890
+ /**
891
+ * A special migration logic for the $_accounts, executed for all the plugins in the system:
892
+ * - Moves some data to the network level storage.
893
+ * - If the plugin's connection was skipped for all sites, set the plugin as if it was network skipped.
894
+ * - If the plugin's connection was ignored for all sites, don't do anything in terms of the network connection.
895
+ * - 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.
896
+ * - 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.
897
+ * - 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.
898
+ *
899
+ * @author Vova Feldman (@svovaf)
900
+ * @since 2.0.0
901
+ */
902
+ private static function migrate_accounts_to_network() {
903
+ $sites = self::get_sites();
904
+ $sites_count = count( $sites );
905
+ $connection_status = array();
906
+ $plugin_slugs = array();
907
+ foreach ( $sites as $site ) {
908
+ $blog_id = self::get_site_blog_id( $site );
909
+
910
+ self::$_accounts->migrate_to_network( $blog_id );
911
+
912
+ /**
913
+ * Build a list of all Freemius powered plugins slugs.
914
+ */
915
+ $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array(), $blog_id );
916
+ foreach ( $id_slug_type_path_map as $module_id => $data ) {
917
+ if ( WP_FS__MODULE_TYPE_PLUGIN === $data['type'] ) {
918
+ $plugin_slugs[ $data['slug'] ] = true;
919
+ }
920
+ }
921
+
922
+ $installs = self::get_account_option( 'sites', WP_FS__MODULE_TYPE_PLUGIN, $blog_id );
923
+
924
+ if ( is_array( $installs ) ) {
925
+ foreach ( $installs as $slug => $install ) {
926
+ if ( ! isset( $connection_status[ $slug ] ) ) {
927
+ $connection_status[ $slug ] = array();
928
+ }
929
+
930
+ if ( is_object( $install ) &&
931
+ FS_Site::is_valid_id( $install->id ) &&
932
+ FS_User::is_valid_id( $install->user_id )
933
+ ) {
934
+ $connection_status[ $slug ][ $blog_id ] = $install->user_id;
935
+ }
936
+ }
937
+ }
938
+ }
939
+
940
+ foreach ( $plugin_slugs as $slug => $true ) {
941
+ if ( ! isset( $connection_status[ $slug ] ) ) {
942
+ $connection_status[ $slug ] = array();
943
+ }
944
+
945
+ foreach ( $sites as $site ) {
946
+ $blog_id = self::get_site_blog_id( $site );
947
+
948
+ if ( isset( $connection_status[ $slug ][ $blog_id ] ) ) {
949
+ continue;
950
+ }
951
+
952
+ $storage = FS_Storage::instance( WP_FS__MODULE_TYPE_PLUGIN, $slug );
953
+
954
+ $is_anonymous = $storage->get( 'is_anonymous', null, $blog_id );
955
+
956
+ if ( ! is_null( $is_anonymous ) ) {
957
+ // Since 1.1.3 is_anonymous is an array.
958
+ if ( is_array( $is_anonymous ) && isset( $is_anonymous['is'] ) ) {
959
+ $is_anonymous = $is_anonymous['is'];
960
+ }
961
+
962
+ if ( is_bool( $is_anonymous ) && true === $is_anonymous ) {
963
+ $connection_status[ $slug ][ $blog_id ] = 'skipped';
964
+ }
965
+ }
966
+
967
+ if ( ! isset( $connection_status[ $slug ][ $blog_id ] ) ) {
968
+ $connection_status[ $slug ][ $blog_id ] = 'ignored';
969
+ }
970
+ }
971
+ }
972
+
973
+ $super_admins = array();
974
+
975
+ foreach ( $connection_status as $slug => $blogs_status ) {
976
+ $skips = 0;
977
+ $ignores = 0;
978
+ $connections = 0;
979
+ $opted_in_users = array();
980
+ $opted_in_super_admins = array();
981
+
982
+ $storage = FS_Storage::instance( WP_FS__MODULE_TYPE_PLUGIN, $slug );
983
+
984
+ foreach ( $blogs_status as $blog_id => $status_or_user_id ) {
985
+ if ( 'skipped' === $status_or_user_id ) {
986
+ $skips ++;
987
+ } else if ( 'ignored' === $status_or_user_id ) {
988
+ $ignores ++;
989
+ } else if ( FS_User::is_valid_id( $status_or_user_id ) ) {
990
+ $connections ++;
991
+
992
+ if ( ! isset( $opted_in_users[ $status_or_user_id ] ) ) {
993
+ $opted_in_users[ $status_or_user_id ] = array();
994
+ }
995
+
996
+ $opted_in_users[ $status_or_user_id ][] = $blog_id;
997
+
998
+ if ( isset( $super_admins[ $status_or_user_id ] ) ||
999
+ self::is_super_admin( $status_or_user_id )
1000
+ ) {
1001
+ // Cache super-admin data.
1002
+ $super_admins[ $status_or_user_id ] = true;
1003
+
1004
+ // Remember opted-in super-admins for the plugin.
1005
+ $opted_in_super_admins[ $status_or_user_id ] = true;
1006
+ }
1007
+ }
1008
+ }
1009
+
1010
+ $main_super_admin_user_id = null;
1011
+ $all_migrated = false;
1012
+ if ( $sites_count == $skips ) {
1013
+ // All sites were skipped -> network skip by copying the anonymous mode from any of the sites.
1014
+ $storage->is_anonymous_ms = $storage->is_anonymous;
1015
+
1016
+ $all_migrated = true;
1017
+ } else if ( $sites_count == $ignores ) {
1018
+ // Don't do anything, still in activation mode.
1019
+
1020
+ $all_migrated = true;
1021
+ } else if ( 0 < count( $opted_in_super_admins ) ) {
1022
+ // Find the super-admin with the majority of installs.
1023
+ $max_installs_by_super_admin = 0;
1024
+ foreach ( $opted_in_super_admins as $user_id => $true ) {
1025
+ $installs_count = count( $opted_in_users[ $user_id ] );
1026
+
1027
+ if ( $installs_count > $max_installs_by_super_admin ) {
1028
+ $max_installs_by_super_admin = $installs_count;
1029
+ $main_super_admin_user_id = $user_id;
1030
+ }
1031
+ }
1032
+
1033
+ if ( $sites_count == $connections && 1 == count( $opted_in_super_admins ) ) {
1034
+ // Super-admin opted-in for all sites in the network.
1035
+ $storage->is_network_connected = true;
1036
+
1037
+ $all_migrated = true;
1038
+ }
1039
+
1040
+ // Store network user.
1041
+ $storage->network_user_id = $main_super_admin_user_id;
1042
+
1043
+ $storage->network_install_blog_id = ( $sites_count == $connections ) ?
1044
+ // Since all sites are opted-in, associating with the main site.
1045
+ get_current_blog_id() :
1046
+ // Associating with the 1st found opted-in site.
1047
+ $opted_in_users[ $main_super_admin_user_id ][0];
1048
+
1049
+ /**
1050
+ * Make sure we migrate the plan ID of the network install, otherwise, if after the migration
1051
+ * the 1st page that will be loaded is the network level WP Admin and $storage->network_install_blog_id
1052
+ * is different than the main site of the network, the $this->_site will not be set since the plan_id
1053
+ * will be empty.
1054
+ */
1055
+ $storage->migrate_to_network();
1056
+ self::migrate_install_plan_to_plan_id( $storage, $storage->network_install_blog_id );
1057
+ } else {
1058
+ // At least one opt-in. All the opt-in were created by a non-super-admin.
1059
+ if ( 0 == $ignores ) {
1060
+ // All sites were opted-in or skipped, all by non-super-admin. So delegate all.
1061
+ $storage->store( 'is_delegated_connection', true, true );
1062
+
1063
+ $all_migrated = true;
1064
+ }
1065
+ }
1066
+
1067
+ if ( ! $all_migrated ) {
1068
+ /**
1069
+ * Delegate all sites that were:
1070
+ * 1) Opted-in by a user that is NOT the main-super-admin.
1071
+ * 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.
1072
+ */
1073
+ foreach ( $blogs_status as $blog_id => $status_or_user_id ) {
1074
+ if ( $status_or_user_id == $main_super_admin_user_id ) {
1075
+ continue;
1076
+ }
1077
+
1078
+ if ( FS_User::is_valid_id( $status_or_user_id ) ||
1079
+ ( 'skipped' === $status_or_user_id && is_null( $main_super_admin_user_id ) )
1080
+ ) {
1081
+ $storage->store( 'is_delegated_connection', true, $blog_id );
1082
+ }
1083
+ }
1084
+ }
1085
+
1086
+
1087
+ if ( ( $connections + $skips > 0 ) ) {
1088
+ if ( $ignores > 0 ) {
1089
+ /**
1090
+ * If admin already opted-in or skipped in any of the network sites, and also
1091
+ * have sites which the connection decision was not yet taken, set this plugin
1092
+ * into network activation mode so the super-admin can choose what to do with
1093
+ * the rest of the sites.
1094
+ */
1095
+ self::set_network_upgrade_mode( $storage );
1096
+ }
1097
+ }
1098
+ }
1099
+ }
1100
+
1101
+ /**
1102
+ * Set a module into network upgrade mode.
1103
+ *
1104
+ * @author Vova Feldman (@svovaf)
1105
+ * @since 2.0.0
1106
+ *
1107
+ * @param \FS_Storage $storage
1108
+ *
1109
+ * @return bool
1110
+ */
1111
+ private static function set_network_upgrade_mode( FS_Storage $storage ) {
1112
+ return $storage->is_network_activation = true;
1113
+ }
1114
+
1115
+ /**
1116
+ * Will return true after upgrading to the SDK with the network level integration,
1117
+ * when the super-admin involvement is required regarding the rest of the sites.
1118
+ *
1119
+ * @author Vova Feldman (@svovaf)
1120
+ * @since 2.0.0
1121
+ *
1122
+ * @return bool
1123
+ */
1124
+ function is_network_upgrade_mode() {
1125
+ return $this->_storage->get( 'is_network_activation' );
1126
+ }
1127
+
1128
+ /**
1129
+ * Clear flag after the upgrade mode completion.
1130
+ *
1131
+ * @author Vova Feldman (@svovaf)
1132
+ * @since 2.0.0
1133
+ *
1134
+ * @return bool True if network activation was on and now completed.
1135
+ */
1136
+ private function network_upgrade_mode_completed() {
1137
+ if ( fs_is_network_admin() && $this->is_network_upgrade_mode() ) {
1138
+ $this->_storage->remove( 'is_network_activation' );
1139
+
1140
+ return true;
1141
+ }
1142
+
1143
+ return false;
1144
+ }
1145
+
1146
+ #endregion
1147
+
1148
+ /**
1149
+ * This action is connected to the 'plugins_loaded' hook and helps to determine
1150
+ * if this is a new plugin installation or a plugin update.
1151
+ *
1152
+ * There are 3 different use-cases:
1153
+ * 1) New plugin installation right with Freemius:
1154
+ * 1.1 _activate_plugin_event_hook() will be executed first
1155
+ * 1.2 Since $this->_storage->is_plugin_new_install is not set,
1156
+ * and $this->_storage->plugin_last_version is not set,
1157
+ * $this->_storage->is_plugin_new_install will be set to TRUE.
1158
+ * 1.3 When _plugins_loaded() will be executed, $this->_storage->is_plugin_new_install will
1159
+ * be already set to TRUE.
1160
+ *
1161
+ * 2) Plugin update, didn't have Freemius before, and now have the SDK:
1162
+ * 2.1 _activate_plugin_event_hook() will not be executed, because
1163
+ * the activation hook do NOT fires on updates since WP 3.1.
1164
+ * 2.2 When _plugins_loaded() will be executed, $this->_storage->is_plugin_new_install will
1165
+ * be empty, therefore, it will be set to FALSE.
1166
+ *
1167
+ * 3) Plugin update, had Freemius in prev version as well:
1168
+ * 3.1 _version_updates_handler() will be executed 1st, since FS was installed
1169
+ * before, $this->_storage->plugin_last_version will NOT be empty,
1170
+ * therefore, $this->_storage->is_plugin_new_install will be set to FALSE.
1171
+ * 3.2 When _plugins_loaded() will be executed, $this->_storage->is_plugin_new_install is
1172
+ * already set, therefore, it will not be modified.
1173
+ *
1174
+ * Use-case #3 is backward compatible, #3.1 will be executed since 1.0.9.
1175
+ *
1176
+ * NOTE:
1177
+ * The only fallback of this mechanism is if an admin updates a plugin based on use-case #2,
1178
+ * and then, the next immediate PageView is the plugin's main settings page, it will not
1179
+ * show the opt-in right away. The reason it will happen is because Freemius execution
1180
+ * will be turned off till the plugin is fully loaded at least once
1181
+ * (till $this->_storage->was_plugin_loaded is TRUE).
1182
+ *
1183
+ * @author Vova Feldman (@svovaf)
1184
+ * @since 1.1.9
1185
+ *
1186
+ */
1187
+ function _plugins_loaded() {
1188
+ // Update flag that plugin was loaded with Freemius at least once.
1189
+ $this->_storage->was_plugin_loaded = true;
1190
+
1191
+ /**
1192
+ * Bug fix - only set to false when it's a plugin, due to the
1193
+ * execution sequence of the theme hooks and our methods, if
1194
+ * this will be set for themes, Freemius will always assume
1195
+ * it's a theme update.
1196
+ *
1197
+ * @author Vova Feldman (@svovaf)
1198
+ * @since 1.2.2.2
1199
+ */
1200
+ if ( $this->is_plugin() &&
1201
+ ! isset( $this->_storage->is_plugin_new_install )
1202
+ ) {
1203
+ $this->_storage->is_plugin_new_install = false;
1204
+ }
1205
+ }
1206
+
1207
+ /**
1208
+ * Add special parameter to WP admin AJAX calls so when we
1209
+ * process AJAX calls we can identify its source properly.
1210
+ *
1211
+ * @author Leo Fajardo (@leorw)
1212
+ * @since 2.0.0
1213
+ */
1214
+ static function _enrich_ajax_url() {
1215
+ $admin_param = is_network_admin() ?
1216
+ '_fs_network_admin' :
1217
+ '_fs_blog_admin';
1218
+ ?>
1219
+ <script type="text/javascript">
1220
+ (function ($) {
1221
+ $(document).ajaxSend(function (event, jqxhr, settings) {
1222
+ if (settings.url &&
1223
+ -1 < settings.url.indexOf('admin-ajax.php') &&
1224
+ ! ( settings.url.indexOf( '<?php echo $admin_param ?>' ) > 0 )
1225
+ ) {
1226
+ if (settings.url.indexOf('?') > 0) {
1227
+ settings.url += '&';
1228
+ } else {
1229
+ settings.url += '?';
1230
+ }
1231
+
1232
+ settings.url += '<?php echo $admin_param ?>=true';
1233
+
1234
+ }
1235
+ });
1236
+ })(jQuery);
1237
+ </script>
1238
+ <?php
1239
+ }
1240
+
1241
+ /**
1242
+ * Opens the support forum subemenu item in a new browser page.
1243
+ *
1244
+ * @author Vova Feldman (@svovaf)
1245
+ * @since 2.1.4
1246
+ */
1247
+ static function _open_support_forum_in_new_page() {
1248
+ ?>
1249
+ <script type="text/javascript">
1250
+ (function ($) {
1251
+ $('.fs-submenu-item.wp-support-forum').parent().attr('target', '_blank');
1252
+ })(jQuery);
1253
+ </script>
1254
+ <?php
1255
+ }
1256
+
1257
+ /**
1258
+ * @author Vova Feldman (@svovaf)
1259
+ * @since 1.0.9
1260
+ */
1261
+ private function _register_hooks() {
1262
+ $this->_logger->entrance();
1263
+
1264
+ if ( is_admin() ) {
1265
+ add_action( 'plugins_loaded', array( &$this, '_hook_action_links_and_register_account_hooks' ) );
1266
+
1267
+ if ( $this->is_plugin() ) {
1268
+ if ( self::is_plugin_install_page() && true !== fs_request_get_bool( 'fs_allow_updater_and_dialog' ) ) {
1269
+ /**
1270
+ * Unless the `fs_allow_updater_and_dialog` URL param exists and its value is `true`, make
1271
+ * Freemius-related updates unavailable on the "Add Plugins" admin page (/plugin-install.php)
1272
+ * so that they won't interfere with the .org plugins' functionalities on that page (e.g.
1273
+ * updating of a .org plugin).
1274
+ */
1275
+ add_filter( 'site_transient_update_plugins', array( 'Freemius', '_remove_fs_updates_from_plugin_install_page' ), 10, 2 );
1276
+ } else if ( self::is_plugins_page() || self::is_updates_page() ) {
1277
+ /**
1278
+ * On the "Plugins" and "Updates" admin pages, if there are premium or non–org-compliant
1279
+ * plugins, modify their details dialog URLs (add a Freemius-specific param) so that the SDK can
1280
+ * determine if the plugin information dialog should show information from Freemius.
1281
+ *
1282
+ * @author Leo Fajardo (@leorw)
1283
+ * @since 2.2.3
1284
+ */
1285
+ add_action( 'admin_footer', array( 'Freemius', '_prepend_fs_allow_updater_and_dialog_flag_url_param' ) );
1286
+ }
1287
+
1288
+ $plugin_dir = dirname( $this->_plugin_dir_path ) . '/';
1289
+
1290
+ /**
1291
+ * @since 1.2.2
1292
+ *
1293
+ * Hook to both free and premium version activations to support
1294
+ * auto deactivation on the other version activation.
1295
+ */
1296
+ register_activation_hook(
1297
+ $plugin_dir . $this->_free_plugin_basename,
1298
+ array( &$this, '_activate_plugin_event_hook' )
1299
+ );
1300
+
1301
+ register_activation_hook(
1302
+ $plugin_dir . $this->premium_plugin_basename(),
1303
+ array( &$this, '_activate_plugin_event_hook' )
1304
+ );
1305
+ } else {
1306
+ add_action( 'after_switch_theme', array( &$this, '_activate_theme_event_hook' ), 10, 2 );
1307
+
1308
+ /**
1309
+ * Include the required hooks to capture the theme settings' page tabs
1310
+ * and cache them.
1311
+ *
1312
+ * @author Vova Feldman (@svovaf)
1313
+ * @since 1.2.2.7
1314
+ */
1315
+ if ( ! $this->_cache->has_valid( 'tabs' ) ) {
1316
+ add_action( 'admin_footer', array( &$this, '_tabs_capture' ) );
1317
+ // Add license activation AJAX callback.
1318
+ $this->add_ajax_action( 'store_tabs', array( &$this, '_store_tabs_ajax_action' ) );
1319
+
1320
+ add_action( 'admin_enqueue_scripts', array( &$this, '_store_tabs_styles' ), 9999999 );
1321
+ }
1322
+
1323
+ add_action(
1324
+ 'admin_footer',
1325
+ array( &$this, '_add_freemius_tabs' ),
1326
+ /**
1327
+ * The tabs JS code must be executed after the tabs capture logic (_tabs_capture()).
1328
+ * That's why the priority is 11 while the tabs capture logic is added
1329
+ * with priority 10.
1330
+ *
1331
+ * @author Vova Feldman (@svovaf)
1332
+ */
1333
+ 11
1334
+ );
1335
+
1336
+ add_action( 'admin_footer', array( &$this, '_style_premium_theme' ) );
1337
+ }
1338
+
1339
+ /**
1340
+ * Part of the mechanism to identify new plugin install vs. plugin update.
1341
+ *
1342
+ * @author Vova Feldman (@svovaf)
1343
+ * @since 1.1.9
1344
+ */
1345
+ if ( empty( $this->_storage->was_plugin_loaded ) ) {
1346
+ /**
1347
+ * During the plugin activation (not theme), 'plugins_loaded' will be already executed
1348
+ * when the logic gets here since the activation logic first add the activate plugins,
1349
+ * then triggers 'plugins_loaded', and only then include the code of the plugin that
1350
+ * is activated. Which means that _plugins_loaded() will NOT be executed during the
1351
+ * plugin activation, and that IS intentional.
1352
+ *
1353
+ * @author Vova Feldman (@svovaf)
1354
+ */
1355
+ if ( $this->is_plugin() && $this->is_activation_mode( false ) ) {
1356
+ add_action( 'plugins_loaded', array( &$this, '_plugins_loaded' ) );
1357
+ } else {
1358
+ // If was activated before, then it was already loaded before.
1359
+ $this->_plugins_loaded();
1360
+ }
1361
+ }
1362
+
1363
+ if ( ! self::is_ajax() ) {
1364
+ if ( ! $this->is_addon() ) {
1365
+ add_action( 'init', array( &$this, '_add_default_submenu_items' ), WP_FS__LOWEST_PRIORITY );
1366
+ }
1367
+ }
1368
+
1369
+ if ( $this->_storage->handle_gdpr_admin_notice ) {
1370
+ add_action( 'init', array( &$this, '_maybe_show_gdpr_admin_notice' ) );
1371
+ }
1372
+
1373
+ add_action( 'init', array( &$this, '_maybe_add_gdpr_optin_ajax_handler') );
1374
+ }
1375
+
1376
+ if ( $this->is_plugin() ) {
1377
+ if ( $this->_is_network_active ) {
1378
+ add_action( 'wpmu_new_blog', array( $this, '_after_new_blog_callback' ), 10, 6 );
1379
+ }
1380
+
1381
+ register_deactivation_hook( $this->_plugin_main_file_path, array( &$this, '_deactivate_plugin_hook' ) );
1382
+ }
1383
+
1384
+ if ( is_multisite() ) {
1385
+ add_action( 'deactivate_blog', array( &$this, '_after_site_deactivated_callback' ) );
1386
+ add_action( 'archive_blog', array( &$this, '_after_site_deactivated_callback' ) );
1387
+ add_action( 'make_spam_blog', array( &$this, '_after_site_deactivated_callback' ) );
1388
+ add_action( 'deleted_blog', array( &$this, '_after_site_deleted_callback' ), 10, 2 );
1389
+
1390
+ add_action( 'activate_blog', array( &$this, '_after_site_reactivated_callback' ) );
1391
+ add_action( 'unarchive_blog', array( &$this, '_after_site_reactivated_callback' ) );
1392
+ add_action( 'make_ham_blog', array( &$this, '_after_site_reactivated_callback' ) );
1393
+ }
1394
+
1395
+ if ( $this->is_theme() &&
1396
+ self::is_customizer() &&
1397
+ $this->apply_filters( 'show_customizer_upsell', true )
1398
+ ) {
1399
+ // Register customizer upsell.
1400
+ add_action( 'customize_register', array( &$this, '_customizer_register' ) );
1401
+ }
1402
+
1403
+ add_action( 'admin_init', array( &$this, '_redirect_on_clicked_menu_link' ), WP_FS__LOWEST_PRIORITY );
1404
+
1405
+ if ( $this->is_theme() ) {
1406
+ add_action( 'admin_init', array( &$this, '_add_tracking_links' ) );
1407
+ }
1408
+
1409
+ add_action( 'admin_init', array( &$this, '_add_license_activation' ) );
1410
+ add_action( 'admin_init', array( &$this, '_add_premium_version_upgrade_selection' ) );
1411
+
1412
+ $this->add_ajax_action( 'update_billing', array( &$this, '_update_billing_ajax_action' ) );
1413
+ $this->add_ajax_action( 'start_trial', array( &$this, '_start_trial_ajax_action' ) );
1414
+
1415
+ if ( $this->_is_network_active && fs_is_network_admin() ) {
1416
+ $this->add_ajax_action( 'network_activate', array( &$this, '_network_activate_ajax_action' ) );
1417
+ }
1418
+
1419
+ $this->add_ajax_action( 'install_premium_version', array(
1420
+ &$this,
1421
+ '_install_premium_version_ajax_action'
1422
+ ) );
1423
+
1424
+ $this->add_ajax_action( 'submit_affiliate_application', array( &$this, '_submit_affiliate_application' ) );
1425
+
1426
+ $this->add_action( 'after_plans_sync', array( &$this, '_check_for_trial_plans' ) );
1427
+
1428
+ $this->add_action( 'sdk_version_update', array( &$this, '_sdk_version_update' ), WP_FS__DEFAULT_PRIORITY, 2 );
1429
+
1430
+ $this->add_action(
1431
+ 'plugin_version_update',
1432
+ array( &$this, '_after_version_update' ),
1433
+ WP_FS__DEFAULT_PRIORITY,
1434
+ 2
1435
+ );
1436
+ $this->add_filter( 'after_code_type_change', array( &$this, '_after_code_type_change' ) );
1437
+
1438
+ add_action( 'admin_init', array( &$this, '_add_trial_notice' ) );
1439
+ add_action( 'admin_init', array( &$this, '_add_affiliate_program_notice' ) );
1440
+ add_action( 'admin_enqueue_scripts', array( &$this, '_enqueue_common_css' ) );
1441
+
1442
+ /**
1443
+ * Handle request to reset anonymous mode for `get_reconnect_url()`.
1444
+ *
1445
+ * @author Vova Feldman (@svovaf)
1446
+ * @since 1.2.1.5
1447
+ */
1448
+ if ( fs_request_is_action( 'reset_anonymous_mode' ) &&
1449
+ $this->get_unique_affix() === fs_request_get( 'fs_unique_affix' )
1450
+ ) {
1451
+ add_action( 'admin_init', array( &$this, 'connect_again' ) );
1452
+ }
1453
+ }
1454
+
1455
+ /**
1456
+ * Makes Freemius-related updates unavailable on the "Add Plugins" admin page (/plugin-install.php) so that
1457
+ * they won't interfere with the .org plugins' functionalities on that page (e.g. updating of a .org plugin).
1458
+ *
1459
+ * @author Leo Fajardo (@leorw)
1460
+ * @since 2.2.3
1461
+ *
1462
+ * @param object $updates
1463
+ * @param string|null $transient
1464
+ *
1465
+ * @return object
1466
+ */
1467
+ static function _remove_fs_updates_from_plugin_install_page( $updates, $transient = null ) {
1468
+ if ( is_object( $updates ) && isset( $updates->response ) ) {
1469
+ foreach ( $updates->response as $file => $plugin ) {
1470
+ if ( false !== strpos( $plugin->package, 'api.freemius' ) ) {
1471
+ unset( $updates->response[ $file ] );
1472
+ }
1473
+ }
1474
+ }
1475
+
1476
+ return $updates;
1477
+ }
1478
+
1479
+ /**
1480
+ * Prepends the `fs_allow_updater_and_dialog` param to the plugin information URLs to tell the SDK to handle
1481
+ * the information that is shown on the plugin details dialog that is shown when the relevant link is clicked.
1482
+ *
1483
+ * @author Leo Fajardo (@leorw)
1484
+ * @since 2.2.3
1485
+ *
1486
+ * @return string
1487
+ */
1488
+ static function _prepend_fs_allow_updater_and_dialog_flag_url_param() {
1489
+ $slug_basename_map = array();
1490
+ foreach ( self::$_instances as $instance ) {
1491
+ if ( ! $instance->is_plugin() ) {
1492
+ continue;
1493
+ }
1494
+
1495
+ $slug_basename_map[ $instance->get_slug() ] = $instance->premium_plugin_basename();
1496
+ }
1497
+ ?>
1498
+ <script type="text/javascript">
1499
+ (function( $ ) {
1500
+ var slugBasenameMap = <?php echo json_encode( $slug_basename_map ) ?>;
1501
+ for ( var slug in slugBasenameMap ) {
1502
+ var basename = slugBasenameMap[ slug ];
1503
+
1504
+ // Try to get the plugin rows if on the "Plugins" page.
1505
+ var $pluginRows = $( '.wp-list-table.plugins tr[data-plugin="' + basename + '"]');
1506
+
1507
+ if ( 0 === $pluginRows.length ) {
1508
+ // Try to get the plugin rows if on the "Updates" page.
1509
+ var $pluginCheckbox = $( '#update-plugins-table input[type="checkbox"][value="' + basename + '"]' );
1510
+ if ( 0 !== $pluginCheckbox.length ) {
1511
+ $pluginRows = $pluginCheckbox.parents( 'tr:first' );
1512
+ }
1513
+ }
1514
+
1515
+ if ( 0 === $pluginRows.length ) {
1516
+ // No plugin rows found.
1517
+ continue;
1518
+ }
1519
+
1520
+ // Find the "View details" links and add the `fs_allow_updater_and_dialog` param to the URL.
1521
+ $pluginRows.find( 'a[href*="plugin-install.php?tab=plugin-information"]' ).each(function() {
1522
+ var $this = $( this ),
1523
+ href = $this.attr( 'href' ).replace( '?tab=', '?fs_allow_updater_and_dialog=true&tab=');
1524
+
1525
+ $this.attr( 'href', href );
1526
+ });
1527
+ }
1528
+ })( jQuery );
1529
+ </script>
1530
+ <?php
1531
+ }
1532
+
1533
+ /**
1534
+ * Keeping the uninstall hook registered for free or premium plugin version may result to a fatal error that
1535
+ * could happen when a user tries to uninstall either version while one of them is still active. Uninstalling a
1536
+ * plugin will trigger inclusion of the free or premium version and if one of them is active during the
1537
+ * uninstallation, a fatal error may occur in case the plugin's class or functions are already defined.
1538
+ *
1539
+ * @author Leo Fajardo (@leorw)
1540
+ *
1541
+ * @since 1.2.0
1542
+ */
1543
+ private function unregister_uninstall_hook() {
1544
+ $uninstallable_plugins = (array) get_option( 'uninstall_plugins' );
1545
+ unset( $uninstallable_plugins[ $this->_free_plugin_basename ] );
1546
+ unset( $uninstallable_plugins[ $this->premium_plugin_basename() ] );
1547
+
1548
+ update_option( 'uninstall_plugins', $uninstallable_plugins );
1549
+ }
1550
+
1551
+ /**
1552
+ * @since 1.2.0 Invalidate module's main file cache, otherwise, FS_Plugin_Updater will not fetch updates.
1553
+ *
1554
+ * @param bool $store_prev_path
1555
+ */
1556
+ private function clear_module_main_file_cache( $store_prev_path = true ) {
1557
+ if ( ! isset( $this->_storage->plugin_main_file ) ||
1558
+ empty( $this->_storage->plugin_main_file->path )
1559
+ ) {
1560
+ return;
1561
+ }
1562
+
1563
+ if ( ! $store_prev_path ) {
1564
+ /**
1565
+ * Storing the previous path is not needed when clearing the cache after an SDK version update since
1566
+ * the main purpose of the cache clearing in that event is to correct a wrong plugin main file path
1567
+ * which causes data mix-up between plugins (e.g. titles and versions of an add-on and its parent plugin).
1568
+ *
1569
+ * @author Leo Fajardo (@leorw)
1570
+ * @since 2.2.1
1571
+ */
1572
+ unset( $this->_storage->plugin_main_file->path );
1573
+ } else {
1574
+ $plugin_main_file = clone $this->_storage->plugin_main_file;
1575
+
1576
+ // Store cached path (2nd layer cache).
1577
+ $plugin_main_file->prev_path = $plugin_main_file->path;
1578
+
1579
+ // Clear cached path.
1580
+ unset( $plugin_main_file->path );
1581
+
1582
+ $this->_storage->plugin_main_file = $plugin_main_file;
1583
+ }
1584
+
1585
+ /**
1586
+ * Clear global cached path.
1587
+ *
1588
+ * @author Leo Fajardo (@leorw)
1589
+ * @since 1.2.2
1590
+ */
1591
+ $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map' );
1592
+ unset( $id_slug_type_path_map[ $this->_module_id ]['path'] );
1593
+ self::$_accounts->set_option( 'id_slug_type_path_map', $id_slug_type_path_map, true );
1594
+ }
1595
+
1596
+ /**
1597
+ * @author Leo Fajardo (@leorw)
1598
+ * @since 2.0.0
1599
+ */
1600
+ function _hook_action_links_and_register_account_hooks() {
1601
+ add_action( 'admin_init', array( &$this, '_add_tracking_links' ) );
1602
+
1603
+ if ( self::is_plugins_page() && $this->is_plugin() ) {
1604
+ $this->hook_plugin_action_links();
1605
+ }
1606
+
1607
+ $this->_register_account_hooks();
1608
+ }
1609
+
1610
+ /**
1611
+ * @author Vova Feldman (@svovaf)
1612
+ * @since 1.0.9
1613
+ */
1614
+ private function _register_account_hooks() {
1615
+ if ( ! is_admin() ) {
1616
+ return;
1617
+ }
1618
+
1619
+ /**
1620
+ * Always show the deactivation feedback form since we added
1621
+ * automatic free version deactivation upon premium code activation.
1622
+ *
1623
+ * @since 1.2.1.6
1624
+ */
1625
+ $this->add_ajax_action(
1626
+ 'submit_uninstall_reason',
1627
+ array( &$this, '_submit_uninstall_reason_action' )
1628
+ );
1629
+
1630
+ $this->add_ajax_action(
1631
+ 'cancel_subscription_or_trial',
1632
+ array( &$this, 'cancel_subscription_or_trial_ajax_action' )
1633
+ );
1634
+
1635
+ if ( ! $this->is_addon() || $this->is_parent_plugin_installed() ) {
1636
+ if ( ( $this->is_plugin() && self::is_plugins_page() ) ||
1637
+ ( $this->is_theme() && self::is_themes_page() )
1638
+ ) {
1639
+ add_action( 'admin_footer', array( &$this, '_add_deactivation_feedback_dialog_box' ) );
1640
+ }
1641
+ }
1642
+ }
1643
+
1644
+ /**
1645
+ * Leverage backtrace to find caller plugin file path.
1646
+ *
1647
+ * @author Vova Feldman (@svovaf)
1648
+ * @since 1.0.6
1649
+ *
1650
+ * @param bool $is_init Is initiation sequence.
1651
+ *
1652
+ * @return string
1653
+ */
1654
+ private function _find_caller_plugin_file( $is_init = false ) {
1655
+ // Try to load the cached value of the file path.
1656
+ if ( isset( $this->_storage->plugin_main_file ) ) {
1657
+ $plugin_main_file = $this->_storage->plugin_main_file;
1658
+ if ( isset( $plugin_main_file->path ) ) {
1659
+ $absolute_path = $this->get_absolute_path( $plugin_main_file->path );
1660
+ if ( file_exists( $absolute_path ) ) {
1661
+ return $absolute_path;
1662
+ }
1663
+ }
1664
+ }
1665
+
1666
+ /**
1667
+ * @since 1.2.1
1668
+ *
1669
+ * `clear_module_main_file_cache()` is clearing the plugin's cached path on
1670
+ * deactivation. Therefore, if any plugin/theme was initiating `Freemius`
1671
+ * with that plugin's slug, it was overriding the empty plugin path with a wrong path.
1672
+ *
1673
+ * So, we've added a special mechanism with a 2nd layer of cache that uses `prev_path`
1674
+ * when the class instantiator isn't the module.
1675
+ */
1676
+ if ( ! $is_init ) {
1677
+ // Fetch prev path cache.
1678
+ if ( isset( $this->_storage->plugin_main_file ) &&
1679
+ isset( $this->_storage->plugin_main_file->prev_path )
1680
+ ) {
1681
+ $absolute_path = $this->get_absolute_path( $this->_storage->plugin_main_file->prev_path );
1682
+ if ( file_exists( $absolute_path ) ) {
1683
+ return $absolute_path;
1684
+ }
1685
+ }
1686
+
1687
+ wp_die(
1688
+ $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' ) .
1689
+ " Module: {$this->_slug}; SDK: " . WP_FS__SDK_VERSION . ";",
1690
+ $this->get_text_inline( 'Error', 'error' ),
1691
+ array( 'back_link' => true )
1692
+ );
1693
+ }
1694
+
1695
+ /**
1696
+ * @since 1.2.1
1697
+ *
1698
+ * Only the original instantiator that calls dynamic_init can modify the module's path.
1699
+ */
1700
+ // Find caller module.
1701
+ $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array() );
1702
+ $this->_storage->plugin_main_file = (object) array(
1703
+ 'path' => $id_slug_type_path_map[ $this->_module_id ]['path'],
1704
+ );
1705
+
1706
+ return $this->get_absolute_path( $id_slug_type_path_map[ $this->_module_id ]['path'] );
1707
+ }
1708
+
1709
+ /**
1710
+ * @author Leo Fajardo (@leorw)
1711
+ * @since 1.2.3
1712
+ *
1713
+ * @param string $path
1714
+ *
1715
+ * @return string
1716
+ */
1717
+ private function get_relative_path( $path ) {
1718
+ $module_root_dir = $this->get_module_root_dir_path();
1719
+ if ( 0 === strpos( $path, $module_root_dir ) ) {
1720
+ $path = substr( $path, strlen( $module_root_dir ) );
1721
+ }
1722
+
1723
+ return $path;
1724
+ }
1725
+
1726
+ /**
1727
+ * @author Leo Fajardo (@leorw)
1728
+ * @since 1.2.3
1729
+ *
1730
+ * @param string $path
1731
+ * @param string|bool $module_type
1732
+ *
1733
+ * @return string
1734
+ */
1735
+ private function get_absolute_path( $path, $module_type = false ) {
1736
+ $module_root_dir = $this->get_module_root_dir_path( $module_type );
1737
+ if ( 0 !== strpos( $path, $module_root_dir ) ) {
1738
+ $path = fs_normalize_path( $module_root_dir . $path );
1739
+ }
1740
+
1741
+ return $path;
1742
+ }
1743
+
1744
+ /**
1745
+ * @author Leo Fajardo (@leorw)
1746
+ * @since 1.2.3
1747
+ *
1748
+ * @param string|bool $module_type
1749
+ *
1750
+ * @return string
1751
+ */
1752
+ private function get_module_root_dir_path( $module_type = false ) {
1753
+ $is_plugin = empty( $module_type ) ?
1754
+ $this->is_plugin() :
1755
+ ( WP_FS__MODULE_TYPE_PLUGIN === $module_type );
1756
+
1757
+ return fs_normalize_path( trailingslashit( $is_plugin ?
1758
+ WP_PLUGIN_DIR :
1759
+ get_theme_root( get_stylesheet() ) ) );
1760
+ }
1761
+
1762
+ /**
1763
+ * @author Leo Fajardo (@leorw)
1764
+ *
1765
+ * @param number $module_id
1766
+ * @param string $slug
1767
+ *
1768
+ * @since 1.2.2
1769
+ */
1770
+ private function store_id_slug_type_path_map( $module_id, $slug ) {
1771
+ $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array() );
1772
+
1773
+ $store_option = false;
1774
+
1775
+ if ( ! isset( $id_slug_type_path_map[ $module_id ] ) ) {
1776
+ $id_slug_type_path_map[ $module_id ] = array(
1777
+ 'slug' => $slug
1778
+ );
1779
+
1780
+ $store_option = true;
1781
+ }
1782
+
1783
+ if ( ! isset( $id_slug_type_path_map[ $module_id ]['path'] ) ||
1784
+ /**
1785
+ * This verification is for cases when suddenly the same module
1786
+ * is installed but with a different folder name.
1787
+ *
1788
+ * @author Vova Feldman (@svovaf)
1789
+ * @since 1.2.3
1790
+ */
1791
+ ! file_exists( $this->get_absolute_path(
1792
+ $id_slug_type_path_map[ $module_id ]['path'],
1793
+ $id_slug_type_path_map[ $module_id ]['type']
1794
+ ) )
1795
+ ) {
1796
+ $caller_main_file_and_type = $this->get_caller_main_file_and_type();
1797
+
1798
+ $id_slug_type_path_map[ $module_id ]['type'] = $caller_main_file_and_type->module_type;
1799
+ $id_slug_type_path_map[ $module_id ]['path'] = $caller_main_file_and_type->path;
1800
+
1801
+ $store_option = true;
1802
+ }
1803
+
1804
+ if ( $store_option ) {
1805
+ self::$_accounts->set_option( 'id_slug_type_path_map', $id_slug_type_path_map, true );
1806
+ }
1807
+ }
1808
+
1809
+ /**
1810
+ * Identifies the caller type: plugin or theme.
1811
+ *
1812
+ * @author Leo Fajardo (@leorw)
1813
+ * @since 1.2.2
1814
+ *
1815
+ * @author Vova Feldman (@svovaf)
1816
+ * @since 1.2.2.3 Find the earliest module in the call stack that calls to the SDK. This fix is for cases when
1817
+ * add-ons are relying on loading the SDK from the parent module, and also allows themes including the
1818
+ * SDK an internal file instead of directly from functions.php.
1819
+ * @since 1.2.1.7 Knows how to handle cases when an add-on includes the parent module logic.
1820
+ */
1821
+ private function get_caller_main_file_and_type() {
1822
+ self::require_plugin_essentials();
1823
+
1824
+ $all_plugins = fs_get_plugins( true );
1825
+ $all_plugins_paths = array();
1826
+
1827
+ // Get active plugin's main files real full names (might be symlinks).
1828
+ foreach ( $all_plugins as $relative_path => $data ) {
1829
+ if ( false === strpos( fs_normalize_path( $relative_path ), '/' ) ) {
1830
+ /**
1831
+ * Ignore plugins that don't have a folder (e.g. Hello Dolly) since they
1832
+ * can't really include the SDK.
1833
+ *
1834
+ * @author Vova Feldman
1835
+ * @since 1.2.1.7
1836
+ */
1837
+ continue;
1838
+ }
1839
+
1840
+ $all_plugins_paths[] = fs_normalize_path( realpath( WP_PLUGIN_DIR . '/' . $relative_path ) );
1841
+ }
1842
+
1843
+ $caller_file_candidate = false;
1844
+ $caller_map = array();
1845
+ $module_type = WP_FS__MODULE_TYPE_PLUGIN;
1846
+ $themes_dir = fs_normalize_path( get_theme_root( get_stylesheet() ) );
1847
+
1848
+ for ( $i = 1, $bt = debug_backtrace(), $len = count( $bt ); $i < $len; $i ++ ) {
1849
+ if ( empty( $bt[ $i ]['file'] ) ) {
1850
+ continue;
1851
+ }
1852
+
1853
+ if ( $i > 1 && ! empty( $bt[ $i - 1 ]['file'] ) && $bt[ $i ]['file'] === $bt[ $i - 1 ]['file'] ) {
1854
+ // If file same as the prev file in the stack, skip it.
1855
+ continue;
1856
+ }
1857
+
1858
+ if ( ! empty( $bt[ $i ]['function'] ) && in_array( $bt[ $i ]['function'], array(
1859
+ 'do_action',
1860
+ 'apply_filter',
1861
+ // The string split is stupid, but otherwise, theme check
1862
+ // throws info notices.
1863
+ 'requir' . 'e_once',
1864
+ 'requir' . 'e',
1865
+ 'includ' . 'e_once',
1866
+ 'includ' . 'e',
1867
+ 'install_and_activate_plugin',
1868
+ 'try_activate_plugin',
1869
+ 'activate_plugin'
1870
+ ) )
1871
+ ) {
1872
+ // Ignore call stack hooks and files inclusion.
1873
+ continue;
1874
+ }
1875
+
1876
+ $caller_file_path = fs_normalize_path( $bt[ $i ]['file'] );
1877
+
1878
+ if ( 'functions.php' === basename( $caller_file_path ) ) {
1879
+ /**
1880
+ * 1. Assumes that theme's starting execution file is functions.php.
1881
+ * 2. This complex logic fixes symlink issues (e.g. with Vargant).
1882
+ *
1883
+ * @author Vova Feldman (@svovaf)
1884
+ * @since 1.2.2.5
1885
+ */
1886
+
1887
+ if ( $caller_file_path == fs_normalize_path( realpath( trailingslashit( $themes_dir ) . basename( dirname( $caller_file_path ) ) . '/' . basename( $caller_file_path ) ) ) ) {
1888
+ $module_type = WP_FS__MODULE_TYPE_THEME;
1889
+
1890
+ /**
1891
+ * Relative path of the theme, e.g.:
1892
+ * `my-theme/functions.php`
1893
+ *
1894
+ * @author Leo Fajardo (@leorw)
1895
+ */
1896
+ $caller_file_candidate = basename( dirname( $caller_file_path ) ) .
1897
+ '/' .
1898
+ basename( $caller_file_path );
1899
+
1900
+ continue;
1901
+ }
1902
+ }
1903
+
1904
+ $caller_file_hash = md5( $caller_file_path );
1905
+
1906
+ if ( ! isset( $caller_map[ $caller_file_hash ] ) ) {
1907
+ foreach ( $all_plugins_paths as $plugin_path ) {
1908
+ if ( false !== strpos( $caller_file_path, fs_normalize_path( dirname( $plugin_path ) . '/' ) ) ) {
1909
+ $caller_map[ $caller_file_hash ] = fs_normalize_path( $plugin_path );
1910
+ break;
1911
+ }
1912
+ }
1913
+ }
1914
+
1915
+ if ( isset( $caller_map[ $caller_file_hash ] ) ) {
1916
+ $module_type = WP_FS__MODULE_TYPE_PLUGIN;
1917
+ $caller_file_candidate = plugin_basename( $caller_map[ $caller_file_hash ] );
1918
+ }
1919
+ }
1920
+
1921
+ return (object) array(
1922
+ 'module_type' => $module_type,
1923
+ 'path' => $caller_file_candidate
1924
+ );
1925
+ }
1926
+
1927
+ #----------------------------------------------------------------------------------
1928
+ #region Deactivation Feedback Form
1929
+ #----------------------------------------------------------------------------------
1930
+
1931
+ /**
1932
+ * Displays a confirmation and feedback dialog box when the user clicks on the "Deactivate" link on the plugins
1933
+ * page.
1934
+ *
1935
+ * @author Vova Feldman (@svovaf)
1936
+ * @author Leo Fajardo (@leorw)
1937
+ * @since 1.1.2
1938
+ */
1939
+ function _add_deactivation_feedback_dialog_box() {
1940
+ /* Check the type of user:
1941
+ * 1. Long-term (long-term)
1942
+ * 2. Non-registered and non-anonymous short-term (non-registered-and-non-anonymous-short-term).
1943
+ * 3. Short-term (short-term)
1944
+ */
1945
+ $is_long_term_user = true;
1946
+
1947
+ // Check if the site is at least 2 days old.
1948
+ $time_installed = $this->_storage->install_timestamp;
1949
+
1950
+ // Difference in seconds.
1951
+ $date_diff = time() - $time_installed;
1952
+
1953
+ // Convert seconds to days.
1954
+ $date_diff_days = floor( $date_diff / ( 60 * 60 * 24 ) );
1955
+
1956
+ if ( $date_diff_days < 2 ) {
1957
+ $is_long_term_user = false;
1958
+ }
1959
+
1960
+ $is_long_term_user = $this->apply_filters( 'is_long_term_user', $is_long_term_user );
1961
+
1962
+ if ( $is_long_term_user ) {
1963
+ $user_type = 'long-term';
1964
+ } else {
1965
+ if ( ! $this->is_registered() && ! $this->is_anonymous() ) {
1966
+ $user_type = 'non-registered-and-non-anonymous-short-term';
1967
+ } else {
1968
+ $user_type = 'short-term';
1969
+ }
1970
+ }
1971
+
1972
+ $uninstall_reasons = $this->_get_uninstall_reasons( $user_type );
1973
+
1974
+ // Load the HTML template for the deactivation feedback dialog box.
1975
+ $vars = array(
1976
+ 'reasons' => $uninstall_reasons,
1977
+ 'id' => $this->_module_id
1978
+ );
1979
+
1980
+ /**
1981
+ * @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.
1982
+ */
1983
+ fs_require_template( 'forms/deactivation/form.php', $vars );
1984
+ }
1985
+
1986
+ /**
1987
+ * @author Leo Fajardo (@leorw)
1988
+ * @since 1.1.2
1989
+ *
1990
+ * @param string $user_type
1991
+ *
1992
+ * @return array The uninstall reasons for the specified user type.
1993
+ */
1994
+ function _get_uninstall_reasons( $user_type = 'long-term' ) {
1995
+ $module_type = $this->_module_type;
1996
+
1997
+ $internal_message_template_var = array(
1998
+ 'id' => $this->_module_id
1999
+ );
2000
+
2001
+ $plan = $this->get_plan();
2002
+
2003
+ if ( $this->is_registered() && is_object( $plan ) && $plan->has_technical_support() ) {
2004
+ $contact_support_template = fs_get_template( 'forms/deactivation/contact.php', $internal_message_template_var );
2005
+ } else {
2006
+ $contact_support_template = '';
2007
+ }
2008
+
2009
+ $reason_found_better_plugin = array(
2010
+ 'id' => self::REASON_FOUND_A_BETTER_PLUGIN,
2011
+ 'text' => sprintf( $this->get_text_inline( 'I found a better %s', 'reason-found-a-better-plugin' ), $module_type ),
2012
+ 'input_type' => 'textfield',
2013
+ 'input_placeholder' => sprintf( $this->get_text_inline( "What's the %s's name?", 'placeholder-plugin-name' ), $module_type ),
2014
+ );
2015
+
2016
+ $reason_temporary_deactivation = array(
2017
+ 'id' => self::REASON_TEMPORARY_DEACTIVATION,
2018
+ 'text' => sprintf(
2019
+ $this->get_text_inline( "It's a temporary %s. I'm just debugging an issue.", 'reason-temporary-x' ),
2020
+ strtolower( $this->is_plugin() ?
2021
+ $this->get_text_inline( 'Deactivation', 'deactivation' ) :
2022
+ $this->get_text_inline( 'Theme Switch', 'theme-switch' )
2023
+ )
2024
+ ),
2025
+ 'input_type' => '',
2026
+ 'input_placeholder' => ''
2027
+ );
2028
+
2029
+ $reason_other = array(
2030
+ 'id' => self::REASON_OTHER,
2031
+ 'text' => $this->get_text_inline( 'Other', 'reason-other' ),
2032
+ 'input_type' => 'textfield',
2033
+ 'input_placeholder' => ''
2034
+ );
2035
+
2036
+ $long_term_user_reasons = array(
2037
+ array(
2038
+ 'id' => self::REASON_NO_LONGER_NEEDED,
2039
+ 'text' => sprintf( $this->get_text_inline( 'I no longer need the %s', 'reason-no-longer-needed' ), $module_type ),
2040
+ 'input_type' => '',
2041
+ 'input_placeholder' => ''
2042
+ ),
2043
+ $reason_found_better_plugin,
2044
+ array(
2045
+ 'id' => self::REASON_NEEDED_FOR_A_SHORT_PERIOD,
2046
+ 'text' => sprintf( $this->get_text_inline( 'I only needed the %s for a short period', 'reason-needed-for-a-short-period' ), $module_type ),
2047
+ 'input_type' => '',
2048
+ 'input_placeholder' => ''
2049
+ ),
2050
+ array(
2051
+ 'id' => self::REASON_BROKE_MY_SITE,
2052
+ 'text' => sprintf( $this->get_text_inline( 'The %s broke my site', 'reason-broke-my-site' ), $module_type ),
2053
+ 'input_type' => '',
2054
+ 'input_placeholder' => '',
2055
+ 'internal_message' => $contact_support_template
2056
+ ),
2057
+ array(
2058
+ 'id' => self::REASON_SUDDENLY_STOPPED_WORKING,
2059
+ 'text' => sprintf( $this->get_text_inline( 'The %s suddenly stopped working', 'reason-suddenly-stopped-working' ), $module_type ),
2060
+ 'input_type' => '',
2061
+ 'input_placeholder' => '',
2062
+ 'internal_message' => $contact_support_template
2063
+ )
2064
+ );
2065
+
2066
+ if ( $this->is_paying() ) {
2067
+ $long_term_user_reasons[] = array(
2068
+ 'id' => self::REASON_CANT_PAY_ANYMORE,
2069
+ 'text' => $this->get_text_inline( "I can't pay for it anymore", 'reason-cant-pay-anymore' ),
2070
+ 'input_type' => 'textfield',
2071
+ 'input_placeholder' => $this->get_text_inline( 'What price would you feel comfortable paying?', 'placeholder-comfortable-price' )
2072
+ );
2073
+ }
2074
+
2075
+ $reason_dont_share_info = array(
2076
+ 'id' => self::REASON_DONT_LIKE_TO_SHARE_MY_INFORMATION,
2077
+ 'text' => $this->get_text_inline( "I don't like to share my information with you", 'reason-dont-like-to-share-my-information' ),
2078
+ 'input_type' => '',
2079
+ 'input_placeholder' => ''
2080
+ );
2081
+
2082
+ /**
2083
+ * If the current user has selected the "don't share data" reason in the deactivation feedback modal, inform the
2084
+ * user by showing additional message that he doesn't have to share data and can just choose to skip the opt-in
2085
+ * (the Skip button is included in the message to show). This message will only be shown if anonymous mode is
2086
+ * enabled and the user's account is currently not in pending activation state (similar to the way the Skip
2087
+ * button in the opt-in form is shown/hidden).
2088
+ */
2089
+ if ( $this->is_enable_anonymous() && ! $this->is_pending_activation() ) {
2090
+ $reason_dont_share_info['internal_message'] = fs_get_template( 'forms/deactivation/retry-skip.php', $internal_message_template_var );
2091
+ }
2092
+
2093
+ $uninstall_reasons = array(
2094
+ 'long-term' => $long_term_user_reasons,
2095
+ 'non-registered-and-non-anonymous-short-term' => array(
2096
+ array(
2097
+ 'id' => self::REASON_DIDNT_WORK,
2098
+ 'text' => sprintf( $this->get_text_inline( "The %s didn't work", 'reason-didnt-work' ), $module_type ),
2099
+ 'input_type' => '',
2100
+ 'input_placeholder' => ''
2101
+ ),
2102
+ $reason_dont_share_info,
2103
+ $reason_found_better_plugin
2104
+ ),
2105
+ 'short-term' => array(
2106
+ array(
2107
+ 'id' => self::REASON_COULDNT_MAKE_IT_WORK,
2108
+ 'text' => $this->get_text_inline( "I couldn't understand how to make it work", 'reason-couldnt-make-it-work' ),
2109
+ 'input_type' => '',
2110
+ 'input_placeholder' => '',
2111
+ 'internal_message' => $contact_support_template
2112
+ ),
2113
+ $reason_found_better_plugin,
2114
+ array(
2115
+ 'id' => self::REASON_GREAT_BUT_NEED_SPECIFIC_FEATURE,
2116
+ '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 ),
2117
+ 'input_type' => 'textarea',
2118
+ 'input_placeholder' => $this->get_text_inline( 'What feature?', 'placeholder-feature' )
2119
+ ),
2120
+ array(
2121
+ 'id' => self::REASON_NOT_WORKING,
2122
+ 'text' => sprintf( $this->get_text_inline( 'The %s is not working', 'reason-not-working' ), $module_type ),
2123
+ 'input_type' => 'textarea',
2124
+ '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' )
2125
+ ),
2126
+ array(
2127
+ 'id' => self::REASON_NOT_WHAT_I_WAS_LOOKING_FOR,
2128
+ 'text' => $this->get_text_inline( "It's not what I was looking for", 'reason-not-what-i-was-looking-for' ),
2129
+ 'input_type' => 'textarea',
2130
+ 'input_placeholder' => $this->get_text_inline( "What you've been looking for?", 'placeholder-what-youve-been-looking-for' )
2131
+ ),
2132
+ array(
2133
+ 'id' => self::REASON_DIDNT_WORK_AS_EXPECTED,
2134
+ 'text' => sprintf( $this->get_text_inline( "The %s didn't work as expected", 'reason-didnt-work-as-expected' ), $module_type ),
2135
+ 'input_type' => 'textarea',
2136
+ 'input_placeholder' => $this->get_text_inline( 'What did you expect?', 'placeholder-what-did-you-expect' )
2137
+ )
2138
+ )
2139
+ );
2140
+
2141
+ // Randomize the reasons for the current user type.
2142
+ shuffle( $uninstall_reasons[ $user_type ] );
2143
+
2144
+ // Keep the following reasons as the last items in the list.
2145
+ $uninstall_reasons[ $user_type ][] = $reason_temporary_deactivation;
2146
+ $uninstall_reasons[ $user_type ][] = $reason_other;
2147
+
2148
+ $uninstall_reasons = $this->apply_filters( 'uninstall_reasons', $uninstall_reasons );
2149
+
2150
+ return $uninstall_reasons[ $user_type ];
2151
+ }
2152
+
2153
+ /**
2154
+ * Called after the user has submitted his reason for deactivating the plugin.
2155
+ *
2156
+ * @author Leo Fajardo (@leorw)
2157
+ * @since 1.1.2
2158
+ */
2159
+ function _submit_uninstall_reason_action() {
2160
+ $this->_logger->entrance();
2161
+
2162
+ $this->check_ajax_referer( 'submit_uninstall_reason' );
2163
+
2164
+ $reason_id = fs_request_get( 'reason_id' );
2165
+
2166
+ // Check if the given reason ID is an unsigned integer.
2167
+ if ( ! ctype_digit( $reason_id ) ) {
2168
+ exit;
2169
+ }
2170
+
2171
+ $reason_info = trim( fs_request_get( 'reason_info', '' ) );
2172
+ if ( ! empty( $reason_info ) ) {
2173
+ $reason_info = substr( $reason_info, 0, 128 );
2174
+ }
2175
+
2176
+ $reason = (object) array(
2177
+ 'id' => $reason_id,
2178
+ 'info' => $reason_info,
2179
+ 'is_anonymous' => fs_request_get_bool( 'is_anonymous' )
2180
+ );
2181
+
2182
+ $this->_storage->store( 'uninstall_reason', $reason );
2183
+
2184
+ /**
2185
+ * If the module type is "theme", trigger the uninstall event here (on theme deactivation) since themes do
2186
+ * not support uninstall hook.
2187
+ *
2188
+ * @author Leo Fajardo (@leorw)
2189
+ * @since 1.2.2
2190
+ */
2191
+ if ( $this->is_theme() ) {
2192
+ if ( $this->is_premium() && ! $this->has_active_valid_license() ) {
2193
+ FS_Plugin_Updater::instance( $this )->delete_update_data();
2194
+ }
2195
+
2196
+ $this->_uninstall_plugin_event( false );
2197
+ $this->remove_sdk_reference();
2198
+ }
2199
+
2200
+ // Print '1' for successful operation.
2201
+ echo 1;
2202
+ exit;
2203
+ }
2204
+
2205
+ /**
2206
+ * @author Leo Fajardo (@leorw)
2207
+ * @since 2.1.4
2208
+ */
2209
+ function cancel_subscription_or_trial_ajax_action() {
2210
+ $this->_logger->entrance();
2211
+
2212
+ $this->check_ajax_referer( 'cancel_subscription_or_trial' );
2213
+
2214
+ $result = $this->cancel_subscription_or_trial( fs_request_get( 'plugin_id', $this->get_id() ), false );
2215
+
2216
+ if ( $this->is_api_error( $result ) ) {
2217
+ $this->shoot_ajax_failure( $result->error->message );
2218
+ }
2219
+
2220
+ $this->shoot_ajax_success();
2221
+ }
2222
+
2223
+ /**
2224
+ * @author Leo Fajardo (@leorw)
2225
+ * @since 2.1.4
2226
+ *
2227
+ * @param number $plugin_id
2228
+ *
2229
+ * @return object
2230
+ */
2231
+ private function cancel_subscription_or_trial( $plugin_id ) {
2232
+ $fs = null;
2233
+ if ( $plugin_id == $this->get_id() ) {
2234
+ $fs = $this;
2235
+ } else if ( $this->is_addon_activated( $plugin_id ) ) {
2236
+ $fs = self::get_instance_by_id( $plugin_id );
2237
+ }
2238
+
2239
+ $result = null;
2240
+
2241
+ if ( ! is_null( $fs ) ) {
2242
+ $result = $fs->is_paid_trial() ?
2243
+ $fs->_cancel_trial() :
2244
+ $fs->_downgrade_site();
2245
+ }
2246
+
2247
+ return $result;
2248
+ }
2249
+
2250
+ /**
2251
+ * @author Leo Fajardo (@leorw)
2252
+ * @since 2.0.2
2253
+ */
2254
+ function _delete_theme_update_data_action() {
2255
+ FS_Plugin_Updater::instance( $this )->delete_update_data();
2256
+ }
2257
+
2258
+ #endregion
2259
+
2260
+ #----------------------------------------------------------------------------------
2261
+ #region Instance
2262
+ #----------------------------------------------------------------------------------
2263
+
2264
+ /**
2265
+ * Main singleton instance.
2266
+ *
2267
+ * @author Vova Feldman (@svovaf)
2268
+ * @since 1.0.0
2269
+ *
2270
+ * @param number $module_id
2271
+ * @param string|bool $slug
2272
+ * @param bool $is_init Is initiation sequence.
2273
+ *
2274
+ * @return Freemius|false
2275
+ */
2276
+ static function instance( $module_id, $slug = false, $is_init = false ) {
2277
+ if ( empty( $module_id ) ) {
2278
+ return false;
2279
+ }
2280
+
2281
+ /**
2282
+ * 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.
2283
+ */
2284
+ self::_load_required_static();
2285
+
2286
+ if ( ! is_numeric( $module_id ) ) {
2287
+ if ( ! $is_init && true === $slug ) {
2288
+ $is_init = true;
2289
+ }
2290
+
2291
+ $slug = $module_id;
2292
+
2293
+ $module = FS_Plugin_Manager::instance( $slug )->get();
2294
+
2295
+ if ( is_object( $module ) ) {
2296
+ $module_id = $module->id;
2297
+ }
2298
+ }
2299
+
2300
+ $key = 'm_' . $module_id;
2301
+
2302
+ if ( ! isset( self::$_instances[ $key ] ) ) {
2303
+ self::$_instances[ $key ] = new Freemius( $module_id, $slug, $is_init );
2304
+ }
2305
+
2306
+ return self::$_instances[ $key ];
2307
+ }
2308
+
2309
+ /**
2310
+ * @author Vova Feldman (@svovaf)
2311
+ * @since 1.0.6
2312
+ *
2313
+ * @param number $addon_id
2314
+ *
2315
+ * @return bool
2316
+ */
2317
+ private static function has_instance( $addon_id ) {
2318
+ return isset( self::$_instances[ 'm_' . $addon_id ] );
2319
+ }
2320
+
2321
+ /**
2322
+ * @author Leo Fajardo (@leorw)
2323
+ * @since 1.2.2
2324
+ *
2325
+ * @param string|number $id_or_slug
2326
+ * @param string $module_type
2327
+ *
2328
+ * @return number|false
2329
+ */
2330
+ private static function get_module_id( $id_or_slug, $module_type = WP_FS__MODULE_TYPE_PLUGIN ) {
2331
+ if ( is_numeric( $id_or_slug ) ) {
2332
+ return $id_or_slug;
2333
+ }
2334
+
2335
+ foreach ( self::$_instances as $instance ) {
2336
+ // Also check the module type since there can be a plugin and a theme with the same slug.
2337
+ if ( ( $module_type === $instance->get_module_type() ) && ( $id_or_slug === $instance->get_slug() ) ) {
2338
+ return $instance->get_id();
2339
+ }
2340
+ }
2341
+
2342
+ return false;
2343
+ }
2344
+
2345
+ /**
2346
+ * @author Vova Feldman (@svovaf)
2347
+ * @since 1.0.6
2348
+ *
2349
+ * @param number $id
2350
+ *
2351
+ * @return false|Freemius
2352
+ */
2353
+ static function get_instance_by_id( $id ) {
2354
+ return isset ( self::$_instances[ 'm_' . $id ] ) ?
2355
+ self::$_instances[ 'm_' . $id ] :
2356
+ false;
2357
+ }
2358
+
2359
+ /**
2360
+ *
2361
+ * @author Vova Feldman (@svovaf)
2362
+ * @since 1.0.1
2363
+ *
2364
+ * @param string $plugin_file
2365
+ * @param string $module_type
2366
+ *
2367
+ * @return false|Freemius
2368
+ */
2369
+ static function get_instance_by_file( $plugin_file, $module_type = WP_FS__MODULE_TYPE_PLUGIN ) {
2370
+ $slug = self::find_slug_by_basename( $plugin_file );
2371
+
2372
+ return ( false !== $slug ) ?
2373
+ self::instance( self::get_module_id( $slug, $module_type ) ) :
2374
+ false;
2375
+ }
2376
+
2377
+ /**
2378
+ * @author Vova Feldman (@svovaf)
2379
+ * @since 1.0.6
2380
+ *
2381
+ * @return false|Freemius
2382
+ */
2383
+ function get_parent_instance() {
2384
+ return self::get_instance_by_id( $this->_plugin->parent_plugin_id );
2385
+ }
2386
+
2387
+ /**
2388
+ * @author Vova Feldman (@svovaf)
2389
+ * @since 1.0.6
2390
+ *
2391
+ * @param string|number $id_or_slug
2392
+ *
2393
+ * @return false|Freemius
2394
+ */
2395
+ function get_addon_instance( $id_or_slug ) {
2396
+ $addon_id = self::get_module_id( $id_or_slug );
2397
+
2398
+ return self::instance( $addon_id );
2399
+ }
2400
+
2401
+ #endregion ------------------------------------------------------------------
2402
+
2403
+ /**
2404
+ * @author Vova Feldman (@svovaf)
2405
+ * @since 1.0.6
2406
+ *
2407
+ * @return bool
2408
+ */
2409
+ function is_parent_plugin_installed() {
2410
+ $is_active = self::has_instance( $this->_plugin->parent_plugin_id );
2411
+
2412
+ if ( $is_active ) {
2413
+ return true;
2414
+ }
2415
+
2416
+ /**
2417
+ * Parent module might be a theme. If that's the case, the add-on's FS
2418
+ * instance will be loaded prior to the theme's FS instance, therefore,
2419
+ * we need to check if it's active with a "look ahead".
2420
+ *
2421
+ * @author Vova Feldman
2422
+ * @since 1.2.2.3
2423
+ */
2424
+ global $fs_active_plugins;
2425
+ if ( is_object( $fs_active_plugins ) && is_array( $fs_active_plugins->plugins ) ) {
2426
+ $active_theme = wp_get_theme();
2427
+
2428
+ foreach ( $fs_active_plugins->plugins as $sdk => $module ) {
2429
+ if ( WP_FS__MODULE_TYPE_THEME === $module->type ) {
2430
+ if ( $module->plugin_path == $active_theme->get_stylesheet() ) {
2431
+ // Parent module is a theme and it's currently active.
2432
+ return true;
2433
+ }
2434
+ }
2435
+ }
2436
+ }
2437
+
2438
+ return false;
2439
+ }
2440
+
2441
+ /**
2442
+ * Check if add-on parent plugin in activation mode.
2443
+ *
2444
+ * @author Vova Feldman (@svovaf)
2445
+ * @since 1.0.7
2446
+ *
2447
+ * @return bool
2448
+ */
2449
+ function is_parent_in_activation() {
2450
+ $parent_fs = $this->get_parent_instance();
2451
+ if ( ! is_object( $parent_fs ) ) {
2452
+ return false;
2453
+ }
2454
+
2455
+ return ( $parent_fs->is_activation_mode() );
2456
+ }
2457
+
2458
+ /**
2459
+ * Is plugin in activation mode.
2460
+ *
2461
+ * @author Vova Feldman (@svovaf)
2462
+ * @since 1.0.7
2463
+ *
2464
+ * @param bool $and_on
2465
+ *
2466
+ * @return bool
2467
+ */
2468
+ function is_activation_mode( $and_on = true ) {
2469
+ return fs_is_network_admin() ?
2470
+ $this->is_network_activation_mode( $and_on ) :
2471
+ $this->is_site_activation_mode( $and_on );
2472
+ }
2473
+
2474
+ /**
2475
+ * Is plugin in activation mode.
2476
+ *
2477
+ * @author Vova Feldman (@svovaf)
2478
+ * @since 1.0.7
2479
+ *
2480
+ * @param bool $and_on
2481
+ *
2482
+ * @return bool
2483
+ */
2484
+ function is_site_activation_mode( $and_on = true ) {
2485
+ return (
2486
+ ( $this->is_on() || ! $and_on ) &&
2487
+ ( $this->is_premium() && true === $this->_storage->require_license_activation ) ||
2488
+ (
2489
+ ( ! $this->is_registered() ||
2490
+ ( $this->is_only_premium() && ! $this->has_features_enabled_license() ) ) &&
2491
+ ( ! $this->is_enable_anonymous() ||
2492
+ ( ! $this->is_anonymous() && ! $this->is_pending_activation() ) )
2493
+ )
2494
+ );
2495
+ }
2496
+
2497
+ /**
2498
+ * Checks if the SDK in network activation mode.
2499
+ *
2500
+ * @author Leo Fajardo (@leorw)
2501
+ * @since 2.0.0
2502
+ *
2503
+ * @param bool $and_on
2504
+ *
2505
+ * @return bool
2506
+ */
2507
+ private function is_network_activation_mode( $and_on = true ) {
2508
+ if ( ! $this->_is_network_active ) {
2509
+ // Not network activated.
2510
+ return false;
2511
+ }
2512
+
2513
+ if ( $this->is_network_upgrade_mode() ) {
2514
+ // Special flag to enforce network activation mode to decide what to do with the sites that are not yet opted-in nor skipped.
2515
+ return true;
2516
+ }
2517
+
2518
+ if ( ! $this->is_site_activation_mode( $and_on ) ) {
2519
+ // 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.
2520
+ return false;
2521
+ }
2522
+
2523
+ if ( $this->is_network_delegated_connection() ) {
2524
+ // Super-admin delegated the connection to the site admins -> not activation mode.
2525
+ return false;
2526
+ }
2527
+
2528
+ if ( $this->is_network_anonymous() && true !== $this->_storage->require_license_activation ) {
2529
+ // Super-admin skipped the connection network wide -> not activation mode.
2530
+ return false;
2531
+ }
2532
+
2533
+ if ( $this->is_network_registered() ) {
2534
+ // Super-admin connected at least one site -> not activation mode.
2535
+ return false;
2536
+ }
2537
+
2538
+ return true;
2539
+ }
2540
+
2541
+ /**
2542
+ * Check if current page is the opt-in/pending-activation page.
2543
+ *
2544
+ * @author Vova Feldman (@svovaf)
2545
+ * @since 1.2.1.7
2546
+ *
2547
+ * @return bool
2548
+ */
2549
+ function is_activation_page() {
2550
+ if ( $this->_menu->is_main_settings_page() ) {
2551
+ return true;
2552
+ }
2553
+
2554
+ if ( ! $this->is_activation_mode() ) {
2555
+ return false;
2556
+ }
2557
+
2558
+ // Check if current page is matching the activation page.
2559
+ return $this->is_matching_url( $this->get_activation_url() );
2560
+ }
2561
+
2562
+ /**
2563
+ * Check if URL path's are matching and that all querystring
2564
+ * arguments of the $sub_url exist in the $url with the same values.
2565
+ *
2566
+ * WARNING:
2567
+ * 1. This method doesn't check if the sub/domain are matching.
2568
+ * 2. Ignore case sensitivity.
2569
+ *
2570
+ * @author Vova Feldman (@svovaf)
2571
+ * @since 1.2.1.7
2572
+ *
2573
+ * @param string $sub_url
2574
+ * @param string $url If argument is not set, check if the sub_url matching the current's page URL.
2575
+ *
2576
+ * @return bool
2577
+ */
2578
+ private function is_matching_url( $sub_url, $url = '' ) {
2579
+ if ( empty( $url ) ) {
2580
+ $url = $_SERVER['REQUEST_URI'];
2581
+ }
2582
+
2583
+ $url = strtolower( $url );
2584
+ $sub_url = strtolower( $sub_url );
2585
+
2586
+ if ( parse_url( $sub_url, PHP_URL_PATH ) !== parse_url( $url, PHP_URL_PATH ) ) {
2587
+ // Different path - DO NOT OVERRIDE PAGE.
2588
+ return false;
2589
+ }
2590
+
2591
+ $url_params = array();
2592
+ parse_str( parse_url( $url, PHP_URL_QUERY ), $url_params );
2593
+
2594
+ $sub_url_params = array();
2595
+ parse_str( parse_url( $sub_url, PHP_URL_QUERY ), $sub_url_params );
2596
+
2597
+ foreach ( $sub_url_params as $key => $val ) {
2598
+ if ( ! isset( $url_params[ $key ] ) || $val != $url_params[ $key ] ) {
2599
+ // Not matching query string - DO NOT OVERRIDE PAGE.
2600
+ return false;
2601
+ }
2602
+ }
2603
+
2604
+ return true;
2605
+ }
2606
+
2607
+ /**
2608
+ * Get the basenames of all active plugins for specific blog. Including network activated plugins.
2609
+ *
2610
+ * @author Vova Feldman (@svovaf)
2611
+ * @since 2.0.0
2612
+ *
2613
+ * @param int $blog_id
2614
+ *
2615
+ * @return string[]
2616
+ */
2617
+ private static function get_active_plugins_basenames( $blog_id = 0 ) {
2618
+ if ( is_multisite() && $blog_id > 0 ) {
2619
+ $active_basenames = get_blog_option( $blog_id, 'active_plugins' );
2620
+ } else {
2621
+ $active_basenames = get_option( 'active_plugins' );
2622
+ }
2623
+
2624
+ if ( is_multisite() ) {
2625
+ $network_active_basenames = get_site_option( 'active_sitewide_plugins' );
2626
+
2627
+ if ( is_array( $network_active_basenames ) && ! empty( $network_active_basenames ) ) {
2628
+ $active_basenames = array_merge( $active_basenames, $network_active_basenames );
2629
+ }
2630
+ }
2631
+
2632
+ return $active_basenames;
2633
+ }
2634
+
2635
+ /**
2636
+ * Get collection of all active plugins. Including network activated plugins.
2637
+ *
2638
+ * @author Vova Feldman (@svovaf)
2639
+ * @since 1.0.9
2640
+ *
2641
+ * @param int $blog_id Since 2.0.0
2642
+ *
2643
+ * @return array[string]array
2644
+ */
2645
+ private static function get_active_plugins( $blog_id = 0 ) {
2646
+ self::require_plugin_essentials();
2647
+
2648
+ $active_plugin = array();
2649
+ $all_plugins = fs_get_plugins();
2650
+ $active_plugins_basenames = self::get_active_plugins_basenames( $blog_id );
2651
+
2652
+ foreach ( $active_plugins_basenames as $plugin_basename ) {
2653
+ $active_plugin[ $plugin_basename ] = $all_plugins[ $plugin_basename ];
2654
+ }
2655
+
2656
+ return $active_plugin;
2657
+ }
2658
+
2659
+ /**
2660
+ * Get collection of all site active plugins for a specified blog.
2661
+ *
2662
+ * @author Vova Feldman (@svovaf)
2663
+ * @since 2.0.0
2664
+ *
2665
+ * @param int $blog_id
2666
+ *
2667
+ * @return array[string]array
2668
+ */
2669
+ private static function get_site_active_plugins( $blog_id = 0 ) {
2670
+ $active_basenames = ( is_multisite() && $blog_id > 0 ) ?
2671
+ get_blog_option( $blog_id, 'active_plugins' ) :
2672
+ get_option( 'active_plugins' );
2673
+
2674
+ $active = array();
2675
+
2676
+ if ( ! is_array( $active_basenames ) ) {
2677
+ return $active;
2678
+ }
2679
+
2680
+ foreach ( $active_basenames as $basename ) {
2681
+ $active[ $basename ] = array(
2682
+ 'is_active' => true,
2683
+ 'Version' => '1.0', // Dummy version.
2684
+ 'slug' => self::get_plugin_slug( $basename ),
2685
+ );
2686
+ }
2687
+
2688
+ return $active;
2689
+ }
2690
+
2691
+ /**
2692
+ * Get collection of all plugins with their activation status for a specified blog.
2693
+ *
2694
+ * @author Vova Feldman (@svovaf)
2695
+ * @since 1.1.8
2696
+ *
2697
+ * @param int $blog_id Since 2.0.0
2698
+ *
2699
+ * @return array Key is the plugin file path and the value is an array of the plugin data.
2700
+ */
2701
+ private static function get_all_plugins( $blog_id = 0 ) {
2702
+ self::require_plugin_essentials();
2703
+
2704
+ $all_plugins = fs_get_plugins();
2705
+
2706
+ $active_plugins_basenames = self::get_active_plugins_basenames( $blog_id );
2707
+
2708
+ foreach ( $all_plugins as $basename => &$data ) {
2709
+ // By default set to inactive (next foreach update the active plugins).
2710
+ $data['is_active'] = false;
2711
+ // Enrich with plugin slug.
2712
+ $data['slug'] = self::get_plugin_slug( $basename );
2713
+ }
2714
+
2715
+ // Flag active plugins.
2716
+ foreach ( $active_plugins_basenames as $basename ) {
2717
+ if ( isset( $all_plugins[ $basename ] ) ) {
2718
+ $all_plugins[ $basename ]['is_active'] = true;
2719
+ }
2720
+ }
2721
+
2722
+ return $all_plugins;
2723
+ }
2724
+
2725
+ /**
2726
+ * Get collection of all plugins and if they are network level activated.
2727
+ *
2728
+ * @author Vova Feldman (@svovaf)
2729
+ * @since 2.0.0
2730
+ *
2731
+ * @return array Key is the plugin basename and the value is an array of the plugin data.
2732
+ */
2733
+ private static function get_network_plugins() {
2734
+ self::require_plugin_essentials();
2735
+
2736
+ $all_plugins = fs_get_plugins();
2737
+
2738
+ $network_active_basenames = is_multisite() ?
2739
+ get_site_option( 'active_sitewide_plugins' ) :
2740
+ array();
2741
+
2742
+ foreach ( $all_plugins as $basename => &$data ) {
2743
+ // By default set to inactive (next foreach update the active plugins).
2744
+ $data['is_active'] = false;
2745
+ // Enrich with plugin slug.
2746
+ $data['slug'] = self::get_plugin_slug( $basename );
2747
+ }
2748
+
2749
+ // Flag active plugins.
2750
+ foreach ( $network_active_basenames as $basename ) {
2751
+ if ( isset( $all_plugins[ $basename ] ) ) {
2752
+ $all_plugins[ $basename ]['is_active'] = true;
2753
+ }
2754
+ }
2755
+
2756
+ return $all_plugins;
2757
+ }
2758
+
2759
+ /**
2760
+ * Cached result of get_site_transient( 'update_plugins' )
2761
+ *
2762
+ * @author Vova Feldman (@svovaf)
2763
+ * @since 1.1.8
2764
+ *
2765
+ * @var object
2766
+ */
2767
+ private static $_plugins_info;
2768
+
2769
+ /**
2770
+ * Helper function to get specified plugin's slug.
2771
+ *
2772
+ * @author Vova Feldman (@svovaf)
2773
+ * @since 1.1.8
2774
+ *
2775
+ * @param $basename
2776
+ *
2777
+ * @return string
2778
+ */
2779
+ private static function get_plugin_slug( $basename ) {
2780
+ if ( ! isset( self::$_plugins_info ) ) {
2781
+ self::$_plugins_info = get_site_transient( 'update_plugins' );
2782
+ }
2783
+
2784
+ $slug = '';
2785
+
2786
+ if ( is_object( self::$_plugins_info ) ) {
2787
+ if ( isset( self::$_plugins_info->no_update ) &&
2788
+ isset( self::$_plugins_info->no_update[ $basename ] ) &&
2789
+ ! empty( self::$_plugins_info->no_update[ $basename ]->slug )
2790
+ ) {
2791
+ $slug = self::$_plugins_info->no_update[ $basename ]->slug;
2792
+ } else if ( isset( self::$_plugins_info->response ) &&
2793
+ isset( self::$_plugins_info->response[ $basename ] ) &&
2794
+ ! empty( self::$_plugins_info->response[ $basename ]->slug )
2795
+ ) {
2796
+ $slug = self::$_plugins_info->response[ $basename ]->slug;
2797
+ }
2798
+ }
2799
+
2800
+ if ( empty( $slug ) ) {
2801
+ // Try to find slug from FS data.
2802
+ $slug = self::find_slug_by_basename( $basename );
2803
+ }
2804
+
2805
+ if ( empty( $slug ) ) {
2806
+ // Fallback to plugin's folder name.
2807
+ $slug = dirname( $basename );
2808
+ }
2809
+
2810
+ return $slug;
2811
+ }
2812
+
2813
+ private static $_statics_loaded = false;
2814
+
2815
+ /**
2816
+ * Load static resources.
2817
+ *
2818
+ * @author Vova Feldman (@svovaf)
2819
+ * @since 1.0.1
2820
+ */
2821
+ private static function _load_required_static() {
2822
+ if ( self::$_statics_loaded ) {
2823
+ return;
2824
+ }
2825
+
2826
+ self::$_static_logger = FS_Logger::get_logger( WP_FS__SLUG, WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
2827
+
2828
+ self::$_static_logger->entrance();
2829
+
2830
+ self::$_accounts = FS_Options::instance( WP_FS__ACCOUNTS_OPTION_NAME, true );
2831
+
2832
+ if ( is_multisite() ) {
2833
+ $has_skipped_migration = (
2834
+ // 'id_slug_type_path_map' - was never stored on older versions, therefore, not exists on the site level.
2835
+ null === self::$_accounts->get_option( 'id_slug_type_path_map', null, false ) &&
2836
+ // 'file_slug_map' stored on the site level, so it was running an SDK version before it was integrated with MS-network.
2837
+ null !== self::$_accounts->get_option( 'file_slug_map', null, false )
2838
+ );
2839
+
2840
+ /**
2841
+ * If the file_slug_map exists on the site level but doesn't exist on the
2842
+ * network level storage, it means that we need to process the storage with migration.
2843
+ *
2844
+ * 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.
2845
+ *
2846
+ * @author Vova Feldman (@svovaf)
2847
+ * @since 2.0.0
2848
+ */
2849
+ if (
2850
+ ( $has_skipped_migration && true !== self::$_accounts->get_option( 'ms_migration_complete', false, true ) ) ||
2851
+ ( null === self::$_accounts->get_option( 'file_slug_map', null, true ) &&
2852
+ null !== self::$_accounts->get_option( 'file_slug_map', null, false ) )
2853
+ ) {
2854
+ self::migrate_options_to_network();
2855
+ }
2856
+ }
2857
+
2858
+ self::$_global_admin_notices = FS_Admin_Notices::instance( 'global' );
2859
+
2860
+ if ( ! WP_FS__DEMO_MODE ) {
2861
+ add_action( ( fs_is_network_admin() ? 'network_' : '' ) . 'admin_menu', array(
2862
+ 'Freemius',
2863
+ '_add_debug_section'
2864
+ ) );
2865
+ }
2866
+
2867
+ add_action( "wp_ajax_fs_toggle_debug_mode", array( 'Freemius', '_toggle_debug_mode' ) );
2868
+
2869
+ self::add_ajax_action_static( 'get_debug_log', array( 'Freemius', '_get_debug_log' ) );
2870
+
2871
+ self::add_ajax_action_static( 'get_db_option', array( 'Freemius', '_get_db_option' ) );
2872
+
2873
+ self::add_ajax_action_static( 'set_db_option', array( 'Freemius', '_set_db_option' ) );
2874
+
2875
+ if ( 0 == did_action( 'plugins_loaded' ) ) {
2876
+ add_action( 'plugins_loaded', array( 'Freemius', '_load_textdomain' ), 1 );
2877
+ }
2878
+
2879
+ add_action( 'admin_footer', array( 'Freemius', '_enrich_ajax_url' ) );
2880
+ add_action( 'admin_footer', array( 'Freemius', '_open_support_forum_in_new_page' ) );
2881
+
2882
+
2883
+ self::$_statics_loaded = true;
2884
+ }
2885
+
2886
+ /**
2887
+ * @author Leo Fajardo (@leorw)
2888
+ *
2889
+ * @since 2.1.3
2890
+ */
2891
+ private static function migrate_options_to_network() {
2892
+ self::migrate_accounts_to_network();
2893
+
2894
+ // Migrate API options from site level to network level.
2895
+ $api_network_options = FS_Option_Manager::get_manager( WP_FS__OPTIONS_OPTION_NAME, true, true );
2896
+ $api_network_options->migrate_to_network();
2897
+
2898
+ // Migrate API cache to network level storage.
2899
+ FS_Cache_Manager::get_manager( WP_FS__API_CACHE_OPTION_NAME )->migrate_to_network();
2900
+
2901
+ self::$_accounts->set_option( 'ms_migration_complete', true, true );
2902
+ }
2903
+
2904
+ #----------------------------------------------------------------------------------
2905
+ #region Localization
2906
+ #----------------------------------------------------------------------------------
2907
+
2908
+ /**
2909
+ * Load framework's text domain.
2910
+ *
2911
+ * @author Vova Feldman (@svovaf)
2912
+ * @since 1.2.1
2913
+ */
2914
+ static function _load_textdomain() {
2915
+ if ( ! is_admin() ) {
2916
+ return;
2917
+ }
2918
+
2919
+ global $fs_active_plugins;
2920
+
2921
+ // Works both for plugins and themes.
2922
+ load_plugin_textdomain(
2923
+ 'freemius',
2924
+ false,
2925
+ $fs_active_plugins->newest->sdk_path . '/languages/'
2926
+ );
2927
+ }
2928
+
2929
+ #endregion
2930
+
2931
+ #----------------------------------------------------------------------------------
2932
+ #region Debugging
2933
+ #----------------------------------------------------------------------------------
2934
+
2935
+ /**
2936
+ * @author Vova Feldman (@svovaf)
2937
+ * @since 1.0.8
2938
+ */
2939
+ static function _add_debug_section() {
2940
+ if ( ! is_super_admin() ) {
2941
+ // Add debug page only for super-admins.
2942
+ return;
2943
+ }
2944
+
2945
+ self::$_static_logger->entrance();
2946
+
2947
+ $title = sprintf( '%s [v.%s]', fs_text_inline( 'Freemius Debug' ), WP_FS__SDK_VERSION );
2948
+
2949
+ if ( WP_FS__DEV_MODE ) {
2950
+ // Add top-level debug menu item.
2951
+ $hook = FS_Admin_Menu_Manager::add_page(
2952
+ $title,
2953
+ $title,
2954
+ 'manage_options',
2955
+ 'freemius',
2956
+ array( 'Freemius', '_debug_page_render' )
2957
+ );
2958
+ } else {
2959
+ // Add hidden debug page.
2960
+ $hook = FS_Admin_Menu_Manager::add_subpage(
2961
+ null,
2962
+ $title,
2963
+ $title,
2964
+ 'manage_options',
2965
+ 'freemius',
2966
+ array( 'Freemius', '_debug_page_render' )
2967
+ );
2968
+ }
2969
+
2970
+ if ( ! empty( $hook ) ) {
2971
+ add_action( "load-$hook", array( 'Freemius', '_debug_page_actions' ) );
2972
+ }
2973
+ }
2974
+
2975
+ /**
2976
+ * @author Vova Feldman (@svovaf)
2977
+ * @since 1.1.7.3
2978
+ */
2979
+ static function _toggle_debug_mode() {
2980
+ $is_on = fs_request_get( 'is_on', false, 'post' );
2981
+
2982
+ if ( fs_request_is_post() && in_array( $is_on, array( 0, 1 ) ) ) {
2983
+ update_option( 'fs_debug_mode', $is_on );
2984
+
2985
+ // Turn on/off storage logging.
2986
+ FS_Logger::_set_storage_logging( ( 1 == $is_on ) );
2987
+ }
2988
+
2989
+ exit;
2990
+ }
2991
+
2992
+ /**
2993
+ * @author Vova Feldman (@svovaf)
2994
+ * @since 1.2.1.6
2995
+ */
2996
+ static function _get_debug_log() {
2997
+ $logs = FS_Logger::load_db_logs(
2998
+ fs_request_get( 'filters', false, 'post' ),
2999
+ ! empty( $_POST['limit'] ) && is_numeric( $_POST['limit'] ) ? $_POST['limit'] : 200,
3000
+ ! empty( $_POST['offset'] ) && is_numeric( $_POST['offset'] ) ? $_POST['offset'] : 0
3001
+ );
3002
+
3003
+ self::shoot_ajax_success( $logs );
3004
+ }
3005
+
3006
+ /**
3007
+ * @author Vova Feldman (@svovaf)
3008
+ * @since 1.2.1.7
3009
+ */
3010
+ static function _get_db_option() {
3011
+ $option_name = fs_request_get( 'option_name' );
3012
+
3013
+ $value = get_option( $option_name );
3014
+
3015
+ $result = array(
3016
+ 'name' => $option_name,
3017
+ );
3018
+
3019
+ if ( false !== $value ) {
3020
+ if ( ! is_string( $value ) ) {
3021
+ $value = json_encode( $value );
3022
+ }
3023
+
3024
+ $result['value'] = $value;
3025
+ }
3026
+
3027
+ self::shoot_ajax_success( $result );
3028
+ }
3029
+
3030
+ /**
3031
+ * @author Vova Feldman (@svovaf)
3032
+ * @since 1.2.1.7
3033
+ */
3034
+ static function _set_db_option() {
3035
+ $option_name = fs_request_get( 'option_name' );
3036
+ $option_value = fs_request_get( 'option_value' );
3037
+
3038
+ if ( ! empty( $option_value ) ) {
3039
+ update_option( $option_name, $option_value );
3040
+ }
3041
+
3042
+ self::shoot_ajax_success();
3043
+ }
3044
+
3045
+ /**
3046
+ * @author Vova Feldman (@svovaf)
3047
+ * @since 1.0.8
3048
+ */
3049
+ static function _debug_page_actions() {
3050
+ self::_clean_admin_content_section();
3051
+
3052
+ if ( fs_request_is_action( 'restart_freemius' ) ) {
3053
+ check_admin_referer( 'restart_freemius' );
3054
+
3055
+ if ( ! is_multisite() ) {
3056
+ // Clear accounts data.
3057
+ self::$_accounts->clear( null, true );
3058
+ } else {
3059
+ $sites = self::get_sites();
3060
+ foreach ( $sites as $site ) {
3061
+ $blog_id = self::get_site_blog_id( $site );
3062
+ self::$_accounts->clear( $blog_id, true );
3063
+ }
3064
+
3065
+ // Clear network level storage.
3066
+ self::$_accounts->clear( true, true );
3067
+ }
3068
+
3069
+ // Clear SDK reference cache.
3070
+ delete_option( 'fs_active_plugins' );
3071
+ } else if ( fs_request_is_action( 'clear_updates_data' ) ) {
3072
+ check_admin_referer( 'clear_updates_data' );
3073
+
3074
+ if ( ! is_multisite() ) {
3075
+ set_site_transient( 'update_plugins', null );
3076
+ set_site_transient( 'update_themes', null );
3077
+ } else {
3078
+ $current_blog_id = get_current_blog_id();
3079
+
3080
+ $sites = self::get_sites();
3081
+ foreach ( $sites as $site ) {
3082
+ switch_to_blog( self::get_site_blog_id( $site ) );
3083
+
3084
+ set_site_transient( 'update_plugins', null );
3085
+ set_site_transient( 'update_themes', null );
3086
+ }
3087
+
3088
+ switch_to_blog( $current_blog_id );
3089
+ }
3090
+ } else if ( fs_request_is_action( 'simulate_trial' ) ) {
3091
+ check_admin_referer( 'simulate_trial' );
3092
+
3093
+ $fs = freemius( fs_request_get( 'module_id' ) );
3094
+
3095
+ // Update SDK install to at least 24 hours before.
3096
+ $fs->_storage->install_timestamp = ( time() - WP_FS__TIME_24_HOURS_IN_SEC );
3097
+ // Unset the trial shown timestamp.
3098
+ unset( $fs->_storage->trial_promotion_shown );
3099
+ } else if ( fs_request_is_action( 'simulate_network_upgrade' ) ) {
3100
+ check_admin_referer( 'simulate_network_upgrade' );
3101
+
3102
+ $fs = freemius( fs_request_get( 'module_id' ) );
3103
+
3104
+ self::set_network_upgrade_mode( $fs->_storage );
3105
+ } else if ( fs_request_is_action( 'delete_install' ) ) {
3106
+ check_admin_referer( 'delete_install' );
3107
+
3108
+ self::_delete_site_by_slug(
3109
+ fs_request_get( 'slug' ),
3110
+ fs_request_get( 'module_type' ),
3111
+ true,
3112
+ fs_request_get( 'blog_id', null )
3113
+ );
3114
+ } else if ( fs_request_is_action( 'delete_user' ) ) {
3115
+ check_admin_referer( 'delete_user' );
3116
+
3117
+ self::delete_user( fs_request_get( 'user_id' ) );
3118
+ } else if ( fs_request_is_action( 'download_logs' ) ) {
3119
+ check_admin_referer( 'download_logs' );
3120
+
3121
+ $download_url = FS_Logger::download_db_logs(
3122
+ fs_request_get( 'filters', false, 'post' )
3123
+ );
3124
+
3125
+ if ( false === $download_url ) {
3126
+ 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.' );
3127
+ }
3128
+
3129
+ fs_redirect( $download_url );
3130
+ } else if ( fs_request_is_action( 'migrate_options_to_network' ) ) {
3131
+ check_admin_referer( 'migrate_options_to_network' );
3132
+
3133
+ self::migrate_options_to_network();
3134
+ }
3135
+ }
3136
+
3137
+ /**
3138
+ * @author Vova Feldman (@svovaf)
3139
+ * @since 1.0.8
3140
+ */
3141
+ static function _debug_page_render() {
3142
+ self::$_static_logger->entrance();
3143
+
3144
+ if ( ! is_multisite() ) {
3145
+ $all_plugins_installs = self::get_all_sites( WP_FS__MODULE_TYPE_PLUGIN );
3146
+ $all_themes_installs = self::get_all_sites( WP_FS__MODULE_TYPE_THEME );
3147
+ } else {
3148
+ $sites = self::get_sites();
3149
+
3150
+ $all_plugins_installs = array();
3151
+ $all_themes_installs = array();
3152
+
3153
+ foreach ( $sites as $site ) {
3154
+ $blog_id = self::get_site_blog_id( $site );
3155
+
3156
+ $plugins_installs = self::get_all_sites( WP_FS__MODULE_TYPE_PLUGIN, $blog_id );
3157
+
3158
+ foreach ( $plugins_installs as $slug => $install ) {
3159
+ if ( ! isset( $all_plugins_installs[ $slug ] ) ) {
3160
+ $all_plugins_installs[ $slug ] = array();
3161
+ }
3162
+
3163
+ $install->blog_id = $blog_id;
3164
+
3165
+ $all_plugins_installs[ $slug ][] = $install;
3166
+ }
3167
+
3168
+ $themes_installs = self::get_all_sites( WP_FS__MODULE_TYPE_THEME, $blog_id );
3169
+
3170
+ foreach ( $themes_installs as $slug => $install ) {
3171
+ if ( ! isset( $all_themes_installs[ $slug ] ) ) {
3172
+ $all_themes_installs[ $slug ] = array();
3173
+ }
3174
+
3175
+ $install->blog_id = $blog_id;
3176
+
3177
+ $all_themes_installs[ $slug ][] = $install;
3178
+ }
3179
+ }
3180
+ }
3181
+
3182
+ $licenses_by_module_type = self::get_all_licenses_by_module_type();
3183
+
3184
+ $vars = array(
3185
+ 'plugin_sites' => $all_plugins_installs,
3186
+ 'theme_sites' => $all_themes_installs,
3187
+ 'users' => self::get_all_users(),
3188
+ 'addons' => self::get_all_addons(),
3189
+ 'account_addons' => self::get_all_account_addons(),
3190
+ 'plugin_licenses' => $licenses_by_module_type[ WP_FS__MODULE_TYPE_PLUGIN ],
3191
+ 'theme_licenses' => $licenses_by_module_type[ WP_FS__MODULE_TYPE_THEME ]
3192
+ );
3193
+
3194
+ fs_enqueue_local_style( 'fs_debug', '/admin/debug.css' );
3195
+ fs_require_once_template( 'debug.php', $vars );
3196
+ }
3197
+
3198
+ #endregion
3199
+
3200
+ #----------------------------------------------------------------------------------
3201
+ #region Connectivity Issues
3202
+ #----------------------------------------------------------------------------------
3203
+
3204
+ /**
3205
+ * Check if Freemius should be turned on for the current plugin install.
3206
+ *
3207
+ * Note:
3208
+ * $this->_is_on is updated in has_api_connectivity()
3209
+ *
3210
+ * @author Vova Feldman (@svovaf)
3211
+ * @since 1.0.9
3212
+ *
3213
+ * @return bool
3214
+ */
3215
+ function is_on() {
3216
+ self::$_static_logger->entrance();
3217
+
3218
+ if ( isset( $this->_is_on ) ) {
3219
+ return $this->_is_on;
3220
+ }
3221
+
3222
+ // If already installed or pending then sure it's on :)
3223
+ if ( $this->is_registered() || $this->is_pending_activation() ) {
3224
+ $this->_is_on = true;
3225
+
3226
+ return true;
3227
+ }
3228
+
3229
+ return false;
3230
+ }
3231
+
3232
+ /**
3233
+ * @author Vova Feldman (@svovaf)
3234
+ * @since 1.1.7.3
3235
+ *
3236
+ * @param bool $flush_if_no_connectivity
3237
+ *
3238
+ * @return bool
3239
+ */
3240
+ private function should_run_connectivity_test( $flush_if_no_connectivity = false ) {
3241
+ if ( ! isset( $this->_storage->connectivity_test ) ) {
3242
+ // Connectivity test was never executed, or cache was cleared.
3243
+ return true;
3244
+ }
3245
+
3246
+ if ( WP_FS__PING_API_ON_IP_OR_HOST_CHANGES ) {
3247
+ if ( WP_FS__IS_HTTP_REQUEST ) {
3248
+ if ( $_SERVER['HTTP_HOST'] != $this->_storage->connectivity_test['host'] ) {
3249
+ // Domain changed.
3250
+ return true;
3251
+ }
3252
+
3253
+ if ( WP_FS__REMOTE_ADDR != $this->_storage->connectivity_test['server_ip'] ) {
3254
+ // Server IP changed.
3255
+ return true;
3256
+ }
3257
+ }
3258
+ }
3259
+
3260
+ if ( $this->_storage->connectivity_test['is_connected'] &&
3261
+ $this->_storage->connectivity_test['is_active']
3262
+ ) {
3263
+ // API connected and Freemius is active - no need to run connectivity check.
3264
+ return false;
3265
+ }
3266
+
3267
+ if ( $flush_if_no_connectivity ) {
3268
+ /**
3269
+ * If explicitly asked to flush when no connectivity - do it only
3270
+ * if at least 10 sec passed from the last API connectivity test.
3271
+ */
3272
+ return ( isset( $this->_storage->connectivity_test['timestamp'] ) &&
3273
+ ( WP_FS__SCRIPT_START_TIME - $this->_storage->connectivity_test['timestamp'] ) > 10 );
3274
+ }
3275
+
3276
+ /**
3277
+ * @since 1.1.7 Don't check for connectivity on plugin downgrade.
3278
+ */
3279
+ $version = $this->get_plugin_version();
3280
+ if ( version_compare( $version, $this->_storage->connectivity_test['version'], '>' ) ) {
3281
+ // If it's a plugin version upgrade and Freemius is off or no connectivity, run connectivity test.
3282
+ return true;
3283
+ }
3284
+
3285
+ return false;
3286
+ }
3287
+
3288
+ /**
3289
+ * @author Vova Feldman (@svovaf)
3290
+ * @since 1.1.7.4
3291
+ *
3292
+ * @param int|null $blog_id Since 2.0.0.
3293
+ * @param bool $is_gdpr_test Since 2.0.2. Perform only the GDPR test.
3294
+ *
3295
+ * @return object|false
3296
+ */
3297
+ private function ping( $blog_id = null, $is_gdpr_test = false ) {
3298
+ if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY ) {
3299
+ return false;
3300
+ }
3301
+
3302
+ $version = $this->get_plugin_version();
3303
+
3304
+ $is_update = $this->apply_filters( 'is_plugin_update', $this->is_plugin_update() );
3305
+
3306
+ return $this->get_api_plugin_scope()->ping(
3307
+ $this->get_anonymous_id( $blog_id ),
3308
+ array(
3309
+ 'is_update' => json_encode( $is_update ),
3310
+ 'version' => $version,
3311
+ 'sdk' => $this->version,
3312
+ 'is_admin' => json_encode( is_admin() ),
3313
+ 'is_ajax' => json_encode( self::is_ajax() ),
3314
+ 'is_cron' => json_encode( self::is_cron() ),
3315
+ 'is_gdpr_test' => $is_gdpr_test,
3316
+ 'is_http' => json_encode( WP_FS__IS_HTTP_REQUEST ),
3317
+ )
3318
+ );
3319
+ }
3320
+
3321
+ /**
3322
+ * Check if there's any connectivity issue to Freemius API.
3323
+ *
3324
+ * @author Vova Feldman (@svovaf)
3325
+ * @since 1.0.9
3326
+ *
3327
+ * @param bool $flush_if_no_connectivity
3328
+ *
3329
+ * @return bool
3330
+ */
3331
+ function has_api_connectivity( $flush_if_no_connectivity = false ) {
3332
+ $this->_logger->entrance();
3333
+
3334
+ if ( isset( $this->_has_api_connection ) && ( $this->_has_api_connection || ! $flush_if_no_connectivity ) ) {
3335
+ return $this->_has_api_connection;
3336
+ }
3337
+
3338
+ if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY &&
3339
+ isset( $this->_storage->connectivity_test ) &&
3340
+ true === $this->_storage->connectivity_test['is_connected']
3341
+ ) {
3342
+ unset( $this->_storage->connectivity_test );
3343
+ }
3344
+
3345
+ if ( ! $this->should_run_connectivity_test( $flush_if_no_connectivity ) ) {
3346
+ $this->_has_api_connection = $this->_storage->connectivity_test['is_connected'];
3347
+ /**
3348
+ * @since 1.1.6 During dev mode, if there's connectivity - turn Freemius on regardless the configuration.
3349
+ *
3350
+ * @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.
3351
+ */
3352
+ $this->_is_on = $this->_storage->connectivity_test['is_active'] ||
3353
+ $this->is_premium() ||
3354
+ ( WP_FS__DEV_MODE && $this->_has_api_connection && ! WP_FS__SIMULATE_FREEMIUS_OFF );
3355
+
3356
+ return $this->_has_api_connection;
3357
+ }
3358
+
3359
+ $pong = $this->ping();
3360
+ $is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
3361
+
3362
+ if ( ! $is_connected ) {
3363
+ // API failure.
3364
+ $this->_add_connectivity_issue_message( $pong );
3365
+ }
3366
+
3367
+ if ( $is_connected ) {
3368
+ FS_GDPR_Manager::instance()->store_is_required( $pong->is_gdpr_required );
3369
+ }
3370
+
3371
+ $this->store_connectivity_info( $pong, $is_connected );
3372
+
3373
+ return $this->_has_api_connection;
3374
+ }
3375
+
3376
+ /**
3377
+ * @author Vova Feldman (@svovaf)
3378
+ * @since 1.1.7.4
3379
+ *
3380
+ * @param object $pong
3381
+ * @param bool $is_connected
3382
+ */
3383
+ private function store_connectivity_info( $pong, $is_connected ) {
3384
+ $this->_logger->entrance();
3385
+
3386
+ $version = $this->get_plugin_version();
3387
+
3388
+ if ( ! $is_connected || WP_FS__SIMULATE_FREEMIUS_OFF ) {
3389
+ $is_active = false;
3390
+ } else {
3391
+ $is_active = ( isset( $pong->is_active ) && true == $pong->is_active );
3392
+ }
3393
+
3394
+ $is_active = $this->apply_filters(
3395
+ 'is_on',
3396
+ $is_active,
3397
+ $this->is_plugin_update(),
3398
+ $version
3399
+ );
3400
+
3401
+ $this->_storage->connectivity_test = array(
3402
+ 'is_connected' => $is_connected,
3403
+ 'host' => $_SERVER['HTTP_HOST'],
3404
+ 'server_ip' => WP_FS__REMOTE_ADDR,
3405
+ 'is_active' => $is_active,
3406
+ 'timestamp' => WP_FS__SCRIPT_START_TIME,
3407
+ // Last version with connectivity attempt.
3408
+ 'version' => $version,
3409
+ );
3410
+
3411
+ $this->_has_api_connection = $is_connected;
3412
+ $this->_is_on = $is_active || ( WP_FS__DEV_MODE && $is_connected && ! WP_FS__SIMULATE_FREEMIUS_OFF );
3413
+ }
3414
+
3415
+ /**
3416
+ * Force turning Freemius on.
3417
+ *
3418
+ * @author Vova Feldman (@svovaf)
3419
+ * @since 1.1.8.1
3420
+ *
3421
+ * @return bool TRUE if successfully turned on.
3422
+ */
3423
+ private function turn_on() {
3424
+ $this->_logger->entrance();
3425
+
3426
+ if ( $this->is_on() || ! isset( $this->_storage->connectivity_test['is_active'] ) ) {
3427
+ return false;
3428
+ }
3429
+
3430
+ $updated_connectivity = $this->_storage->connectivity_test;
3431
+ $updated_connectivity['is_active'] = true;
3432
+ $updated_connectivity['timestamp'] = WP_FS__SCRIPT_START_TIME;
3433
+ $this->_storage->connectivity_test = $updated_connectivity;
3434
+
3435
+ $this->_is_on = true;
3436
+
3437
+ return true;
3438
+ }
3439
+
3440
+ /**
3441
+ * Anonymous and unique site identifier (Hash).
3442
+ *
3443
+ * @author Vova Feldman (@svovaf)
3444
+ * @since 1.1.0
3445
+ *
3446
+ * @param null|int $blog_id Since 2.0.0
3447
+ *
3448
+ * @return string
3449
+ */
3450
+ function get_anonymous_id( $blog_id = null ) {
3451
+ $unique_id = self::$_accounts->get_option( 'unique_id', null, $blog_id );
3452
+
3453
+ if ( empty( $unique_id ) || ! is_string( $unique_id ) ) {
3454
+ $key = fs_strip_url_protocol( get_site_url( $blog_id ) );
3455
+
3456
+ $secure_auth = SECURE_AUTH_KEY;
3457
+ if ( empty( $secure_auth ) || false !== strpos( $secure_auth, ' ' ) ) {
3458
+ // Protect against default auth key.
3459
+ $secure_auth = md5( microtime() );
3460
+ }
3461
+
3462
+ /**
3463
+ * Base the unique identifier on the WP secure authentication key. Which
3464
+ * turns the key into a secret anonymous identifier. This will help us
3465
+ * to avoid duplicate installs generation on the backend upon opt-in.
3466
+ *
3467
+ * @author Vova Feldman (@svovaf)
3468
+ * @since 1.2.3
3469
+ */
3470
+ $unique_id = md5( $key . $secure_auth );
3471
+
3472
+ self::$_accounts->set_option( 'unique_id', $unique_id, true, $blog_id );
3473
+ }
3474
+
3475
+ $this->_logger->departure( $unique_id );
3476
+
3477
+ return $unique_id;
3478
+ }
3479
+
3480
+ /**
3481
+ * @author Vova Feldman (@svovaf)
3482
+ * @since 1.1.7.4
3483
+ *
3484
+ * @return \WP_User
3485
+ */
3486
+ static function _get_current_wp_user() {
3487
+ self::require_pluggable_essentials();
3488
+ self::wp_cookie_constants();
3489
+
3490
+ return wp_get_current_user();
3491
+ }
3492
+
3493
+ /**
3494
+ * Define cookie constants which are required by Freemius::_get_current_wp_user() since
3495
+ * it uses wp_get_current_user() which needs the cookie constants set. When a plugin
3496
+ * is network activated the cookie constants are only configured after the network
3497
+ * plugins activation, therefore, if we don't define those constants WP will throw
3498
+ * PHP warnings/notices.
3499
+ *
3500
+ * @author Vova Feldman (@svovaf)
3501
+ * @since 2.1.1
3502
+ */
3503
+ private static function wp_cookie_constants() {
3504
+ if ( defined( 'LOGGED_IN_COOKIE' ) &&
3505
+ ( defined( 'AUTH_COOKIE' ) || defined( 'SECURE_AUTH_COOKIE' ) )
3506
+ ) {
3507
+ return;
3508
+ }
3509
+
3510
+ /**
3511
+ * Used to guarantee unique hash cookies
3512
+ *
3513
+ * @since 1.5.0
3514
+ */
3515
+ if ( ! defined( 'COOKIEHASH' ) ) {
3516
+ $siteurl = get_site_option( 'siteurl' );
3517
+ if ( $siteurl ) {
3518
+ define( 'COOKIEHASH', md5( $siteurl ) );
3519
+ } else {
3520
+ define( 'COOKIEHASH', '' );
3521
+ }
3522
+ }
3523
+
3524
+ if ( ! defined( 'LOGGED_IN_COOKIE' ) ) {
3525
+ define( 'LOGGED_IN_COOKIE', 'wordpress_logged_in_' . COOKIEHASH );
3526
+ }
3527
+
3528
+ /**
3529
+ * @since 2.5.0
3530
+ */
3531
+ if ( ! defined( 'AUTH_COOKIE' ) ) {
3532
+ define( 'AUTH_COOKIE', 'wordpress_' . COOKIEHASH );
3533
+ }
3534
+
3535
+ /**
3536
+ * @since 2.6.0
3537
+ */
3538
+ if ( ! defined( 'SECURE_AUTH_COOKIE' ) ) {
3539
+ define( 'SECURE_AUTH_COOKIE', 'wordpress_sec_' . COOKIEHASH );
3540
+ }
3541
+ }
3542
+
3543
+ /**
3544
+ * @author Vova Feldman (@svovaf)
3545
+ * @since 2.1.0
3546
+ *
3547
+ * @return int
3548
+ */
3549
+ static function get_current_wp_user_id() {
3550
+ $wp_user = self::_get_current_wp_user();
3551
+
3552
+ return $wp_user->ID;
3553
+ }
3554
+
3555
+ /**
3556
+ * @author Vova Feldman (@svovaf)
3557
+ * @since 1.2.1.7
3558
+ *
3559
+ * @param string $email
3560
+ *
3561
+ * @return bool
3562
+ */
3563
+ static function is_valid_email( $email ) {
3564
+ if ( false === filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
3565
+ return false;
3566
+ }
3567
+
3568
+ $parts = explode( '@', $email );
3569
+
3570
+ if ( 2 !== count( $parts ) || empty( $parts[1] ) ) {
3571
+ return false;
3572
+ }
3573
+
3574
+ $blacklist = array(
3575
+ 'admin.',
3576
+ 'webmaster.',
3577
+ 'localhost.',
3578
+ 'dev.',
3579
+ 'development.',
3580
+ 'test.',
3581
+ 'stage.',
3582
+ 'staging.',
3583
+ );
3584
+
3585
+ // Make sure domain is not one of the blacklisted.
3586
+ foreach ( $blacklist as $invalid ) {
3587
+ if ( 0 === strpos( $parts[1], $invalid ) ) {
3588
+ return false;
3589
+ }
3590
+ }
3591
+
3592
+ // Get the UTF encoded domain name.
3593
+ $domain = idn_to_ascii( $parts[1] ) . '.';
3594
+
3595
+ return ( checkdnsrr( $domain, 'MX' ) || checkdnsrr( $domain, 'A' ) );
3596
+ }
3597
+
3598
+ /**
3599
+ * Generate API connectivity issue message.
3600
+ *
3601
+ * @author Vova Feldman (@svovaf)
3602
+ * @since 1.0.9
3603
+ *
3604
+ * @param mixed $api_result
3605
+ * @param bool $is_first_failure
3606
+ */
3607
+ function _add_connectivity_issue_message( $api_result, $is_first_failure = true ) {
3608
+ if ( ! $this->is_premium() && $this->_enable_anonymous ) {
3609
+ // Don't add message if it's the free version and can run anonymously.
3610
+ return;
3611
+ }
3612
+
3613
+ if ( ! function_exists( 'wp_nonce_url' ) ) {
3614
+ require_once ABSPATH . 'wp-includes/functions.php';
3615
+ }
3616
+
3617
+ $current_user = self::_get_current_wp_user();
3618
+ // $admin_email = get_option( 'admin_email' );
3619
+ $admin_email = $current_user->user_email;
3620
+
3621
+ // Aliases.
3622
+ $deactivate_plugin_title = $this->esc_html_inline( 'That\'s exhausting, please deactivate', 'deactivate-plugin-title' );
3623
+ $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' );
3624
+ $install_previous_title = $this->esc_html_inline( 'Let\'s try your previous version', 'install-previous-title' );
3625
+ $install_previous_desc = $this->esc_html_inline( 'Uninstall this version and install the previous one.', 'install-previous-desc' );
3626
+ $fix_issue_title = $this->esc_html_inline( 'Yes - I\'m giving you a chance to fix it', 'fix-issue-title' );
3627
+ $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' );
3628
+ /* translators: %s: product title (e.g. "Awesome Plugin" requires an access to...) */
3629
+ $x_requires_access_to_api = $this->esc_html_inline( '%s requires an access to our API.', 'x-requires-access-to-api' );
3630
+ $sysadmin_title = $this->esc_html_inline( 'I\'m a system administrator', 'sysadmin-title' );
3631
+ $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' );
3632
+
3633
+ $message = false;
3634
+ if ( is_object( $api_result ) &&
3635
+ isset( $api_result->error ) &&
3636
+ isset( $api_result->error->code )
3637
+ ) {
3638
+ switch ( $api_result->error->code ) {
3639
+ case 'curl_missing':
3640
+ $missing_methods = '';
3641
+ if ( is_array( $api_result->missing_methods ) &&
3642
+ ! empty( $api_result->missing_methods )
3643
+ ) {
3644
+ foreach ( $api_result->missing_methods as $m ) {
3645
+ if ( 'curl_version' === $m ) {
3646
+ continue;
3647
+ }
3648
+
3649
+ if ( ! empty( $missing_methods ) ) {
3650
+ $missing_methods .= ', ';
3651
+ }
3652
+
3653
+ $missing_methods .= sprintf( '<code>%s</code>', $m );
3654
+ }
3655
+
3656
+ if ( ! empty( $missing_methods ) ) {
3657
+ $missing_methods = sprintf(
3658
+ '<br><br><b>%s</b> %s',
3659
+ $this->esc_html_inline( 'Disabled method(s):', 'curl-disabled-methods' ),
3660
+ $missing_methods
3661
+ );
3662
+ }
3663
+ }
3664
+
3665
+ $message = sprintf(
3666
+ $x_requires_access_to_api . ' ' .
3667
+ $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' ) . ' ' .
3668
+ $missing_methods .
3669
+ ' %s',
3670
+ '<b>' . $this->get_plugin_name() . '</b>',
3671
+ sprintf(
3672
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
3673
+ sprintf(
3674
+ '<a class="fs-resolve" data-type="curl" href="#"><b>%s</b></a>%s',
3675
+ $this->get_text_inline( 'I don\'t know what is cURL or how to install it, help me!', 'curl-missing-no-clue-title' ),
3676
+ ' - ' . sprintf(
3677
+ $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' ),
3678
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
3679
+ )
3680
+ ),
3681
+ sprintf(
3682
+ '<b>%s</b> - %s',
3683
+ $sysadmin_title,
3684
+ 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 ) ) )
3685
+ ),
3686
+ sprintf(
3687
+ '<a href="%s"><b>%s</b></a> - %s',
3688
+ 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 ),
3689
+ $deactivate_plugin_title,
3690
+ $deactivate_plugin_desc
3691
+ )
3692
+ )
3693
+ );
3694
+ break;
3695
+ case 'cloudflare_ddos_protection':
3696
+ $message = sprintf(
3697
+ $x_requires_access_to_api . ' ' .
3698
+ $this->esc_html_inline( 'From unknown reason, CloudFlare, the firewall we use, blocks the connection.', 'cloudflare-blocks-connection-message' ) . ' ' .
3699
+ $happy_to_resolve_issue_asap .
3700
+ ' %s',
3701
+ '<b>' . $this->get_plugin_name() . '</b>',
3702
+ sprintf(
3703
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
3704
+ sprintf(
3705
+ '<a class="fs-resolve" data-type="cloudflare" href="#"><b>%s</b></a>%s',
3706
+ $fix_issue_title,
3707
+ ' - ' . sprintf(
3708
+ $fix_issue_desc,
3709
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
3710
+ )
3711
+ ),
3712
+ sprintf(
3713
+ '<a href="%s" target="_blank"><b>%s</b></a> - %s',
3714
+ sprintf( 'https://wordpress.org/plugins/%s/download/', $this->_slug ),
3715
+ $install_previous_title,
3716
+ $install_previous_desc
3717
+ ),
3718
+ sprintf(
3719
+ '<a href="%s"><b>%s</b></a> - %s',
3720
+ 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 ),
3721
+ $deactivate_plugin_title,
3722
+ $deactivate_plugin_desc
3723
+ )
3724
+ )
3725
+ );
3726
+ break;
3727
+ case 'squid_cache_block':
3728
+ $message = sprintf(
3729
+ $x_requires_access_to_api . ' ' .
3730
+ $this->esc_html_inline( 'It looks like your server is using Squid ACL (access control lists), which blocks the connection.', 'squid-blocks-connection-message' ) .
3731
+ ' %s',
3732
+ '<b>' . $this->get_plugin_name() . '</b>',
3733
+ sprintf(
3734
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
3735
+ sprintf(
3736
+ '<a class="fs-resolve" data-type="squid" href="#"><b>%s</b></a> - %s',
3737
+ $this->esc_html_inline( 'I don\'t know what is Squid or ACL, help me!', 'squid-no-clue-title' ),
3738
+ sprintf(
3739
+ $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' ),
3740
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
3741
+ )
3742
+ ),
3743
+ sprintf(
3744
+ '<b>%s</b> - %s',
3745
+ $sysadmin_title,
3746
+ sprintf(
3747
+ $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' ),
3748
+ // We use a filter since the plugin might require additional API connectivity.
3749
+ '<b>' . implode( ', ', $this->apply_filters( 'api_domains', array(
3750
+ 'api.freemius.com',
3751
+ 'wp.freemius.com'
3752
+ ) ) ) . '</b>',
3753
+ $this->_module_type
3754
+ )
3755
+ ),
3756
+ sprintf(
3757
+ '<a href="%s"><b>%s</b></a> - %s',
3758
+ 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 ),
3759
+ $deactivate_plugin_title,
3760
+ $deactivate_plugin_desc
3761
+ )
3762
+ )
3763
+ );
3764
+ break;
3765
+ // default:
3766
+ // $message = $this->get_text_inline( 'connectivity-test-fails-message' );
3767
+ // break;
3768
+ }
3769
+ }
3770
+
3771
+ $message_id = 'failed_connect_api';
3772
+ $type = 'error';
3773
+
3774
+ $connectivity_test_fails_message = $this->esc_html_inline( 'From unknown reason, the API connectivity test failed.', 'connectivity-test-fails-message' );
3775
+
3776
+ if ( false === $message ) {
3777
+ if ( $is_first_failure ) {
3778
+ // First attempt failed.
3779
+ $message = sprintf(
3780
+ $x_requires_access_to_api . ' ' .
3781
+ $connectivity_test_fails_message . ' ' .
3782
+ $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>' .
3783
+ '%s',
3784
+ '<b>' . $this->get_plugin_name() . '</b>',
3785
+ sprintf(
3786
+ '<div id="fs_firewall_issue_options">%s %s</div>',
3787
+ sprintf(
3788
+ '<a class="button button-primary fs-resolve" data-type="retry_ping" href="#">%s</a>',
3789
+ $this->get_text_inline( 'Yes - do your thing', 'yes-do-your-thing' )
3790
+ ),
3791
+ sprintf(
3792
+ '<a href="%s" class="button">%s</a>',
3793
+ 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 ),
3794
+ $this->get_text_inline( 'No - just deactivate', 'no-deactivate' )
3795
+ )
3796
+ )
3797
+ );
3798
+
3799
+ $message_id = 'failed_connect_api_first';
3800
+ $type = 'promotion';
3801
+ } else {
3802
+ // Second connectivity attempt failed.
3803
+ $message = sprintf(
3804
+ $x_requires_access_to_api . ' ' .
3805
+ $connectivity_test_fails_message . ' ' .
3806
+ $happy_to_resolve_issue_asap .
3807
+ ' %s',
3808
+ '<b>' . $this->get_plugin_name() . '</b>',
3809
+ sprintf(
3810
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
3811
+ sprintf(
3812
+ '<a class="fs-resolve" data-type="general" href="#"><b>%s</b></a>%s',
3813
+ $fix_issue_title,
3814
+ ' - ' . sprintf(
3815
+ $fix_issue_desc,
3816
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
3817
+ )
3818
+ ),
3819
+ sprintf(
3820
+ '<a href="%s" target="_blank"><b>%s</b></a> - %s',
3821
+ sprintf( 'https://wordpress.org/plugins/%s/download/', $this->_slug ),
3822
+ $install_previous_title,
3823
+ $install_previous_desc
3824
+ ),
3825
+ sprintf(
3826
+ '<a href="%s"><b>%s</b></a> - %s',
3827
+ 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 ),
3828
+ $deactivate_plugin_title,
3829
+ $deactivate_plugin_desc
3830
+ )
3831
+ )
3832
+ );
3833
+ }
3834
+ }
3835
+
3836
+ $this->_admin_notices->add_sticky(
3837
+ $message,
3838
+ $message_id,
3839
+ $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
3840
+ $type
3841
+ );
3842
+ }
3843
+
3844
+ /**
3845
+ * Handle user request to resolve connectivity issue.
3846
+ * This method will send an email to Freemius API technical staff for resolution.
3847
+ * The email will contain server's info and installed plugins (might be caching issue).
3848
+ *
3849
+ * @author Vova Feldman (@svovaf)
3850
+ * @since 1.0.9
3851
+ */
3852
+ function _email_about_firewall_issue() {
3853
+ $this->_admin_notices->remove_sticky( 'failed_connect_api' );
3854
+
3855
+ $pong = $this->ping();
3856
+
3857
+ $is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
3858
+
3859
+ if ( $is_connected ) {
3860
+ FS_GDPR_Manager::instance()->store_is_required( $pong->is_gdpr_required );
3861
+
3862
+ $this->store_connectivity_info( $pong, $is_connected );
3863
+
3864
+ echo $this->get_after_plugin_activation_redirect_url();
3865
+ exit;
3866
+ }
3867
+
3868
+ $current_user = self::_get_current_wp_user();
3869
+ $admin_email = $current_user->user_email;
3870
+
3871
+ $error_type = fs_request_get( 'error_type', 'general' );
3872
+
3873
+ switch ( $error_type ) {
3874
+ case 'squid':
3875
+ $title = 'Squid ACL Blocking Issue';
3876
+ break;
3877
+ case 'cloudflare':
3878
+ $title = 'CloudFlare Blocking Issue';
3879
+ break;
3880
+ default:
3881
+ $title = 'API Connectivity Issue';
3882
+ break;
3883
+ }
3884
+
3885
+ $custom_email_sections = array();
3886
+
3887
+ // Add 'API Error' custom email section.
3888
+ $custom_email_sections['api_error'] = array(
3889
+ 'title' => 'API Error',
3890
+ 'rows' => array(
3891
+ 'ping' => array(
3892
+ 'API Error',
3893
+ is_string( $pong ) ? htmlentities( $pong ) : json_encode( $pong )
3894
+ ),
3895
+ )
3896
+ );
3897
+
3898
+ // Send email with technical details to resolve API connectivity issues.
3899
+ $this->send_email(
3900
+ 'api@freemius.com', // recipient
3901
+ $title . ' [' . $this->get_plugin_name() . ']', // subject
3902
+ $custom_email_sections,
3903
+ array( "Reply-To: $admin_email <$admin_email>" ) // headers
3904
+ );
3905
+
3906
+ $this->_admin_notices->add_sticky(
3907
+ sprintf(
3908
+ $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' ),
3909
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
3910
+ ),
3911
+ 'server_details_sent'
3912
+ );
3913
+
3914
+ // Action was taken, tell that API connectivity troubleshooting should be off now.
3915
+
3916
+ echo "1";
3917
+ exit;
3918
+ }
3919
+
3920
+ /**
3921
+ * Handle connectivity test retry approved by the user.
3922
+ *
3923
+ * @author Vova Feldman (@svovaf)
3924
+ * @since 1.1.7.4
3925
+ */
3926
+ function _retry_connectivity_test() {
3927
+ $this->_admin_notices->remove_sticky( 'failed_connect_api_first' );
3928
+
3929
+ $pong = $this->ping();
3930
+
3931
+ $is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
3932
+
3933
+ if ( $is_connected ) {
3934
+ FS_GDPR_Manager::instance()->store_is_required( $pong->is_gdpr_required );
3935
+
3936
+ $this->store_connectivity_info( $pong, $is_connected );
3937
+
3938
+ echo $this->get_after_plugin_activation_redirect_url();
3939
+ } else {
3940
+ // Add connectivity issue message after 2nd failed attempt.
3941
+ $this->_add_connectivity_issue_message( $pong, false );
3942
+
3943
+ echo "1";
3944
+ }
3945
+
3946
+ exit;
3947
+ }
3948
+
3949
+ static function _add_firewall_issues_javascript() {
3950
+ $params = array();
3951
+ fs_require_once_template( 'firewall-issues-js.php', $params );
3952
+ }
3953
+
3954
+ #endregion
3955
+
3956
+ #----------------------------------------------------------------------------------
3957
+ #region Email
3958
+ #----------------------------------------------------------------------------------
3959
+
3960
+ /**
3961
+ * Generates and sends an HTML email with customizable sections.
3962
+ *
3963
+ * @author Leo Fajardo (@leorw)
3964
+ * @since 1.1.2
3965
+ *
3966
+ * @param string $to_address
3967
+ * @param string $subject
3968
+ * @param array $sections
3969
+ * @param array $headers
3970
+ *
3971
+ * @return bool Whether the email contents were sent successfully.
3972
+ */
3973
+ private function send_email(
3974
+ $to_address,
3975
+ $subject,
3976
+ $sections = array(),
3977
+ $headers = array()
3978
+ ) {
3979
+ $default_sections = $this->get_email_sections();
3980
+
3981
+ // Insert new sections or replace the default email sections.
3982
+ if ( is_array( $sections ) && ! empty( $sections ) ) {
3983
+ foreach ( $sections as $section_id => $custom_section ) {
3984
+ if ( ! isset( $default_sections[ $section_id ] ) ) {
3985
+ // If the section does not exist, add it.
3986
+ $default_sections[ $section_id ] = $custom_section;
3987
+ } else {
3988
+ // If the section already exists, override it.
3989
+ $current_section = $default_sections[ $section_id ];
3990
+
3991
+ // Replace the current section's title if a custom section title exists.
3992
+ if ( isset( $custom_section['title'] ) ) {
3993
+ $current_section['title'] = $custom_section['title'];
3994
+ }
3995
+
3996
+ // Insert new rows under the current section or replace the default rows.
3997
+ if ( isset( $custom_section['rows'] ) && is_array( $custom_section['rows'] ) && ! empty( $custom_section['rows'] ) ) {
3998
+ foreach ( $custom_section['rows'] as $row_id => $row ) {
3999
+ $current_section['rows'][ $row_id ] = $row;
4000
+ }
4001
+ }
4002
+
4003
+ $default_sections[ $section_id ] = $current_section;
4004
+ }
4005
+ }
4006
+ }
4007
+
4008
+ $vars = array( 'sections' => $default_sections );
4009
+ $message = fs_get_template( 'email.php', $vars );
4010
+
4011
+ // Set the type of email to HTML.
4012
+ $headers[] = 'Content-type: text/html; charset=UTF-8';
4013
+
4014
+ $header_string = implode( "\r\n", $headers );
4015
+
4016
+ return wp_mail(
4017
+ $to_address,
4018
+ $subject,
4019
+ $message,
4020
+ $header_string
4021
+ );
4022
+ }
4023
+
4024
+ /**
4025
+ * Generates the data for the sections of the email content.
4026
+ *
4027
+ * @author Leo Fajardo (@leorw)
4028
+ * @since 1.1.2
4029
+ *
4030
+ * @return array
4031
+ */
4032
+ private function get_email_sections() {
4033
+ // Retrieve the current user's information so that we can get the user's email, first name, and last name below.
4034
+ $current_user = self::_get_current_wp_user();
4035
+
4036
+ // Retrieve the cURL version information so that we can get the version number below.
4037
+ $curl_version_information = curl_version();
4038
+
4039
+ $active_plugin = self::get_active_plugins();
4040
+
4041
+ // Generate the list of active plugins separated by new line.
4042
+ $active_plugin_string = '';
4043
+ foreach ( $active_plugin as $plugin ) {
4044
+ $active_plugin_string .= sprintf(
4045
+ '<a href="%s">%s</a> [v%s]<br>',
4046
+ $plugin['PluginURI'],
4047
+ $plugin['Name'],
4048
+ $plugin['Version']
4049
+ );
4050
+ }
4051
+
4052
+ $server_ip = WP_FS__REMOTE_ADDR;
4053
+
4054
+ // Add PHP info for deeper investigation.
4055
+ ob_start();
4056
+ phpinfo();
4057
+ $php_info = ob_get_clean();
4058
+
4059
+ $api_domain = substr( FS_API__ADDRESS, strpos( FS_API__ADDRESS, ':' ) + 3 );
4060
+
4061
+ // Generate the default email sections.
4062
+ $sections = array(
4063
+ 'sdk' => array(
4064
+ 'title' => 'SDK',
4065
+ 'rows' => array(
4066
+ 'fs_version' => array( 'FS Version', $this->version ),
4067
+ 'curl_version' => array( 'cURL Version', $curl_version_information['version'] )
4068
+ )
4069
+ ),
4070
+ 'plugin' => array(
4071
+ 'title' => ucfirst( $this->get_module_type() ),
4072
+ 'rows' => array(
4073
+ 'name' => array( 'Name', $this->get_plugin_name() ),
4074
+ 'version' => array( 'Version', $this->get_plugin_version() )
4075
+ )
4076
+ ),
4077
+ 'api' => array(
4078
+ 'title' => 'API Subdomain',
4079
+ 'rows' => array(
4080
+ 'dns' => array(
4081
+ 'DNS_CNAME',
4082
+ function_exists( 'dns_get_record' ) ?
4083
+ var_export( dns_get_record( $api_domain, DNS_CNAME ), true ) :
4084
+ 'dns_get_record() disabled/blocked'
4085
+ ),
4086
+ 'ip' => array(
4087
+ 'IP',
4088
+ function_exists( 'gethostbyname' ) ?
4089
+ gethostbyname( $api_domain ) :
4090
+ 'gethostbyname() disabled/blocked'
4091
+ ),
4092
+ ),
4093
+ ),
4094
+ 'site' => array(
4095
+ 'title' => 'Site',
4096
+ 'rows' => array(
4097
+ 'unique_id' => array( 'Unique ID', $this->get_anonymous_id() ),
4098
+ 'address' => array( 'Address', site_url() ),
4099
+ 'host' => array(
4100
+ 'HTTP_HOST',
4101
+ ( ! empty( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : '' )
4102
+ ),
4103
+ 'hosting' => array(
4104
+ 'Hosting Company' => fs_request_has( 'hosting_company' ) ?
4105
+ fs_request_get( 'hosting_company' ) :
4106
+ 'Unknown',
4107
+ ),
4108
+ 'server_addr' => array(
4109
+ 'SERVER_ADDR',
4110
+ '<a href="http://www.projecthoneypot.org/ip_' . $server_ip . '">' . $server_ip . '</a>'
4111
+ )
4112
+ )
4113
+ ),
4114
+ 'user' => array(
4115
+ 'title' => 'User',
4116
+ 'rows' => array(
4117
+ 'email' => array( 'Email', $current_user->user_email ),
4118
+ 'first' => array( 'First', $current_user->user_firstname ),
4119
+ 'last' => array( 'Last', $current_user->user_lastname )
4120
+ )
4121
+ ),
4122
+ 'plugins' => array(
4123
+ 'title' => 'Plugins',
4124
+ 'rows' => array(
4125
+ 'active_plugins' => array( 'Active Plugins', $active_plugin_string )
4126
+ )
4127
+ ),
4128
+ 'php_info' => array(
4129
+ 'title' => 'PHP Info',
4130
+ 'rows' => array(
4131
+ 'info' => array( $php_info )
4132
+ ),
4133
+ )
4134
+ );
4135
+
4136
+ // Allow the sections to be modified by other code.
4137
+ $sections = $this->apply_filters( 'email_template_sections', $sections );
4138
+
4139
+ return $sections;
4140
+ }
4141
+
4142
+ #endregion
4143
+
4144
+ #----------------------------------------------------------------------------------
4145
+ #region Initialization
4146
+ #----------------------------------------------------------------------------------
4147
+
4148
+ /**
4149
+ * Init plugin's Freemius instance.
4150
+ *
4151
+ * @author Vova Feldman (@svovaf)
4152
+ * @since 1.0.1
4153
+ *
4154
+ * @param number $id
4155
+ * @param string $public_key
4156
+ * @param bool $is_live
4157
+ * @param bool $is_premium
4158
+ */
4159
+ function init( $id, $public_key, $is_live = true, $is_premium = true ) {
4160
+ $this->_logger->entrance();
4161
+
4162
+ $this->dynamic_init( array(
4163
+ 'id' => $id,
4164
+ 'public_key' => $public_key,
4165
+ 'is_live' => $is_live,
4166
+ 'is_premium' => $is_premium,
4167
+ ) );
4168
+ }
4169
+
4170
+ /**
4171
+ * Dynamic initiator, originally created to support initiation
4172
+ * with parent_id for add-ons.
4173
+ *
4174
+ * @author Vova Feldman (@svovaf)
4175
+ * @since 1.0.6
4176
+ *
4177
+ * @param array $plugin_info
4178
+ *
4179
+ * @throws Freemius_Exception
4180
+ */
4181
+ function dynamic_init( array $plugin_info ) {
4182
+ $this->_logger->entrance();
4183
+
4184
+ $this->parse_settings( $plugin_info );
4185
+
4186
+ if ( is_admin() && $this->is_theme() && $this->is_premium() && ! $this->has_active_valid_license() ) {
4187
+ $this->add_ajax_action(
4188
+ 'delete_theme_update_data',
4189
+ array( &$this, '_delete_theme_update_data_action' )
4190
+ );
4191
+ }
4192
+
4193
+ if ( ! self::is_ajax() ) {
4194
+ if ( ! $this->is_addon() || $this->is_only_premium() ) {
4195
+ add_action(
4196
+ ( $this->_is_network_active && fs_is_network_admin() ? 'network_' : '' ) . 'admin_menu',
4197
+ array( &$this, '_prepare_admin_menu' ),
4198
+ WP_FS__LOWEST_PRIORITY
4199
+ );
4200
+ }
4201
+ }
4202
+
4203
+ if ( $this->should_stop_execution() ) {
4204
+ return;
4205
+ }
4206
+
4207
+ if ( ! $this->is_registered() ) {
4208
+ if ( $this->is_anonymous() ) {
4209
+ // If user skipped, no need to test connectivity.
4210
+ $this->_has_api_connection = true;
4211
+ $this->_is_on = true;
4212
+ } else {
4213
+ if ( ! $this->has_api_connectivity() ) {
4214
+ if ( $this->_admin_notices->has_sticky( 'failed_connect_api_first' ) ||
4215
+ $this->_admin_notices->has_sticky( 'failed_connect_api' )
4216
+ ) {
4217
+ if ( ! $this->_enable_anonymous || $this->is_premium() ) {
4218
+ // If anonymous mode is disabled, add firewall admin-notice message.
4219
+ add_action( 'admin_footer', array( 'Freemius', '_add_firewall_issues_javascript' ) );
4220
+
4221
+ $ajax_action_suffix = $this->_slug . ( $this->is_theme() ? ':theme' : '' );
4222
+ add_action( "wp_ajax_fs_resolve_firewall_issues_{$ajax_action_suffix}", array(
4223
+ &$this,
4224
+ '_email_about_firewall_issue'
4225
+ ) );
4226
+
4227
+ add_action( "wp_ajax_fs_retry_connectivity_test_{$ajax_action_suffix}", array(
4228
+ &$this,
4229
+ '_retry_connectivity_test'
4230
+ ) );
4231
+
4232
+ /**
4233
+ * 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.
4234
+ *
4235
+ * @author Vova Feldman (@svovaf)
4236
+ * @since 2.0.0
4237
+ */
4238
+ /*$this->add_ajax_action( 'resolve_firewall_issues', array(
4239
+ &$this,
4240
+ '_email_about_firewall_issue'
4241
+ ) );
4242
+
4243
+ $this->add_ajax_action( 'retry_connectivity_test', array(
4244
+ &$this,
4245
+ '_retry_connectivity_test'
4246
+ ) );*/
4247
+ }
4248
+ }
4249
+
4250
+ return;
4251
+ } else {
4252
+ $this->_admin_notices->remove_sticky( array(
4253
+ 'failed_connect_api_first',
4254
+ 'failed_connect_api',
4255
+ ) );
4256
+
4257
+ if ( $this->_anonymous_mode ) {
4258
+ // Simulate anonymous mode.
4259
+ $this->_is_anonymous = true;
4260
+ }
4261
+ }
4262
+ }
4263
+ }
4264
+
4265
+ /**
4266
+ * This should be executed even if Freemius is off for the core module,
4267
+ * otherwise, the add-ons dialogbox won't work properly. This is esepcially
4268
+ * relevant when the developer decided to turn FS off for existing users.
4269
+ *
4270
+ * @author Vova Feldman (@svovaf)
4271
+ */
4272
+ if ( $this->is_user_in_admin() &&
4273
+ 'plugin-information' === fs_request_get( 'tab', false ) &&
4274
+ $this->should_use_freemius_updater_and_dialog() &&
4275
+ (
4276
+ ( $this->is_addon() && $this->get_slug() == fs_request_get( 'plugin', false ) ) ||
4277
+ ( $this->has_addons() && $this->get_id() == fs_request_get( 'parent_plugin_id', false ) )
4278
+ )
4279
+ ) {
4280
+ require_once WP_FS__DIR_INCLUDES . '/fs-plugin-info-dialog.php';
4281
+
4282
+ new FS_Plugin_Info_Dialog( $this->is_addon() ? $this->get_parent_instance() : $this );
4283
+ }
4284
+
4285
+ // Check if Freemius is on for the current plugin.
4286
+ // This MUST be executed after all the plugin variables has been loaded.
4287
+ if ( ! $this->is_registered() && ! $this->is_on() ) {
4288
+ return;
4289
+ }
4290
+
4291
+ if ( $this->has_api_connectivity() ) {
4292
+ if ( self::is_cron() ) {
4293
+ $this->hook_callback_to_sync_cron();
4294
+ } else if ( $this->is_user_in_admin() ) {
4295
+ /**
4296
+ * Schedule daily data sync cron if:
4297
+ *
4298
+ * 1. User opted-in (for tracking).
4299
+ * 2. If skipped, but later upgraded (opted-in via upgrade).
4300
+ *
4301
+ * @author Vova Feldman (@svovaf)
4302
+ * @since 1.1.7.3
4303
+ *
4304
+ */
4305
+ if ( $this->is_registered() ) {
4306
+ if ( ! $this->is_sync_cron_on() && $this->is_tracking_allowed() ) {
4307
+ $this->schedule_sync_cron();
4308
+ }
4309
+ }
4310
+
4311
+ /**
4312
+ * Check if requested for manual blocking background sync.
4313
+ */
4314
+ if ( fs_request_has( 'background_sync' ) ) {
4315
+ $this->run_manual_sync();
4316
+ }
4317
+ }
4318
+ }
4319
+
4320
+ if ( $this->is_registered() ) {
4321
+ $this->hook_callback_to_install_sync();
4322
+ }
4323
+
4324
+ if ( $this->is_addon() ) {
4325
+ if ( $this->is_parent_plugin_installed() ) {
4326
+ // Link to parent FS.
4327
+ $this->_parent = self::get_instance_by_id( $this->_plugin->parent_plugin_id );
4328
+
4329
+ // Get parent plugin reference.
4330
+ $this->_parent_plugin = $this->_parent->get_plugin();
4331
+ }
4332
+ }
4333
+
4334
+ if ( $this->is_user_in_admin() ) {
4335
+ if ( $this->is_addon() ) {
4336
+ if ( ! $this->is_parent_plugin_installed() ) {
4337
+ $parent_name = $this->get_option( $plugin_info, 'parent_name', null );
4338
+
4339
+ if ( isset( $plugin_info['parent'] ) ) {
4340
+ $parent_name = $this->get_option( $plugin_info['parent'], 'name', null );
4341
+ }
4342
+
4343
+ $this->_admin_notices->add(
4344
+ ( ! empty( $parent_name ) ?
4345
+ 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 ) :
4346
+ 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() )
4347
+ ),
4348
+ $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
4349
+ 'error'
4350
+ );
4351
+
4352
+ return;
4353
+ } else {
4354
+ if ( $this->_parent->is_registered() && ! $this->is_registered() ) {
4355
+ // If parent plugin activated, automatically install add-on for the user.
4356
+ $this->_activate_addon_account( $this->_parent );
4357
+ } else if ( ! $this->_parent->is_registered() && $this->is_registered() ) {
4358
+ // If add-on activated and parent not, automatically install parent for the user.
4359
+ $this->activate_parent_account( $this->_parent );
4360
+ }
4361
+
4362
+ // @todo This should be only executed on activation. It should be migrated to register_activation_hook() together with other activation related logic.
4363
+ if ( $this->is_premium() ) {
4364
+ // Remove add-on download admin-notice.
4365
+ $this->_parent->_admin_notices->remove_sticky( array(
4366
+ 'addon_plan_upgraded_' . $this->_slug,
4367
+ 'no_addon_license_' . $this->_slug,
4368
+ ) );
4369
+ }
4370
+
4371
+ // $this->deactivate_premium_only_addon_without_license();
4372
+ }
4373
+ }
4374
+
4375
+ add_action( 'admin_init', array( &$this, '_admin_init_action' ) );
4376
+
4377
+ // if ( $this->is_registered() ||
4378
+ // $this->is_anonymous() ||
4379
+ // $this->is_pending_activation()
4380
+ // ) {
4381
+ // $this->_init_admin();
4382
+ // }
4383
+ }
4384
+
4385
+ /**
4386
+ * Should be called outside `$this->is_user_in_admin()` scope
4387
+ * because the updater has some logic that needs to be executed
4388
+ * during AJAX calls.
4389
+ *
4390
+ * Currently we need to hook to the `http_request_host_is_external` filter.
4391
+ * In the future, there might be additional logic added.
4392
+ *
4393
+ * @author Vova Feldman
4394
+ * @since 1.2.1.6
4395
+ */
4396
+ if (
4397
+ $this->should_use_freemius_updater_and_dialog() &&
4398
+ (
4399
+ $this->is_premium() ||
4400
+ /**
4401
+ * If not premium but the premium version is installed, also instantiate the updater so that the
4402
+ * plugin information dialog of the premium version will have the information from the server.
4403
+ *
4404
+ * @author Leo Fajardo (@leorw)
4405
+ * @since 2.2.3
4406
+ */
4407
+ ( file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $this->premium_plugin_basename() ) ) )
4408
+ ) &&
4409
+ $this->has_release_on_freemius()
4410
+ ) {
4411
+ FS_Plugin_Updater::instance( $this );
4412
+ }
4413
+
4414
+ $this->do_action( 'initiated' );
4415
+
4416
+ if ( $this->_storage->prev_is_premium !== $this->_plugin->is_premium ) {
4417
+ if ( isset( $this->_storage->prev_is_premium ) ) {
4418
+ $this->apply_filters(
4419
+ 'after_code_type_change',
4420
+ // New code type.
4421
+ $this->_plugin->is_premium
4422
+ );
4423
+ } else {
4424
+ // Set for code type for the first time.
4425
+ $this->_storage->prev_is_premium = $this->_plugin->is_premium;
4426
+ }
4427
+ }
4428
+
4429
+ if ( ! $this->is_addon() ) {
4430
+ if ( $this->is_registered() ) {
4431
+ // Fix for upgrade from versions < 1.0.9.
4432
+ if ( ! isset( $this->_storage->activation_timestamp ) ) {
4433
+ $this->_storage->activation_timestamp = WP_FS__SCRIPT_START_TIME;
4434
+ }
4435
+
4436
+ $this->do_action( 'after_init_plugin_registered' );
4437
+ } else if ( $this->is_anonymous() ) {
4438
+ $this->do_action( 'after_init_plugin_anonymous' );
4439
+ } else if ( $this->is_pending_activation() ) {
4440
+ $this->do_action( 'after_init_plugin_pending_activations' );
4441
+ }
4442
+ } else {
4443
+ if ( $this->is_registered() ) {
4444
+ $this->do_action( 'after_init_addon_registered' );
4445
+ } else if ( $this->is_anonymous() ) {
4446
+ $this->do_action( 'after_init_addon_anonymous' );
4447
+ } else if ( $this->is_pending_activation() ) {
4448
+ $this->do_action( 'after_init_addon_pending_activations' );
4449
+ }
4450
+ }
4451
+ }
4452
+
4453
+ /**
4454
+ * @author Leo Fajardo (@leorw)
4455
+ * @since 2.2.3
4456
+ *
4457
+ * @return bool
4458
+ */
4459
+ private function should_use_freemius_updater_and_dialog() {
4460
+ return (
4461
+ /**
4462
+ * Unless the `fs_allow_updater_and_dialog` URL param exists and its value is `true`, disallow updater
4463
+ * and dialog on the "Add Plugins" admin page (/plugin-install.php) so that they won't interfere with
4464
+ * the .org plugins' functionalities on that page (e.g. installation and viewing plugin details from
4465
+ * .org).
4466
+ */
4467
+ ( ! self::is_plugin_install_page() || true === fs_request_get_bool( 'fs_allow_updater_and_dialog' ) ) &&
4468
+ // Disallow updater and dialog when installing a plugin, otherwise .org "add-on" plugins will be affected.
4469
+ ( 'install-plugin' !== fs_request_get( 'action' ) )
4470
+ );
4471
+ }
4472
+
4473
+ /**
4474
+ * @author Leo Fajardo (@leorw)
4475
+ *
4476
+ * @since 1.2.1.5
4477
+ */
4478
+ function _stop_tracking_callback() {
4479
+ $this->_logger->entrance();
4480
+
4481
+ $this->check_ajax_referer( 'stop_tracking' );
4482
+
4483
+ $result = $this->stop_tracking( fs_is_network_admin() );
4484
+
4485
+ if ( true === $result ) {
4486
+ self::shoot_ajax_success();
4487
+ }
4488
+
4489
+ $this->_logger->api_error( $result );
4490
+
4491
+ self::shoot_ajax_failure(
4492
+ sprintf( $this->get_text_inline( 'Unexpected API error. Please contact the %s\'s author with the following error.', 'unexpected-api-error' ), $this->_module_type ) .
4493
+ ( $this->is_api_error( $result ) && isset( $result->error ) ?
4494
+ $result->error->message :
4495
+ var_export( $result, true ) )
4496
+ );
4497
+ }
4498
+
4499
+ /**
4500
+ * @author Leo Fajardo (@leorw)
4501
+ * @since 1.2.1.5
4502
+ */
4503
+ function _allow_tracking_callback() {
4504
+ $this->_logger->entrance();
4505
+
4506
+ $this->check_ajax_referer( 'allow_tracking' );
4507
+
4508
+ $result = $this->allow_tracking( fs_is_network_admin() );
4509
+
4510
+ if ( true === $result ) {
4511
+ self::shoot_ajax_success();
4512
+ }
4513
+
4514
+ $this->_logger->api_error( $result );
4515
+
4516
+ self::shoot_ajax_failure(
4517
+ sprintf( $this->get_text_inline( 'Unexpected API error. Please contact the %s\'s author with the following error.', 'unexpected-api-error' ), $this->_module_type ) .
4518
+ ( $this->is_api_error( $result ) && isset( $result->error ) ?
4519
+ $result->error->message :
4520
+ var_export( $result, true ) )
4521
+ );
4522
+ }
4523
+
4524
+ /**
4525
+ * Opt-out from usage tracking.
4526
+ *
4527
+ * Note: This will not delete the account information but will stop all tracking.
4528
+ *
4529
+ * Returns:
4530
+ * 1. FALSE - If the user never opted-in.
4531
+ * 2. TRUE - If successfully opted-out.
4532
+ * 3. object - API result on failure.
4533
+ *
4534
+ * @author Leo Fajardo (@leorw)
4535
+ * @since 1.2.1.5
4536
+ *
4537
+ * @return bool|object
4538
+ */
4539
+ function stop_site_tracking() {
4540
+ $this->_logger->entrance();
4541
+
4542
+ if ( ! $this->is_registered() ) {
4543
+ // User never opted-in.
4544
+ return false;
4545
+ }
4546
+
4547
+ if ( $this->is_tracking_prohibited() ) {
4548
+ // Already disconnected.
4549
+ return true;
4550
+ }
4551
+
4552
+ // Send update to FS.
4553
+ $result = $this->get_api_site_scope()->call( '/?fields=is_disconnected', 'put', array(
4554
+ 'is_disconnected' => true
4555
+ ) );
4556
+
4557
+ if ( ! $this->is_api_result_entity( $result ) ||
4558
+ ! isset( $result->is_disconnected ) ||
4559
+ ! $result->is_disconnected
4560
+ ) {
4561
+ $this->_logger->api_error( $result );
4562
+
4563
+ return $result;
4564
+ }
4565
+
4566
+ $this->_site->is_disconnected = $result->is_disconnected;
4567
+ $this->_store_site();
4568
+
4569
+ $this->clear_sync_cron();
4570
+
4571
+ // Successfully disconnected.
4572
+ return true;
4573
+ }
4574
+
4575
+ /**
4576
+ * Opt-out network from usage tracking.
4577
+ *
4578
+ * Note: This will not delete the account information but will stop all tracking.
4579
+ *
4580
+ * Returns:
4581
+ * 1. FALSE - If the user never opted-in.
4582
+ * 2. TRUE - If successfully opted-out.
4583
+ * 3. object - API result on failure.
4584
+ *
4585
+ * @author Leo Fajardo (@leorw)
4586
+ * @since 1.2.1.5
4587
+ *
4588
+ * @return bool|object
4589
+ */
4590
+ function stop_network_tracking() {
4591
+ $this->_logger->entrance();
4592
+
4593
+ if ( ! $this->is_registered() ) {
4594
+ // User never opted-in.
4595
+ return false;
4596
+ }
4597
+
4598
+ $install_id_2_blog_id = array();
4599
+ $installs_map = $this->get_blog_install_map();
4600
+
4601
+ $opt_out_all = true;
4602
+
4603
+ $params = array();
4604
+ foreach ( $installs_map as $blog_id => $install ) {
4605
+ if ( $install->is_tracking_prohibited() ) {
4606
+ // Already opted-out.
4607
+ continue;
4608
+ }
4609
+
4610
+ if ( $this->is_site_delegated_connection( $blog_id ) ) {
4611
+ // Opt-out only from non-delegated installs.
4612
+ $opt_out_all = false;
4613
+ continue;
4614
+ }
4615
+
4616
+ $params[] = array( 'id' => $install->id );
4617
+
4618
+ $install_id_2_blog_id[ $install->id ] = $blog_id;
4619
+ }
4620
+
4621
+ if ( empty( $install_id_2_blog_id ) ) {
4622
+ return true;
4623
+ }
4624
+
4625
+ $params[] = array( 'is_disconnected' => true );
4626
+
4627
+ // Send update to FS.
4628
+ $result = $this->get_current_or_network_user_api_scope()->call( "/plugins/{$this->_module_id}/installs.json", 'put', $params );
4629
+
4630
+ if ( ! $this->is_api_result_object( $result, 'installs' ) ) {
4631
+ $this->_logger->api_error( $result );
4632
+
4633
+ return $result;
4634
+ }
4635
+
4636
+ foreach ( $result->installs as $r_install ) {
4637
+ $blog_id = $install_id_2_blog_id[ $r_install->id ];
4638
+ $install = $installs_map[ $blog_id ];
4639
+ $install->is_disconnected = $r_install->is_disconnected;
4640
+ $this->_store_site( true, $blog_id, $install );
4641
+ }
4642
+
4643
+ $this->clear_sync_cron( $opt_out_all );
4644
+
4645
+ // Successfully disconnected.
4646
+ return true;
4647
+ }
4648
+
4649
+ /**
4650
+ * Opt-out from usage tracking.
4651
+ *
4652
+ * Note: This will not delete the account information but will stop all tracking.
4653
+ *
4654
+ * Returns:
4655
+ * 1. FALSE - If the user never opted-in.
4656
+ * 2. TRUE - If successfully opted-out.
4657
+ * 3. object - API result on failure.
4658
+ *
4659
+ * @author Leo Fajardo (@leorw)
4660
+ * @since 1.2.1.5
4661
+ *
4662
+ * @param bool $is_network_action
4663
+ *
4664
+ * @return bool|object
4665
+ */
4666
+ function stop_tracking( $is_network_action = false ) {
4667
+ $this->_logger->entrance();
4668
+
4669
+ return $is_network_action ?
4670
+ $this->stop_network_tracking() :
4671
+ $this->stop_site_tracking();
4672
+ }
4673
+
4674
+ /**
4675
+ * Opt-in back into usage tracking.
4676
+ *
4677
+ * Note: This will only work if the user opted-in previously.
4678
+ *
4679
+ * Returns:
4680
+ * 1. FALSE - If the user never opted-in.
4681
+ * 2. TRUE - If successfully opted-in back to usage tracking.
4682
+ * 3. object - API result on failure.
4683
+ *
4684
+ * @author Leo Fajardo (@leorw)
4685
+ * @since 1.2.1.5
4686
+ *
4687
+ * @return bool|object
4688
+ */
4689
+ function allow_site_tracking() {
4690
+ $this->_logger->entrance();
4691
+
4692
+ if ( ! $this->is_registered() ) {
4693
+ // User never opted-in.
4694
+ return false;
4695
+ }
4696
+
4697
+ if ( $this->is_tracking_allowed() ) {
4698
+ // Tracking already allowed.
4699
+ return true;
4700
+ }
4701
+
4702
+ $result = $this->get_api_site_scope()->call( '/?is_disconnected', 'put', array(
4703
+ 'is_disconnected' => false
4704
+ ) );
4705
+
4706
+ if ( ! $this->is_api_result_entity( $result ) ||
4707
+ ! isset( $result->is_disconnected ) ||
4708
+ $result->is_disconnected
4709
+ ) {
4710
+ $this->_logger->api_error( $result );
4711
+
4712
+ return $result;
4713
+ }
4714
+
4715
+ $this->_site->is_disconnected = $result->is_disconnected;
4716
+ $this->_store_site();
4717
+
4718
+ $this->schedule_sync_cron();
4719
+
4720
+ // Successfully reconnected.
4721
+ return true;
4722
+ }
4723
+
4724
+ /**
4725
+ * Opt-in network back into usage tracking.
4726
+ *
4727
+ * Note: This will only work if the user opted-in previously.
4728
+ *
4729
+ * Returns:
4730
+ * 1. FALSE - If the user never opted-in.
4731
+ * 2. TRUE - If successfully opted-in back to usage tracking.
4732
+ * 3. object - API result on failure.
4733
+ *
4734
+ * @author Leo Fajardo (@leorw)
4735
+ * @since 1.2.1.5
4736
+ *
4737
+ * @return bool|object
4738
+ */
4739
+ function allow_network_tracking() {
4740
+ $this->_logger->entrance();
4741
+
4742
+ if ( ! $this->is_registered() ) {
4743
+ // User never opted-in.
4744
+ return false;
4745
+ }
4746
+
4747
+ $install_id_2_blog_id = array();
4748
+ $installs_map = $this->get_blog_install_map();
4749
+
4750
+ $params = array();
4751
+ foreach ( $installs_map as $blog_id => $install ) {
4752
+ if ( $install->is_tracking_allowed() ) {
4753
+ continue;
4754
+ }
4755
+
4756
+ $params[] = array( 'id' => $install->id );
4757
+
4758
+ $install_id_2_blog_id[ $install->id ] = $blog_id;
4759
+ }
4760
+
4761
+ if ( empty( $install_id_2_blog_id ) ) {
4762
+ return true;
4763
+ }
4764
+
4765
+ $params[] = array( 'is_disconnected' => false );
4766
+
4767
+ // Send update to FS.
4768
+ $result = $this->get_current_or_network_user_api_scope()->call( "/plugins/{$this->_module_id}/installs.json", 'put', $params );
4769
+
4770
+
4771
+ if ( ! $this->is_api_result_object( $result, 'installs' ) ) {
4772
+ $this->_logger->api_error( $result );
4773
+
4774
+ return $result;
4775
+ }
4776
+
4777
+ foreach ( $result->installs as $r_install ) {
4778
+ $blog_id = $install_id_2_blog_id[ $r_install->id ];
4779
+ $install = $installs_map[ $blog_id ];
4780
+ $install->is_disconnected = $r_install->is_disconnected;
4781
+ $this->_store_site( true, $blog_id, $install );
4782
+ }
4783
+
4784
+ $this->schedule_sync_cron();
4785
+
4786
+ // Successfully reconnected.
4787
+ return true;
4788
+ }
4789
+
4790
+ /**
4791
+ * Opt-in back into usage tracking.
4792
+ *
4793
+ * Note: This will only work if the user opted-in previously.
4794
+ *
4795
+ * Returns:
4796
+ * 1. FALSE - If the user never opted-in.
4797
+ * 2. TRUE - If successfully opted-in back to usage tracking.
4798
+ * 3. object - API result on failure.
4799
+ *
4800
+ * @author Leo Fajardo (@leorw)
4801
+ * @since 1.2.1.5
4802
+ *
4803
+ * @param bool $is_network_action
4804
+ *
4805
+ * @return bool|object
4806
+ */
4807
+ function allow_tracking( $is_network_action = false ) {
4808
+ $this->_logger->entrance();
4809
+
4810
+ return $is_network_action ?
4811
+ $this->allow_network_tracking() :
4812
+ $this->allow_site_tracking();
4813
+ }
4814
+
4815
+ /**
4816
+ * If user opted-in and later disabled usage-tracking,
4817
+ * re-allow tracking for licensing and updates.
4818
+ *
4819
+ * @author Leo Fajardo (@leorw)
4820
+ * @since 1.2.1.5
4821
+ *
4822
+ * @param bool $is_context_single_site
4823
+ */
4824
+ private function reconnect_locally( $is_context_single_site = false ) {
4825
+ $this->_logger->entrance();
4826
+
4827
+ if ( ! $this->is_registered() ) {
4828
+ return;
4829
+ }
4830
+
4831
+ if ( ! fs_is_network_admin() || $is_context_single_site ) {
4832
+ if ( $this->is_tracking_prohibited() ) {
4833
+ $this->_site->is_disconnected = false;
4834
+ $this->_store_site();
4835
+ }
4836
+ } else {
4837
+ $installs_map = $this->get_blog_install_map();
4838
+ foreach ( $installs_map as $blog_id => $install ) {
4839
+ /**
4840
+ * @var FS_Site $install
4841
+ */
4842
+ if ( $install->is_tracking_prohibited() ) {
4843
+ $install->is_disconnected = false;
4844
+ $this->_store_site( true, $blog_id, $install );
4845
+ }
4846
+ }
4847
+ }
4848
+ }
4849
+
4850
+ /**
4851
+ * Parse plugin's settings (as defined by the plugin dev).
4852
+ *
4853
+ * @author Vova Feldman (@svovaf)
4854
+ * @since 1.1.7.3
4855
+ *
4856
+ * @param array $plugin_info
4857
+ *
4858
+ * @throws \Freemius_Exception
4859
+ */
4860
+ private function parse_settings( &$plugin_info ) {
4861
+ $this->_logger->entrance();
4862
+
4863
+ $id = $this->get_numeric_option( $plugin_info, 'id', false );
4864
+ $public_key = $this->get_option( $plugin_info, 'public_key', false );
4865
+ $secret_key = $this->get_option( $plugin_info, 'secret_key', null );
4866
+ $parent_id = $this->get_numeric_option( $plugin_info, 'parent_id', null );
4867
+ $parent_name = $this->get_option( $plugin_info, 'parent_name', null );
4868
+
4869
+ /**
4870
+ * @author Vova Feldman (@svovaf)
4871
+ * @since 1.1.9 Try to pull secret key from external config.
4872
+ */
4873
+ if ( is_null( $secret_key ) && defined( "WP_FS__{$this->_slug}_SECRET_KEY" ) ) {
4874
+ $secret_key = constant( "WP_FS__{$this->_slug}_SECRET_KEY" );
4875
+ }
4876
+
4877
+ if ( isset( $plugin_info['parent'] ) ) {
4878
+ $parent_id = $this->get_numeric_option( $plugin_info['parent'], 'id', null );
4879
+ // $parent_slug = $this->get_option( $plugin_info['parent'], 'slug', null );
4880
+ // $parent_public_key = $this->get_option( $plugin_info['parent'], 'public_key', null );
4881
+ // $parent_name = $this->get_option( $plugin_info['parent'], 'name', null );
4882
+ }
4883
+
4884
+ if ( false === $id ) {
4885
+ throw new Freemius_Exception( array(
4886
+ 'error' => array(
4887
+ 'type' => 'ParameterNotSet',
4888
+ 'message' => 'Plugin id parameter is not set.',
4889
+ 'code' => 'plugin_id_not_set',
4890
+ 'http' => 500,
4891
+ )
4892
+ ) );
4893
+ }
4894
+ if ( false === $public_key ) {
4895
+ throw new Freemius_Exception( array(
4896
+ 'error' => array(
4897
+ 'type' => 'ParameterNotSet',
4898
+ 'message' => 'Plugin public_key parameter is not set.',
4899
+ 'code' => 'plugin_public_key_not_set',
4900
+ 'http' => 500,
4901
+ )
4902
+ ) );
4903
+ }
4904
+
4905
+ $plugin = ( $this->_plugin instanceof FS_Plugin ) ?
4906
+ $this->_plugin :
4907
+ new FS_Plugin();
4908
+
4909
+ $premium_suffix = $this->get_option( $plugin_info, 'premium_suffix', '(Premium)' );
4910
+
4911
+ $plugin->update( array(
4912
+ 'id' => $id,
4913
+ 'type' => $this->get_option( $plugin_info, 'type', $this->_module_type ),
4914
+ 'public_key' => $public_key,
4915
+ 'slug' => $this->_slug,
4916
+ 'premium_slug' => $this->get_option( $plugin_info, 'premium_slug', "{$this->_slug}-premium" ),
4917
+ 'parent_plugin_id' => $parent_id,
4918
+ 'version' => $this->get_plugin_version(),
4919
+ 'title' => $this->get_plugin_name( $premium_suffix ),
4920
+ 'file' => $this->_plugin_basename,
4921
+ 'is_premium' => $this->get_bool_option( $plugin_info, 'is_premium', true ),
4922
+ 'premium_suffix' => $premium_suffix,
4923
+ 'is_live' => $this->get_bool_option( $plugin_info, 'is_live', true ),
4924
+ 'affiliate_moderation' => $this->get_option( $plugin_info, 'has_affiliation' ),
4925
+ ) );
4926
+
4927
+ if ( $plugin->is_updated() ) {
4928
+ // Update plugin details.
4929
+ $this->_plugin = FS_Plugin_Manager::instance( $this->_module_id )->store( $plugin );
4930
+ }
4931
+ // Set the secret key after storing the plugin, we don't want to store the key in the storage.
4932
+ $this->_plugin->secret_key = $secret_key;
4933
+
4934
+ if ( ! isset( $plugin_info['menu'] ) ) {
4935
+ $plugin_info['menu'] = array();
4936
+
4937
+ if ( ! empty( $this->_storage->sdk_last_version ) &&
4938
+ version_compare( $this->_storage->sdk_last_version, '1.1.2', '<=' )
4939
+ ) {
4940
+ // Backward compatibility to 1.1.2
4941
+ $plugin_info['menu']['slug'] = isset( $plugin_info['menu_slug'] ) ?
4942
+ $plugin_info['menu_slug'] :
4943
+ $this->_slug;
4944
+ }
4945
+ }
4946
+
4947
+ $this->_menu = FS_Admin_Menu_Manager::instance(
4948
+ $this->_module_id,
4949
+ $this->_module_type,
4950
+ $this->get_unique_affix()
4951
+ );
4952
+
4953
+ $this->_menu->init( $plugin_info['menu'], $this->is_addon() );
4954
+
4955
+ $this->_has_addons = $this->get_bool_option( $plugin_info, 'has_addons', false );
4956
+ $this->_has_paid_plans = $this->get_bool_option( $plugin_info, 'has_paid_plans', true );
4957
+ $this->_has_premium_version = $this->get_bool_option( $plugin_info, 'has_premium_version', $this->_has_paid_plans );
4958
+ $this->_ignore_pending_mode = $this->get_bool_option( $plugin_info, 'ignore_pending_mode', false );
4959
+ $this->_is_org_compliant = $this->get_bool_option( $plugin_info, 'is_org_compliant', true );
4960
+ $this->_is_premium_only = $this->get_bool_option( $plugin_info, 'is_premium_only', false );
4961
+ if ( $this->_is_premium_only ) {
4962
+ // If premium only plugin, disable anonymous mode.
4963
+ $this->_enable_anonymous = false;
4964
+ $this->_anonymous_mode = false;
4965
+ } else {
4966
+ $this->_enable_anonymous = $this->get_bool_option( $plugin_info, 'enable_anonymous', true );
4967
+ $this->_anonymous_mode = $this->get_bool_option( $plugin_info, 'anonymous_mode', false );
4968
+ }
4969
+ $this->_permissions = $this->get_option( $plugin_info, 'permissions', array() );
4970
+
4971
+ if ( ! empty( $plugin_info['trial'] ) ) {
4972
+ $this->_trial_days = $this->get_numeric_option(
4973
+ $plugin_info['trial'],
4974
+ 'days',
4975
+ // Default to 0 - trial without days specification.
4976
+ 0
4977
+ );
4978
+
4979
+ $this->_is_trial_require_payment = $this->get_bool_option( $plugin_info['trial'], 'is_require_payment', false );
4980
+ }
4981
+ }
4982
+
4983
+ /**
4984
+ * @param string[] $options
4985
+ * @param string $key
4986
+ * @param mixed $default
4987
+ *
4988
+ * @return bool
4989
+ */
4990
+ private function get_option( &$options, $key, $default = false ) {
4991
+ return ! empty( $options[ $key ] ) ? $options[ $key ] : $default;
4992
+ }
4993
+
4994
+ private function get_bool_option( &$options, $key, $default = false ) {
4995
+ return isset( $options[ $key ] ) && is_bool( $options[ $key ] ) ? $options[ $key ] : $default;
4996
+ }
4997
+
4998
+ private function get_numeric_option( &$options, $key, $default = false ) {
4999
+ return isset( $options[ $key ] ) && is_numeric( $options[ $key ] ) ? $options[ $key ] : $default;
5000
+ }
5001
+
5002
+ /**
5003
+ * Gate keeper.
5004
+ *
5005
+ * @author Vova Feldman (@svovaf)
5006
+ * @since 1.1.7.3
5007
+ *
5008
+ * @return bool
5009
+ */
5010
+ private function should_stop_execution() {
5011
+ if ( empty( $this->_storage->was_plugin_loaded ) ) {
5012
+ /**
5013
+ * Don't execute Freemius until plugin was fully loaded at least once,
5014
+ * to give the opportunity for the activation hook to run before pinging
5015
+ * the API for connectivity test. This logic is relevant for the
5016
+ * identification of new plugin install vs. plugin update.
5017
+ *
5018
+ * @author Vova Feldman (@svovaf)
5019
+ * @since 1.1.9
5020
+ */
5021
+ return true;
5022
+ }
5023
+
5024
+ if ( $this->is_activation_mode() ) {
5025
+ if ( ! is_admin() ) {
5026
+ /**
5027
+ * If in activation mode, don't execute Freemius outside of the
5028
+ * admin dashboard.
5029
+ *
5030
+ * @author Vova Feldman (@svovaf)
5031
+ * @since 1.1.7.3
5032
+ */
5033
+ return true;
5034
+ }
5035
+
5036
+ if ( ! WP_FS__IS_HTTP_REQUEST ) {
5037
+ /**
5038
+ * If in activation and executed without HTTP context (e.g. CLI, Cronjob),
5039
+ * then don't start Freemius.
5040
+ *
5041
+ * @author Vova Feldman (@svovaf)
5042
+ * @since 1.1.6.3
5043
+ *
5044
+ * @link https://wordpress.org/support/topic/errors-in-the-freemius-class-when-running-in-wordpress-in-cli
5045
+ */
5046
+ return true;
5047
+ }
5048
+
5049
+ if ( self::is_cron() ) {
5050
+ /**
5051
+ * If in activation mode, don't execute Freemius during wp crons
5052
+ * (wp crons have HTTP context - called as HTTP request).
5053
+ *
5054
+ * @author Vova Feldman (@svovaf)
5055
+ * @since 1.1.7.3
5056
+ */
5057
+ return true;
5058
+ }
5059
+
5060
+ if ( self::is_ajax() &&
5061
+ ! $this->_admin_notices->has_sticky( 'failed_connect_api_first' ) &&
5062
+ ! $this->_admin_notices->has_sticky( 'failed_connect_api' )
5063
+ ) {
5064
+ /**
5065
+ * During activation, if running in AJAX mode, unless there's a sticky
5066
+ * connectivity issue notice, don't run Freemius.
5067
+ *
5068
+ * @author Vova Feldman (@svovaf)
5069
+ * @since 1.1.7.3
5070
+ */
5071
+ return true;
5072
+ }
5073
+ }
5074
+
5075
+ return false;
5076
+ }
5077
+
5078
+ /**
5079
+ * Triggered after code type has changed.
5080
+ *
5081
+ * @author Vova Feldman (@svovaf)
5082
+ * @since 1.1.9.1
5083
+ */
5084
+ function _after_code_type_change() {
5085
+ $this->_logger->entrance();
5086
+
5087
+ if ( $this->is_theme() ) {
5088
+ // Expire the cache of the previous tabs since the theme may
5089
+ // have setting updates after code type has changed.
5090
+ $this->_cache->expire( 'tabs' );
5091
+ $this->_cache->expire( 'tabs_stylesheets' );
5092
+ }
5093
+
5094
+ if ( $this->is_registered() ) {
5095
+ if ( ! $this->is_addon() ) {
5096
+ add_action(
5097
+ is_admin() ? 'admin_init' : 'init',
5098
+ array( &$this, '_plugin_code_type_changed' )
5099
+ );
5100
+ }
5101
+
5102
+ if ( $this->is_premium() ) {
5103
+ // Purge cached payments after switching to the premium version.
5104
+ // @todo This logic doesn't handle purging the cache for serviceware module upgrade.
5105
+ $this->get_api_user_scope()->purge_cache( "/plugins/{$this->_module_id}/payments.json?include_addons=true" );
5106
+ }
5107
+ }
5108
+ }
5109
+
5110
+ /**
5111
+ * Handles plugin's code type change (free <--> premium).
5112
+ *
5113
+ * @author Vova Feldman (@svovaf)
5114
+ * @since 1.0.9
5115
+ */
5116
+ function _plugin_code_type_changed() {
5117
+ $this->_logger->entrance();
5118
+
5119
+ if ( $this->is_premium() ) {
5120
+ $this->reconnect_locally();
5121
+
5122
+ // Activated premium code.
5123
+ $this->do_action( 'after_premium_version_activation' );
5124
+
5125
+ // Remove all sticky messages related to download of the premium version.
5126
+ $this->_admin_notices->remove_sticky( array(
5127
+ 'trial_started',
5128
+ 'plan_upgraded',
5129
+ 'plan_changed',
5130
+ 'license_activated',
5131
+ ) );
5132
+
5133
+ $notice = '';
5134
+ if ( ! $this->is_only_premium() ) {
5135
+ $notice = sprintf( $this->get_text_inline( 'Premium %s version was successfully activated.', 'premium-activated-message' ), $this->_module_type );
5136
+ }
5137
+
5138
+ $license_notice = $this->get_license_network_activation_notice();
5139
+ if ( ! empty( $license_notice ) ) {
5140
+ $notice .= ' ' . $license_notice;
5141
+ }
5142
+
5143
+ if ( ! empty( $notice ) ) {
5144
+ $this->_admin_notices->add_sticky(
5145
+ trim( $notice ),
5146
+ 'premium_activated',
5147
+ $this->get_text_x_inline( 'W00t',
5148
+ 'Used to express elation, enthusiasm, or triumph (especially in electronic communication).', 'woot' ) . '!'
5149
+ );
5150
+ }
5151
+ } else {
5152
+ // Remove sticky message related to premium code activation.
5153
+ $this->_admin_notices->remove_sticky( 'premium_activated' );
5154
+
5155
+ // Activated free code (after had the premium before).
5156
+ $this->do_action( 'after_free_version_reactivation' );
5157
+
5158
+ if ( $this->is_paying() && ! $this->is_premium() ) {
5159
+ $this->_admin_notices->add_sticky(
5160
+ sprintf(
5161
+ /* translators: %s: License type (e.g. you have a professional license) */
5162
+ $this->get_text_inline( 'You have a %s license.', 'you-have-x-license' ),
5163
+ $this->get_plan_title()
5164
+ ) . $this->get_complete_upgrade_instructions(),
5165
+ 'plan_upgraded',
5166
+ $this->get_text_x_inline( 'Yee-haw', 'interjection expressing joy or exuberance', 'yee-haw' ) . '!'
5167
+ );
5168
+ }
5169
+ }
5170
+
5171
+ // Schedule code type changes event.
5172
+ $this->schedule_install_sync();
5173
+
5174
+ /**
5175
+ * Unregister the uninstall hook for the other version of the plugin (with different code type) to avoid
5176
+ * triggering a fatal error when uninstalling that plugin. For example, after deactivating the "free" version
5177
+ * of a specific plugin, its uninstall hook should be unregistered after the "premium" version has been
5178
+ * activated. If we don't do that, a fatal error will occur when we try to uninstall the "free" version since
5179
+ * the main file of the "free" version will be loaded first before calling the hooked callback. Since the
5180
+ * free and premium versions are almost identical (same class or have same functions), a fatal error like
5181
+ * "Cannot redeclare class MyClass" or "Cannot redeclare my_function()" will occur.
5182
+ */
5183
+ $this->unregister_uninstall_hook();
5184
+
5185
+ $this->clear_module_main_file_cache();
5186
+
5187
+ // Update is_premium of latest version.
5188
+ $this->_storage->prev_is_premium = $this->_plugin->is_premium;
5189
+ }
5190
+
5191
+ #endregion
5192
+
5193
+ #----------------------------------------------------------------------------------
5194
+ #region Add-ons
5195
+ #----------------------------------------------------------------------------------
5196
+
5197
+ /**
5198
+ * Check if add-on installed and activated on site.
5199
+ *
5200
+ * @author Vova Feldman (@svovaf)
5201
+ * @since 1.0.6
5202
+ *
5203
+ * @param string|number $id_or_slug
5204
+ * @param bool|null $is_premium Since 1.2.1.7 can check for specified add-on version.
5205
+ *
5206
+ * @return bool
5207
+ */
5208
+ function is_addon_activated( $id_or_slug, $is_premium = null ) {
5209
+ $this->_logger->entrance();
5210
+
5211
+ $addon_id = self::get_module_id( $id_or_slug );
5212
+ $is_activated = self::has_instance( $addon_id );
5213
+
5214
+ if ( ! $is_activated ) {
5215
+ return false;
5216
+ }
5217
+
5218
+ if ( is_bool( $is_premium ) ) {
5219
+ // Check if the specified code version is activate.
5220
+ $addon = $this->get_addon_instance( $addon_id );
5221
+ $is_activated = ( $is_premium === $addon->is_premium() );
5222
+ }
5223
+
5224
+ return $is_activated;
5225
+ }
5226
+
5227
+ /**
5228
+ * Check if add-on was connected to install
5229
+ *
5230
+ * @author Vova Feldman (@svovaf)
5231
+ * @since 1.1.7
5232
+ *
5233
+ * @param string|number $id_or_slug
5234
+ *
5235
+ * @return bool
5236
+ */
5237
+ function is_addon_connected( $id_or_slug ) {
5238
+ $this->_logger->entrance();
5239
+
5240
+ $sites = self::get_all_sites( WP_FS__MODULE_TYPE_PLUGIN );
5241
+
5242
+ $addon_id = self::get_module_id( $id_or_slug );
5243
+ $addon = $this->get_addon( $addon_id );
5244
+ $slug = $addon->slug;
5245
+ if ( ! isset( $sites[ $slug ] ) ) {
5246
+ return false;
5247
+ }
5248
+
5249
+ $site = $sites[ $slug ];
5250
+
5251
+ $plugin = FS_Plugin_Manager::instance( $addon_id )->get();
5252
+
5253
+ if ( $plugin->parent_plugin_id != $this->_plugin->id ) {
5254
+ // The given slug do NOT belong to any of the plugin's add-ons.
5255
+ return false;
5256
+ }
5257
+
5258
+ return ( is_object( $site ) &&
5259
+ is_numeric( $site->id ) &&
5260
+ is_numeric( $site->user_id ) &&
5261
+ FS_Plugin_Plan::is_valid_id( $site->plan_id )
5262
+ );
5263
+ }
5264
+
5265
+ /**
5266
+ * Determines if add-on installed.
5267
+ *
5268
+ * NOTE: This is a heuristic and only works if the folder/file named as the slug.
5269
+ *
5270
+ * @author Vova Feldman (@svovaf)
5271
+ * @since 1.0.6
5272
+ *
5273
+ * @param string|number $id_or_slug
5274
+ *
5275
+ * @return bool
5276
+ */
5277
+ function is_addon_installed( $id_or_slug ) {
5278
+ $this->_logger->entrance();
5279
+
5280
+ $addon_id = self::get_module_id( $id_or_slug );
5281
+
5282
+ return file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $this->get_addon_basename( $addon_id ) ) );
5283
+ }
5284
+
5285
+ /**
5286
+ * Get add-on basename.
5287
+ *
5288
+ * @author Vova Feldman (@svovaf)
5289
+ * @since 1.0.6
5290
+ *
5291
+ * @param string|number $id_or_slug
5292
+ *
5293
+ * @return string
5294
+ */
5295
+ function get_addon_basename( $id_or_slug ) {
5296
+ $addon_id = self::get_module_id( $id_or_slug );
5297
+
5298
+ if ( $this->is_addon_activated( $addon_id ) ) {
5299
+ return self::instance( $addon_id )->get_plugin_basename();
5300
+ }
5301
+
5302
+ $addon = $this->get_addon( $addon_id );
5303
+ $premium_basename = "{$addon->premium_slug}/{$addon->slug}.php";
5304
+
5305
+ if ( file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $premium_basename ) ) ) {
5306
+ return $premium_basename;
5307
+ }
5308
+
5309
+ $all_plugins = $this->get_all_plugins();
5310
+
5311
+ foreach ( $all_plugins as $basename => $data ) {
5312
+ if ( $addon->slug === $data['slug'] ||
5313
+ $addon->premium_slug === $data['slug']
5314
+ ) {
5315
+ return $basename;
5316
+ }
5317
+ }
5318
+
5319
+ $free_basename = "{$addon->slug}/{$addon->slug}.php";
5320
+
5321
+ return $free_basename;
5322
+ }
5323
+
5324
+ /**
5325
+ * Get installed add-ons instances.
5326
+ *
5327
+ * @author Vova Feldman (@svovaf)
5328
+ * @since 1.0.6
5329
+ *
5330
+ * @return Freemius[]
5331
+ */
5332
+ function get_installed_addons() {
5333
+ $installed_addons = array();
5334
+ foreach ( self::$_instances as $instance ) {
5335
+ if ( $instance->is_addon() && is_object( $instance->_parent_plugin ) ) {
5336
+ if ( $this->_plugin->id == $instance->_parent_plugin->id ) {
5337
+ $installed_addons[] = $instance;
5338
+ }
5339
+ }
5340
+ }
5341
+
5342
+ return $installed_addons;
5343
+ }
5344
+
5345
+ /**
5346
+ * Check if any add-ons of the plugin are installed.
5347
+ *
5348
+ * @author Leo Fajardo (@leorw)
5349
+ * @since 1.1.1
5350
+ *
5351
+ * @return bool
5352
+ */
5353
+ function has_installed_addons() {
5354
+ if ( ! $this->has_addons() ) {
5355
+ return false;
5356
+ }
5357
+
5358
+ foreach ( self::$_instances as $instance ) {
5359
+ if ( $instance->is_addon() && is_object( $instance->_parent_plugin ) ) {
5360
+ if ( $this->_plugin->id == $instance->_parent_plugin->id ) {
5361
+ return true;
5362
+ }
5363
+ }
5364
+ }
5365
+
5366
+ return false;
5367
+ }
5368
+
5369
+ /**
5370
+ * Tell Freemius that the current plugin is an add-on.
5371
+ *
5372
+ * @author Vova Feldman (@svovaf)
5373
+ * @since 1.0.6
5374
+ *
5375
+ * @param number $parent_plugin_id The parent plugin ID
5376
+ */
5377
+ function init_addon( $parent_plugin_id ) {
5378
+ $this->_plugin->parent_plugin_id = $parent_plugin_id;
5379
+ }
5380
+
5381
+ /**
5382
+ * @author Vova Feldman (@svovaf)
5383
+ * @since 1.0.6
5384
+ *
5385
+ * @return bool
5386
+ */
5387
+ function is_addon() {
5388
+ return isset( $this->_plugin->parent_plugin_id ) && is_numeric( $this->_plugin->parent_plugin_id );
5389
+ }
5390
+
5391
+ /**
5392
+ * Deactivate add-on if it's premium only and the user does't have a valid license.
5393
+ *
5394
+ * @param bool $is_after_trial_cancel
5395
+ *
5396
+ * @return bool If add-on was deactivated.
5397
+ */
5398
+ private function deactivate_premium_only_addon_without_license( $is_after_trial_cancel = false ) {
5399
+ if ( ! $this->has_free_plan() &&
5400
+ ! $this->has_features_enabled_license() &&
5401
+ ! $this->_has_premium_license()
5402
+ ) {
5403
+ if ( $this->is_registered() ) {
5404
+ // IF wrapper is turned off because activation_timestamp is currently only stored for plugins (not addons).
5405
+ // if (empty($this->_storage->activation_timestamp) ||
5406
+ // (WP_FS__SCRIPT_START_TIME - $this->_storage->activation_timestamp) > 30
5407
+ // ) {
5408
+ /**
5409
+ * @todo When it's first fail, there's no reason to try and re-sync because the licenses were just synced after initial activation.
5410
+ *
5411
+ * Retry syncing the user add-on licenses.
5412
+ */
5413
+ // Sync licenses.
5414
+ $this->_sync_licenses();
5415
+ // }
5416
+
5417
+ // Try to activate premium license.
5418
+ $this->_activate_license( true );
5419
+ }
5420
+
5421
+ if ( ! $this->has_free_plan() &&
5422
+ ! $this->has_features_enabled_license() &&
5423
+ ! $this->_has_premium_license()
5424
+ ) {
5425
+ // @todo Check if deactivate plugins also call the deactivation hook.
5426
+
5427
+ $this->_parent->_admin_notices->add_sticky(
5428
+ sprintf(
5429
+ ( $is_after_trial_cancel ?
5430
+ $this->_parent->get_text_inline(
5431
+ '%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.',
5432
+ 'addon-trial-cancelled-message'
5433
+ ) :
5434
+ $this->_parent->get_text_inline(
5435
+ '%s is a premium only add-on. You have to purchase a license first before activating the plugin.',
5436
+ 'addon-no-license-message'
5437
+ )
5438
+ ),
5439
+ '<b>' . $this->_plugin->title . '</b>'
5440
+ ) . ' ' . sprintf(
5441
+ '<a href="%s" aria-label="%s" class="button button-primary" style="margin-left: 10px; vertical-align: middle;">%s &nbsp;&#10140;</a>',
5442
+ $this->_parent->addon_url( $this->_slug ),
5443
+ esc_attr( sprintf( $this->_parent->get_text_inline( 'More information about %s', 'more-information-about-x' ), $this->_plugin->title ) ),
5444
+ $this->_parent->get_text_inline( 'Purchase License', 'purchase-license' )
5445
+ ),
5446
+ 'no_addon_license_' . $this->_slug,
5447
+ ( $is_after_trial_cancel ? '' : $this->_parent->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...' ),
5448
+ ( $is_after_trial_cancel ? 'success' : 'error' )
5449
+ );
5450
+
5451
+ deactivate_plugins( array( $this->_plugin_basename ), true );
5452
+
5453
+ return true;
5454
+ }
5455
+ }
5456
+
5457
+ return false;
5458
+ }
5459
+
5460
+ #endregion
5461
+
5462
+ #----------------------------------------------------------------------------------
5463
+ #region Sandbox
5464
+ #----------------------------------------------------------------------------------
5465
+
5466
+ /**
5467
+ * Set Freemius into sandbox mode for debugging.
5468
+ *
5469
+ * @author Vova Feldman (@svovaf)
5470
+ * @since 1.0.4
5471
+ *
5472
+ * @param string $secret_key
5473
+ */
5474
+ function init_sandbox( $secret_key ) {
5475
+ $this->_plugin->secret_key = $secret_key;
5476
+
5477
+ // Update plugin details.
5478
+ FS_Plugin_Manager::instance( $this->_module_id )->update( $this->_plugin, true );
5479
+ }
5480
+
5481
+ /**
5482
+ * Check if running payments in sandbox mode.
5483
+ *
5484
+ * @author Vova Feldman (@svovaf)
5485
+ * @since 1.0.4
5486
+ *
5487
+ * @return bool
5488
+ */
5489
+ function is_payments_sandbox() {
5490
+ return ( ! $this->is_live() ) || isset( $this->_plugin->secret_key );
5491
+ }
5492
+
5493
+ #endregion
5494
+
5495
+ /**
5496
+ * Check if running test vs. live plugin.
5497
+ *
5498
+ * @author Vova Feldman (@svovaf)
5499
+ * @since 1.0.5
5500
+ *
5501
+ * @return bool
5502
+ */
5503
+ function is_live() {
5504
+ return $this->_plugin->is_live;
5505
+ }
5506
+
5507
+ /**
5508
+ * Check if super-admin skipped connection for all sites in the network.
5509
+ *
5510
+ * @author Vova Feldman (@svovaf)
5511
+ * @since 2.0.0
5512
+ */
5513
+ function is_network_anonymous() {
5514
+ if ( ! $this->_is_network_active ) {
5515
+ return false;
5516
+ }
5517
+
5518
+ $is_anonymous_ms = $this->_storage->get( 'is_anonymous_ms' );
5519
+
5520
+ if ( empty( $is_anonymous_ms ) ) {
5521
+ return false;
5522
+ }
5523
+
5524
+ return $is_anonymous_ms['is'];
5525
+ }
5526
+
5527
+ /**
5528
+ * Check if super-admin opted-in for all sites in the network.
5529
+ *
5530
+ * @author Vova Feldman (@svovaf)
5531
+ * @since 2.0.0
5532
+ */
5533
+ function is_network_connected() {
5534
+ if ( ! $this->_is_network_active ) {
5535
+ return false;
5536
+ }
5537
+
5538
+ return $this->_storage->get( 'is_network_connected' );
5539
+ }
5540
+
5541
+ /**
5542
+ * Check if the user skipped connecting the account with Freemius.
5543
+ *
5544
+ * @author Vova Feldman (@svovaf)
5545
+ * @since 1.0.7
5546
+ *
5547
+ * @return bool
5548
+ */
5549
+ function is_anonymous() {
5550
+ if ( ! isset( $this->_is_anonymous ) ) {
5551
+ if ( $this->is_network_anonymous() ) {
5552
+ $this->_is_anonymous = true;
5553
+ } else if ( ! fs_is_network_admin() ) {
5554
+ if ( ! isset( $this->_storage->is_anonymous ) ) {
5555
+ // Not skipped.
5556
+ $this->_is_anonymous = false;
5557
+ } else if ( is_bool( $this->_storage->is_anonymous ) ) {
5558
+ // For back compatibility, since the variable was boolean before.
5559
+ $this->_is_anonymous = $this->_storage->is_anonymous;
5560
+
5561
+ // Upgrade stored data format to 1.1.3 format.
5562
+ $this->set_anonymous_mode( $this->_storage->is_anonymous );
5563
+ } else {
5564
+ // Version 1.1.3 and later.
5565
+ $this->_is_anonymous = $this->_storage->is_anonymous['is'];
5566
+ }
5567
+ }
5568
+ }
5569
+
5570
+ return $this->_is_anonymous;
5571
+ }
5572
+
5573
+ /**
5574
+ * Check if the user skipped the connection of a specified site.
5575
+ *
5576
+ * @author Vova Feldman (@svovaf)
5577
+ * @since 2.0.0
5578
+ *
5579
+ * @param int $blog_id
5580
+ *
5581
+ * @return bool
5582
+ */
5583
+ function is_anonymous_site( $blog_id = 0 ) {
5584
+ if ( $this->is_network_anonymous() ) {
5585
+ return true;
5586
+ }
5587
+
5588
+ $is_anonymous = $this->_storage->get( 'is_anonymous', false, $blog_id );
5589
+
5590
+ if ( empty( $is_anonymous ) ) {
5591
+ return false;
5592
+ }
5593
+
5594
+ return $is_anonymous['is'];
5595
+ }
5596
+
5597
+ /**
5598
+ * Check if user connected his account and install pending email activation.
5599
+ *
5600
+ * @author Vova Feldman (@svovaf)
5601
+ * @since 1.0.7
5602
+ *
5603
+ * @return bool
5604
+ */
5605
+ function is_pending_activation() {
5606
+ return $this->_storage->get( 'is_pending_activation', false );
5607
+ }
5608
+
5609
+ /**
5610
+ * Check if plugin must be WordPress.org compliant.
5611
+ *
5612
+ * @since 1.0.7
5613
+ *
5614
+ * @return bool
5615
+ */
5616
+ function is_org_repo_compliant() {
5617
+ return $this->_is_org_compliant;
5618
+ }
5619
+
5620
+ #--------------------------------------------------------------------------------
5621
+ #region WP Cron Common
5622
+ #--------------------------------------------------------------------------------
5623
+
5624
+ /**
5625
+ * @author Vova Feldman (@svovaf)
5626
+ * @since 2.0.0
5627
+ *
5628
+ * @param string $name Cron name.
5629
+ *
5630
+ * @return object
5631
+ */
5632
+ private function get_cron_data( $name ) {
5633
+ $this->_logger->entrance( $name );
5634
+
5635
+ /**
5636
+ * @var object $cron_data
5637
+ */
5638
+ return $this->_storage->get( "{$name}_cron", null );
5639
+ }
5640
+
5641
+ /**
5642
+ * @author Vova Feldman (@svovaf)
5643
+ * @since 2.0.0
5644
+ *
5645
+ * @param string $name Cron name.
5646
+ */
5647
+ private function clear_cron_data( $name ) {
5648
+ $this->_logger->entrance( $name );
5649
+
5650
+ $this->_storage->remove( "{$name}_cron" );
5651
+ }
5652
+
5653
+ /**
5654
+ * @author Vova Feldman (@svovaf)
5655
+ * @since 2.0.0
5656
+ *
5657
+ * @param string $name Cron name.
5658
+ * @param int $cron_blog_id The cron executing blog ID.
5659
+ */
5660
+ private function set_cron_data( $name, $cron_blog_id = 0 ) {
5661
+ $this->_logger->entrance( $name );
5662
+
5663
+ $this->_storage->store( "{$name}_cron", (object) array(
5664
+ 'version' => $this->get_plugin_version(),
5665
+ 'blog_id' => $cron_blog_id,
5666
+ 'sdk_version' => $this->version,
5667
+ 'timestamp' => WP_FS__SCRIPT_START_TIME,
5668
+ 'on' => true,
5669
+ ) );
5670
+ }
5671
+
5672
+ /**
5673
+ * Get the cron's executing blog ID.
5674
+ *
5675
+ * @author Vova Feldman (@svovaf)
5676
+ * @since 2.0.0
5677
+ *
5678
+ * @param string $name Cron name.
5679
+ *
5680
+ * @return int
5681
+ */
5682
+ private function get_cron_blog_id( $name ) {
5683
+ $this->_logger->entrance( $name );
5684
+
5685
+ /**
5686
+ * @var object $cron_data
5687
+ */
5688
+ $cron_data = $this->get_cron_data( $name );
5689
+
5690
+ return ( is_object( $cron_data ) && is_numeric( $cron_data->blog_id ) ) ?
5691
+ $cron_data->blog_id :
5692
+ 0;
5693
+ }
5694
+
5695
+ /**
5696
+ * @author Vova Feldman (@svovaf)
5697
+ * @since 2.0.0
5698
+ *
5699
+ * @param string $name Cron name.
5700
+ *
5701
+ * @return bool
5702
+ */
5703
+ private function is_cron_on( $name ) {
5704
+ $this->_logger->entrance( $name );
5705
+
5706
+ /**
5707
+ * @var object $cron_data
5708
+ */
5709
+ $cron_data = $this->get_cron_data( $name );
5710
+
5711
+ return ( ! is_null( $cron_data ) && true === $cron_data->on );
5712
+ }
5713
+
5714
+ /**
5715
+ * Unix timestamp for previous cron execution or false if never executed.
5716
+ *
5717
+ * @author Vova Feldman (@svovaf)
5718
+ * @since 2.0.0
5719
+ *
5720
+ * @param string $name Cron name.
5721
+ *
5722
+ * @return int|false
5723
+ */
5724
+ private function cron_last_execution( $name ) {
5725
+ $this->_logger->entrance( $name );
5726
+
5727
+ return $this->_storage->get( "{$name}_timestamp" );
5728
+ }
5729
+
5730
+ /**
5731
+ * Set cron execution time to now.
5732
+ *
5733
+ * @author Vova Feldman (@svovaf)
5734
+ * @since 2.0.0
5735
+ *
5736
+ * @param string $name Cron name.
5737
+ */
5738
+ private function set_cron_execution_timestamp( $name ) {
5739
+ $this->_logger->entrance( $name );
5740
+
5741
+ $this->_storage->store( "{$name}_timestamp", time() );
5742
+ }
5743
+
5744
+ /**
5745
+ * Sets the keepalive time to now.
5746
+ *
5747
+ * @author Leo Fajardo (@leorw)
5748
+ * @since 2.2.3
5749
+ *
5750
+ * @param bool|null $use_network_level_storage
5751
+ */
5752
+ private function set_keepalive_timestamp( $use_network_level_storage = null ) {
5753
+ $this->_logger->entrance();
5754
+
5755
+ $this->_storage->store( 'keepalive_timestamp', time(), $use_network_level_storage );
5756
+ }
5757
+
5758
+ /**
5759
+ * Check if cron was executed in the last $period of seconds.
5760
+ *
5761
+ * @author Vova Feldman (@svovaf)
5762
+ * @since 2.0.0
5763
+ *
5764
+ * @param string $name Cron name.
5765
+ * @param int $period In seconds
5766
+ *
5767
+ * @return bool
5768
+ */
5769
+ private function is_cron_executed( $name, $period = WP_FS__TIME_24_HOURS_IN_SEC ) {
5770
+ $this->_logger->entrance( $name );
5771
+
5772
+ $last_execution = $this->cron_last_execution( $name );
5773
+
5774
+ if ( ! is_numeric( $last_execution ) ) {
5775
+ return false;
5776
+ }
5777
+
5778
+ return ( $last_execution > ( WP_FS__SCRIPT_START_TIME - $period ) );
5779
+ }
5780
+
5781
+ /**
5782
+ * WP Cron is executed on a site level. When running in a multisite network environment
5783
+ * with the network integration activated, for optimization reasons, we are consolidating
5784
+ * the installs data sync cron to be executed only from a single site.
5785
+ *
5786
+ * @author Vova Feldman (@svovaf)
5787
+ * @since 2.0.0
5788
+ *
5789
+ * @param int $except_blog_id Target any except the excluded blog ID.
5790
+ *
5791
+ * @return int
5792
+ */
5793
+ private function get_cron_target_blog_id( $except_blog_id = 0 ) {
5794
+ if ( ! is_multisite() ) {
5795
+ return 0;
5796
+ }
5797
+
5798
+ if ( $this->_is_network_active &&
5799
+ is_numeric( $this->_storage->network_install_blog_id ) &&
5800
+ $except_blog_id != $this->_storage->network_install_blog_id &&
5801
+ self::is_site_active( $this->_storage->network_install_blog_id )
5802
+ ) {
5803
+ // Try to run cron from the main network blog.
5804
+ $install = $this->get_install_by_blog_id( $this->_storage->network_install_blog_id );
5805
+
5806
+ if ( is_object( $install ) &&
5807
+ ( $this->is_premium() || $install->is_tracking_allowed() )
5808
+ ) {
5809
+ return $this->_storage->network_install_blog_id;
5810
+ }
5811
+ }
5812
+
5813
+ // Get first opted-in blog ID with active tracking.
5814
+ $installs = $this->get_blog_install_map();
5815
+ foreach ( $installs as $blog_id => $install ) {
5816
+ if ( $except_blog_id != $blog_id &&
5817
+ self::is_site_active( $blog_id ) &&
5818
+ ( $this->is_premium() || $install->is_tracking_allowed() )
5819
+ ) {
5820
+ return $blog_id;
5821
+ }
5822
+ }
5823
+
5824
+ return 0;
5825
+ }
5826
+
5827
+ /**
5828
+ * @author Vova Feldman (@svovaf)
5829
+ * @since 2.0.0
5830
+ *
5831
+ * @param string $name Cron name.
5832
+ * @param string $action_tag Callback action tag.
5833
+ * @param bool $is_network_clear If set to TRUE, clear sync cron even if there are installs that are still connected.
5834
+ */
5835
+ private function clear_cron( $name, $action_tag = '', $is_network_clear = false ) {
5836
+ $this->_logger->entrance( $name );
5837
+
5838
+ if ( ! $this->is_cron_on( $name ) ) {
5839
+ return;
5840
+ }
5841
+
5842
+ $clear_cron = true;
5843
+ if ( ! $is_network_clear && $this->_is_network_active ) {
5844
+ $installs = $this->get_blog_install_map();
5845
+
5846
+ foreach ( $installs as $blog_id => $install ) {
5847
+ /**
5848
+ * @var FS_Site $install
5849
+ */
5850
+ if ( $install->is_tracking_allowed() ) {
5851
+ $clear_cron = false;
5852
+ break;
5853
+ }
5854
+ }
5855
+ }
5856
+
5857
+ if ( ! $clear_cron ) {
5858
+ return;
5859
+ }
5860
+
5861
+ /**
5862
+ * @var object $cron_data
5863
+ */
5864
+ $cron_data = $this->get_cron_data( $name );
5865
+
5866
+ $cron_blog_id = is_object( $cron_data ) && isset( $cron_data->blog_id ) ?
5867
+ $cron_data->blog_id :
5868
+ 0;
5869
+
5870
+ $this->clear_cron_data( $name );
5871
+
5872
+ if ( 0 < $cron_blog_id ) {
5873
+ switch_to_blog( $cron_blog_id );
5874
+ }
5875
+
5876
+ if ( empty( $action_tag ) ) {
5877
+ $action_tag = $name;
5878
+ }
5879
+
5880
+ wp_clear_scheduled_hook( $this->get_action_tag( $action_tag ) );
5881
+
5882
+ if ( 0 < $cron_blog_id ) {
5883
+ restore_current_blog();
5884
+ }
5885
+ }
5886
+
5887
+ /**
5888
+ * Unix timestamp for next cron execution or false if not scheduled.
5889
+ *
5890
+ * @author Vova Feldman (@svovaf)
5891
+ * @since 2.0.0
5892
+ *
5893
+ * @param string $name Cron name.
5894
+ * @param string $action_tag Callback action tag.
5895
+ *
5896
+ * @return int|false
5897
+ */
5898
+ private function get_next_scheduled_cron( $name, $action_tag = '' ) {
5899
+ $this->_logger->entrance( $name );
5900
+
5901
+ if ( ! $this->is_cron_on( $name ) ) {
5902
+ return false;
5903
+ }
5904
+
5905
+ /**
5906
+ * @var object $cron_data
5907
+ */
5908
+ $cron_data = $this->get_cron_data( $name );
5909
+
5910
+ $cron_blog_id = is_object( $cron_data ) && isset( $cron_data->blog_id ) ?
5911
+ $cron_data->blog_id :
5912
+ 0;
5913
+
5914
+ if ( 0 < $cron_blog_id ) {
5915
+ switch_to_blog( $cron_blog_id );
5916
+ }
5917
+
5918
+ if ( empty( $action_tag ) ) {
5919
+ $action_tag = $name;
5920
+ }
5921
+
5922
+ $next_scheduled = wp_next_scheduled( $this->get_action_tag( $action_tag ) );
5923
+
5924
+ if ( 0 < $cron_blog_id ) {
5925
+ restore_current_blog();
5926
+ }
5927
+
5928
+ return $next_scheduled;
5929
+ }
5930
+
5931
+ /**
5932
+ * @author Vova Feldman (@svovaf)
5933
+ * @since 2.0.0
5934
+ *
5935
+ * @param string $name Cron name.
5936
+ * @param string $action_tag Callback action tag.
5937
+ * @param string $recurrence 'single' or 'daily'.
5938
+ * @param int $start_at Defaults to now.
5939
+ * @param bool $randomize_start If true, schedule first job randomly during the next 12 hours. Otherwise, schedule job to start right away.
5940
+ * @param int $except_blog_id Target any except the excluded blog ID.
5941
+ */
5942
+ private function schedule_cron(
5943
+ $name,
5944
+ $action_tag = '',
5945
+ $recurrence = 'single',
5946
+ $start_at = WP_FS__SCRIPT_START_TIME,
5947
+ $randomize_start = true,
5948
+ $except_blog_id = 0
5949
+ ) {
5950
+ $this->_logger->entrance( $name );
5951
+
5952
+ $this->clear_cron( $name, $action_tag, true );
5953
+
5954
+ $cron_blog_id = $this->get_cron_target_blog_id( $except_blog_id );
5955
+
5956
+ if ( is_multisite() && 0 == $cron_blog_id ) {
5957
+ // Don't schedule cron since couldn't find a target blog.
5958
+ return;
5959
+ }
5960
+
5961
+ if ( 0 < $cron_blog_id ) {
5962
+ switch_to_blog( $cron_blog_id );
5963
+ }
5964
+
5965
+ if ( 'daily' === $recurrence ) {
5966
+ if ( $randomize_start ) {
5967
+ // Schedule first sync with a random 12 hour time range from now.
5968
+ $start_at += rand( 0, ( WP_FS__TIME_24_HOURS_IN_SEC / 2 ) );
5969
+ }
5970
+
5971
+ // Schedule daily WP cron.
5972
+ wp_schedule_event(
5973
+ $start_at,
5974
+ 'daily',
5975
+ $this->get_action_tag( $action_tag )
5976
+ );
5977
+ } else if ( 'single' === $recurrence ) {
5978
+ // Schedule single cron.
5979
+ wp_schedule_single_event(
5980
+ $start_at,
5981
+ $this->get_action_tag( $action_tag )
5982
+ );
5983
+ }
5984
+
5985
+ $this->set_cron_data( $name, $cron_blog_id );
5986
+
5987
+ if ( 0 < $cron_blog_id ) {
5988
+ restore_current_blog();
5989
+ }
5990
+ }
5991
+
5992
+ /**
5993
+ * Consolidated cron execution for performance optimization. The max number of API requests is based on the number of unique opted-in users.
5994
+ * that doesn't halt page loading.
5995
+ *
5996
+ * @author Vova Feldman (@svovaf)
5997
+ * @since 2.0.0
5998
+ *
5999
+ * @param string $name Cron name.
6000
+ * @param callable $callable The function that should be executed.
6001
+ */
6002
+ private function execute_cron( $name, $callable ) {
6003
+ $this->_logger->entrance( $name );
6004
+
6005
+ // Store the last time data sync was executed.
6006
+ $this->set_cron_execution_timestamp( $name );
6007
+
6008
+ // Check if API is temporary down.
6009
+ if ( FS_Api::is_temporary_down() ) {
6010
+ return;
6011
+ }
6012
+
6013
+ // @todo Add logic that identifies API latency, and reschedule the next background sync randomly between 8-16 hours.
6014
+
6015
+ $users_2_blog_ids = array();
6016
+
6017
+ if ( ! is_multisite() ) {
6018
+ // Add dummy blog.
6019
+ $users_2_blog_ids[0] = array( 0 );
6020
+ } else {
6021
+ $installs = $this->get_blog_install_map();
6022
+ foreach ( $installs as $blog_id => $install ) {
6023
+ if ( $this->is_premium() || $install->is_tracking_allowed() ) {
6024
+ if ( ! isset( $users_2_blog_ids[ $install->user_id ] ) ) {
6025
+ $users_2_blog_ids[ $install->user_id ] = array();
6026
+ }
6027
+
6028
+ $users_2_blog_ids[ $install->user_id ][] = $blog_id;
6029
+ }
6030
+ }
6031
+ }
6032
+
6033
+ $current_blog_id = get_current_blog_id();
6034
+
6035
+ foreach ( $users_2_blog_ids as $user_id => $blog_ids ) {
6036
+ if ( 0 < $blog_ids[0] ) {
6037
+ $this->switch_to_blog( $blog_ids[0] );
6038
+ }
6039
+
6040
+ call_user_func_array( $callable, array( $blog_ids, ( is_multisite() ? $current_blog_id : null ) ) );
6041
+
6042
+ foreach ( $blog_ids as $blog_id ) {
6043
+ $this->do_action( "after_{$name}_cron", $blog_id );
6044
+ }
6045
+ }
6046
+
6047
+ if ( is_multisite() ) {
6048
+ $this->switch_to_blog( $current_blog_id );
6049
+
6050
+ $this->do_action( "after_{$name}_cron_multisite" );
6051
+ }
6052
+ }
6053
+
6054
+ #endregion
6055
+
6056
+ #----------------------------------------------------------------------------------
6057
+ #region Daily Sync Cron
6058
+ #----------------------------------------------------------------------------------
6059
+
6060
+
6061
+ /**
6062
+ * @author Vova Feldman (@svovaf)
6063
+ * @since 2.0.0
6064
+ *
6065
+ * @return bool
6066
+ */
6067
+ private function is_sync_cron_scheduled() {
6068
+ return $this->is_cron_on( 'sync' );
6069
+ }
6070
+
6071
+ /**
6072
+ * Get the sync cron's executing blog ID.
6073
+ *
6074
+ * @author Vova Feldman (@svovaf)
6075
+ * @since 2.0.0
6076
+ *
6077
+ * @return int
6078
+ */
6079
+ private function get_sync_cron_blog_id() {
6080
+ return $this->get_cron_blog_id( 'sync' );
6081
+ }
6082
+
6083
+ /**
6084
+ * @author Vova Feldman (@svovaf)
6085
+ * @since 1.1.7.3
6086
+ */
6087
+ private function run_manual_sync() {
6088
+ self::require_pluggable_essentials();
6089
+
6090
+ if ( ! $this->is_user_admin() ) {
6091
+ return;
6092
+ }
6093
+
6094
+ // Run manual sync.
6095
+ $this->_sync_cron();
6096
+
6097
+ // Reschedule next cron to run 24 hours from now (performance optimization).
6098
+ $this->schedule_sync_cron( time() + WP_FS__TIME_24_HOURS_IN_SEC, false );
6099
+ }
6100
+
6101
+ /**
6102
+ * Data sync cron job. Replaces the background sync non blocking HTTP request
6103
+ * that doesn't halt page loading.
6104
+ *
6105
+ * @author Vova Feldman (@svovaf)
6106
+ * @since 1.1.7.3
6107
+ * @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.
6108
+ */
6109
+ function _sync_cron() {
6110
+ $this->_logger->entrance();
6111
+
6112
+ $this->execute_cron( 'sync', array( &$this, '_sync_cron_method' ) );
6113
+ }
6114
+
6115
+ /**
6116
+ * The actual data sync cron logic.
6117
+ *
6118
+ * @author Vova Feldman (@svovaf)
6119
+ * @since 2.0.0
6120
+ *
6121
+ * @param int[] $blog_ids
6122
+ * @param int|null $current_blog_id @since 2.2.3. This is passed from the `execute_cron` method and used by the
6123
+ * `_sync_plugin_license` method in order to switch to the previous blog when sending
6124
+ * updates for a single site in case `execute_cron` has switched to a different blog.
6125
+ */
6126
+ function _sync_cron_method( array $blog_ids, $current_blog_id = null ) {
6127
+ if ( $this->is_registered() ) {
6128
+ if ( $this->has_paid_plan() ) {
6129
+ // Initiate background plan sync.
6130
+ $this->_sync_license( true, false, $current_blog_id );
6131
+
6132
+ if ( $this->is_paying() ) {
6133
+ // Check for premium plugin updates.
6134
+ $this->check_updates( true );
6135
+ }
6136
+ } else {
6137
+ // Sync install(s) (only if something changed locally).
6138
+ if ( 1 < count( $blog_ids ) ) {
6139
+ $this->sync_installs();
6140
+ } else {
6141
+ $this->sync_install();
6142
+ }
6143
+ }
6144
+ }
6145
+ }
6146
+
6147
+ /**
6148
+ * Check if sync was executed in the last $period of seconds.
6149
+ *
6150
+ * @author Vova Feldman (@svovaf)
6151
+ * @since 1.1.7.3
6152
+ *
6153
+ * @param int $period In seconds
6154
+ *
6155
+ * @return bool
6156
+ */
6157
+ private function is_sync_executed( $period = WP_FS__TIME_24_HOURS_IN_SEC ) {
6158
+ return $this->is_cron_executed( 'sync', $period );
6159
+ }
6160
+
6161
+ /**
6162
+ * @author Vova Feldman (@svovaf)
6163
+ * @since 1.1.7.3
6164
+ *
6165
+ * @return bool
6166
+ */
6167
+ private function is_sync_cron_on() {
6168
+ return $this->is_cron_on( 'sync' );
6169
+ }
6170
+
6171
+ /**
6172
+ * @author Vova Feldman (@svovaf)
6173
+ * @since 1.1.7.3
6174
+ *
6175
+ * @param int $start_at Defaults to now.
6176
+ * @param bool $randomize_start If true, schedule first job randomly during the next 12 hours. Otherwise, schedule job to start right away.
6177
+ * @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.
6178
+ */
6179
+ private function schedule_sync_cron(
6180
+ $start_at = WP_FS__SCRIPT_START_TIME,
6181
+ $randomize_start = true,
6182
+ $except_blog_id = 0
6183
+ ) {
6184
+ $this->schedule_cron(
6185
+ 'sync',
6186
+ 'data_sync',
6187
+ 'daily',
6188
+ $start_at,
6189
+ $randomize_start,
6190
+ $except_blog_id
6191
+ );
6192
+ }
6193
+
6194
+ /**
6195
+ * Add the actual sync function to the cron job hook.
6196
+ *
6197
+ * @author Vova Feldman (@svovaf)
6198
+ * @since 1.1.7.3
6199
+ */
6200
+ private function hook_callback_to_sync_cron() {
6201
+ $this->add_action( 'data_sync', array( &$this, '_sync_cron' ) );
6202
+ }
6203
+
6204
+ /**
6205
+ * @author Vova Feldman (@svovaf)
6206
+ * @since 1.1.7.3
6207
+ *
6208
+ * @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.
6209
+ */
6210
+ private function clear_sync_cron( $is_network_clear = false ) {
6211
+ $this->_logger->entrance();
6212
+
6213
+ $this->clear_cron( 'sync', 'data_sync', $is_network_clear );
6214
+ }
6215
+
6216
+ /**
6217
+ * Unix timestamp for next sync cron execution or false if not scheduled.
6218
+ *
6219
+ * @author Vova Feldman (@svovaf)
6220
+ * @since 1.1.7.3
6221
+ *
6222
+ * @return int|false
6223
+ */
6224
+ function next_sync_cron() {
6225
+ return $this->get_next_scheduled_cron( 'sync', 'data_sync' );
6226
+ }
6227
+
6228
+ /**
6229
+ * Unix timestamp for previous sync cron execution or false if never executed.
6230
+ *
6231
+ * @author Vova Feldman (@svovaf)
6232
+ * @since 1.1.7.3
6233
+ *
6234
+ * @return int|false
6235
+ */
6236
+ function last_sync_cron() {
6237
+ return $this->cron_last_execution( 'sync' );
6238
+ }
6239
+
6240
+ #endregion Daily Sync Cron ------------------------------------------------------------------
6241
+
6242
+ #----------------------------------------------------------------------------------
6243
+ #region Async Install Sync
6244
+ #----------------------------------------------------------------------------------
6245
+
6246
+ /**
6247
+ * @author Vova Feldman (@svovaf)
6248
+ * @since 1.1.7.3
6249
+ *
6250
+ * @return bool
6251
+ */
6252
+ private function is_install_sync_scheduled() {
6253
+ return $this->is_cron_on( 'install_sync' );
6254
+ }
6255
+
6256
+ /**
6257
+ * Get the sync cron's executing blog ID.
6258
+ *
6259
+ * @author Vova Feldman (@svovaf)
6260
+ * @since 2.0.0
6261
+ *
6262
+ * @return int
6263
+ */
6264
+ private function get_install_sync_cron_blog_id() {
6265
+ return $this->get_cron_blog_id( 'install_sync' );
6266
+ }
6267
+
6268
+ /**
6269
+ * Instead of running blocking install sync event, execute non blocking scheduled wp-cron.
6270
+ *
6271
+ * @author Vova Feldman (@svovaf)
6272
+ * @since 1.1.7.3
6273
+ *
6274
+ * @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.
6275
+ */
6276
+ private function schedule_install_sync( $except_blog_id = 0 ) {
6277
+ $this->schedule_cron( 'install_sync', 'install_sync', 'single', WP_FS__SCRIPT_START_TIME, false, $except_blog_id );
6278
+ }
6279
+
6280
+ /**
6281
+ * Unix timestamp for previous install sync cron execution or false if never executed.
6282
+ *
6283
+ * @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.
6284
+ *
6285
+ * @author Vova Feldman (@svovaf)
6286
+ * @since 1.1.7.3
6287
+ *
6288
+ * @return int|false
6289
+ */
6290
+ function last_install_sync() {
6291
+ return $this->cron_last_execution( 'install_sync' );
6292
+ }
6293
+
6294
+ /**
6295
+ * Unix timestamp for next install sync cron execution or false if not scheduled.
6296
+ *
6297
+ * @author Vova Feldman (@svovaf)
6298
+ * @since 1.1.7.3
6299
+ *
6300
+ * @return int|false
6301
+ */
6302
+ function next_install_sync() {
6303
+ return $this->get_next_scheduled_cron( 'install_sync', 'install_sync' );
6304
+ }
6305
+
6306
+ /**
6307
+ * Add the actual install sync function to the cron job hook.
6308
+ *
6309
+ * @author Vova Feldman (@svovaf)
6310
+ * @since 1.1.7.3
6311
+ */
6312
+ private function hook_callback_to_install_sync() {
6313
+ $this->add_action( 'install_sync', array( &$this, '_run_sync_install' ) );
6314
+ }
6315
+
6316
+ /**
6317
+ * @author Vova Feldman (@svovaf)
6318
+ * @since 1.1.7.3
6319
+ *
6320
+ * @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.
6321
+ */
6322
+ private function clear_install_sync_cron( $is_network_clear = false ) {
6323
+ $this->_logger->entrance();
6324
+
6325
+ $this->clear_cron( 'install_sync', 'install_sync', $is_network_clear );
6326
+ }
6327
+
6328
+ /**
6329
+ * @author Vova Feldman (@svovaf)
6330
+ * @since 1.1.7.3
6331
+ * @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.
6332
+ */
6333
+ public function _run_sync_install() {
6334
+ $this->_logger->entrance();
6335
+
6336
+ $this->execute_cron( 'sync', array( &$this, '_sync_install_cron_method' ) );
6337
+ }
6338
+
6339
+ /**
6340
+ * The actual install(s) sync cron logic.
6341
+ *
6342
+ * @author Vova Feldman (@svovaf)
6343
+ * @since 2.0.0
6344
+ *
6345
+ * @param int[] $blog_ids
6346
+ * @param int|null $current_blog_id
6347
+ */
6348
+ function _sync_install_cron_method( array $blog_ids, $current_blog_id = null ) {
6349
+ if ( $this->is_registered() ) {
6350
+ if ( 1 < count( $blog_ids ) ) {
6351
+ $this->sync_installs( array(), true );
6352
+ } else {
6353
+ $this->sync_install( array(), true );
6354
+ }
6355
+ }
6356
+ }
6357
+
6358
+ #endregion Async Install Sync ------------------------------------------------------------------
6359
+
6360
+ /**
6361
+ * Show a notice that activation is currently pending.
6362
+ *
6363
+ * @author Vova Feldman (@svovaf)
6364
+ * @since 1.0.7
6365
+ *
6366
+ * @param bool|string $email
6367
+ * @param bool $is_pending_trial Since 1.2.1.5
6368
+ */
6369
+ function _add_pending_activation_notice( $email = false, $is_pending_trial = false ) {
6370
+ if ( ! is_string( $email ) ) {
6371
+ $current_user = self::_get_current_wp_user();
6372
+ $email = $current_user->user_email;
6373
+ }
6374
+
6375
+ $this->_admin_notices->add_sticky(
6376
+ sprintf(
6377
+ $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' ),
6378
+ '<b>' . $this->get_plugin_name() . '</b>',
6379
+ '<b>' . $email . '</b>',
6380
+ ( $is_pending_trial ?
6381
+ $this->get_text_inline( 'start the trial', 'start-the-trial' ) :
6382
+ $this->get_text_inline( 'complete the install', 'complete-the-install' ) )
6383
+ ),
6384
+ 'activation_pending',
6385
+ 'Thanks!'
6386
+ );
6387
+ }
6388
+
6389
+ /**
6390
+ * Check if currently in plugin activation.
6391
+ *
6392
+ * @author Vova Feldman (@svovaf)
6393
+ * @since 1.1.4
6394
+ *
6395
+ * @return bool
6396
+ */
6397
+ function is_plugin_activation() {
6398
+ $result = get_transient( "fs_{$this->_module_type}_{$this->_slug}_activated" );
6399
+
6400
+ return !empty($result);
6401
+ }
6402
+
6403
+ /**
6404
+ *
6405
+ * NOTE: admin_menu action executed before admin_init.
6406
+ *
6407
+ * @author Vova Feldman (@svovaf)
6408
+ * @since 1.0.7
6409
+ */
6410
+ function _admin_init_action() {
6411
+ /**
6412
+ * Automatically redirect to connect/activation page after plugin activation.
6413
+ *
6414
+ * @since 1.1.7 Do NOT redirect to opt-in when running in network admin mode.
6415
+ */
6416
+ if ( $this->is_plugin_activation() ) {
6417
+ delete_transient( "fs_{$this->_module_type}_{$this->_slug}_activated" );
6418
+
6419
+ if ( isset( $_GET['activate-multi'] ) ) {
6420
+ /**
6421
+ * Don't redirect if activating multiple plugins at once (bulk activation).
6422
+ */
6423
+ } else {
6424
+ $this->_redirect_on_activation_hook();
6425
+ return;
6426
+ }
6427
+ }
6428
+
6429
+ if ( fs_request_is_action( $this->get_unique_affix() . '_skip_activation' ) ) {
6430
+ check_admin_referer( $this->get_unique_affix() . '_skip_activation' );
6431
+
6432
+ $this->skip_connection( null, fs_is_network_admin() );
6433
+
6434
+ fs_redirect( $this->get_after_activation_url( 'after_skip_url' ) );
6435
+ }
6436
+
6437
+ if ( $this->is_network_activation_mode() &&
6438
+ fs_request_is_action( $this->get_unique_affix() . '_delegate_activation' )
6439
+ ) {
6440
+ check_admin_referer( $this->get_unique_affix() . '_delegate_activation' );
6441
+
6442
+ $this->delegate_connection();
6443
+
6444
+ fs_redirect( $this->get_after_activation_url( 'after_delegation_url' ) );
6445
+ }
6446
+
6447
+ $this->_add_upgrade_action_link();
6448
+
6449
+ if ( ! $this->is_addon() &&
6450
+ ! ( ! $this->_is_network_active && fs_is_network_admin() ) &&
6451
+ (
6452
+ ( true === $this->_storage->require_license_activation ) ||
6453
+ // Not registered nor anonymous.
6454
+ ( ! $this->is_registered() && ! $this->is_anonymous() ) ||
6455
+ // OR, network level and in network upgrade mode.
6456
+ ( fs_is_network_admin() && $this->_is_network_active && $this->is_network_upgrade_mode() )
6457
+ )
6458
+ ) {
6459
+ if ( ! $this->is_pending_activation() ) {
6460
+ if ( ! $this->_menu->is_main_settings_page() ) {
6461
+ /**
6462
+ * If a user visits any other admin page before activating the premium-only theme with a valid
6463
+ * license, reactivate the previous theme.
6464
+ *
6465
+ * @author Leo Fajardo (@leorw)
6466
+ * @since 1.2.2
6467
+ */
6468
+ if ( $this->is_theme()
6469
+ && ! $this->has_settings_menu()
6470
+ && ! isset( $_REQUEST['fs_action'] )
6471
+ && $this->can_activate_previous_theme()
6472
+ ) {
6473
+ if ( $this->is_only_premium() ) {
6474
+ $this->activate_previous_theme();
6475
+ return;
6476
+ }
6477
+
6478
+ if ( true === $this->_storage->require_license_activation ) {
6479
+ $this->_storage->require_license_activation = false;
6480
+ }
6481
+ }
6482
+
6483
+ if ( ! fs_is_network_admin() &&
6484
+ $this->is_network_activation_mode() &&
6485
+ ! $this->is_delegated_connection()
6486
+ ) {
6487
+ return;
6488
+ }
6489
+
6490
+ if ( $this->is_plugin_new_install() || $this->is_only_premium() ) {
6491
+ if ( ! $this->_anonymous_mode ) {
6492
+ // Show notice for new plugin installations.
6493
+ $this->_admin_notices->add(
6494
+ sprintf(
6495
+ $this->get_text_inline( 'You are just one step away - %s', 'you-are-step-away' ),
6496
+ sprintf( '<b><a href="%s">%s</a></b>',
6497
+ $this->get_activation_url( array(), ! $this->is_delegated_connection() ),
6498
+ sprintf( $this->get_text_x_inline( 'Complete "%s" Activation Now',
6499
+ '%s - plugin name. As complete "PluginX" activation now', 'activate-x-now' ), $this->get_plugin_name() )
6500
+ )
6501
+ ),
6502
+ '',
6503
+ 'update-nag'
6504
+ );
6505
+ }
6506
+ } else {
6507
+ if ( $this->should_add_sticky_optin_notice() ) {
6508
+ $this->add_sticky_optin_admin_notice();
6509
+ }
6510
+
6511
+ if ( $this->has_filter( 'optin_pointer_element' ) ) {
6512
+ // Don't show admin nag if plugin update.
6513
+ wp_enqueue_script( 'wp-pointer' );
6514
+ wp_enqueue_style( 'wp-pointer' );
6515
+
6516
+ $this->_enqueue_connect_essentials();
6517
+
6518
+ add_action( 'admin_print_footer_scripts', array(
6519
+ $this,
6520
+ '_add_connect_pointer_script'
6521
+ ) );
6522
+ }
6523
+ }
6524
+ }
6525
+ }
6526
+
6527
+ if ( $this->is_theme() &&
6528
+ $this->_menu->is_main_settings_page()
6529
+ ) {
6530
+ $this->_show_theme_activation_optin_dialog();
6531
+ }
6532
+ }
6533
+ }
6534
+
6535
+ /**
6536
+ * @author Vova Feldman (@svovaf)
6537
+ * @since 2.0.0
6538
+ *
6539
+ * @return bool
6540
+ */
6541
+ private function should_add_sticky_optin_notice() {
6542
+ if ( fs_is_network_admin() ) {
6543
+ if ( ! $this->_is_network_active ) {
6544
+ return false;
6545
+ }
6546
+
6547
+ if ( ! $this->is_network_activation_mode() ) {
6548
+ return false;
6549
+ }
6550
+
6551
+ return ! isset( $this->_storage->sticky_optin_added_ms );
6552
+ }
6553
+
6554
+ if ( ! $this->is_activation_mode() ) {
6555
+ return false;
6556
+ }
6557
+
6558
+ // If running from a blog admin and delegated the connection.
6559
+ return ! isset( $this->_storage->sticky_optin_added );
6560
+ }
6561
+
6562
+ /**
6563
+ * @author Leo Fajardo (@leorw)
6564
+ * @since 2.0.0
6565
+ */
6566
+ private function add_sticky_optin_admin_notice() {
6567
+ if ( ! $this->_is_network_active || ! fs_is_network_admin() ) {
6568
+ $this->_storage->sticky_optin_added = true;
6569
+ } else {
6570
+ $this->_storage->sticky_optin_added_ms = true;
6571
+ }
6572
+
6573
+ // Show notice for new plugin installations.
6574
+ $this->_admin_notices->add_sticky(
6575
+ sprintf(
6576
+ $this->get_text_inline( 'We made a few tweaks to the %s, %s', 'few-plugin-tweaks' ),
6577
+ $this->_module_type,
6578
+ sprintf( '<b><a href="%s">%s</a></b>',
6579
+ $this->get_activation_url(),
6580
+ sprintf( $this->get_text_inline( 'Opt in to make "%s" better!', 'optin-x-now' ), $this->get_plugin_name() )
6581
+ )
6582
+ ),
6583
+ 'connect_account',
6584
+ '',
6585
+ 'update-nag'
6586
+ );
6587
+ }
6588
+
6589
+ /**
6590
+ * Enqueue connect requires scripts and styles.
6591
+ *
6592
+ * @author Vova Feldman (@svovaf)
6593
+ * @since 1.1.4
6594
+ */
6595
+ function _enqueue_connect_essentials() {
6596
+ wp_enqueue_script( 'jquery' );
6597
+ wp_enqueue_script( 'json2' );
6598
+
6599
+ fs_enqueue_local_script( 'postmessage', 'nojquery.ba-postmessage.min.js' );
6600
+ fs_enqueue_local_script( 'fs-postmessage', 'postmessage.js' );
6601
+
6602
+ fs_enqueue_local_style( 'fs_connect', '/admin/connect.css' );
6603
+ }
6604
+
6605
+ /**
6606
+ * Add connect / opt-in pointer.
6607
+ *
6608
+ * @author Vova Feldman (@svovaf)
6609
+ * @since 1.1.4
6610
+ */
6611
+ function _add_connect_pointer_script() {
6612
+ $vars = array( 'id' => $this->_module_id );
6613
+ $pointer_content = fs_get_template( 'connect.php', $vars );
6614
+ ?>
6615
+ <script type="text/javascript">// <![CDATA[
6616
+ jQuery(document).ready(function ($) {
6617
+ if ('undefined' !== typeof(jQuery().pointer)) {
6618
+
6619
+ var element = <?php echo $this->apply_filters( 'optin_pointer_element', '$("#non_existing_element");' ) ?>;
6620
+
6621
+ if (element.length > 0) {
6622
+ var optin = $(element).pointer($.extend(true, {}, {
6623
+ content : <?php echo json_encode( $pointer_content ) ?>,
6624
+ position : {
6625
+ edge : 'left',
6626
+ align: 'center'
6627
+ },
6628
+ buttons : function () {
6629
+ // Don't show pointer buttons.
6630
+ return '';
6631
+ },
6632
+ pointerWidth: 482
6633
+ }, <?php echo $this->apply_filters( 'optin_pointer_options_json', '{}' ) ?>));
6634
+
6635
+ <?php
6636
+ echo $this->apply_filters( 'optin_pointer_execute', "
6637
+
6638
+ optin.pointer('open');
6639
+
6640
+ // Tag the opt-in pointer with custom class.
6641
+ $('.wp-pointer #fs_connect')
6642
+ .parents('.wp-pointer.wp-pointer-top')
6643
+ .addClass('fs-opt-in-pointer');
6644
+
6645
+ ", 'element', 'optin' ) ?>
6646
+ }
6647
+ }
6648
+ });
6649
+ // ]]></script>
6650
+ <?php
6651
+ }
6652
+
6653
+ /**
6654
+ * Return current page's URL.
6655
+ *
6656
+ * @author Vova Feldman (@svovaf)
6657
+ * @since 1.0.7
6658
+ *
6659
+ * @return string
6660
+ */
6661
+ function current_page_url() {
6662
+ $url = 'http';
6663
+
6664
+ if ( isset( $_SERVER["HTTPS"] ) ) {
6665
+ if ( $_SERVER["HTTPS"] == "on" ) {
6666
+ $url .= "s";
6667
+ }
6668
+ }
6669
+ $url .= "://";
6670
+ if ( $_SERVER["SERVER_PORT"] != "80" ) {
6671
+ $url .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
6672
+ } else {
6673
+ $url .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
6674
+ }
6675
+
6676
+ return esc_url( $url );
6677
+ }
6678
+
6679
+ /**
6680
+ * Check if the current page is the plugin's main admin settings page.
6681
+ *
6682
+ * @author Vova Feldman (@svovaf)
6683
+ * @since 1.0.7
6684
+ *
6685
+ * @return bool
6686
+ */
6687
+ function _is_plugin_page() {
6688
+ return fs_is_plugin_page( $this->_menu->get_raw_slug() ) ||
6689
+ fs_is_plugin_page( $this->_slug );
6690
+ }
6691
+
6692
+ /* Events
6693
+ ------------------------------------------------------------------------------------------------------------------*/
6694
+ /**
6695
+ * Delete site install from Database.
6696
+ *
6697
+ * @author Vova Feldman (@svovaf)
6698
+ * @since 1.0.1
6699
+ *
6700
+ * @param bool $store
6701
+ * @param int|null $blog_id Since 2.0.0
6702
+ *
6703
+ * @return false|int The install ID if deleted. Otherwise, FALSE (when install not exist).
6704
+ */
6705
+ function _delete_site( $store = true, $blog_id = null ) {
6706
+ return self::_delete_site_by_slug( $this->_slug, $this->_module_type, $store, $blog_id );
6707
+ }
6708
+
6709
+ /**
6710
+ * Delete site install from Database.
6711
+ *
6712
+ * @author Vova Feldman (@svovaf)
6713
+ * @since 1.2.2.7
6714
+ *
6715
+ * @param string $slug
6716
+ * @param string $module_type
6717
+ * @param bool $store
6718
+ * @param int|null $blog_id Since 2.0.0
6719
+ *
6720
+ * @return false|int The install ID if deleted. Otherwise, FALSE (when install not exist).
6721
+ */
6722
+ static function _delete_site_by_slug( $slug, $module_type, $store = true, $blog_id = null ) {
6723
+ $sites = self::get_all_sites( $module_type, $blog_id );
6724
+
6725
+ $install_id = false;
6726
+
6727
+ if ( isset( $sites[ $slug ] ) ) {
6728
+ if ( is_object( $sites[ $slug ] ) ) {
6729
+ $install_id = $sites[ $slug ]->id;
6730
+ }
6731
+
6732
+ unset( $sites[ $slug ] );
6733
+
6734
+ self::set_account_option_by_module( $module_type, 'sites', $sites, $store, $blog_id );
6735
+ }
6736
+
6737
+ return $install_id;
6738
+ }
6739
+
6740
+ /**
6741
+ * Delete user.
6742
+ *
6743
+ * @author Vova Feldman (@svovaf)
6744
+ * @since 2.0.0
6745
+ *
6746
+ * @param number $user_id
6747
+ * @param bool $store
6748
+ *
6749
+ * @return false|int The user ID if deleted. Otherwise, FALSE (when install not exist).
6750
+ */
6751
+ private static function delete_user( $user_id, $store = true ) {
6752
+ $users = self::get_all_users();
6753
+
6754
+ if ( ! is_array( $users ) || ! isset( $users[ $user_id ] ) ) {
6755
+ return false;
6756
+ }
6757
+
6758
+ unset( $users[ $user_id ] );
6759
+
6760
+ self::$_accounts->set_option( 'users', $users, $store );
6761
+
6762
+ return $user_id;
6763
+ }
6764
+
6765
+ /**
6766
+ * Delete plugin's plans information.
6767
+ *
6768
+ * @param bool $store Flush to Database if true.
6769
+ * @param bool $keep_associated_plans If set to false, delete all plans, even if a plan is associated with an install.
6770
+ *
6771
+ * @author Vova Feldman (@svovaf)
6772
+ * @since 1.0.9
6773
+ */
6774
+ private function _delete_plans( $store = true, $keep_associated_plans = true ) {
6775
+ $this->_logger->entrance();
6776
+
6777
+ $plans = self::get_all_plans( $this->_module_type );
6778
+
6779
+ $plans_to_keep = array();
6780
+
6781
+ if ( $keep_associated_plans ) {
6782
+ $plans_ids_to_keep = $this->get_plans_ids_associated_with_installs();
6783
+ foreach ( $plans_ids_to_keep as $plan_id ) {
6784
+ $plan = self::_get_plan_by_id( $plan_id );
6785
+ if ( is_object( $plan ) ) {
6786
+ $plans_to_keep[] = $plan;
6787
+ }
6788
+ }
6789
+ }
6790
+
6791
+ if ( ! empty( $plans_to_keep ) ) {
6792
+ $plans[ $this->_slug ] = $plans_to_keep;
6793
+ } else {
6794
+ unset( $plans[ $this->_slug ] );
6795
+ }
6796
+
6797
+ $this->set_account_option( 'plans', $plans, $store );
6798
+ }
6799
+
6800
+ /**
6801
+ * Delete all plugin licenses.
6802
+ *
6803
+ * @author Vova Feldman (@svovaf)
6804
+ * @since 1.0.9
6805
+ *
6806
+ * @param bool $store
6807
+ */
6808
+ private function _delete_licenses( $store = true ) {
6809
+ $this->_logger->entrance();
6810
+
6811
+ $all_licenses = self::get_all_licenses();
6812
+
6813
+ unset( $all_licenses[ $this->_module_id ] );
6814
+
6815
+ self::$_accounts->set_option( 'all_licenses', $all_licenses, $store );
6816
+ }
6817
+
6818
+ /**
6819
+ * Check if Freemius was added on new plugin installation.
6820
+ *
6821
+ * @author Vova Feldman (@svovaf)
6822
+ * @since 1.1.5
6823
+ *
6824
+ * @return bool
6825
+ */
6826
+ function is_plugin_new_install() {
6827
+ return isset( $this->_storage->is_plugin_new_install ) &&
6828
+ $this->_storage->is_plugin_new_install;
6829
+ }
6830
+
6831
+ /**
6832
+ * Check if it's the first plugin release that is running Freemius.
6833
+ *
6834
+ * @author Vova Feldman (@svovaf)
6835
+ * @since 1.2.1.5
6836
+ *
6837
+ * @return bool
6838
+ */
6839
+ function is_first_freemius_powered_version() {
6840
+ return empty( $this->_storage->plugin_last_version );
6841
+ }
6842
+
6843
+ /**
6844
+ * @author Leo Fajardo (@leorw)
6845
+ * @since 1.2.2
6846
+ *
6847
+ * @return bool|string
6848
+ */
6849
+ private function get_previous_theme_slug() {
6850
+ return isset( $this->_storage->previous_theme ) ?
6851
+ $this->_storage->previous_theme :
6852
+ false;
6853
+ }
6854
+
6855
+ /**
6856
+ * @author Leo Fajardo (@leorw)
6857
+ * @since 1.2.2
6858
+ *
6859
+ * @return string
6860
+ */
6861
+ private function can_activate_previous_theme() {
6862
+ $slug = $this->get_previous_theme_slug();
6863
+ if ( false !== $slug && current_user_can( 'switch_themes' ) ) {
6864
+ $theme_instance = wp_get_theme( $slug );
6865
+
6866
+ return $theme_instance->exists();
6867
+ }
6868
+
6869
+ return false;
6870
+ }
6871
+
6872
+ /**
6873
+ * @author Leo Fajardo (@leorw)
6874
+ * @since 1.2.2
6875
+ */
6876
+ private function activate_previous_theme() {
6877
+ switch_theme( $this->get_previous_theme_slug() );
6878
+ unset( $this->_storage->previous_theme );
6879
+
6880
+ global $pagenow;
6881
+ if ( 'themes.php' === $pagenow ) {
6882
+ /**
6883
+ * Refresh the active theme information.
6884
+ *
6885
+ * @author Leo Fajardo (@leorw)
6886
+ * @since 1.2.2
6887
+ */
6888
+ fs_redirect( $this->admin_url( $pagenow ) );
6889
+ }
6890
+ }
6891
+
6892
+ /**
6893
+ * @author Leo Fajardo (@leorw)
6894
+ * @since 1.2.2
6895
+ *
6896
+ * @return string
6897
+ */
6898
+ function get_previous_theme_activation_url() {
6899
+ if ( ! $this->can_activate_previous_theme() ) {
6900
+ return '';
6901
+ }
6902
+
6903
+ /**
6904
+ * Activation URL
6905
+ *
6906
+ * @author Leo Fajardo (@leorw)
6907
+ * @since 1.2.2
6908
+ */
6909
+ return wp_nonce_url(
6910
+ $this->admin_url( 'themes.php?action=activate&stylesheet=' . urlencode( $this->get_previous_theme_slug() ) ),
6911
+ 'switch-theme_' . $this->get_previous_theme_slug()
6912
+ );
6913
+ }
6914
+
6915
+ /**
6916
+ * Saves the slug of the previous theme if it still exists so that it can be used by the logic in the opt-in
6917
+ * form that decides whether to add a close button to the opt-in dialog or not. So after a premium-only theme is
6918
+ * activated, the close button will appear and will reactivate the previous theme if clicked. If the previous
6919
+ * theme doesn't exist, then there will be no close button.
6920
+ *
6921
+ * @author Leo Fajardo (@leorw)
6922
+ * @since 1.2.2
6923
+ *
6924
+ * @param string $slug_or_name Old theme's slug or name.
6925
+ * @param bool|WP_Theme $old_theme WP_Theme instance of the old theme if it still exists.
6926
+ */
6927
+ function _activate_theme_event_hook( $slug_or_name, $old_theme = false ) {
6928
+ $this->_storage->previous_theme = ( false !== $old_theme ) ?
6929
+ $old_theme->get_stylesheet() :
6930
+ $slug_or_name;
6931
+
6932
+ $this->_activate_plugin_event_hook();
6933
+ }
6934
+
6935
+ /**
6936
+ * Plugin activated hook.
6937
+ *
6938
+ * @author Vova Feldman (@svovaf)
6939
+ * @since 1.0.1
6940
+ *
6941
+ * @uses FS_Api
6942
+ */
6943
+ function _activate_plugin_event_hook() {
6944
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
6945
+
6946
+ if ( ! $this->is_user_admin() ) {
6947
+ return;
6948
+ }
6949
+
6950
+ $this->unregister_uninstall_hook();
6951
+
6952
+ // Clear API cache on activation.
6953
+ FS_Api::clear_cache();
6954
+
6955
+ $is_premium_version_activation = ( current_filter() !== ( 'activate_' . $this->_free_plugin_basename ) );
6956
+
6957
+ $this->_logger->info( 'Activating ' . ( $is_premium_version_activation ? 'premium' : 'free' ) . ' plugin version.' );
6958
+
6959
+ // 1. If running in the activation of the FREE module, get the basename of the PREMIUM.
6960
+ // 2. If running in the activation of the PREMIUM module, get the basename of the FREE.
6961
+ $other_version_basename = $is_premium_version_activation ?
6962
+ $this->_free_plugin_basename :
6963
+ $this->premium_plugin_basename();
6964
+
6965
+ if ( ! $this->_is_network_active ) {
6966
+ /**
6967
+ * During the activation, the plugin isn't yet active, therefore,
6968
+ * _is_network_active will be set to false even if it's a network level
6969
+ * activation. So we need to fix that by looking at the is_network_admin() value.
6970
+ *
6971
+ * @author Vova Feldman
6972
+ */
6973
+ $this->_is_network_active = (
6974
+ $this->_is_multisite_integrated &&
6975
+ // Themes are always network activated, but the ACTUAL activation is per site.
6976
+ $this->is_plugin() &&
6977
+ fs_is_network_admin()
6978
+ );
6979
+ }
6980
+
6981
+ /**
6982
+ * If the other module version is activate, deactivate it.
6983
+ *
6984
+ * is_plugin_active() checks if the plugin active on the site or the network level
6985
+ * and deactivate_plugins() deactivates the plugin whether its activated on the site
6986
+ * or network level.
6987
+ *
6988
+ * @author Leo Fajardo (@leorw)
6989
+ * @since 1.2.2
6990
+ */
6991
+ if ( is_plugin_active( $other_version_basename ) ) {
6992
+ deactivate_plugins( $other_version_basename );
6993
+ }
6994
+
6995
+ if ( $this->is_registered() ) {
6996
+ if ( $is_premium_version_activation ) {
6997
+ $this->reconnect_locally();
6998
+ }
6999
+
7000
+
7001
+ // Schedule re-activation event and sync.
7002
+ // $this->sync_install( array(), true );
7003
+ $this->schedule_install_sync();
7004
+
7005
+ // If activating the premium module version, add an admin notice to congratulate for an upgrade completion.
7006
+ if ( $is_premium_version_activation ) {
7007
+ $this->_admin_notices->add(
7008
+ sprintf( $this->get_text_inline( 'The upgrade of %s was successfully completed.', 'successful-version-upgrade-message' ), sprintf( '<b>%s</b>', $this->_plugin->title ) ),
7009
+ $this->get_text_x_inline( 'W00t',
7010
+ 'Used to express elation, enthusiasm, or triumph (especially in electronic communication).', 'woot' ) . '!'
7011
+ );
7012
+ }
7013
+ } else if ( $this->is_anonymous() ) {
7014
+ if ( isset( $this->_storage->is_anonymous_ms ) && $this->_storage->is_anonymous_ms['is'] ) {
7015
+ $plugin_version = $this->_storage->is_anonymous_ms['version'];
7016
+ $network = true;
7017
+ } else {
7018
+ $plugin_version = $this->_storage->is_anonymous['version'];
7019
+ $network = false;
7020
+ }
7021
+
7022
+ /**
7023
+ * Reset "skipped" click cache on the following:
7024
+ * 1. Freemius DEV mode.
7025
+ * 2. WordPress DEBUG mode.
7026
+ * 3. If a plugin and the user skipped the exact same version before.
7027
+ *
7028
+ * @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).
7029
+ *
7030
+ * @todo 4. If explicitly asked to retry after every activation.
7031
+ */
7032
+ if ( WP_FS__DEV_MODE ||
7033
+ (
7034
+ ( $this->is_plugin() || ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ) &&
7035
+ $this->get_plugin_version() == $plugin_version
7036
+ )
7037
+ ) {
7038
+ $this->reset_anonymous_mode( $network );
7039
+ }
7040
+ }
7041
+
7042
+ if (
7043
+ $is_premium_version_activation &&
7044
+ (
7045
+ ( ! $this->is_registered() && $this->is_anonymous() ) ||
7046
+ (
7047
+ $this->is_registered() &&
7048
+ ! $this->is_trial() &&
7049
+ ! $this->has_features_enabled_license()
7050
+ )
7051
+ )
7052
+ ) {
7053
+ $this->_storage->require_license_activation = true;
7054
+ }
7055
+
7056
+ if ( ! isset( $this->_storage->is_plugin_new_install ) ) {
7057
+ /**
7058
+ * If no previous version of plugin's version exist, it means that it's either
7059
+ * the first time that the plugin installed on the site, or the plugin was installed
7060
+ * before but didn't have Freemius integrated.
7061
+ *
7062
+ * Since register_activation_hook() do NOT fires on updates since 3.1, and only fires
7063
+ * on manual activation via the dashboard, is_plugin_activation() is TRUE
7064
+ * only after immediate activation.
7065
+ *
7066
+ * @since 1.1.4
7067
+ * @link https://make.wordpress.org/core/2010/10/27/plugin-activation-hooks-no-longer-fire-for-updates/
7068
+ */
7069
+ $this->_storage->is_plugin_new_install = empty( $this->_storage->plugin_last_version );
7070
+ }
7071
+
7072
+ if ( ! $this->_anonymous_mode &&
7073
+ $this->has_api_connectivity( WP_FS__DEV_MODE ) &&
7074
+ ! $this->_isAutoInstall
7075
+ ) {
7076
+ // Store hint that the plugin was just activated to enable auto-redirection to settings.
7077
+ set_transient( "fs_{$this->_module_type}_{$this->_slug}_activated", true, 60 );
7078
+ }
7079
+
7080
+ /**
7081
+ * Activation hook is executed after the plugin's main file is loaded, therefore,
7082
+ * after the plugin was loaded. The logic is located at activate_plugin()
7083
+ * ./wp-admin/includes/plugin.php.
7084
+ *
7085
+ * @author Vova Feldman (@svovaf)
7086
+ * @since 1.1.9
7087
+ */
7088
+ $this->_storage->was_plugin_loaded = true;
7089
+ }
7090
+
7091
+ /**
7092
+ * Delete account.
7093
+ *
7094
+ * @author Vova Feldman (@svovaf)
7095
+ * @since 1.0.3
7096
+ *
7097
+ * @param bool $check_user Enforce checking if user have plugins activation privileges.
7098
+ */
7099
+ function delete_account_event( $check_user = true ) {
7100
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
7101
+
7102
+ if ( $check_user && ! $this->is_user_admin() ) {
7103
+ return;
7104
+ }
7105
+
7106
+ $this->do_action( 'before_account_delete' );
7107
+
7108
+ // Clear all admin notices.
7109
+ $this->_admin_notices->clear_all_sticky( false );
7110
+
7111
+ $this->_delete_site( false );
7112
+
7113
+ $delete_network_common_data = true;
7114
+
7115
+ if ( $this->_is_network_active ) {
7116
+ $installs = $this->get_blog_install_map();
7117
+
7118
+ // Don't delete common network data unless no other installs left.
7119
+ $delete_network_common_data = empty( $installs );
7120
+ }
7121
+
7122
+ if ( $delete_network_common_data ) {
7123
+ $this->_delete_plans( false );
7124
+
7125
+ $this->_delete_licenses( false );
7126
+
7127
+ // Delete add-ons related to plugin's account.
7128
+ $this->_delete_account_addons( false );
7129
+ }
7130
+
7131
+ // @todo Delete plans and licenses of add-ons.
7132
+
7133
+ self::$_accounts->store();
7134
+
7135
+ /**
7136
+ * IMPORTANT:
7137
+ * Clear crons must be executed before clearing all storage.
7138
+ * Otherwise, the cron will not be cleared.
7139
+ */
7140
+ if ( $delete_network_common_data ) {
7141
+ $this->clear_sync_cron();
7142
+ }
7143
+
7144
+ $this->clear_install_sync_cron();
7145
+
7146
+ // Clear all storage data.
7147
+ $this->_storage->clear_all( true, array(
7148
+ 'connectivity_test',
7149
+ 'is_on',
7150
+ ), false );
7151
+
7152
+ // Send delete event.
7153
+ $this->get_api_site_scope()->call( '/', 'delete' );
7154
+
7155
+ $this->do_action( 'after_account_delete' );
7156
+ }
7157
+
7158
+ /**
7159
+ * Delete network level account.
7160
+ *
7161
+ * @author Vova Feldman (@svovaf)
7162
+ * @since 2.0.0
7163
+ *
7164
+ * @param bool $check_user Enforce checking if user have plugins activation privileges.
7165
+ */
7166
+ function delete_network_account_event( $check_user = true ) {
7167
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
7168
+
7169
+ if ( $check_user && ! $this->is_user_admin() ) {
7170
+ return;
7171
+ }
7172
+
7173
+ $this->do_action( 'before_network_account_delete' );
7174
+
7175
+ // Clear all admin notices.
7176
+ $this->_admin_notices->clear_all_sticky();
7177
+
7178
+ $this->_delete_plans( false, false );
7179
+
7180
+ $this->_delete_licenses( false );
7181
+
7182
+ // Delete add-ons related to plugin's account.
7183
+ $this->_delete_account_addons( false );
7184
+
7185
+ // @todo Delete plans and licenses of add-ons.
7186
+
7187
+ self::$_accounts->store( true );
7188
+
7189
+ /**
7190
+ * IMPORTANT:
7191
+ * Clear crons must be executed before clearing all storage.
7192
+ * Otherwise, the cron will not be cleared.
7193
+ */
7194
+ $this->clear_sync_cron( true );
7195
+ $this->clear_install_sync_cron( true );
7196
+
7197
+ $sites = self::get_sites();
7198
+
7199
+ $install_ids = array();
7200
+ foreach ( $sites as $site ) {
7201
+ $blog_id = self::get_site_blog_id( $site );
7202
+
7203
+ $install_id = $this->_delete_site( true, $blog_id );
7204
+
7205
+ // Clear all storage data.
7206
+ $this->_storage->clear_all( true, array( 'connectivity_test' ), $blog_id );
7207
+
7208
+ if ( FS_Site::is_valid_id( $install_id ) ) {
7209
+ $install_ids[] = $install_id;
7210
+ }
7211
+
7212
+ switch_to_blog( $blog_id );
7213
+
7214
+ $this->do_action( 'after_account_delete' );
7215
+
7216
+ restore_current_blog();
7217
+ }
7218
+
7219
+ $this->_storage->clear_all( true, array(
7220
+ 'connectivity_test',
7221
+ 'is_on',
7222
+ ), true );
7223
+
7224
+ // Send delete event.
7225
+ if ( ! empty( $install_ids ) ) {
7226
+ $result = $this->get_current_or_network_user_api_scope()->call( "/plugins/{$this->_module_id}/installs.json?ids=" . implode( ',', $install_ids ), 'delete' );
7227
+ }
7228
+
7229
+ $this->do_action( 'after_network_account_delete' );
7230
+ }
7231
+
7232
+ /**
7233
+ * Plugin deactivation hook.
7234
+ *
7235
+ * @author Vova Feldman (@svovaf)
7236
+ * @since 1.0.1
7237
+ */
7238
+ function _deactivate_plugin_hook() {
7239
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
7240
+
7241
+ if ( ! $this->is_user_admin() ) {
7242
+ return;
7243
+ }
7244
+
7245
+ $is_network_deactivation = fs_is_network_admin();
7246
+ $storage_keys_for_removal = array();
7247
+
7248
+ $this->_admin_notices->clear_all_sticky();
7249
+
7250
+ $storage_keys_for_removal[] = 'sticky_optin_added';
7251
+ if ( isset( $this->_storage->sticky_optin_added ) ) {
7252
+ unset( $this->_storage->sticky_optin_added );
7253
+ }
7254
+
7255
+ if ( ! isset( $this->_storage->is_plugin_new_install ) ) {
7256
+ // Remember that plugin was already installed.
7257
+ $this->_storage->is_plugin_new_install = false;
7258
+ }
7259
+
7260
+ // Hook to plugin uninstall.
7261
+ register_uninstall_hook( $this->_plugin_main_file_path, array( 'Freemius', '_uninstall_plugin_hook' ) );
7262
+
7263
+ $this->clear_module_main_file_cache();
7264
+ $this->clear_sync_cron( $this->_is_network_active );
7265
+ $this->clear_install_sync_cron();
7266
+
7267
+ if ( $this->is_registered() ) {
7268
+ if ( $this->is_premium() && ! $this->has_active_valid_license() ) {
7269
+ FS_Plugin_Updater::instance( $this )->delete_update_data();
7270
+ }
7271
+
7272
+ if ( $is_network_deactivation ) {
7273
+ // Send deactivation event.
7274
+ $this->sync_installs( array(
7275
+ 'is_active' => false,
7276
+ ) );
7277
+ } else {
7278
+ // Send deactivation event.
7279
+ $this->sync_install( array(
7280
+ 'is_active' => false,
7281
+ ) );
7282
+ }
7283
+ } else {
7284
+ if ( ! $this->has_api_connectivity() ) {
7285
+ // Reset connectivity test cache.
7286
+ unset( $this->_storage->connectivity_test );
7287
+
7288
+ $storage_keys_for_removal[] = 'connectivity_test';
7289
+ }
7290
+ }
7291
+
7292
+ if ( $is_network_deactivation ) {
7293
+ if ( isset( $this->_storage->sticky_optin_added_ms ) ) {
7294
+ unset( $this->_storage->sticky_optin_added_ms );
7295
+ }
7296
+
7297
+ if ( ! empty( $storage_keys_for_removal ) ) {
7298
+ $sites = self::get_sites();
7299
+
7300
+ foreach ( $sites as $site ) {
7301
+ $blog_id = self::get_site_blog_id( $site );
7302
+
7303
+ foreach ( $storage_keys_for_removal as $key ) {
7304
+ $this->_storage->remove( $key, false, $blog_id );
7305
+ }
7306
+
7307
+ $this->_storage->save( $blog_id );
7308
+ }
7309
+ }
7310
+ }
7311
+
7312
+ // Clear API cache on deactivation.
7313
+ FS_Api::clear_cache();
7314
+
7315
+ $this->remove_sdk_reference();
7316
+ }
7317
+
7318
+ /**
7319
+ * @author Vova Feldman (@svovaf)
7320
+ * @since 1.1.6
7321
+ */
7322
+ private function remove_sdk_reference() {
7323
+ global $fs_active_plugins;
7324
+
7325
+ foreach ( $fs_active_plugins->plugins as $sdk_path => $data ) {
7326
+ if ( $this->_plugin_basename == $data->plugin_path ) {
7327
+ unset( $fs_active_plugins->plugins[ $sdk_path ] );
7328
+ break;
7329
+ }
7330
+ }
7331
+
7332
+ fs_fallback_to_newest_active_sdk();
7333
+ }
7334
+
7335
+ /**
7336
+ * @author Vova Feldman (@svovaf)
7337
+ * @since 1.1.3
7338
+ *
7339
+ * @param bool $is_anonymous
7340
+ * @param bool|int $network_or_blog_id Since 2.0.0
7341
+ */
7342
+ private function set_anonymous_mode( $is_anonymous = true, $network_or_blog_id = 0 ) {
7343
+ // Store information regarding skip to try and opt-in the user
7344
+ // again in the future.
7345
+ $skip_info = array(
7346
+ 'is' => $is_anonymous,
7347
+ 'timestamp' => WP_FS__SCRIPT_START_TIME,
7348
+ 'version' => $this->get_plugin_version(),
7349
+ );
7350
+
7351
+ if ( true === $network_or_blog_id ) {
7352
+ $this->_storage->is_anonymous_ms = $skip_info;
7353
+ } else {
7354
+ $this->_storage->store( 'is_anonymous', $skip_info, $network_or_blog_id );
7355
+ }
7356
+
7357
+ $this->network_upgrade_mode_completed();
7358
+
7359
+ // Update anonymous mode cache.
7360
+ $this->_is_anonymous = $is_anonymous;
7361
+ }
7362
+
7363
+ /**
7364
+ * @author Vova Feldman (@svovaf)
7365
+ * @since 2.0.0
7366
+ *
7367
+ * @param int $blog_id Site ID.
7368
+ * @param int $user_id User ID.
7369
+ * @param string $domain Site domain.
7370
+ * @param string $path Site path.
7371
+ * @param int $network_id Network ID. Only relevant on multi-network installations.
7372
+ * @param array $meta Metadata. Used to set initial site options.
7373
+ *
7374
+ * @uses Freemius::is_license_network_active() to check if the context license was network activated by the super-admin.
7375
+ * @uses Freemius::is_network_connected() to check if the super-admin network opted-in.
7376
+ * @uses Freemius::is_network_anonymous() to check if the super-admin network skipped.
7377
+ * @uses Freemius::is_network_delegated_connection() to check if the super-admin network delegated the connection to the site admins.
7378
+ */
7379
+ function _after_new_blog_callback( $blog_id, $user_id, $domain, $path, $network_id, $meta ) {
7380
+ $this->_logger->entrance();
7381
+
7382
+ if ( $this->is_premium() &&
7383
+ $this->is_network_connected() &&
7384
+ is_object( $this->_license ) &&
7385
+ $this->_license->can_activate( FS_Site::is_localhost_by_address( $domain ) ) &&
7386
+ $this->is_license_network_active( $blog_id )
7387
+ ) {
7388
+ /**
7389
+ * 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.
7390
+ */
7391
+ $current_blog_id = get_current_blog_id();
7392
+ $license = clone $this->_license;
7393
+
7394
+ $this->switch_to_blog( $blog_id );
7395
+
7396
+ // Opt-in with network user.
7397
+ $this->install_with_user(
7398
+ $this->get_network_user(),
7399
+ $license->secret_key,
7400
+ false,
7401
+ false,
7402
+ false
7403
+ );
7404
+
7405
+ if ( is_object( $this->_site ) ) {
7406
+ if ( $this->_site->license_id == $license->id ) {
7407
+ /**
7408
+ * If the license was activated successfully, sync the license data from the remote server.
7409
+ */
7410
+ $this->_license = $license;
7411
+ $this->sync_site_license();
7412
+ }
7413
+ }
7414
+
7415
+ $this->switch_to_blog( $current_blog_id );
7416
+
7417
+ if ( is_object( $this->_site ) ) {
7418
+ // Already connected (with or without a license), so no need to continue.
7419
+ return;
7420
+ }
7421
+ }
7422
+
7423
+ if ( $this->is_network_anonymous() ) {
7424
+ /**
7425
+ * Opt-in was network skipped so automatically skip the opt-in for the new site.
7426
+ */
7427
+ $this->skip_site_connection( $blog_id );
7428
+ } else if ( $this->is_network_delegated_connection() ) {
7429
+ /**
7430
+ * Opt-in was network delegated so automatically delegate the opt-in for the new site's admin.
7431
+ */
7432
+ $this->delegate_site_connection( $blog_id );
7433
+ } else if ( $this->is_network_connected() ) {
7434
+ /**
7435
+ * Opt-in was network activated so automatically opt-in with the network user and new site admin.
7436
+ */
7437
+ $current_blog_id = get_current_blog_id();
7438
+
7439
+ $this->switch_to_blog( $blog_id );
7440
+
7441
+ // Opt-in with network user.
7442
+ $this->install_with_user(
7443
+ $this->get_network_user(),
7444
+ false,
7445
+ false,
7446
+ false,
7447
+ false
7448
+ );
7449
+
7450
+ $this->switch_to_blog( $current_blog_id );
7451
+ } else {
7452
+ /**
7453
+ * If the super-admin mixed different options (connect, skip, delegated):
7454
+ * a) If at least one site connection was delegated, then automatically delegate connection.
7455
+ * 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.
7456
+ */
7457
+ $has_delegated_site = false;
7458
+
7459
+ $sites = self::get_sites();
7460
+ foreach ( $sites as $site ) {
7461
+ $blog_id = self::get_site_blog_id( $site );
7462
+
7463
+ if ( $this->is_site_delegated_connection( $blog_id ) ) {
7464
+ $has_delegated_site = true;
7465
+ break;
7466
+ }
7467
+ }
7468
+
7469
+ if ( $has_delegated_site ) {
7470
+ $this->delegate_site_connection( $blog_id );
7471
+ } else {
7472
+ $this->skip_site_connection( $blog_id );
7473
+ }
7474
+ }
7475
+ }
7476
+
7477
+ /**
7478
+ * @author Vova Feldman (@svovaf)
7479
+ * @since 1.1.3
7480
+ *
7481
+ * @param bool|int $network_or_blog_id Since 2.0.0.
7482
+ */
7483
+ private function reset_anonymous_mode( $network_or_blog_id = 0 ) {
7484
+ if ( true === $network_or_blog_id ) {
7485
+ unset( $this->_storage->is_anonymous_ms );
7486
+ } else {
7487
+ $this->_storage->remove( 'is_anonymous', true, $network_or_blog_id );
7488
+ }
7489
+
7490
+ /**
7491
+ * Ensure that this field is also "false", otherwise, if the current module's type is "theme" and the module
7492
+ * has no menus, the opt-in popup will not be shown immediately (in this case, the user will have to click
7493
+ * on the admin notice that contains the opt-in link in order to trigger the opt-in popup).
7494
+ *
7495
+ * @author Leo Fajardo (@leorw)
7496
+ * @since 1.2.2
7497
+ */
7498
+ if ( ! $this->_is_network_active ||
7499
+ 0 === $network_or_blog_id ||
7500
+ get_current_blog_id() == $network_or_blog_id ||
7501
+ ( true === $network_or_blog_id && fs_is_network_admin() )
7502
+ ) {
7503
+ unset( $this->_is_anonymous );
7504
+ }
7505
+ }
7506
+
7507
+ /**
7508
+ * This is used to ensure that before redirecting to the opt-in page after resetting the anonymous mode or
7509
+ * deleting the account in the network level, the URL of the page to redirect to is correct.
7510
+ *
7511
+ * @author Leo Fajardo (@leorw)
7512
+ *
7513
+ * @since 2.1.3
7514
+ */
7515
+ private function maybe_set_slug_and_network_menu_exists_flag() {
7516
+ if ( ! empty( $this->_dynamically_added_top_level_page_hook_name ) ) {
7517
+ $this->_menu->set_slug_and_network_menu_exists_flag( $this->_menu->has_menu() ?
7518
+ $this->_menu->get_slug() :
7519
+ $this->_slug
7520
+ );
7521
+ }
7522
+ }
7523
+
7524
+ /**
7525
+ * Clears the anonymous mode and redirects to the opt-in screen.
7526
+ *
7527
+ * @author Vova Feldman (@svovaf)
7528
+ * @since 1.1.7
7529
+ */
7530
+ function connect_again() {
7531
+ if ( ! $this->is_anonymous() ) {
7532
+ return;
7533
+ }
7534
+
7535
+ $this->reset_anonymous_mode( fs_is_network_admin() );
7536
+
7537
+ $this->maybe_set_slug_and_network_menu_exists_flag();
7538
+
7539
+ fs_redirect( $this->get_activation_url() );
7540
+ }
7541
+
7542
+ /**
7543
+ * Skip account connect, and set anonymous mode.
7544
+ *
7545
+ * @author Vova Feldman (@svovaf)
7546
+ * @since 1.1.1
7547
+ *
7548
+ * @param array|null $sites Since 2.0.0. Specific sites.
7549
+ * @param bool $skip_all_network Since 2.0.0. If true, skip connection for all sites.
7550
+ */
7551
+ function skip_connection( $sites = null, $skip_all_network = false ) {
7552
+ $this->_logger->entrance();
7553
+
7554
+ $this->_admin_notices->remove_sticky( 'connect_account' );
7555
+
7556
+ if ( $skip_all_network ) {
7557
+ $this->set_anonymous_mode( true, true );
7558
+ }
7559
+
7560
+ if ( ! $skip_all_network && empty( $sites ) ) {
7561
+ $this->skip_site_connection();
7562
+ } else {
7563
+ $uids = array();
7564
+
7565
+ if ( $skip_all_network ) {
7566
+ $this->set_anonymous_mode( true, true );
7567
+
7568
+ $sites = self::get_sites();
7569
+ foreach ( $sites as $site ) {
7570
+ $blog_id = self::get_site_blog_id( $site );
7571
+ $this->skip_site_connection( $blog_id, false );
7572
+ $uids[] = $this->get_anonymous_id( $blog_id );
7573
+ }
7574
+ } else if ( ! empty( $sites ) ) {
7575
+ foreach ( $sites as $site ) {
7576
+ $uids[] = $site['uid'];
7577
+ $this->skip_site_connection( $site['blog_id'], false );
7578
+ }
7579
+ }
7580
+
7581
+ // Send anonymous skip event.
7582
+ // No user identified info nor any tracking will be sent after the user skips the opt-in.
7583
+ $this->get_api_plugin_scope()->call( 'skip.json', 'put', array(
7584
+ 'uids' => $uids,
7585
+ ) );
7586
+ }
7587
+
7588
+ $this->network_upgrade_mode_completed();
7589
+ }
7590
+
7591
+ /**
7592
+ * Skip connection for specific site in the network.
7593
+ *
7594
+ * @author Vova Feldman (@svovaf)
7595
+ * @since 2.0.0
7596
+ *
7597
+ * @param int|null $blog_id
7598
+ * @param bool $send_skip
7599
+ */
7600
+ private function skip_site_connection( $blog_id = null, $send_skip = true ) {
7601
+ $this->_logger->entrance();
7602
+
7603
+ $this->_admin_notices->remove_sticky( 'connect_account', $blog_id );
7604
+
7605
+ $this->set_anonymous_mode( true, $blog_id );
7606
+
7607
+ if ( $send_skip ) {
7608
+ $this->get_api_plugin_scope()->call( 'skip.json', 'put', array(
7609
+ 'uids' => array( $this->get_anonymous_id( $blog_id ) ),
7610
+ ) );
7611
+ }
7612
+ }
7613
+
7614
+ /**
7615
+ * Plugin version update hook.
7616
+ *
7617
+ * @author Vova Feldman (@svovaf)
7618
+ * @since 1.0.4
7619
+ */
7620
+ private function update_plugin_version_event() {
7621
+ $this->_logger->entrance();
7622
+
7623
+ if ( ! $this->is_registered() ) {
7624
+ return;
7625
+ }
7626
+
7627
+ $this->schedule_install_sync();
7628
+ // $this->sync_install( array(), true );
7629
+ }
7630
+
7631
+ /**
7632
+ * Generate an MD5 signature of a plugins collection.
7633
+ * This helper methods used to identify changes in a plugins collection.
7634
+ *
7635
+ * @author Vova Feldman (@svovaf)
7636
+ * @since 2.0.0
7637
+ *
7638
+ * @param array [string]array $plugins
7639
+ *
7640
+ * @return string
7641
+ */
7642
+ private function get_plugins_thumbprint( $plugins ) {
7643
+ ksort( $plugins );
7644
+
7645
+ $thumbprint = '';
7646
+ foreach ( $plugins as $basename => $data ) {
7647
+ $thumbprint .= $data['slug'] . ',' .
7648
+ $data['Version'] . ',' .
7649
+ ( $data['is_active'] ? '1' : '0' ) . ';';
7650
+ }
7651
+
7652
+ return md5( $thumbprint );
7653
+ }
7654
+
7655
+ /**
7656
+ * Return a list of modified plugins since the last sync.
7657
+ *
7658
+ * Note:
7659
+ * There's no point to store a plugins counter since even if the number of
7660
+ * plugins didn't change, we still need to check if the versions are all the
7661
+ * same and the activity state is similar.
7662
+ *
7663
+ * @author Vova Feldman (@svovaf)
7664
+ * @since 1.1.8
7665
+ *
7666
+ * @return array|false
7667
+ */
7668
+ private function get_plugins_data_for_api() {
7669
+ // Alias.
7670
+ $site_active_plugins_option_name = 'active_plugins';
7671
+ $network_plugins_option_name = 'all_plugins';
7672
+
7673
+ /**
7674
+ * Collection of all site level active plugins.
7675
+ */
7676
+ $site_active_plugins_cache = self::$_accounts->get_option( $site_active_plugins_option_name );
7677
+
7678
+ if ( ! is_object( $site_active_plugins_cache ) ) {
7679
+ $site_active_plugins_cache = (object) array(
7680
+ 'timestamp' => '',
7681
+ 'md5' => '',
7682
+ 'plugins' => array(),
7683
+ );
7684
+ }
7685
+
7686
+ $time = time();
7687
+
7688
+ if ( ! empty( $site_active_plugins_cache->timestamp ) &&
7689
+ ( $time - $site_active_plugins_cache->timestamp ) < WP_FS__TIME_5_MIN_IN_SEC
7690
+ ) {
7691
+ // Don't send plugin updates if last update was in the past 5 min.
7692
+ return false;
7693
+ }
7694
+
7695
+ // Write timestamp to lock the logic.
7696
+ $site_active_plugins_cache->timestamp = $time;
7697
+ self::$_accounts->set_option( $site_active_plugins_option_name, $site_active_plugins_cache, true );
7698
+
7699
+ // Reload options from DB.
7700
+ self::$_accounts->load( true );
7701
+ $site_active_plugins_cache = self::$_accounts->get_option( $site_active_plugins_option_name );
7702
+
7703
+ if ( $time != $site_active_plugins_cache->timestamp ) {
7704
+ // If timestamp is different, then another thread captured the lock.
7705
+ return false;
7706
+ }
7707
+
7708
+ /**
7709
+ * Collection of all plugins (network level).
7710
+ */
7711
+ $network_plugins_cache = self::$_accounts->get_option( $network_plugins_option_name );
7712
+
7713
+ if ( ! is_object( $network_plugins_cache ) ) {
7714
+ $network_plugins_cache = (object) array(
7715
+ 'timestamp' => '',
7716
+ 'md5' => '',
7717
+ 'plugins' => array(),
7718
+ );
7719
+ }
7720
+
7721
+ // Check if there's a change in plugins.
7722
+ $network_plugins = self::get_network_plugins();
7723
+ $site_active_plugins = self::get_site_active_plugins();
7724
+
7725
+ $network_plugins_thumbprint = $this->get_plugins_thumbprint( $network_plugins );
7726
+ $site_active_plugins_thumbprint = $this->get_plugins_thumbprint( $site_active_plugins );
7727
+
7728
+ // Check if plugins status changed (version or active/inactive).
7729
+ $network_plugins_changed = ( $network_plugins_cache->md5 !== $network_plugins_thumbprint );
7730
+ $site_active_plugins_changed = ( $site_active_plugins_cache->md5 !== $site_active_plugins_thumbprint );
7731
+
7732
+ if ( ! $network_plugins_changed &&
7733
+ ! $site_active_plugins_changed
7734
+ ) {
7735
+ // No changes.
7736
+ return array();
7737
+ }
7738
+
7739
+ $plugins_update_data = array();
7740
+
7741
+ foreach ( $network_plugins_cache->plugins as $basename => $data ) {
7742
+ if ( ! isset( $network_plugins[ $basename ] ) ) {
7743
+ // Plugin uninstalled.
7744
+ $uninstalled_plugin_data = $data;
7745
+ $uninstalled_plugin_data['is_active'] = false;
7746
+ $uninstalled_plugin_data['is_uninstalled'] = true;
7747
+ $plugins_update_data[] = $uninstalled_plugin_data;
7748
+
7749
+ unset( $network_plugins[ $basename ] );
7750
+
7751
+ unset( $network_plugins_cache->plugins[ $basename ] );
7752
+ unset( $site_active_plugins_cache->plugins[ $basename ] );
7753
+
7754
+ continue;
7755
+ }
7756
+
7757
+ $was_active = $data['is_active'] ||
7758
+ ( isset( $site_active_plugins_cache->plugins[ $basename ] ) &&
7759
+ true === $site_active_plugins_cache->plugins[ $basename ]['is_active'] );
7760
+ $is_active = $network_plugins[ $basename ]['is_active'] ||
7761
+ ( isset( $site_active_plugins[ $basename ] ) &&
7762
+ $site_active_plugins[ $basename ]['is_active'] );
7763
+
7764
+ if ( ! isset( $site_active_plugins_cache->plugins[ $basename ] ) &&
7765
+ isset( $site_active_plugins[ $basename ] )
7766
+ ) {
7767
+ // Plugin was site level activated.
7768
+ $site_active_plugins_cache->plugins[ $basename ] = $network_plugins[ $basename ];
7769
+ $site_active_plugins_cache->plugins[ $basename ]['is_active'] = true;
7770
+ } else if ( isset( $site_active_plugins_cache->plugins[ $basename ] ) &&
7771
+ ! isset( $site_active_plugins[ $basename ] )
7772
+ ) {
7773
+ // Plugin was site level deactivated.
7774
+ unset( $site_active_plugins_cache->plugins[ $basename ] );
7775
+ }
7776
+
7777
+ $prev_version = $data['version'];
7778
+ $current_version = $network_plugins[ $basename ]['Version'];
7779
+
7780
+ if ( $was_active !== $is_active || $prev_version !== $current_version ) {
7781
+ // Plugin activated or deactivated, or version changed.
7782
+
7783
+ if ( $was_active !== $is_active ) {
7784
+ if ( $data['is_active'] != $network_plugins[ $basename ]['is_active'] ) {
7785
+ $network_plugins_cache->plugins[ $basename ]['is_active'] = $data['is_active'];
7786
+ }
7787
+ }
7788
+
7789
+ if ( $prev_version !== $current_version ) {
7790
+ $network_plugins_cache->plugins[ $basename ]['Version'] = $current_version;
7791
+ }
7792
+
7793
+ $updated_plugin_data = $data;
7794
+ $updated_plugin_data['is_active'] = $is_active;
7795
+ $updated_plugin_data['version'] = $current_version;
7796
+ $updated_plugin_data['title'] = $network_plugins[ $basename ]['Name'];
7797
+ $plugins_update_data[] = $updated_plugin_data;
7798
+ }
7799
+ }
7800
+
7801
+ // Find new plugins that weren't yet seen before.
7802
+ foreach ( $network_plugins as $basename => $data ) {
7803
+ if ( ! isset( $network_plugins_cache->plugins[ $basename ] ) ) {
7804
+ // New plugin.
7805
+ $new_plugin = array(
7806
+ 'slug' => $data['slug'],
7807
+ 'version' => $data['Version'],
7808
+ 'title' => $data['Name'],
7809
+ 'is_active' => $data['is_active'],
7810
+ 'is_uninstalled' => false,
7811
+ );
7812
+
7813
+ $plugins_update_data[] = $new_plugin;
7814
+ $network_plugins_cache->plugins[ $basename ] = $new_plugin;
7815
+
7816
+ if ( isset( $site_active_plugins[ $basename ] ) ) {
7817
+ $site_active_plugins_cache->plugins[ $basename ] = $new_plugin;
7818
+ $site_active_plugins_cache->plugins[ $basename ]['is_active'] = true;
7819
+ }
7820
+ }
7821
+ }
7822
+
7823
+ $site_active_plugins_cache->md5 = $site_active_plugins_thumbprint;
7824
+ $site_active_plugins_cache->timestamp = $time;
7825
+ self::$_accounts->set_option( $site_active_plugins_option_name, $site_active_plugins_cache, true );
7826
+
7827
+ $network_plugins_cache->md5 = $network_plugins_thumbprint;
7828
+ $network_plugins_cache->timestamp = $time;
7829
+ self::$_accounts->set_option( $network_plugins_option_name, $network_plugins_cache, true );
7830
+
7831
+ return $plugins_update_data;
7832
+ }
7833
+
7834
+ /**
7835
+ * Return a list of modified themes since the last sync.
7836
+ *
7837
+ * Note:
7838
+ * There's no point to store a themes counter since even if the number of
7839
+ * themes didn't change, we still need to check if the versions are all the
7840
+ * same and the activity state is similar.
7841
+ *
7842
+ * @author Vova Feldman (@svovaf)
7843
+ * @since 1.1.8
7844
+ *
7845
+ * @return array|false
7846
+ */
7847
+ private function get_themes_data_for_api() {
7848
+ // Alias.
7849
+ $option_name = 'all_themes';
7850
+
7851
+ $all_cached_themes = self::$_accounts->get_option( $option_name );
7852
+
7853
+ if ( ! is_object( $all_cached_themes ) ) {
7854
+ $all_cached_themes = (object) array(
7855
+ 'timestamp' => '',
7856
+ 'md5' => '',
7857
+ 'themes' => array(),
7858
+ );
7859
+ }
7860
+
7861
+ $time = time();
7862
+
7863
+ if ( ! empty( $all_cached_themes->timestamp ) &&
7864
+ ( $time - $all_cached_themes->timestamp ) < WP_FS__TIME_5_MIN_IN_SEC
7865
+ ) {
7866
+ // Don't send theme updates if last update was in the past 5 min.
7867
+ return false;
7868
+ }
7869
+
7870
+ // Write timestamp to lock the logic.
7871
+ $all_cached_themes->timestamp = $time;
7872
+ self::$_accounts->set_option( $option_name, $all_cached_themes, true );
7873
+
7874
+ // Reload options from DB.
7875
+ self::$_accounts->load( true );
7876
+ $all_cached_themes = self::$_accounts->get_option( $option_name );
7877
+
7878
+ if ( $time != $all_cached_themes->timestamp ) {
7879
+ // If timestamp is different, then another thread captured the lock.
7880
+ return false;
7881
+ }
7882
+
7883
+ // Get active theme.
7884
+ $active_theme = wp_get_theme();
7885
+ $active_theme_stylesheet = $active_theme->get_stylesheet();
7886
+
7887
+ // Check if there's a change in themes.
7888
+ $all_themes = wp_get_themes();
7889
+
7890
+ // Check if themes changed.
7891
+ ksort( $all_themes );
7892
+
7893
+ $themes_signature = '';
7894
+ foreach ( $all_themes as $slug => $data ) {
7895
+ $is_active = ( $slug === $active_theme_stylesheet );
7896
+ $themes_signature .= $slug . ',' .
7897
+ $data->version . ',' .
7898
+ ( $is_active ? '1' : '0' ) . ';';
7899
+ }
7900
+
7901
+ // Check if themes status changed (version or active/inactive).
7902
+ $themes_changed = ( $all_cached_themes->md5 !== md5( $themes_signature ) );
7903
+
7904
+ $themes_update_data = array();
7905
+
7906
+ if ( $themes_changed ) {
7907
+ // Change in themes, report changes.
7908
+
7909
+ // Update existing themes info.
7910
+ foreach ( $all_cached_themes->themes as $slug => $data ) {
7911
+ $is_active = ( $slug === $active_theme_stylesheet );
7912
+
7913
+ if ( ! isset( $all_themes[ $slug ] ) ) {
7914
+ // Plugin uninstalled.
7915
+ $uninstalled_theme_data = $data;
7916
+ $uninstalled_theme_data['is_active'] = false;
7917
+ $uninstalled_theme_data['is_uninstalled'] = true;
7918
+ $themes_update_data[] = $uninstalled_theme_data;
7919
+
7920
+ unset( $all_themes[ $slug ] );
7921
+ unset( $all_cached_themes->themes[ $slug ] );
7922
+ } else if ( $data['is_active'] !== $is_active ||
7923
+ $data['version'] !== $all_themes[ $slug ]->version
7924
+ ) {
7925
+ // Plugin activated or deactivated, or version changed.
7926
+
7927
+ $all_cached_themes->themes[ $slug ]['is_active'] = $is_active;
7928
+ $all_cached_themes->themes[ $slug ]['version'] = $all_themes[ $slug ]->version;
7929
+
7930
+ $themes_update_data[] = $all_cached_themes->themes[ $slug ];
7931
+ }
7932
+ }
7933
+
7934
+ // Find new themes that weren't yet seen before.
7935
+ foreach ( $all_themes as $slug => $data ) {
7936
+ if ( ! isset( $all_cached_themes->themes[ $slug ] ) ) {
7937
+ $is_active = ( $slug === $active_theme_stylesheet );
7938
+
7939
+ // New plugin.
7940
+ $new_plugin = array(
7941
+ 'slug' => $slug,
7942
+ 'version' => $data->version,
7943
+ 'title' => $data->name,
7944
+ 'is_active' => $is_active,
7945
+ 'is_uninstalled' => false,
7946
+ );
7947
+
7948
+ $themes_update_data[] = $new_plugin;
7949
+ $all_cached_themes->themes[ $slug ] = $new_plugin;
7950
+ }
7951
+ }
7952
+
7953
+ $all_cached_themes->md5 = md5( $themes_signature );
7954
+ $all_cached_themes->timestamp = time();
7955
+ self::$_accounts->set_option( $option_name, $all_cached_themes, true );
7956
+ }
7957
+
7958
+ return $themes_update_data;
7959
+ }
7960
+
7961
+ /**
7962
+ * Get site data for API install request.
7963
+ *
7964
+ * @author Vova Feldman (@svovaf)
7965
+ * @since 1.1.2
7966
+ *
7967
+ * @param string[] string $override
7968
+ * @param bool $include_plugins Since 1.1.8 by default include plugin changes.
7969
+ * @param bool $include_themes Since 1.1.8 by default include plugin changes.
7970
+ *
7971
+ * @return array
7972
+ */
7973
+ private function get_install_data_for_api(
7974
+ array $override,
7975
+ $include_plugins = true,
7976
+ $include_themes = true
7977
+ ) {
7978
+ if ( ! defined( 'WP_FS__TRACK_PLUGINS' ) || false !== WP_FS__TRACK_PLUGINS ) {
7979
+ /**
7980
+ * @since 1.1.8 Also send plugin updates.
7981
+ */
7982
+ if ( $include_plugins && ! isset( $override['plugins'] ) ) {
7983
+ $plugins = $this->get_plugins_data_for_api();
7984
+ if ( ! empty( $plugins ) ) {
7985
+ $override['plugins'] = $plugins;
7986
+ }
7987
+ }
7988
+ }
7989
+
7990
+ if ( ! defined( 'WP_FS__TRACK_THEMES' ) || false !== WP_FS__TRACK_THEMES ) {
7991
+ /**
7992
+ * @since 1.1.8 Also send themes updates.
7993
+ */
7994
+ if ( $include_themes && ! isset( $override['themes'] ) ) {
7995
+ $themes = $this->get_themes_data_for_api();
7996
+ if ( ! empty( $themes ) ) {
7997
+ $override['themes'] = $themes;
7998
+ }
7999
+ }
8000
+ }
8001
+
8002
+ $versions = $this->get_versions();
8003
+
8004
+ return array_merge( $versions, array(
8005
+ 'version' => $this->get_plugin_version(),
8006
+ 'is_premium' => $this->is_premium(),
8007
+ 'language' => get_bloginfo( 'language' ),
8008
+ 'charset' => get_bloginfo( 'charset' ),
8009
+ 'title' => get_bloginfo( 'name' ),
8010
+ 'url' => get_site_url(),
8011
+ // Special params.
8012
+ 'is_active' => true,
8013
+ 'is_disconnected' => $this->is_tracking_prohibited(),
8014
+ 'is_uninstalled' => false,
8015
+ ), $override );
8016
+ }
8017
+
8018
+ /**
8019
+ * Update installs details.
8020
+ *
8021
+ * @todo V1 of multiste network support doesn't support plugin and theme data sending.
8022
+ *
8023
+ * @author Vova Feldman (@svovaf)
8024
+ * @since 2.0.0
8025
+ *
8026
+ * @param string[] string $override
8027
+ * @param bool $only_diff
8028
+ * @param bool $include_plugins Since 1.1.8 by default include plugin changes.
8029
+ * @param bool $include_themes Since 1.1.8 by default include plugin changes.
8030
+ *
8031
+ * @return array
8032
+ */
8033
+ private function get_installs_data_for_api(
8034
+ array $override,
8035
+ $only_diff = false,
8036
+ $include_plugins = true,
8037
+ $include_themes = true
8038
+ ) {
8039
+ /**
8040
+ * @since 1.1.8 Also send plugin updates.
8041
+ */
8042
+ // if ( $include_plugins && ! isset( $override['plugins'] ) ) {
8043
+ // $plugins = $this->get_plugins_data_for_api();
8044
+ // if ( ! empty( $plugins ) ) {
8045
+ // $override['plugins'] = $plugins;
8046
+ // }
8047
+ // }
8048
+ /**
8049
+ * @since 1.1.8 Also send themes updates.
8050
+ */
8051
+ // if ( $include_themes && ! isset( $override['themes'] ) ) {
8052
+ // $themes = $this->get_themes_data_for_api();
8053
+ // if ( ! empty( $themes ) ) {
8054
+ // $override['themes'] = $themes;
8055
+ // }
8056
+ // }
8057
+
8058
+ // Common properties.
8059
+ $versions = $this->get_versions();
8060
+ $common = array_merge( $versions, array(
8061
+ 'version' => $this->get_plugin_version(),
8062
+ 'is_premium' => $this->is_premium(),
8063
+ ), $override );
8064
+
8065
+
8066
+ $is_common_diff_for_any_site = false;
8067
+ $common_diff_union = array();
8068
+
8069
+ $installs_data = array();
8070
+
8071
+ $sites = self::get_sites();
8072
+
8073
+ foreach ( $sites as $site ) {
8074
+ $blog_id = self::get_site_blog_id( $site );
8075
+
8076
+ $install = $this->get_install_by_blog_id( $blog_id );
8077
+
8078
+ if ( is_object( $install ) ) {
8079
+ if ( $install->user_id != $this->_user->id ) {
8080
+ // Install belongs to a different owner.
8081
+ continue;
8082
+ }
8083
+
8084
+ if ( ! $this->is_premium() && $install->is_tracking_prohibited() ) {
8085
+ // Don't send updates regarding opted-out installs.
8086
+ continue;
8087
+ }
8088
+
8089
+ $install_data = $this->get_site_info( $site );
8090
+
8091
+ $uid = $install_data['uid'];
8092
+
8093
+ unset( $install_data['blog_id'] );
8094
+ unset( $install_data['uid'] );
8095
+
8096
+ $install_data['is_disconnected'] = $install->is_disconnected;
8097
+ $install_data['is_active'] = $this->is_active_for_site( $blog_id );
8098
+ $install_data['is_uninstalled'] = $install->is_uninstalled;
8099
+
8100
+ $common_diff = null;
8101
+ $is_common_diff = false;
8102
+ if ( $only_diff ) {
8103
+ $install_data = $this->get_install_diff_for_api( $install_data, $install, $override );
8104
+ $common_diff = $this->get_install_diff_for_api( $common, $install, $override );
8105
+
8106
+ $is_common_diff = ! empty( $common_diff );
8107
+
8108
+ if ( $is_common_diff ) {
8109
+ foreach ( $common_diff as $k => $v ) {
8110
+ if ( ! isset( $common_diff_union[ $k ] ) ) {
8111
+ $common_diff_union[ $k ] = $v;
8112
+ }
8113
+ }
8114
+ }
8115
+
8116
+ $is_common_diff_for_any_site = $is_common_diff_for_any_site || $is_common_diff;
8117
+ }
8118
+
8119
+ if ( ! empty( $install_data ) || $is_common_diff ) {
8120
+ // Add install ID and site unique ID.
8121
+ $install_data['id'] = $install->id;
8122
+ $install_data['uid'] = $uid;
8123
+
8124
+ $installs_data[] = $install_data;
8125
+ }
8126
+ }
8127
+ }
8128
+
8129
+ restore_current_blog();
8130
+
8131
+ if ( 0 < count( $installs_data ) && ( $is_common_diff_for_any_site || ! $only_diff ) ) {
8132
+ if ( ! $only_diff ) {
8133
+ $installs_data[] = $common;
8134
+ } else if ( ! empty( $common_diff_union ) ) {
8135
+ $installs_data[] = $common_diff_union;
8136
+ }
8137
+ }
8138
+
8139
+ foreach ( $installs_data as &$data ) {
8140
+ $data = (object) $data;
8141
+ }
8142
+
8143
+ return $installs_data;
8144
+ }
8145
+
8146
+ /**
8147
+ * Compare site actual data to the stored install data and return the differences for an API data sync.
8148
+ *
8149
+ * @author Vova Feldman (@svovaf)
8150
+ * @since 2.0.0
8151
+ *
8152
+ * @param array $site
8153
+ * @param FS_Site $install
8154
+ * @param string[] string $override
8155
+ *
8156
+ * @return array
8157
+ */
8158
+ private function get_install_diff_for_api( $site, $install, $override = array() ) {
8159
+ $diff = array();
8160
+ $special = array();
8161
+ $special_override = false;
8162
+
8163
+ foreach ( $site as $p => $v ) {
8164
+ if ( property_exists( $install, $p ) ) {
8165
+ if ( ( is_bool( $install->{$p} ) || ! empty( $install->{$p} ) ) &&
8166
+ $install->{$p} != $v
8167
+ ) {
8168
+ $install->{$p} = $v;
8169
+ $diff[ $p ] = $v;
8170
+ }
8171
+ } else {
8172
+ $special[ $p ] = $v;
8173
+
8174
+ if ( isset( $override[ $p ] ) ||
8175
+ 'plugins' === $p ||
8176
+ 'themes' === $p
8177
+ ) {
8178
+ $special_override = true;
8179
+ }
8180
+ }
8181
+ }
8182
+
8183
+ if ( $special_override || 0 < count( $diff ) ) {
8184
+ // Add special params only if has at least one
8185
+ // standard param, or if explicitly requested to
8186
+ // override a special param or a param which is not exist
8187
+ // in the install object.
8188
+ $diff = array_merge( $diff, $special );
8189
+ }
8190
+
8191
+ return $diff;
8192
+ }
8193
+
8194
+ /**
8195
+ * Update install only if changed.
8196
+ *
8197
+ * @author Vova Feldman (@svovaf)
8198
+ * @since 1.0.9
8199
+ *
8200
+ * @param string[] string $override
8201
+ * @param bool $flush
8202
+ *
8203
+ * @return false|object|string
8204
+ */
8205
+ private function send_install_update( $override = array(), $flush = false ) {
8206
+ $this->_logger->entrance();
8207
+
8208
+ $check_properties = $this->get_install_data_for_api( $override );
8209
+
8210
+ if ( $flush ) {
8211
+ $params = $check_properties;
8212
+ } else {
8213
+ $params = $this->get_install_diff_for_api( $check_properties, $this->_site, $override );
8214
+ }
8215
+
8216
+ $keepalive_only_update = false;
8217
+ if ( empty( $params ) ) {
8218
+ $keepalive_only_update = $this->should_send_keepalive_update();
8219
+
8220
+ if ( ! $keepalive_only_update ) {
8221
+ /**
8222
+ * There are no updates to send including keepalive.
8223
+ *
8224
+ * @author Leo Fajardo (@leorw)
8225
+ * @since 2.2.3
8226
+ */
8227
+ return false;
8228
+ }
8229
+ }
8230
+
8231
+ if ( ! $keepalive_only_update ) {
8232
+ /**
8233
+ * Do not update the last install sync timestamp after a keepalive-only call since there were no actual
8234
+ * updates sent.
8235
+ *
8236
+ * @author Leo Fajardo (@leorw)
8237
+ * @since 2.2.3
8238
+ */
8239
+ if ( ! is_multisite() ) {
8240
+ // Update last install sync timestamp.
8241
+ $this->set_cron_execution_timestamp( 'install_sync' );
8242
+ }
8243
+
8244
+ $params['uid'] = $this->get_anonymous_id();
8245
+ }
8246
+
8247
+ $this->set_keepalive_timestamp();
8248
+
8249
+ // Send updated values to FS.
8250
+ $site = $this->get_api_site_scope()->call( '/', 'put', $params );
8251
+
8252
+ if ( ! $keepalive_only_update && $this->is_api_result_entity( $site ) ) {
8253
+ /**
8254
+ * Do not clear scheduled sync after a keepalive-only call since there were no actual updates sent.
8255
+ *
8256
+ * @author Leo Fajardo (@leorw)
8257
+ * @since 2.2.3
8258
+ */
8259
+ if ( ! is_multisite() ) {
8260
+ // I successfully sent install update, clear scheduled sync if exist.
8261
+ $this->clear_install_sync_cron();
8262
+ }
8263
+ }
8264
+
8265
+ return $site;
8266
+ }
8267
+
8268
+ /**
8269
+ * Update installs only if changed.
8270
+ *
8271
+ * @author Vova Feldman (@svovaf)
8272
+ * @since 2.0.0
8273
+ *
8274
+ * @param string[] string $override
8275
+ * @param bool $flush
8276
+ *
8277
+ * @return false|object|string
8278
+ */
8279
+ private function send_installs_update( $override = array(), $flush = false ) {
8280
+ $this->_logger->entrance();
8281
+
8282
+ $installs_data = $this->get_installs_data_for_api( $override, ! $flush );
8283
+
8284
+ $keepalive_only_update = false;
8285
+ if ( empty( $installs_data ) ) {
8286
+ /**
8287
+ * Pass `true` to use the network level storage since the update is for many installs.
8288
+ *
8289
+ * @author Leo Fajardo (@leorw)
8290
+ * @since 2.2.3
8291
+ */
8292
+ $keepalive_only_update = $this->should_send_keepalive_update( true );
8293
+
8294
+ if ( ! $keepalive_only_update ) {
8295
+ /**
8296
+ * There are no updates to send including keepalive.
8297
+ *
8298
+ * @author Leo Fajardo (@leorw)
8299
+ * @since 2.2.3
8300
+ */
8301
+ return false;
8302
+ }
8303
+ }
8304
+
8305
+ if ( ! $keepalive_only_update ) {
8306
+ // Update last install sync timestamp if there were actual updates sent (i.e., not a keepalive-only call).
8307
+ $this->set_cron_execution_timestamp( 'install_sync' );
8308
+ }
8309
+
8310
+ /**
8311
+ * Pass `true` to use the network level storage since the update is for many installs.
8312
+ *
8313
+ * @author Leo Fajardo (@leorw)
8314
+ * @since 2.2.3
8315
+ */
8316
+ $this->set_keepalive_timestamp( true );
8317
+
8318
+ // Send updated values to FS.
8319
+ $result = $this->get_api_user_scope()->call( "/plugins/{$this->_plugin->id}/installs.json", 'put', $installs_data );
8320
+
8321
+ if ( ! $keepalive_only_update && $this->is_api_result_object( $result, 'installs' ) ) {
8322
+ // I successfully sent installs update (there was an actual update sent and it's not just a keepalive-only call), clear scheduled sync if exist.
8323
+ $this->clear_install_sync_cron();
8324
+ }
8325
+
8326
+ return $result;
8327
+ }
8328
+
8329
+ /**
8330
+ * @author Leo Fajardo (@leorw)
8331
+ *
8332
+ * @param bool|null $use_network_level_storage
8333
+ *
8334
+ * @return bool
8335
+ */
8336
+ private function should_send_keepalive_update( $use_network_level_storage = null ) {
8337
+ $keepalive_timestamp = $this->_storage->get( 'keepalive_timestamp', 0, $use_network_level_storage );
8338
+
8339
+ if ( $keepalive_timestamp < ( time() - WP_FS__TIME_WEEK_IN_SEC ) ) {
8340
+ // If updated more than 7 days ago, trigger a keepalive and update the time it was triggered.
8341
+ return true;
8342
+ } else {
8343
+ // 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.
8344
+ return ( 7 == rand( 1, 7 ) );
8345
+ }
8346
+ }
8347
+
8348
+ /**
8349
+ * Update install only if changed.
8350
+ *
8351
+ * @author Vova Feldman (@svovaf)
8352
+ * @since 1.0.9
8353
+ *
8354
+ * @param string[] string $override
8355
+ * @param bool $flush
8356
+ */
8357
+ private function sync_install( $override = array(), $flush = false ) {
8358
+ $this->_logger->entrance();
8359
+
8360
+ $site = $this->send_install_update( $override, $flush );
8361
+
8362
+ if ( false === $site ) {
8363
+ // No sync required.
8364
+ return;
8365
+ }
8366
+
8367
+ if ( ! $this->is_api_result_entity( $site ) ) {
8368
+ // Failed to sync, don't update locally.
8369
+ return;
8370
+ }
8371
+
8372
+ $this->_site = new FS_Site( $site );
8373
+
8374
+ $this->_store_site( true );
8375
+ }
8376
+
8377
+ /**
8378
+ * Update install only if changed.
8379
+ *
8380
+ * @author Vova Feldman (@svovaf)
8381
+ * @since 1.0.9
8382
+ *
8383
+ * @param string[] string $override
8384
+ * @param bool $flush
8385
+ */
8386
+ private function sync_installs( $override = array(), $flush = false ) {
8387
+ $this->_logger->entrance();
8388
+
8389
+ $result = $this->send_installs_update( $override, $flush );
8390
+
8391
+ if ( false === $result ) {
8392
+ // No sync required.
8393
+ return;
8394
+ }
8395
+
8396
+ if ( ! $this->is_api_result_object( $result, 'installs' ) ) {
8397
+ // Failed to sync, don't update locally.
8398
+ return;
8399
+ }
8400
+
8401
+ $address_to_blog_map = $this->get_address_to_blog_map();
8402
+
8403
+ foreach ( $result->installs as $install ) {
8404
+ $this->_site = new FS_Site( $install );
8405
+
8406
+ $address = trailingslashit( fs_strip_url_protocol( $install->url ) );
8407
+ $blog_id = $address_to_blog_map[ $address ];
8408
+
8409
+ $this->_store_site( true, $blog_id );
8410
+ }
8411
+ }
8412
+
8413
+ /**
8414
+ * Track install's custom event.
8415
+ *
8416
+ * IMPORTANT:
8417
+ * Custom event tracking is currently only supported for specific clients.
8418
+ * If you are not one of them, please don't use this method. If you will,
8419
+ * the API will simply ignore your request based on the plugin ID.
8420
+ *
8421
+ * Need custom tracking for your plugin or theme?
8422
+ * If you are interested in custom event tracking please contact yo@freemius.com
8423
+ * for further details.
8424
+ *
8425
+ * @author Vova Feldman (@svovaf)
8426
+ * @since 1.2.1
8427
+ *
8428
+ * @param string $name Event name.
8429
+ * @param array $properties Associative key/value array with primitive values only
8430
+ * @param bool $process_at A valid future date-time in the following format Y-m-d H:i:s.
8431
+ * @param bool $once If true, event will be tracked only once. IMPORTANT: Still trigger the API call.
8432
+ *
8433
+ * @return object|false Event data or FALSE on failure.
8434
+ *
8435
+ * @throws \Freemius_InvalidArgumentException
8436
+ */
8437
+ public function track_event( $name, $properties = array(), $process_at = false, $once = false ) {
8438
+ $this->_logger->entrance( http_build_query( array( 'name' => $name, 'once' => $once ) ) );
8439
+
8440
+ if ( ! $this->is_registered() ) {
8441
+ return false;
8442
+ }
8443
+
8444
+ $event = array( 'type' => $name );
8445
+
8446
+ if ( is_numeric( $process_at ) && $process_at > time() ) {
8447
+ $event['process_at'] = $process_at;
8448
+ }
8449
+
8450
+ if ( $once ) {
8451
+ $event['once'] = true;
8452
+ }
8453
+
8454
+ if ( ! empty( $properties ) ) {
8455
+ // Verify associative array values are primitive.
8456
+ foreach ( $properties as $k => $v ) {
8457
+ if ( ! is_scalar( $v ) ) {
8458
+ throw new Freemius_InvalidArgumentException( 'The $properties argument must be an associative key/value array with primitive values only.' );
8459
+ }
8460
+ }
8461
+
8462
+ $event['properties'] = $properties;
8463
+ }
8464
+
8465
+ $result = $this->get_api_site_scope()->call( 'events.json', 'post', $event );
8466
+
8467
+ return $this->is_api_error( $result ) ?
8468
+ false :
8469
+ $result;
8470
+ }
8471
+
8472
+ /**
8473
+ * Track install's custom event only once, but it still triggers the API call.
8474
+ *
8475
+ * IMPORTANT:
8476
+ * Custom event tracking is currently only supported for specific clients.
8477
+ * If you are not one of them, please don't use this method. If you will,
8478
+ * the API will simply ignore your request based on the plugin ID.
8479
+ *
8480
+ * Need custom tracking for your plugin or theme?
8481
+ * If you are interested in custom event tracking please contact yo@freemius.com
8482
+ * for further details.
8483
+ *
8484
+ * @author Vova Feldman (@svovaf)
8485
+ * @since 1.2.1
8486
+ *
8487
+ * @param string $name Event name.
8488
+ * @param array $properties Associative key/value array with primitive values only
8489
+ * @param bool $process_at A valid future date-time in the following format Y-m-d H:i:s.
8490
+ *
8491
+ * @return object|false Event data or FALSE on failure.
8492
+ *
8493
+ * @throws \Freemius_InvalidArgumentException
8494
+ *
8495
+ * @user Freemius::track_event()
8496
+ */
8497
+ public function track_event_once( $name, $properties = array(), $process_at = false ) {
8498
+ return $this->track_event( $name, $properties, $process_at, true );
8499
+ }
8500
+
8501
+ /**
8502
+ * Plugin uninstall hook.
8503
+ *
8504
+ * @author Vova Feldman (@svovaf)
8505
+ * @since 1.0.1
8506
+ *
8507
+ * @param bool $check_user Enforce checking if user have plugins activation privileges.
8508
+ */
8509
+ function _uninstall_plugin_event( $check_user = true ) {
8510
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
8511
+
8512
+ if ( $check_user && ! current_user_can( 'activate_plugins' ) ) {
8513
+ return;
8514
+ }
8515
+
8516
+ $params = array();
8517
+ $uninstall_reason = null;
8518
+ if ( isset( $this->_storage->uninstall_reason ) ) {
8519
+ $uninstall_reason = $this->_storage->uninstall_reason;
8520
+ $params['reason_id'] = $uninstall_reason->id;
8521
+ $params['reason_info'] = $uninstall_reason->info;
8522
+ }
8523
+
8524
+ if ( ! $this->is_registered() ) {
8525
+ // Send anonymous uninstall event only if user submitted a feedback.
8526
+ if ( isset( $uninstall_reason ) ) {
8527
+ if ( isset( $uninstall_reason->is_anonymous ) && ! $uninstall_reason->is_anonymous ) {
8528
+ $this->opt_in( false, false, false, false, true );
8529
+ } else {
8530
+ $params['uid'] = $this->get_anonymous_id();
8531
+ $this->get_api_plugin_scope()->call( 'uninstall.json', 'put', $params );
8532
+ }
8533
+ }
8534
+ } else {
8535
+ $params = array_merge( $params, array(
8536
+ 'is_active' => false,
8537
+ 'is_uninstalled' => true,
8538
+ ) );
8539
+
8540
+ if ( $this->_is_network_active ) {
8541
+ // Send uninstall event.
8542
+ $this->send_installs_update( $params );
8543
+ } else {
8544
+ // Send uninstall event.
8545
+ $this->send_install_update( $params );
8546
+ }
8547
+ }
8548
+
8549
+ // @todo Decide if we want to delete plugin information from db.
8550
+ }
8551
+
8552
+ /**
8553
+ * Set the basename of the current product and hook _activate_plugin_event_hook() to the activation action.
8554
+ *
8555
+ * @author Vova Feldman (@svovaf)
8556
+ * @since 2.2.1
8557
+ *
8558
+ * @param string $is_premium
8559
+ * @param string $caller
8560
+ *
8561
+ * @return string
8562
+ */
8563
+ function set_basename( $is_premium, $caller ) {
8564
+ $basename = plugin_basename( $caller );
8565
+
8566
+ $current_basename = $is_premium ?
8567
+ $this->_premium_plugin_basename :
8568
+ $this->_free_plugin_basename;
8569
+
8570
+ if ( $current_basename == $basename ) {
8571
+ // Basename value set correctly.
8572
+ return;
8573
+ }
8574
+
8575
+ if ( $is_premium ) {
8576
+ $this->_premium_plugin_basename = $basename;
8577
+ } else {
8578
+ $this->_free_plugin_basename = $basename;
8579
+ }
8580
+
8581
+ $plugin_dir = dirname( $this->_plugin_dir_path ) . '/';
8582
+
8583
+ register_activation_hook(
8584
+ $plugin_dir . $basename,
8585
+ array( &$this, '_activate_plugin_event_hook' )
8586
+ );
8587
+ }
8588
+
8589
+ /**
8590
+ * @author Vova Feldman (@svovaf)
8591
+ * @since 1.1.1
8592
+ * @since 2.2.1 If the context product is in its premium version, use the current module's basename, even if it was renamed.
8593
+ *
8594
+ * @return string
8595
+ */
8596
+ function premium_plugin_basename() {
8597
+ if ( ! isset( $this->_premium_plugin_basename ) ) {
8598
+ $this->_premium_plugin_basename = $this->is_premium() ?
8599
+ // The product is premium, so use the current basename.
8600
+ $this->_plugin_basename :
8601
+ $this->get_premium_slug() . '/' . basename( $this->_free_plugin_basename );
8602
+ }
8603
+
8604
+ return $this->_premium_plugin_basename;
8605
+ }
8606
+
8607
+ /**
8608
+ * Uninstall plugin hook. Called only when connected his account with Freemius for active sites tracking.
8609
+ *
8610
+ * @author Vova Feldman (@svovaf)
8611
+ * @since 1.0.2
8612
+ */
8613
+ public static function _uninstall_plugin_hook() {
8614
+ self::_load_required_static();
8615
+
8616
+ self::$_static_logger->entrance();
8617
+
8618
+ if ( ! current_user_can( 'activate_plugins' ) ) {
8619
+ return;
8620
+ }
8621
+
8622
+ $plugin_file = substr( current_filter(), strlen( 'uninstall_' ) );
8623
+
8624
+ self::$_static_logger->info( 'plugin = ' . $plugin_file );
8625
+
8626
+ define( 'WP_FS__UNINSTALL_MODE', true );
8627
+
8628
+ $fs = self::get_instance_by_file( $plugin_file );
8629
+
8630
+ if ( is_object( $fs ) ) {
8631
+ self::require_plugin_essentials();
8632
+
8633
+ if ( is_plugin_active( $fs->_free_plugin_basename ) ||
8634
+ is_plugin_active( $fs->premium_plugin_basename() )
8635
+ ) {
8636
+ // Deleting Free or Premium plugin version while the other version still installed.
8637
+ return;
8638
+ }
8639
+
8640
+ $fs->_uninstall_plugin_event();
8641
+
8642
+ $fs->do_action( 'after_uninstall' );
8643
+ }
8644
+ }
8645
+
8646
+ #----------------------------------------------------------------------------------
8647
+ #region Plugin Information
8648
+ #----------------------------------------------------------------------------------
8649
+
8650
+ /**
8651
+ * Load WordPress core plugin.php essential module.
8652
+ *
8653
+ * @author Vova Feldman (@svovaf)
8654
+ * @since 1.1.1
8655
+ */
8656
+ private static function require_plugin_essentials() {
8657
+ if ( ! function_exists( 'get_plugins' ) ) {
8658
+ self::$_static_logger->log( 'Including wp-admin/includes/plugin.php...' );
8659
+
8660
+ require_once ABSPATH . 'wp-admin/includes/plugin.php';
8661
+ }
8662
+ }
8663
+
8664
+ /**
8665
+ * Load WordPress core pluggable.php module.
8666
+ *
8667
+ * @author Vova Feldman (@svovaf)
8668
+ * @since 1.1.2
8669
+ */
8670
+ private static function require_pluggable_essentials() {
8671
+ if ( ! function_exists( 'wp_get_current_user' ) ) {
8672
+ require_once ABSPATH . 'wp-includes/pluggable.php';
8673
+ }
8674
+ }
8675
+
8676
+ /**
8677
+ * Return plugin data.
8678
+ *
8679
+ * @author Vova Feldman (@svovaf)
8680
+ * @since 1.0.1
8681
+ *
8682
+ * @return array
8683
+ */
8684
+ function get_plugin_data() {
8685
+ if ( ! isset( $this->_plugin_data ) ) {
8686
+ self::require_plugin_essentials();
8687
+
8688
+ if ( $this->is_plugin() ) {
8689
+ /**
8690
+ * @author Vova Feldman (@svovaf)
8691
+ * @since 1.2.0 When using get_plugin_data() do NOT translate plugin data.
8692
+ *
8693
+ * @link https://github.com/Freemius/wordpress-sdk/issues/77
8694
+ */
8695
+ $plugin_data = get_plugin_data(
8696
+ $this->_plugin_main_file_path,
8697
+ false,
8698
+ false
8699
+ );
8700
+ } else {
8701
+ $theme_data = wp_get_theme();
8702
+
8703
+ if ( $this->_plugin_basename !== $theme_data->get_stylesheet() && is_child_theme() ) {
8704
+ $parent_theme = $theme_data->parent();
8705
+
8706
+ if ( ( $parent_theme instanceof WP_Theme ) && $this->_plugin_basename === $parent_theme->get_stylesheet() ) {
8707
+ $theme_data = $parent_theme;
8708
+ }
8709
+ }
8710
+
8711
+ $plugin_data = array(
8712
+ 'Name' => $theme_data->get( 'Name' ),
8713
+ 'Version' => $theme_data->get( 'Version' ),
8714
+ 'Author' => $theme_data->get( 'Author' ),
8715
+ 'Description' => $theme_data->get( 'Description' ),
8716
+ 'PluginURI' => $theme_data->get( 'ThemeURI' ),
8717
+ );
8718
+ }
8719
+
8720
+ $this->_plugin_data = $plugin_data;
8721
+ }
8722
+
8723
+ return $this->_plugin_data;
8724
+ }
8725
+
8726
+ /**
8727
+ * @author Vova Feldman (@svovaf)
8728
+ * @since 1.0.1
8729
+ * @since 1.2.2.5 If slug not set load slug by module ID.
8730
+ *
8731
+ * @return string Plugin slug.
8732
+ */
8733
+ function get_slug() {
8734
+ if ( ! isset( $this->_slug ) ) {
8735
+ $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array() );
8736
+ $this->_slug = $id_slug_type_path_map[ $this->_module_id ]['slug'];
8737
+ }
8738
+
8739
+ return $this->_slug;
8740
+ }
8741
+
8742
+ /**
8743
+ * @author Leo Fajardo (@leorw)
8744
+ * @since 2.2.1
8745
+ *
8746
+ * @return string
8747
+ */
8748
+ function get_premium_slug() {
8749
+ return is_object( $this->_plugin ) ?
8750
+ $this->_plugin->premium_slug :
8751
+ "{$this->_slug}-premium";
8752
+ }
8753
+
8754
+ /**
8755
+ * Retrieve the desired folder name for the product.
8756
+ *
8757
+ * @author Vova Feldman (@svovaf)
8758
+ * @since 1.2.1.7
8759
+ *
8760
+ * @return string Plugin slug.
8761
+ */
8762
+ function get_target_folder_name() {
8763
+ return $this->can_use_premium_code() ?
8764
+ $this->_plugin->premium_slug :
8765
+ $this->_slug;
8766
+ }
8767
+
8768
+ /**
8769
+ * @author Vova Feldman (@svovaf)
8770
+ * @since 1.0.1
8771
+ *
8772
+ * @return number Plugin ID.
8773
+ */
8774
+ function get_id() {
8775
+ return $this->_plugin->id;
8776
+ }
8777
+
8778
+ /**
8779
+ * @author Vova Feldman (@svovaf)
8780
+ * @since 1.2.1.5
8781
+ *
8782
+ * @return string Freemius SDK version
8783
+ */
8784
+ function get_sdk_version() {
8785
+ return $this->version;
8786
+ }
8787
+
8788
+ /**
8789
+ * @author Vova Feldman (@svovaf)
8790
+ * @since 1.2.1.5
8791
+ *
8792
+ * @return number Parent plugin ID (if parent exist).
8793
+ */
8794
+ function get_parent_id() {
8795
+ return $this->is_addon() ?
8796
+ $this->get_parent_instance()->get_id() :
8797
+ $this->_plugin->id;
8798
+ }
8799
+
8800
+ /**
8801
+ * @author Vova Feldman (@svovaf)
8802
+ * @since 1.0.1
8803
+ *
8804
+ * @return string Plugin public key.
8805
+ */
8806
+ function get_public_key() {
8807
+ return $this->_plugin->public_key;
8808
+ }
8809
+
8810
+ /**
8811
+ * Will be available only on sandbox mode.
8812
+ *
8813
+ * @author Vova Feldman (@svovaf)
8814
+ * @since 1.0.4
8815
+ *
8816
+ * @return mixed Plugin secret key.
8817
+ */
8818
+ function get_secret_key() {
8819
+ return $this->_plugin->secret_key;
8820
+ }
8821
+
8822
+ /**
8823
+ * @author Vova Feldman (@svovaf)
8824
+ * @since 1.1.1
8825
+ *
8826
+ * @return bool
8827
+ */
8828
+ function has_secret_key() {
8829
+ return ! empty( $this->_plugin->secret_key );
8830
+ }
8831
+
8832
+ /**
8833
+ * @author Vova Feldman (@svovaf)
8834
+ * @since 1.0.9
8835
+ *
8836
+ * @param string|bool $premium_suffix
8837
+ *
8838
+ * @return string
8839
+ */
8840
+ function get_plugin_name( $premium_suffix = false ) {
8841
+ $this->_logger->entrance();
8842
+
8843
+ /**
8844
+ * This `if-else` can be squeezed into a single `if` but I intentionally split it for code readability.
8845
+ *
8846
+ * @author Vova Feldman
8847
+ */
8848
+ if ( ! isset( $this->_plugin_name ) ) {
8849
+ // Name is not yet set.
8850
+ $this->set_name( $premium_suffix );
8851
+ } else if (
8852
+ ! empty( $premium_suffix ) &&
8853
+ ( ! is_object( $this->_plugin ) || $this->_plugin->premium_suffix !== $premium_suffix )
8854
+ ) {
8855
+ // Name is already set, but there's a change in the premium suffix.
8856
+ $this->set_name( $premium_suffix );
8857
+ }
8858
+
8859
+ return $this->_plugin_name;
8860
+ }
8861
+
8862
+ /**
8863
+ * Calculates and stores the product's name. This helper function was created specifically for get_plugin_name() just to make the code clearer.
8864
+ *
8865
+ * @author Vova Feldman (@svovaf)
8866
+ * @since 2.2.1
8867
+ *
8868
+ * @param string $premium_suffix
8869
+ */
8870
+ private function set_name( $premium_suffix = '' ) {
8871
+ $plugin_data = $this->get_plugin_data();
8872
+
8873
+ // Get name.
8874
+ $this->_plugin_name = $plugin_data['Name'];
8875
+
8876
+ if ( is_string( $premium_suffix ) ) {
8877
+ $premium_suffix = trim( $premium_suffix );
8878
+
8879
+ if ( ! empty( $premium_suffix ) ) {
8880
+ // Check if plugin name contains " (premium)" or a custom suffix and remove it.
8881
+ $suffix = ( ' ' . strtolower( $premium_suffix ) );
8882
+ $suffix_len = strlen( $suffix );
8883
+
8884
+ if ( strlen( $plugin_data['Name'] ) > $suffix_len &&
8885
+ $suffix === substr( strtolower( $plugin_data['Name'] ), - $suffix_len )
8886
+ ) {
8887
+ $this->_plugin_name = substr( $plugin_data['Name'], 0, - $suffix_len );
8888
+ }
8889
+ }
8890
+ }
8891
+
8892
+ $this->_logger->departure( 'Name = ' . $this->_plugin_name );
8893
+ }
8894
+
8895
+ /**
8896
+ * @author Vova Feldman (@svovaf)
8897
+ * @since 1.0.0
8898
+ *
8899
+ * @return string
8900
+ */
8901
+ function get_plugin_version() {
8902
+ $this->_logger->entrance();
8903
+
8904
+ $plugin_data = $this->get_plugin_data();
8905
+
8906
+ $this->_logger->departure( 'Version = ' . $plugin_data['Version'] );
8907
+
8908
+ return $this->apply_filters( 'plugin_version', $plugin_data['Version'] );
8909
+ }
8910
+
8911
+ /**
8912
+ * @author Vova Feldman (@svovaf)
8913
+ * @since 1.2.1.7
8914
+ *
8915
+ * @return string
8916
+ */
8917
+ function get_plugin_title() {
8918
+ $this->_logger->entrance();
8919
+
8920
+ $title = $this->_plugin->title;
8921
+
8922
+ return $this->apply_filters( 'plugin_title', $title );
8923
+ }
8924
+
8925
+ /**
8926
+ * @author Vova Feldman (@svovaf)
8927
+ * @since 1.2.2.7
8928
+ *
8929
+ * @param bool $lowercase
8930
+ *
8931
+ * @return string
8932
+ */
8933
+ function get_module_label( $lowercase = false ) {
8934
+ $label = $this->is_addon() ?
8935
+ $this->get_text_inline( 'Add-On', 'addon' ) :
8936
+ ( $this->is_plugin() ?
8937
+ $this->get_text_inline( 'Plugin', 'plugin' ) :
8938
+ $this->get_text_inline( 'Theme', 'theme' ) );
8939
+
8940
+ if ( $lowercase ) {
8941
+ $label = strtolower( $label );
8942
+ }
8943
+
8944
+ return $label;
8945
+ }
8946
+
8947
+ /**
8948
+ * @author Vova Feldman (@svovaf)
8949
+ * @since 1.0.4
8950
+ *
8951
+ * @return string
8952
+ */
8953
+ function get_plugin_basename() {
8954
+ if ( ! isset( $this->_plugin_basename ) ) {
8955
+ if ( $this->is_plugin() ) {
8956
+ $this->_plugin_basename = plugin_basename( $this->_plugin_main_file_path );
8957
+ } else {
8958
+ $this->_plugin_basename = basename( dirname( $this->_plugin_main_file_path ) );
8959
+ }
8960
+ }
8961
+
8962
+ return $this->_plugin_basename;
8963
+ }
8964
+
8965
+ function get_plugin_folder_name() {
8966
+ $this->_logger->entrance();
8967
+
8968
+ $plugin_folder = $this->_plugin_basename;
8969
+
8970
+ while ( '.' !== dirname( $plugin_folder ) ) {
8971
+ $plugin_folder = dirname( $plugin_folder );
8972
+ }
8973
+
8974
+ $this->_logger->departure( 'Folder Name = ' . $plugin_folder );
8975
+
8976
+ return $plugin_folder;
8977
+ }
8978
+
8979
+ #endregion ------------------------------------------------------------------
8980
+
8981
+ /* Account
8982
+ ------------------------------------------------------------------------------------------------------------------*/
8983
+
8984
+ /**
8985
+ * Find plugin's slug by plugin's basename.
8986
+ *
8987
+ * @author Vova Feldman (@svovaf)
8988
+ * @since 1.0.9
8989
+ *
8990
+ * @param string $plugin_base_name
8991
+ *
8992
+ * @return false|string
8993
+ */
8994
+ private static function find_slug_by_basename( $plugin_base_name ) {
8995
+ $file_slug_map = self::$_accounts->get_option( 'file_slug_map', array() );
8996
+
8997
+ if ( ! array( $file_slug_map ) || ! isset( $file_slug_map[ $plugin_base_name ] ) ) {
8998
+ return false;
8999
+ }
9000
+
9001
+ return $file_slug_map[ $plugin_base_name ];
9002
+ }
9003
+
9004
+ /**
9005
+ * Store the map between the plugin's basename to the slug.
9006
+ *
9007
+ * @author Vova Feldman (@svovaf)
9008
+ * @since 1.0.9
9009
+ */
9010
+ private function store_file_slug_map() {
9011
+ $file_slug_map = self::$_accounts->get_option( 'file_slug_map', array() );
9012
+
9013
+ if ( ! array( $file_slug_map ) ) {
9014
+ $file_slug_map = array();
9015
+ }
9016
+
9017
+ if ( ! isset( $file_slug_map[ $this->_plugin_basename ] ) ||
9018
+ $file_slug_map[ $this->_plugin_basename ] !== $this->_slug
9019
+ ) {
9020
+ $file_slug_map[ $this->_plugin_basename ] = $this->_slug;
9021
+ self::$_accounts->set_option( 'file_slug_map', $file_slug_map, true );
9022
+ }
9023
+ }
9024
+
9025
+ /**
9026
+ * @return array[number]FS_User
9027
+ */
9028
+ static function get_all_users() {
9029
+ $users = self::$_accounts->get_option( 'users', array() );
9030
+
9031
+ if ( ! is_array( $users ) ) {
9032
+ $users = array();
9033
+ }
9034
+
9035
+ return $users;
9036
+ }
9037
+
9038
+ /**
9039
+ * @param string $module_type
9040
+ * @param null|int $blog_id Since 2.0.0
9041
+ *
9042
+ * @return array[string]FS_Site
9043
+ */
9044
+ private static function get_all_sites(
9045
+ $module_type = WP_FS__MODULE_TYPE_PLUGIN,
9046
+ $blog_id = null
9047
+ ) {
9048
+ $sites = self::get_account_option( 'sites', $module_type, $blog_id );
9049
+
9050
+ if ( ! is_array( $sites ) ) {
9051
+ $sites = array();
9052
+ }
9053
+
9054
+ return $sites;
9055
+ }
9056
+
9057
+ /**
9058
+ * @author Leo Fajardo (@leorw)
9059
+ *
9060
+ * @since 1.2.2
9061
+ *
9062
+ * @param string $option_name
9063
+ * @param string $module_type
9064
+ * @param null|int $network_level_or_blog_id Since 2.0.0
9065
+ *
9066
+ * @return mixed
9067
+ */
9068
+ private static function get_account_option( $option_name, $module_type = null, $network_level_or_blog_id = null ) {
9069
+ if ( ! is_null( $module_type ) && WP_FS__MODULE_TYPE_PLUGIN !== $module_type ) {
9070
+ $option_name = $module_type . '_' . $option_name;
9071
+ }
9072
+
9073
+ return self::$_accounts->get_option( $option_name, array(), $network_level_or_blog_id );
9074
+ }
9075
+
9076
+ /**
9077
+ * @author Leo Fajardo (@leorw)
9078
+ *
9079
+ * @since 1.2.2
9080
+ *
9081
+ * @param string $option_name
9082
+ * @param mixed $option_value
9083
+ * @param bool $store
9084
+ * @param null|int $network_level_or_blog_id Since 2.0.0
9085
+ */
9086
+ private function set_account_option( $option_name, $option_value, $store, $network_level_or_blog_id = null ) {
9087
+ self::set_account_option_by_module(
9088
+ $this->_module_type,
9089
+ $option_name,
9090
+ $option_value,
9091
+ $store,
9092
+ $network_level_or_blog_id
9093
+ );
9094
+ }
9095
+
9096
+ /**
9097
+ * @author Vova Feldman (@svovaf)
9098
+ *
9099
+ * @since 1.2.2.7
9100
+ *
9101
+ * @param string $module_type
9102
+ * @param string $option_name
9103
+ * @param mixed $option_value
9104
+ * @param bool $store
9105
+ * @param null|int $network_level_or_blog_id Since 2.0.0
9106
+ */
9107
+ private static function set_account_option_by_module(
9108
+ $module_type,
9109
+ $option_name,
9110
+ $option_value,
9111
+ $store,
9112
+ $network_level_or_blog_id = null
9113
+ ) {
9114
+ if ( WP_FS__MODULE_TYPE_PLUGIN != $module_type ) {
9115
+ $option_name = $module_type . '_' . $option_name;
9116
+ }
9117
+
9118
+ self::$_accounts->set_option( $option_name, $option_value, $store, $network_level_or_blog_id );
9119
+ }
9120
+
9121
+ /**
9122
+ * @author Vova Feldman (@svovaf)
9123
+ * @since 1.0.6
9124
+ *
9125
+ * @param number|null $module_id
9126
+ *
9127
+ * @return FS_Plugin_License[]
9128
+ */
9129
+ private static function get_all_licenses( $module_id = null ) {
9130
+ $licenses = self::get_account_option( 'all_licenses' );
9131
+
9132
+ if ( ! is_array( $licenses ) ) {
9133
+ $licenses = array();
9134
+ }
9135
+
9136
+ if ( is_null( $module_id ) ) {
9137
+ return $licenses;
9138
+ }
9139
+
9140
+ $licenses = isset( $licenses[ $module_id ] ) ?
9141
+ $licenses[ $module_id ] :
9142
+ array();
9143
+
9144
+ return $licenses;
9145
+ }
9146
+
9147
+ /**
9148
+ * @author Leo Fajardo (@leorw)
9149
+ * @since 2.0.0
9150
+ *
9151
+ * @return array
9152
+ */
9153
+ private static function get_all_licenses_by_module_type() {
9154
+ $licenses = self::get_account_option( 'all_licenses' );
9155
+
9156
+ $licenses_by_module_type = array(
9157
+ WP_FS__MODULE_TYPE_PLUGIN => array(),
9158
+ WP_FS__MODULE_TYPE_THEME => array()
9159
+ );
9160
+
9161
+ if ( ! is_array( $licenses ) ) {
9162
+ return $licenses_by_module_type;
9163
+ }
9164
+
9165
+ foreach ( $licenses as $module_id => $module_licenses ) {
9166
+ $fs = self::get_instance_by_id( $module_id );
9167
+ if ( false === $fs ) {
9168
+ continue;
9169
+ }
9170
+
9171
+ $licenses_by_module_type[ $fs->_module_type ] = array_merge( $licenses_by_module_type[ $fs->_module_type ], $module_licenses );
9172
+ }
9173
+
9174
+ return $licenses_by_module_type;
9175
+ }
9176
+
9177
+ /**
9178
+ * @author Leo Fajardo (@leorw)
9179
+ * @since 2.0.0
9180
+ *
9181
+ * @param number $module_id
9182
+ * @param number|null $user_id
9183
+ *
9184
+ * @return array
9185
+ */
9186
+ private static function get_user_id_license_ids_map( $module_id, $user_id = null ) {
9187
+ $all_modules_user_id_license_ids_map = self::get_account_option( 'user_id_license_ids_map' );
9188
+
9189
+ if ( ! is_array( $all_modules_user_id_license_ids_map ) ) {
9190
+ $all_modules_user_id_license_ids_map = array();
9191
+ }
9192
+
9193
+ $user_id_license_ids_map = isset( $all_modules_user_id_license_ids_map[ $module_id ] ) ?
9194
+ $all_modules_user_id_license_ids_map[ $module_id ] :
9195
+ array();
9196
+
9197
+ if ( FS_User::is_valid_id( $user_id ) ) {
9198
+ $user_id_license_ids_map = isset( $user_id_license_ids_map[ $user_id ] ) ?
9199
+ $user_id_license_ids_map[ $user_id ] :
9200
+ array();
9201
+ }
9202
+
9203
+ return $user_id_license_ids_map;
9204
+ }
9205
+
9206
+ /**
9207
+ * @author Leo Fajardo (@leorw)
9208
+ * @since 2.0.0
9209
+ *
9210
+ * @param array $new_user_id_license_ids_map
9211
+ * @param number $module_id
9212
+ * @param number|null $user_id
9213
+ */
9214
+ private static function store_user_id_license_ids_map( $new_user_id_license_ids_map, $module_id, $user_id = null ) {
9215
+ $all_modules_user_id_license_ids_map = self::get_account_option( 'user_id_license_ids_map' );
9216
+ if ( ! is_array( $all_modules_user_id_license_ids_map ) ) {
9217
+ $all_modules_user_id_license_ids_map = array();
9218
+ }
9219
+
9220
+ if ( ! isset( $all_modules_user_id_license_ids_map[ $module_id ] ) ) {
9221
+ $all_modules_user_id_license_ids_map[ $module_id ] = array();
9222
+ }
9223
+
9224
+ if ( FS_User::is_valid_id( $user_id ) ) {
9225
+ $all_modules_user_id_license_ids_map[ $module_id ][ $user_id ] = $new_user_id_license_ids_map;
9226
+ } else {
9227
+ $all_modules_user_id_license_ids_map[ $module_id ] = $new_user_id_license_ids_map;
9228
+ }
9229
+
9230
+ self::$_accounts->set_option( 'user_id_license_ids_map', $all_modules_user_id_license_ids_map, true );
9231
+ }
9232
+
9233
+ /**
9234
+ * Get a collection of the user's linked license IDs.
9235
+ *
9236
+ * @author Vova Feldman (@svovaf)
9237
+ * @since 2.0.0
9238
+ *
9239
+ * @param number $user_id
9240
+ *
9241
+ * @return number[]
9242
+ */
9243
+ private function get_user_linked_license_ids( $user_id ) {
9244
+ return self::get_user_id_license_ids_map( $this->_module_id, $user_id );
9245
+ }
9246
+
9247
+ /**
9248
+ * Override the user's linked license IDs with a new IDs collection.
9249
+ *
9250
+ * @author Vova Feldman (@svovaf)
9251
+ * @since 2.0.0
9252
+ *
9253
+ * @param number $user_id
9254
+ * @param number[] $license_ids
9255
+ */
9256
+ private function set_user_linked_license_ids( $user_id, array $license_ids ) {
9257
+ self::store_user_id_license_ids_map( $license_ids, $this->_module_id, $user_id );
9258
+ }
9259
+
9260
+ /**
9261
+ * Link a specified license ID to a given user.
9262
+ *
9263
+ * @author Vova Feldman (@svovaf)
9264
+ * @since 2.0.0
9265
+ *
9266
+ * @param number $license_id
9267
+ * @param number $user_id
9268
+ */
9269
+ private function link_license_2_user( $license_id, $user_id ) {
9270
+ $license_ids = $this->get_user_linked_license_ids( $user_id );
9271
+
9272
+ if ( in_array( $license_id, $license_ids ) ) {
9273
+ // License already linked.
9274
+ return;
9275
+ }
9276
+
9277
+ $license_ids[] = $license_id;
9278
+
9279
+ $this->set_user_linked_license_ids( $user_id, $license_ids );
9280
+ }
9281
+
9282
+ /**
9283
+ * @param string|bool $module_type
9284
+ *
9285
+ * @return FS_Plugin_Plan[]
9286
+ */
9287
+ private static function get_all_plans( $module_type = false ) {
9288
+ $plans = self::get_account_option( 'plans', $module_type );
9289
+
9290
+ if ( ! is_array( $plans ) ) {
9291
+ $plans = array();
9292
+ }
9293
+
9294
+ return $plans;
9295
+ }
9296
+
9297
+ /**
9298
+ * @author Vova Feldman (@svovaf)
9299
+ * @since 1.0.4
9300
+ *
9301
+ * @return FS_Plugin_Tag[]
9302
+ */
9303
+ private static function get_all_updates() {
9304
+ $updates = self::$_accounts->get_option( 'updates', array() );
9305
+
9306
+ if ( ! is_array( $updates ) ) {
9307
+ $updates = array();
9308
+ }
9309
+
9310
+ return $updates;
9311
+ }
9312
+
9313
+ /**
9314
+ * @author Vova Feldman (@svovaf)
9315
+ * @since 1.0.6
9316
+ *
9317
+ * @return array<number,FS_Plugin[]>|false
9318
+ */
9319
+ private static function get_all_addons() {
9320
+ $addons = self::$_accounts->get_option( 'addons', array() );
9321
+
9322
+ if ( ! is_array( $addons ) ) {
9323
+ $addons = array();
9324
+ }
9325
+
9326
+ return $addons;
9327
+ }
9328
+
9329
+ /**
9330
+ * @author Vova Feldman (@svovaf)
9331
+ * @since 1.0.6
9332
+ *
9333
+ * @return FS_Plugin[]|false
9334
+ */
9335
+ private static function get_all_account_addons() {
9336
+ $addons = self::$_accounts->get_option( 'account_addons', array() );
9337
+
9338
+ if ( ! is_array( $addons ) ) {
9339
+ $addons = array();
9340
+ }
9341
+
9342
+ return $addons;
9343
+ }
9344
+
9345
+ /**
9346
+ * Check if user has connected his account (opted-in).
9347
+ *
9348
+ * Note:
9349
+ * If the user opted-in and opted-out on a later stage,
9350
+ * this will still return true. If you want to check if the
9351
+ * user is currently opted-in, use:
9352
+ * `$fs->is_registered() && $fs->is_tracking_allowed()`
9353
+ *
9354
+ * @author Vova Feldman (@svovaf)
9355
+ * @since 1.0.1
9356
+ * @return bool
9357
+ */
9358
+ function is_registered() {
9359
+ return is_object( $this->_user );
9360
+ }
9361
+
9362
+ /**
9363
+ * Returns TRUE if the user opted-in and didn't disconnect (opt-out).
9364
+ *
9365
+ * @author Leo Fajardo (@leorw)
9366
+ * @since 1.2.1.5
9367
+ *
9368
+ * @return bool
9369
+ */
9370
+ function is_tracking_allowed() {
9371
+ return ( is_object( $this->_site ) && $this->_site->is_tracking_allowed() );
9372
+ }
9373
+
9374
+ /**
9375
+ * @author Vova Feldman (@svovaf)
9376
+ * @since 1.0.4
9377
+ *
9378
+ * @return FS_Plugin
9379
+ */
9380
+ function get_plugin() {
9381
+ return $this->_plugin;
9382
+ }
9383
+
9384
+ /**
9385
+ * @author Vova Feldman (@svovaf)
9386
+ * @since 1.0.3
9387
+ *
9388
+ * @return FS_User
9389
+ */
9390
+ function get_user() {
9391
+ return $this->_user;
9392
+ }
9393
+
9394
+ /**
9395
+ * @author Vova Feldman (@svovaf)
9396
+ * @since 1.0.3
9397
+ *
9398
+ * @return FS_Site
9399
+ */
9400
+ function get_site() {
9401
+ return $this->_site;
9402
+ }
9403
+
9404
+ /**
9405
+ * Get plugin add-ons.
9406
+ *
9407
+ * @author Vova Feldman (@svovaf)
9408
+ * @since 1.0.6
9409
+ *
9410
+ * @since 1.1.7.3 If not yet loaded, fetch data from the API.
9411
+ *
9412
+ * @param bool $flush
9413
+ *
9414
+ * @return FS_Plugin[]|false
9415
+ */
9416
+ function get_addons( $flush = false ) {
9417
+ $this->_logger->entrance();
9418
+
9419
+ if ( ! $this->_has_addons ) {
9420
+ return false;
9421
+ }
9422
+
9423
+ $addons = $this->sync_addons( $flush );
9424
+
9425
+ return ( ! is_array( $addons ) || empty( $addons ) ) ?
9426
+ false :
9427
+ $addons;
9428
+ }
9429
+
9430
+ /**
9431
+ * @author Vova Feldman (@svovaf)
9432
+ * @since 1.0.6
9433
+ *
9434
+ * @return FS_Plugin[]|false
9435
+ */
9436
+ function get_account_addons() {
9437
+ $this->_logger->entrance();
9438
+
9439
+ $addons = self::get_all_account_addons();
9440
+
9441
+ if ( ! is_array( $addons ) ||
9442
+ ! isset( $addons[ $this->_plugin->id ] ) ||
9443
+ ! is_array( $addons[ $this->_plugin->id ] ) ||
9444
+ 0 === count( $addons[ $this->_plugin->id ] )
9445
+ ) {
9446
+ return false;
9447
+ }
9448
+
9449
+ return $addons[ $this->_plugin->id ];
9450
+ }
9451
+
9452
+ /**
9453
+ * Check if user has any
9454
+ *
9455
+ * @author Vova Feldman (@svovaf)
9456
+ * @since 1.1.6
9457
+ *
9458
+ * @return bool
9459
+ */
9460
+ function has_account_addons() {
9461
+ $addons = $this->get_account_addons();
9462
+
9463
+ return is_array( $addons ) && ( 0 < count( $addons ) );
9464
+ }
9465
+
9466
+
9467
+ /**
9468
+ * Get add-on by ID (from local data).
9469
+ *
9470
+ * @author Vova Feldman (@svovaf)
9471
+ * @since 1.0.6
9472
+ *
9473
+ * @param number $id
9474
+ *
9475
+ * @return FS_Plugin|false
9476
+ */
9477
+ function get_addon( $id ) {
9478
+ $this->_logger->entrance();
9479
+
9480
+ $addons = $this->get_addons();
9481
+
9482
+ if ( is_array( $addons ) ) {
9483
+ foreach ( $addons as $addon ) {
9484
+ if ( $id == $addon->id ) {
9485
+ return $addon;
9486
+ }
9487
+ }
9488
+ }
9489
+
9490
+ return false;
9491
+ }
9492
+
9493
+ /**
9494
+ * Get add-on by slug (from local data).
9495
+ *
9496
+ * @author Vova Feldman (@svovaf)
9497
+ * @since 1.0.6
9498
+ *
9499
+ * @param string $slug
9500
+ *
9501
+ * @param bool $flush
9502
+ *
9503
+ * @return FS_Plugin|false
9504
+ */
9505
+ function get_addon_by_slug( $slug, $flush = false ) {
9506
+ $this->_logger->entrance();
9507
+
9508
+ $addons = $this->get_addons( $flush );
9509
+
9510
+ if ( is_array( $addons ) ) {
9511
+ foreach ( $addons as $addon ) {
9512
+ if ( $slug === $addon->slug ) {
9513
+ return $addon;
9514
+ }
9515
+ }
9516
+ }
9517
+
9518
+ return false;
9519
+ }
9520
+
9521
+ /**
9522
+ * @author Vova Feldman (@svovaf)
9523
+ * @since 2.0.0
9524
+ *
9525
+ * @param number $user_id
9526
+ *
9527
+ * @return FS_User
9528
+ */
9529
+ static function _get_user_by_id( $user_id ) {
9530
+ self::$_static_logger->entrance( "user_id = {$user_id}" );
9531
+
9532
+ $users = self::get_all_users();
9533
+
9534
+ if ( is_array( $users ) ) {
9535
+ if ( isset( $users[ $user_id ] ) &&
9536
+ $users[ $user_id ] instanceof FS_User &&
9537
+ $user_id == $users[ $user_id ]->id
9538
+ ) {
9539
+ return $users[ $user_id ];
9540
+ }
9541
+
9542
+ // If user wasn't found by the key, iterate over all the users collection.
9543
+ foreach ( $users as $user ) {
9544
+ /**
9545
+ * @var FS_User $user
9546
+ */
9547
+ if ( $user_id == $user->id ) {
9548
+ return $user;
9549
+ }
9550
+ }
9551
+ }
9552
+
9553
+ return null;
9554
+ }
9555
+
9556
+ /**
9557
+ * Checks if a Freemius user_id is associated with a super-admin.
9558
+ *
9559
+ * @author Vova Feldman (@svovaf)
9560
+ * @since 2.0.0
9561
+ *
9562
+ * @param number $user_id
9563
+ *
9564
+ * @return bool
9565
+ */
9566
+ private static function is_super_admin( $user_id ) {
9567
+ $is_super_admin = false;
9568
+
9569
+ $user = self::_get_user_by_id( $user_id );
9570
+
9571
+ if ( $user instanceof FS_User && ! empty( $user->email ) ) {
9572
+ self::require_pluggable_essentials();
9573
+
9574
+ $wp_user = get_user_by( 'email', $user->email );
9575
+
9576
+ if ( $wp_user instanceof WP_User ) {
9577
+ $super_admins = get_super_admins();
9578
+ $is_super_admin = ( is_array( $super_admins ) && in_array( $wp_user->user_login, $super_admins ) );
9579
+ }
9580
+ }
9581
+
9582
+ return $is_super_admin;
9583
+ }
9584
+
9585
+ #----------------------------------------------------------------------------------
9586
+ #region Plans & Licensing
9587
+ #----------------------------------------------------------------------------------
9588
+
9589
+ /**
9590
+ * Check if running premium plugin code.
9591
+ *
9592
+ * @author Vova Feldman (@svovaf)
9593
+ * @since 1.0.5
9594
+ *
9595
+ * @return bool
9596
+ */
9597
+ function is_premium() {
9598
+ /**
9599
+ * `$this->_plugin` will be `false` when `is_activation_mode` calls this method directly from the
9600
+ * `_register_hooks` method.
9601
+ *
9602
+ * @author Leo Fajardo (@leorw)
9603
+ * @since 2.2.3
9604
+ */
9605
+ return is_object( $this->_plugin ) ?
9606
+ $this->_plugin->is_premium :
9607
+ false;
9608
+ }
9609
+
9610
+ /**
9611
+ * Get site's plan ID.
9612
+ *
9613
+ * @author Vova Feldman (@svovaf)
9614
+ * @since 1.0.2
9615
+ *
9616
+ * @return number
9617
+ */
9618
+ function get_plan_id() {
9619
+ return $this->_site->plan_id;
9620
+ }
9621
+
9622
+ /**
9623
+ * Get site's plan title.
9624
+ *
9625
+ * @author Vova Feldman (@svovaf)
9626
+ * @since 1.0.2
9627
+ *
9628
+ * @return string
9629
+ */
9630
+ function get_plan_title() {
9631
+ $plan = $this->get_plan();
9632
+
9633
+ return is_object( $plan ) ? $plan->title : 'PLAN_TITLE';
9634
+ }
9635
+
9636
+ /**
9637
+ * Get site's plan name.
9638
+ *
9639
+ * @author Vova Feldman (@svovaf)
9640
+ * @since 2.0.0
9641
+ *
9642
+ * @return string
9643
+ */
9644
+ function get_plan_name() {
9645
+ $plan = $this->get_plan();
9646
+
9647
+ return is_object( $plan ) ? $plan->name : 'PLAN_NAME';
9648
+ }
9649
+
9650
+ /**
9651
+ * @author Vova Feldman (@svovaf)
9652
+ * @since 1.0.9
9653
+ *
9654
+ * @return FS_Plugin_Plan|false
9655
+ */
9656
+ function get_plan() {
9657
+ if ( ! is_object( $this->_site ) ) {
9658
+ return false;
9659
+ }
9660
+
9661
+ return FS_Plugin_Plan::is_valid_id( $this->_site->plan_id ) ?
9662
+ $this->_get_plan_by_id( $this->_site->plan_id ) :
9663
+ false;
9664
+ }
9665
+
9666
+ /**
9667
+ * @author Vova Feldman (@svovaf)
9668
+ * @since 1.0.3
9669
+ *
9670
+ * @return bool
9671
+ */
9672
+ function is_trial() {
9673
+ $this->_logger->entrance();
9674
+
9675
+ if ( ! $this->is_registered() || ! is_object( $this->_site ) ) {
9676
+ return false;
9677
+ }
9678
+
9679
+ return $this->_site->is_trial();
9680
+ }
9681
+
9682
+ /**
9683
+ * Check if currently in a trial with payment method (credit card or paypal).
9684
+ *
9685
+ * @author Vova Feldman (@svovaf)
9686
+ * @since 1.1.7
9687
+ *
9688
+ * @return bool
9689
+ */
9690
+ function is_paid_trial() {
9691
+ $this->_logger->entrance();
9692
+
9693
+ if ( ! $this->is_trial() ) {
9694
+ return false;
9695
+ }
9696
+
9697
+ return $this->has_active_valid_license() && ( $this->_site->trial_plan_id == $this->_license->plan_id );
9698
+ }
9699
+
9700
+ /**
9701
+ * Check if trial already utilized.
9702
+ *
9703
+ * @since 1.0.9
9704
+ *
9705
+ * @return bool
9706
+ */
9707
+ function is_trial_utilized() {
9708
+ $this->_logger->entrance();
9709
+
9710
+ if ( ! $this->is_registered() ) {
9711
+ return false;
9712
+ }
9713
+
9714
+ return $this->_site->is_trial_utilized();
9715
+ }
9716
+
9717
+ /**
9718
+ * Get trial plan information (if in trial).
9719
+ *
9720
+ * @author Vova Feldman (@svovaf)
9721
+ * @since 1.0.9
9722
+ *
9723
+ * @return bool|FS_Plugin_Plan
9724
+ */
9725
+ function get_trial_plan() {
9726
+ $this->_logger->entrance();
9727
+
9728
+ if ( ! $this->is_trial() ) {
9729
+ return false;
9730
+ }
9731
+
9732
+ // Try to load plan from local cache.
9733
+ $trial_plan = $this->_get_plan_by_id( $this->_site->trial_plan_id );
9734
+
9735
+ if ( ! is_object( $trial_plan ) ) {
9736
+ $trial_plan = $this->_fetch_site_plan( $this->_site->trial_plan_id );
9737
+
9738
+ /**
9739
+ * If managed to fetch the plan, add it to the plans collection.
9740
+ */
9741
+ if ( $trial_plan instanceof FS_Plugin_Plan ) {
9742
+ if ( ! is_array( $this->_plans ) ) {
9743
+ $this->_plans = array();
9744
+ }
9745
+
9746
+ $this->_plans[] = $trial_plan;
9747
+ $this->_store_plans();
9748
+ }
9749
+ }
9750
+
9751
+ if ( $trial_plan instanceof FS_Plugin_Plan ) {
9752
+ return $trial_plan;
9753
+ }
9754
+
9755
+ /**
9756
+ * If for some reason failed to get the trial plan, fallback to a dummy name and title.
9757
+ */
9758
+ $trial_plan = new FS_Plugin_Plan();
9759
+ $trial_plan->id = $this->_site->trial_plan_id;
9760
+ $trial_plan->name = 'pro';
9761
+ $trial_plan->title = 'Pro';
9762
+
9763
+ return $trial_plan;
9764
+ }
9765
+
9766
+ /**
9767
+ * Check if the user has an activate, non-expired license on current plugin's install.
9768
+ *
9769
+ * @since 1.0.9
9770
+ *
9771
+ * @return bool
9772
+ */
9773
+ function is_paying() {
9774
+ $this->_logger->entrance();
9775
+
9776
+ if ( ! $this->is_registered() ) {
9777
+ return false;
9778
+ }
9779
+
9780
+ if ( ! $this->has_paid_plan() ) {
9781
+ return false;
9782
+ }
9783
+
9784
+ return (
9785
+ ! $this->is_trial() &&
9786
+ 'free' !== $this->get_plan_name() &&
9787
+ $this->has_active_valid_license()
9788
+ );
9789
+ }
9790
+
9791
+ /**
9792
+ * @author Vova Feldman (@svovaf)
9793
+ * @since 1.0.4
9794
+ *
9795
+ * @return bool
9796
+ */
9797
+ function is_free_plan() {
9798
+ if ( ! $this->is_registered() ) {
9799
+ return true;
9800
+ }
9801
+
9802
+ if ( ! $this->has_paid_plan() ) {
9803
+ return true;
9804
+ }
9805
+
9806
+ return (
9807
+ 'free' === $this->get_plan_name() ||
9808
+ ! $this->has_features_enabled_license()
9809
+ );
9810
+ }
9811
+
9812
+ /**
9813
+ * @author Vova Feldman (@svovaf)
9814
+ * @since 1.0.5
9815
+ *
9816
+ * @return bool
9817
+ */
9818
+ function _has_premium_license() {
9819
+ $this->_logger->entrance();
9820
+
9821
+ $premium_license = $this->_get_available_premium_license();
9822
+
9823
+ return ( false !== $premium_license );
9824
+ }
9825
+
9826
+ /**
9827
+ * Check if user has any licenses associated with the plugin (including expired or blocking).
9828
+ *
9829
+ * @author Vova Feldman (@svovaf)
9830
+ * @since 1.1.7.3
9831
+ *
9832
+ * @return bool
9833
+ */
9834
+ function has_any_license() {
9835
+ return is_array( $this->_licenses ) && ( 0 < count( $this->_licenses ) );
9836
+ }
9837
+
9838
+ /**
9839
+ * @author Vova Feldman (@svovaf)
9840
+ * @since 1.0.5
9841
+ *
9842
+ * @param bool|null $is_localhost
9843
+ *
9844
+ * @return FS_Plugin_License|false
9845
+ */
9846
+ function _get_available_premium_license( $is_localhost = null ) {
9847
+ $this->_logger->entrance();
9848
+
9849
+ $licenses = $this->get_available_premium_licenses( $is_localhost );
9850
+ if ( ! empty( $licenses ) ) {
9851
+ return $licenses[0];
9852
+ }
9853
+
9854
+ return false;
9855
+ }
9856
+
9857
+ /**
9858
+ * @author Vova Feldman (@svovaf)
9859
+ * @since 1.0.5
9860
+ *
9861
+ * @param bool|null $is_localhost
9862
+ *
9863
+ * @return FS_Plugin_License[]
9864
+ */
9865
+ function get_available_premium_licenses( $is_localhost = null ) {
9866
+ $this->_logger->entrance();
9867
+
9868
+ $licenses = array();
9869
+ if ( ! $this->has_paid_plan() ) {
9870
+ return $licenses;
9871
+ }
9872
+
9873
+ if ( is_array( $this->_licenses ) ) {
9874
+ foreach ( $this->_licenses as $license ) {
9875
+ if ( ! $license->can_activate( $is_localhost ) ) {
9876
+ continue;
9877
+ }
9878
+
9879
+ $licenses[] = $license;
9880
+ }
9881
+ }
9882
+
9883
+ return $licenses;
9884
+ }
9885
+
9886
+ /**
9887
+ * Sync local plugin plans with remote server.
9888
+ *
9889
+ * 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).
9890
+ *
9891
+ * @author Vova Feldman (@svovaf)
9892
+ * @since 1.0.5
9893
+ *
9894
+ * @return FS_Plugin_Plan[]|object
9895
+ */
9896
+ function _sync_plans() {
9897
+ $plans = $this->_fetch_plugin_plans();
9898
+
9899
+ if ( $this->is_array_instanceof( $plans, 'FS_Plugin_Plan' ) ) {
9900
+ $plans_map = array();
9901
+ foreach ( $plans as $plan ) {
9902
+ $plans_map[ $plan->id ] = true;
9903
+ }
9904
+
9905
+ $plans_ids_to_keep = $this->get_plans_ids_associated_with_installs();
9906
+
9907
+ foreach ( $plans_ids_to_keep as $plan_id ) {
9908
+ if ( isset( $plans_map[ $plan_id ] ) ) {
9909
+ continue;
9910
+ }
9911
+
9912
+ $missing_plan = self::_get_plan_by_id( $plan_id );
9913
+
9914
+ if ( is_object( $missing_plan ) ) {
9915
+ $plans[] = $missing_plan;
9916
+ }
9917
+ }
9918
+
9919
+ $this->_plans = $plans;
9920
+ $this->_store_plans();
9921
+ }
9922
+
9923
+ $this->do_action( 'after_plans_sync', $plans );
9924
+
9925
+ return $this->_plans;
9926
+ }
9927
+
9928
+ /**
9929
+ * Check if specified plan exists locally. If not, fetch it and store it.
9930
+ *
9931
+ * @author Vova Feldman (@svovaf)
9932
+ * @since 2.0.0
9933
+ *
9934
+ * @param number $plan_id
9935
+ *
9936
+ * @return \FS_Plugin_Plan|object The plan entity or the API error object on failure.
9937
+ */
9938
+ private function sync_plan_if_not_exist( $plan_id ) {
9939
+ $plan = self::_get_plan_by_id( $plan_id );
9940
+
9941
+ if ( is_object( $plan ) ) {
9942
+ // Plan already exists.
9943
+ return $plan;
9944
+ }
9945
+
9946
+ $plan = $this->fetch_plan_by_id( $plan_id );
9947
+
9948
+ if ( $plan instanceof FS_Plugin_Plan ) {
9949
+ $this->_plans[] = $plan;
9950
+ $this->_store_plans();
9951
+
9952
+ return $plan;
9953
+ }
9954
+
9955
+ return $plan;
9956
+ }
9957
+
9958
+ /**
9959
+ * Check if specified license exists locally. If not, fetch it and store it.
9960
+ *
9961
+ * @author Vova Feldman (@svovaf)
9962
+ * @since 2.0.0
9963
+ *
9964
+ * @param number $license_id
9965
+ * @param string $license_key
9966
+ *
9967
+ * @return \FS_Plugin_Plan|object The plan entity or the API error object on failure.
9968
+ */
9969
+ private function sync_license_if_not_exist( $license_id, $license_key ) {
9970
+ $license = $this->_get_license_by_id( $license_id );
9971
+
9972
+ if ( is_object( $license ) ) {
9973
+ // License already exists.
9974
+ return $license;
9975
+ }
9976
+
9977
+ $license = $this->fetch_license_by_key( $license_id, $license_key );
9978
+
9979
+ if ( $license instanceof FS_Plugin_License ) {
9980
+ $this->_licenses[] = $license;
9981
+ $this->_license = $license;
9982
+ $this->_store_licenses();
9983
+
9984
+ return $license;
9985
+ }
9986
+
9987
+ return $license;
9988
+ }
9989
+
9990
+ /**
9991
+ * Get a collection of unique plan IDs that are associated with any installs in the network.
9992
+ *
9993
+ * @author Leo Fajardo (@leorw)
9994
+ * @since 2.0.0
9995
+ *
9996
+ * @return number[]
9997
+ */
9998
+ private function get_plans_ids_associated_with_installs() {
9999
+ if ( ! $this->_is_network_active ) {
10000
+ if ( ! is_object( $this->_site ) ||
10001
+ ! FS_Plugin_Plan::is_valid_id( $this->_site->plan_id )
10002
+ ) {
10003
+ return array();
10004
+ }
10005
+
10006
+ return array( $this->_site->plan_id );
10007
+ }
10008
+
10009
+ $plan_ids = array();
10010
+ $sites = self::get_sites();
10011
+ foreach ( $sites as $site ) {
10012
+ $blog_id = self::get_site_blog_id( $site );
10013
+ $install = $this->get_install_by_blog_id( $blog_id );
10014
+
10015
+ if ( ! is_object( $install ) ||
10016
+ ! FS_Plugin_Plan::is_valid_id( $install->plan_id )
10017
+ ) {
10018
+ continue;
10019
+ }
10020
+
10021
+ $plan_ids[ $install->plan_id ] = true;
10022
+ }
10023
+
10024
+ return array_keys( $plan_ids );
10025
+ }
10026
+
10027
+ /**
10028
+ * Get a collection of unique license IDs that are associated with any installs in the network.
10029
+ *
10030
+ * @author Leo Fajardo (@leorw)
10031
+ * @since 2.0.0
10032
+ *
10033
+ * @return number[]
10034
+ */
10035
+ private function get_license_ids_associated_with_installs() {
10036
+ if ( ! $this->_is_network_active ) {
10037
+ if ( ! is_object( $this->_site ) ||
10038
+ ! FS_Plugin_License::is_valid_id( $this->_site->license_id )
10039
+ ) {
10040
+ return array();
10041
+ }
10042
+
10043
+ return array( $this->_site->license_id );
10044
+ }
10045
+
10046
+ $license_ids = array();
10047
+ $sites = self::get_sites();
10048
+ foreach ( $sites as $site ) {
10049
+ $blog_id = self::get_site_blog_id( $site );
10050
+ $install = $this->get_install_by_blog_id( $blog_id );
10051
+
10052
+ if ( ! is_object( $install ) ||
10053
+ ! FS_Plugin_License::is_valid_id( $install->license_id )
10054
+ ) {
10055
+ continue;
10056
+ }
10057
+
10058
+ $license_ids[ $install->license_id ] = true;
10059
+ }
10060
+
10061
+ return array_keys( $license_ids );
10062
+ }
10063
+
10064
+ /**
10065
+ * @author Vova Feldman (@svovaf)
10066
+ * @since 1.0.5
10067
+ *
10068
+ * @param number $id
10069
+ *
10070
+ * @return FS_Plugin_Plan|false
10071
+ */
10072
+ function _get_plan_by_id( $id ) {
10073
+ $this->_logger->entrance();
10074
+
10075
+ if ( ! is_array( $this->_plans ) || 0 === count( $this->_plans ) ) {
10076
+ $this->_sync_plans();
10077
+ }
10078
+
10079
+ foreach ( $this->_plans as $plan ) {
10080
+ if ( $id == $plan->id ) {
10081
+ return $plan;
10082
+ }
10083
+ }
10084
+
10085
+ return false;
10086
+ }
10087
+
10088
+ /**
10089
+ * @author Vova Feldman (@svovaf)
10090
+ * @since 1.1.8.1
10091
+ *
10092
+ * @param string $name
10093
+ *
10094
+ * @return FS_Plugin_Plan|false
10095
+ */
10096
+ private function get_plan_by_name( $name ) {
10097
+ $this->_logger->entrance();
10098
+
10099
+ if ( ! is_array( $this->_plans ) || 0 === count( $this->_plans ) ) {
10100
+ $this->_sync_plans();
10101
+ }
10102
+
10103
+ foreach ( $this->_plans as $plan ) {
10104
+ if ( $name == $plan->name ) {
10105
+ return $plan;
10106
+ }
10107
+ }
10108
+
10109
+ return false;
10110
+ }
10111
+
10112
+ /**
10113
+ * Sync local licenses with remote server.
10114
+ *
10115
+ * @author Vova Feldman (@svovaf)
10116
+ * @since 1.0.6
10117
+ *
10118
+ * @param number|bool $site_license_id
10119
+ * @param number|null $blog_id
10120
+ *
10121
+ * @return FS_Plugin_License[]|object
10122
+ */
10123
+ function _sync_licenses( $site_license_id = false, $blog_id = null ) {
10124
+ $this->_logger->entrance();
10125
+
10126
+ $is_network_admin = fs_is_network_admin();
10127
+
10128
+ if ( $is_network_admin && is_null( $blog_id ) ) {
10129
+ $all_licenses = self::get_all_licenses( $this->_module_id );
10130
+ } else {
10131
+ $all_licenses = $this->get_user_licenses( $this->_user->id );
10132
+ }
10133
+
10134
+ $foreign_licenses = array(
10135
+ 'ids' => array(),
10136
+ 'license_keys' => array()
10137
+ );
10138
+
10139
+ $all_licenses_map = array();
10140
+ foreach ( $all_licenses as $license ) {
10141
+ $all_licenses_map[ $license->id ] = true;
10142
+ if ( $license->user_id == $this->_user->id || $license->id == $site_license_id ) {
10143
+ continue;
10144
+ }
10145
+
10146
+ $foreign_licenses['ids'][] = $license->id;
10147
+ $foreign_licenses['license_keys'][] = $license->secret_key;
10148
+ }
10149
+
10150
+ if ( empty( $foreign_licenses['ids'] ) ) {
10151
+ $foreign_licenses = array();
10152
+ }
10153
+
10154
+ $licenses = $this->_fetch_licenses( false, $site_license_id, $foreign_licenses, $blog_id );
10155
+
10156
+ if ( $this->is_array_instanceof( $licenses, 'FS_Plugin_License' ) ) {
10157
+ $licenses_map = array();
10158
+ foreach ( $licenses as $license ) {
10159
+ $licenses_map[ $license->id ] = true;
10160
+ }
10161
+
10162
+ // $license_ids_to_keep = $this->get_license_ids_associated_with_installs();
10163
+ // foreach ( $license_ids_to_keep as $license_id ) {
10164
+ // if ( isset( $licenses_map[ $license_id ] ) ) {
10165
+ // continue;
10166
+ // }
10167
+ //
10168
+ // $missing_license = self::_get_license_by_id( $license_id, false );
10169
+ // if ( is_object( $missing_license ) ) {
10170
+ // $licenses[] = $missing_license;
10171
+ // $licenses_map[ $missing_license->id ] = true;
10172
+ // }
10173
+ // }
10174
+
10175
+ $user_license_ids = $this->get_user_linked_license_ids( $this->_user->id );
10176
+
10177
+ foreach ( $user_license_ids as $key => $license_id ) {
10178
+ if ( ! isset( $licenses_map[ $license_id ] ) ) {
10179
+ // Remove access to licenses that no longer exist.
10180
+ unset( $user_license_ids[ $key ] );
10181
+ }
10182
+ }
10183
+
10184
+ if ( ! empty( $user_license_ids ) ) {
10185
+ foreach ( $licenses_map as $license_id => $value ) {
10186
+ if ( ! isset( $all_licenses_map[ $license_id ] ) ) {
10187
+ // Associate new licenses with the user who triggered the license syncing.
10188
+ $user_license_ids[] = $license_id;
10189
+ }
10190
+ }
10191
+
10192
+ $user_license_ids = array_unique( $user_license_ids );
10193
+ } else {
10194
+ $user_license_ids = array_keys( $licenses_map );
10195
+ }
10196
+
10197
+ if ( ! $is_network_admin || ! is_null( $blog_id ) ) {
10198
+ $user_licenses = array();
10199
+ foreach ( $licenses as $license ) {
10200
+ if ( ! in_array( $license->id, $user_license_ids ) ) {
10201
+ continue;
10202
+ }
10203
+
10204
+ $user_licenses[] = $license;
10205
+ }
10206
+
10207
+ $this->_licenses = $user_licenses;
10208
+ } else {
10209
+ $this->_licenses = $licenses;
10210
+ }
10211
+
10212
+ $this->set_user_linked_license_ids( $this->_user->id, $user_license_ids );
10213
+
10214
+ $this->_store_licenses( true, $this->_module_id, $licenses );
10215
+ }
10216
+
10217
+ // Update current license.
10218
+ if ( is_object( $this->_license ) ) {
10219
+ $this->_license = $this->_get_license_by_id( $this->_license->id );
10220
+ }
10221
+
10222
+ return $this->_licenses;
10223
+ }
10224
+
10225
+ /**
10226
+ * @author Vova Feldman (@svovaf)
10227
+ * @since 1.0.5
10228
+ *
10229
+ * @param number $id
10230
+ * @param bool $sync_licenses
10231
+ *
10232
+ * @return FS_Plugin_License|false
10233
+ */
10234
+ function _get_license_by_id( $id, $sync_licenses = true ) {
10235
+ $this->_logger->entrance();
10236
+
10237
+ if ( ! FS_Plugin_License::is_valid_id( $id ) ) {
10238
+ return false;
10239
+ }
10240
+
10241
+ /**
10242
+ * When running from the network level admin and opted-in from the network,
10243
+ * check if the license exists in the network user licenses collection.
10244
+ *
10245
+ * @author Vova Feldman (@svovaf)
10246
+ * @since 2.0.0
10247
+ */
10248
+ if ( fs_is_network_admin() &&
10249
+ $this->is_network_registered() &&
10250
+ ( ! is_object( $this->_user ) || $this->_storage->network_user_id != $this->_user->id )
10251
+ ) {
10252
+ $licenses = $this->get_user_licenses( $this->_storage->network_user_id );
10253
+
10254
+ foreach ( $licenses as $license ) {
10255
+ if ( $id == $license->id ) {
10256
+ return $license;
10257
+ }
10258
+ }
10259
+ }
10260
+
10261
+ if ( ! $this->has_any_license() && $sync_licenses ) {
10262
+ $this->_sync_licenses( $id );
10263
+ }
10264
+
10265
+ if ( is_array( $this->_licenses ) ) {
10266
+ foreach ( $this->_licenses as $license ) {
10267
+ if ( $id == $license->id ) {
10268
+ return $license;
10269
+ }
10270
+ }
10271
+ }
10272
+
10273
+ return false;
10274
+ }
10275
+
10276
+ /**
10277
+ * 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.
10278
+ *
10279
+ * @author Vova Feldman (@svovaf)
10280
+ * @since 2.0.0
10281
+ *
10282
+ * @param number $id
10283
+ *
10284
+ * @return FS_Plugin_License
10285
+ */
10286
+ private function get_license_by_id( $id ) {
10287
+ $licenses = self::get_all_licenses( $this->_module_id );
10288
+
10289
+ if ( is_array( $licenses ) && ! empty( $licenses ) ) {
10290
+ foreach ( $licenses as $license ) {
10291
+ if ( $id == $license->id ) {
10292
+ return $license;
10293
+ }
10294
+ }
10295
+ }
10296
+
10297
+ return null;
10298
+ }
10299
+
10300
+ /**
10301
+ * Synchronize the site's context license by fetching the license form the API and updating the local data with it.
10302
+ *
10303
+ * @author Vova Feldman (@svovaf)
10304
+ * @since 2.0.0
10305
+ *
10306
+ * @return \FS_Plugin_License|mixed
10307
+ */
10308
+ private function sync_site_license() {
10309
+ $api = $this->get_api_user_scope();
10310
+
10311
+ $result = $api->get( "/licenses/{$this->_license->id}.json?license_key=" . urlencode( $this->_license->secret_key ), true );
10312
+
10313
+ if ( ! $this->is_api_result_entity( $result ) ) {
10314
+ return $result;
10315
+ }
10316
+
10317
+ $license = $this->_update_site_license( new FS_Plugin_License( $result ) );
10318
+ $this->_store_licenses();
10319
+
10320
+ return $license;
10321
+ }
10322
+
10323
+ /**
10324
+ * Get all user's available licenses for the current module.
10325
+ *
10326
+ * @author Vova Feldman (@svovaf)
10327
+ * @since 2.0.0
10328
+ *
10329
+ * @param number $user_id
10330
+ *
10331
+ * @return FS_Plugin_License[]
10332
+ */
10333
+ private function get_user_licenses( $user_id ) {
10334
+ $all_licenses = self::get_all_licenses( $this->_module_id );
10335
+ if ( empty( $all_licenses ) ) {
10336
+ return array();
10337
+ }
10338
+
10339
+ $user_license_ids = $this->get_user_linked_license_ids( $user_id );
10340
+ if ( empty( $user_license_ids ) ) {
10341
+ return array();
10342
+ }
10343
+
10344
+ $licenses = array();
10345
+ foreach ( $all_licenses as $license ) {
10346
+ if ( in_array( $license->id, $user_license_ids ) ) {
10347
+ $licenses[] = $license;
10348
+ }
10349
+ }
10350
+
10351
+ return $licenses;
10352
+ }
10353
+
10354
+ /**
10355
+ * Checks if the context license is network activated except on the given blog ID.
10356
+ *
10357
+ * @author Vova Feldman (@svovaf)
10358
+ * @since 2.0.0
10359
+ *
10360
+ * @param int $except_blog_id
10361
+ *
10362
+ * @return bool
10363
+ */
10364
+ private function is_license_network_active( $except_blog_id = 0 ) {
10365
+ $this->_logger->entrance();
10366
+
10367
+ if ( ! is_object( $this->_license ) ) {
10368
+ return false;
10369
+ }
10370
+
10371
+ $sites = self::get_sites();
10372
+
10373
+ if ( $this->_license->total_activations() < ( count( $sites ) - 1 ) ) {
10374
+ // There are more sites than the number of activations, so license cannot be network activated.
10375
+ return false;
10376
+ }
10377
+
10378
+ foreach ( $sites as $site ) {
10379
+ $blog_id = self::get_site_blog_id( $site );
10380
+
10381
+ if ( $except_blog_id == $blog_id ) {
10382
+ // Skip excluded blog.
10383
+ continue;
10384
+ }
10385
+
10386
+ $install = $this->get_install_by_blog_id( $blog_id );
10387
+
10388
+ if ( is_object( $install ) && $install->license_id != $this->_license->id ) {
10389
+ return false;
10390
+ }
10391
+ }
10392
+
10393
+ return true;
10394
+ }
10395
+
10396
+ /**
10397
+ * 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.
10398
+ *
10399
+ * Notice: On success, this method will also update the license activations counters (without updating the license in the storage).
10400
+ *
10401
+ * @author Vova Feldman (@svovaf)
10402
+ * @since 2.0.0
10403
+ *
10404
+ * @param \FS_User $user
10405
+ * @param \FS_Plugin_License $license
10406
+ *
10407
+ * @return bool
10408
+ */
10409
+ private function try_activate_license_on_network( FS_User $user, FS_Plugin_License $license ) {
10410
+ $this->_logger->entrance();
10411
+
10412
+ $result = $this->can_activate_license_on_network( $license );
10413
+
10414
+ if ( false === $result ) {
10415
+ return false;
10416
+ }
10417
+
10418
+ $installs_without_license = $result['installs'];
10419
+ if ( ! empty( $installs_without_license ) ) {
10420
+ $this->activate_license_on_many_installs( $user, $license->secret_key, $installs_without_license );
10421
+ }
10422
+
10423
+ $disconnected_site_ids = $result['sites'];
10424
+ if ( ! empty( $disconnected_site_ids ) ) {
10425
+ $this->activate_license_on_many_sites( $user, $license->secret_key, $disconnected_site_ids );
10426
+ }
10427
+
10428
+ $this->link_license_2_user( $license->id, $user->id );
10429
+
10430
+ // Sync license after activations.
10431
+ $license->activated += $result['production_count'];
10432
+ $license->activated_local += $result['localhost_count'];
10433
+
10434
+ // $this->_store_licenses()
10435
+
10436
+ return true;
10437
+ }
10438
+
10439
+ /**
10440
+ * Checks if the given license can be activated on the whole network.
10441
+ *
10442
+ * @author Vova Feldman (@svovaf)
10443
+ * @since 2.0.0
10444
+ *
10445
+ * @param \FS_Plugin_License $license
10446
+ *
10447
+ * @return false|array {
10448
+ * @type array[int]FS_Site $installs Blog ID to install map.
10449
+ * @type int[] $sites Non-connected blog IDs.
10450
+ * @type int $production_count Production sites count.
10451
+ * @type int $localhost_count Production sites count.
10452
+ * }
10453
+ */
10454
+ private function can_activate_license_on_network( FS_Plugin_License $license ) {
10455
+ $sites = self::get_sites();
10456
+
10457
+ $production_count = 0;
10458
+ $localhost_count = 0;
10459
+
10460
+ $installs_without_license = array();
10461
+ $disconnected_site_ids = array();
10462
+
10463
+ foreach ( $sites as $site ) {
10464
+ $blog_id = self::get_site_blog_id( $site );
10465
+ $install = $this->get_install_by_blog_id( $blog_id );
10466
+
10467
+ if ( is_object( $install ) ) {
10468
+ if ( FS_Plugin_License::is_valid_id( $install->license_id ) ) {
10469
+ // License already activated on the install.
10470
+ continue;
10471
+ }
10472
+
10473
+ $url = $install->url;
10474
+
10475
+ $installs_without_license[ $blog_id ] = $install;
10476
+ } else {
10477
+ $url = is_object( $site ) ?
10478
+ $site->siteurl :
10479
+ get_site_url( $blog_id );
10480
+
10481
+ $disconnected_site_ids[] = $blog_id;
10482
+ }
10483
+
10484
+ if ( FS_Site::is_localhost_by_address( $url ) ) {
10485
+ $localhost_count ++;
10486
+ } else {
10487
+ $production_count ++;
10488
+ }
10489
+ }
10490
+
10491
+ if ( ! $license->can_activate_bulk( $production_count, $localhost_count ) ) {
10492
+ return false;
10493
+ }
10494
+
10495
+ return array(
10496
+ 'installs' => $installs_without_license,
10497
+ 'sites' => $disconnected_site_ids,
10498
+ 'production_count' => $production_count,
10499
+ 'localhost_count' => $localhost_count,
10500
+ );
10501
+ }
10502
+
10503
+ /**
10504
+ * Activate a given license on a collection of installs.
10505
+ *
10506
+ * @author Vova Feldman (@svovaf)
10507
+ * @since 2.0.0
10508
+ *
10509
+ * @param \FS_User $user
10510
+ * @param string $license_key
10511
+ * @param array $blog_2_install_map {
10512
+ * @key int Blog ID.
10513
+ * @value FS_Site Blog's associated install.
10514
+ * }
10515
+ *
10516
+ * @return mixed|true
10517
+ */
10518
+ private function activate_license_on_many_installs(
10519
+ FS_User $user,
10520
+ $license_key,
10521
+ array $blog_2_install_map
10522
+ ) {
10523
+ $params = array(
10524
+ array( 'license_key' => $this->apply_filters( 'license_key', $license_key ) )
10525
+ );
10526
+
10527
+ $install_2_blog_map = array();
10528
+ foreach ( $blog_2_install_map as $blog_id => $install ) {
10529
+ $params[] = array( 'id' => $install->id );
10530
+
10531
+ $install_2_blog_map[ $install->id ] = $blog_id;
10532
+ }
10533
+
10534
+ $result = $this->get_api_user_scope_by_user( $user )->call(
10535
+ "plugins/{$this->_plugin->id}/installs.json",
10536
+ 'PUT',
10537
+ $params
10538
+ );
10539
+
10540
+ if ( ! $this->is_api_result_object( $result, 'installs' ) ) {
10541
+ return $result;
10542
+ }
10543
+
10544
+ foreach ( $result->installs as $r_install ) {
10545
+ $install = new FS_Site( $r_install );
10546
+ $install->is_disconnected = false;
10547
+
10548
+ // Update install.
10549
+ $this->_store_site(
10550
+ true,
10551
+ $install_2_blog_map[ $r_install->id ],
10552
+ $install
10553
+ );
10554
+ }
10555
+
10556
+ return true;
10557
+ }
10558
+
10559
+ /**
10560
+ * Activate a given license on a collection of blogs/sites that are not yet opted-in.
10561
+ *
10562
+ * @author Vova Feldman (@svovaf)
10563
+ * @since 2.0.0
10564
+ *
10565
+ * @param \FS_User $user
10566
+ * @param string $license_key
10567
+ * @param int[] $site_ids
10568
+ *
10569
+ * @return true|mixed True if successful, otherwise, the API result.
10570
+ */
10571
+ private function activate_license_on_many_sites(
10572
+ FS_User $user,
10573
+ $license_key,
10574
+ array $site_ids
10575
+ ) {
10576
+ $sites = array();
10577
+ foreach ( $site_ids as $site_id ) {
10578
+ $sites[] = $this->get_site_info( array( 'blog_id' => $site_id ) );
10579
+ }
10580
+
10581
+ // Install the plugin.
10582
+ $result = $this->create_installs_with_user(
10583
+ $user,
10584
+ $license_key,
10585
+ false,
10586
+ $sites,
10587
+ false,
10588
+ true
10589
+ );
10590
+
10591
+ if ( ! $this->is_api_result_entity( $result ) &&
10592
+ ! $this->is_api_result_object( $result, 'installs' )
10593
+ ) {
10594
+ return $result;
10595
+ }
10596
+
10597
+ $installs = array();
10598
+ foreach ( $result->installs as $install ) {
10599
+ $installs[] = new FS_Site( $install );
10600
+ }
10601
+
10602
+ // Map site addresses to their blog IDs.
10603
+ $address_to_blog_map = $this->get_address_to_blog_map();
10604
+
10605
+ $first_blog_id = null;
10606
+
10607
+ foreach ( $installs as $install ) {
10608
+ $address = trailingslashit( fs_strip_url_protocol( $install->url ) );
10609
+ $blog_id = $address_to_blog_map[ $address ];
10610
+
10611
+ $this->_store_site( true, $blog_id, $install );
10612
+
10613
+ $this->reset_anonymous_mode( $blog_id );
10614
+
10615
+ if ( is_null( $first_blog_id ) ) {
10616
+ $first_blog_id = $blog_id;
10617
+ }
10618
+ }
10619
+
10620
+ if ( ! FS_Site::is_valid_id( $this->_storage->network_install_blog_id ) ) {
10621
+ $this->_storage->network_install_blog_id = $first_blog_id;
10622
+ }
10623
+
10624
+ return true;
10625
+ }
10626
+
10627
+ /**
10628
+ * Sync site's license with user licenses.
10629
+ *
10630
+ * @author Vova Feldman (@svovaf)
10631
+ * @since 1.0.6
10632
+ *
10633
+ * @param FS_Plugin_License|null $new_license
10634
+ *
10635
+ * @return FS_Plugin_License|null
10636
+ */
10637
+ function _update_site_license( $new_license ) {
10638
+ $this->_logger->entrance();
10639
+
10640
+ $this->_license = $new_license;
10641
+
10642
+ if ( ! is_object( $new_license ) ) {
10643
+ $this->_site->license_id = null;
10644
+ $this->_sync_site_subscription( null );
10645
+
10646
+ return $this->_license;
10647
+ }
10648
+
10649
+ $this->_site->license_id = $this->_license->id;
10650
+
10651
+ if ( ! is_array( $this->_licenses ) ) {
10652
+ $this->_licenses = array();
10653
+ }
10654
+
10655
+ $is_license_found = false;
10656
+ for ( $i = 0, $len = count( $this->_licenses ); $i < $len; $i ++ ) {
10657
+ if ( $new_license->id == $this->_licenses[ $i ]->id ) {
10658
+ $this->_licenses[ $i ] = $new_license;
10659
+
10660
+ $is_license_found = true;
10661
+ break;
10662
+ }
10663
+ }
10664
+
10665
+ // If new license just append.
10666
+ if ( ! $is_license_found ) {
10667
+ $this->_licenses[] = $new_license;
10668
+ }
10669
+
10670
+ $this->_sync_site_subscription( $new_license );
10671
+
10672
+ return $this->_license;
10673
+ }
10674
+
10675
+ /**
10676
+ * Sync site's subscription.
10677
+ *
10678
+ * @author Vova Feldman (@svovaf)
10679
+ * @since 1.0.9
10680
+ *
10681
+ * @param FS_Plugin_License|null $license
10682
+ *
10683
+ * @return bool|\FS_Subscription
10684
+ */
10685
+ private function _sync_site_subscription( $license ) {
10686
+ if ( ! is_object( $license ) ) {
10687
+ $this->delete_unused_subscriptions();
10688
+
10689
+ return false;
10690
+ }
10691
+
10692
+ // Load subscription details if not lifetime.
10693
+ $subscription = $license->is_lifetime() ?
10694
+ false :
10695
+ $this->_fetch_site_license_subscription();
10696
+
10697
+ if ( is_object( $subscription ) && ! isset( $subscription->error ) ) {
10698
+ $this->store_subscription( $subscription );
10699
+ } else {
10700
+ $this->delete_unused_subscriptions();
10701
+ }
10702
+
10703
+ return $subscription;
10704
+ }
10705
+
10706
+ /**
10707
+ * @author Vova Feldman (@svovaf)
10708
+ * @since 1.0.6
10709
+ *
10710
+ * @return bool|\FS_Plugin_License
10711
+ */
10712
+ function _get_license() {
10713
+ if ( ! fs_is_network_admin() || is_object( $this->_license ) ) {
10714
+ return $this->_license;
10715
+ }
10716
+
10717
+ return $this->_get_available_premium_license();
10718
+ }
10719
+
10720
+ /**
10721
+ * @param number $license_id
10722
+ *
10723
+ * @return null|\FS_Subscription
10724
+ */
10725
+ function _get_subscription( $license_id ) {
10726
+ if ( ! isset( $this->_storage->subscriptions ) ||
10727
+ empty( $this->_storage->subscriptions )
10728
+ ) {
10729
+ return null;
10730
+ }
10731
+
10732
+ foreach ( $this->_storage->subscriptions as $subscription ) {
10733
+ if ( $subscription->license_id == $license_id ) {
10734
+ return $subscription;
10735
+ }
10736
+ }
10737
+
10738
+ return null;
10739
+ }
10740
+
10741
+ /**
10742
+ * @author Leo Fajardo (@leorw)
10743
+ * @since 2.0.0
10744
+ *
10745
+ * @param FS_Subscription $subscription
10746
+ */
10747
+ function store_subscription( FS_Subscription $subscription ) {
10748
+ if ( ! isset( $this->_storage->subscriptions ) ) {
10749
+ $this->_storage->subscriptions = array();
10750
+ }
10751
+
10752
+ if ( empty( $this->_storage->subscriptions ) || ! is_multisite() ) {
10753
+ $this->_storage->subscriptions = array( $subscription );
10754
+
10755
+ return;
10756
+ }
10757
+
10758
+ $subscriptions = $this->_storage->subscriptions;
10759
+
10760
+ $updated_subscription = false;
10761
+ foreach ( $subscriptions as $key => $existing_subscription ) {
10762
+ if ( $existing_subscription->id == $subscription->id ) {
10763
+ $subscriptions[ $key ] = $subscription;
10764
+ $updated_subscription = true;
10765
+ break;
10766
+ }
10767
+ }
10768
+
10769
+ if ( ! $updated_subscription ) {
10770
+ $subscriptions[] = $subscription;
10771
+ }
10772
+
10773
+ $this->_storage->subscriptions = $subscriptions;
10774
+ }
10775
+
10776
+ /**
10777
+ * @author Leo Fajardo (@leorw)
10778
+ * @since 2.0.0
10779
+ */
10780
+ function delete_unused_subscriptions() {
10781
+ if ( ! isset( $this->_storage->subscriptions ) ||
10782
+ empty( $this->_storage->subscriptions ) ||
10783
+ // Clean up only if there are already at least 3 subscriptions.
10784
+ ( count( $this->_storage->subscriptions ) < 3 )
10785
+ ) {
10786
+ return;
10787
+ }
10788
+
10789
+ if ( ! is_multisite() ) {
10790
+ // If not multisite, there should only be 1 subscription, so just clear the array.
10791
+ $this->_storage->subscriptions = array();
10792
+
10793
+ return;
10794
+ }
10795
+
10796
+ $subscriptions_to_keep_by_license_id_map = array();
10797
+ $sites = self::get_sites();
10798
+ foreach ( $sites as $site ) {
10799
+ $blog_id = self::get_site_blog_id( $site );
10800
+ $install = $this->get_install_by_blog_id( $blog_id );
10801
+
10802
+ if ( ! is_object( $install ) ||
10803
+ ! FS_Plugin_License::is_valid_id( $install->license_id )
10804
+ ) {
10805
+ continue;
10806
+ }
10807
+
10808
+ $subscriptions_to_keep_by_license_id_map[ $install->license_id ] = true;
10809
+ }
10810
+
10811
+ if ( empty( $subscriptions_to_keep_by_license_id_map ) ) {
10812
+ $this->_storage->subscriptions = array();
10813
+
10814
+ return;
10815
+ }
10816
+
10817
+ foreach ( $this->_storage->subscriptions as $key => $subscription ) {
10818
+ if ( ! isset( $subscriptions_to_keep_by_license_id_map[ $subscription->license_id ] ) ) {
10819
+ unset( $this->_storage->subscriptions[ $key ] );
10820
+ }
10821
+ }
10822
+ }
10823
+
10824
+ /**
10825
+ * @author Vova Feldman (@svovaf)
10826
+ * @since 1.0.2
10827
+ *
10828
+ * @param string $plan Plan name
10829
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
10830
+ *
10831
+ * @return bool
10832
+ */
10833
+ function is_plan( $plan, $exact = false ) {
10834
+ $this->_logger->entrance();
10835
+
10836
+ if ( ! $this->is_registered() ) {
10837
+ return false;
10838
+ }
10839
+
10840
+ $plan = strtolower( $plan );
10841
+
10842
+ $current_plan_name = $this->get_plan_name();
10843
+
10844
+ if ( $current_plan_name === $plan ) {
10845
+ // Exact plan.
10846
+ return true;
10847
+ } else if ( $exact ) {
10848
+ // Required exact, but plans are different.
10849
+ return false;
10850
+ }
10851
+
10852
+ $current_plan_order = - 1;
10853
+ $required_plan_order = - 1;
10854
+ for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
10855
+ if ( $plan === $this->_plans[ $i ]->name ) {
10856
+ $required_plan_order = $i;
10857
+ } else if ( $current_plan_name === $this->_plans[ $i ]->name ) {
10858
+ $current_plan_order = $i;
10859
+ }
10860
+ }
10861
+
10862
+ return ( $current_plan_order > $required_plan_order );
10863
+ }
10864
+
10865
+ /**
10866
+ * Check if module has only one plan.
10867
+ *
10868
+ * @author Vova Feldman (@svovaf)
10869
+ * @since 1.2.1.7
10870
+ *
10871
+ * @return bool
10872
+ */
10873
+ function is_single_plan() {
10874
+ $this->_logger->entrance();
10875
+
10876
+ if ( ! $this->is_registered() ||
10877
+ ! is_array( $this->_plans ) ||
10878
+ 0 === count( $this->_plans )
10879
+ ) {
10880
+ return true;
10881
+ }
10882
+
10883
+ return ( 1 === count( $this->_plans ) );
10884
+ }
10885
+
10886
+ /**
10887
+ * Check if plan based on trial. If not in trial mode, should return false.
10888
+ *
10889
+ * @since 1.0.9
10890
+ *
10891
+ * @param string $plan Plan name
10892
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
10893
+ *
10894
+ * @return bool
10895
+ */
10896
+ function is_trial_plan( $plan, $exact = false ) {
10897
+ $this->_logger->entrance();
10898
+
10899
+ if ( ! $this->is_registered() ) {
10900
+ return false;
10901
+ }
10902
+
10903
+ if ( ! $this->is_trial() ) {
10904
+ return false;
10905
+ }
10906
+
10907
+ $trial_plan = $this->get_trial_plan();
10908
+
10909
+ if ( $trial_plan->name === $plan ) {
10910
+ // Exact plan.
10911
+ return true;
10912
+ } else if ( $exact ) {
10913
+ // Required exact, but plans are different.
10914
+ return false;
10915
+ }
10916
+
10917
+ $current_plan_order = - 1;
10918
+ $required_plan_order = - 1;
10919
+ for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
10920
+ if ( $plan === $this->_plans[ $i ]->name ) {
10921
+ $required_plan_order = $i;
10922
+ } else if ( $trial_plan->name === $this->_plans[ $i ]->name ) {
10923
+ $current_plan_order = $i;
10924
+ }
10925
+ }
10926
+
10927
+ return ( $current_plan_order > $required_plan_order );
10928
+ }
10929
+
10930
+ /**
10931
+ * Check if plugin has any paid plans.
10932
+ *
10933
+ * @author Vova Feldman (@svovaf)
10934
+ * @since 1.0.7
10935
+ *
10936
+ * @return bool
10937
+ */
10938
+ function has_paid_plan() {
10939
+ return $this->_has_paid_plans ||
10940
+ FS_Plan_Manager::instance()->has_paid_plan( $this->_plans );
10941
+ }
10942
+
10943
+ /**
10944
+ * Check if plugin has any plan with a trail.
10945
+ *
10946
+ * @author Vova Feldman (@svovaf)
10947
+ * @since 1.0.9
10948
+ *
10949
+ * @return bool
10950
+ */
10951
+ function has_trial_plan() {
10952
+ /**
10953
+ * @author Vova Feldman(@svovaf)
10954
+ * @since 1.2.1.5
10955
+ *
10956
+ * Allow setting a trial from the SDK without calling the API.
10957
+ * But, if the user did opt-in, continue using the real data from the API.
10958
+ */
10959
+ if ( $this->_trial_days >= 0 ) {
10960
+ return true;
10961
+ }
10962
+
10963
+ return $this->_storage->get( 'has_trial_plan', false );
10964
+ }
10965
+
10966
+ /**
10967
+ * Check if plugin has any free plan, or is it premium only.
10968
+ *
10969
+ * Note: If no plans configured, assume plugin is free.
10970
+ *
10971
+ * @author Vova Feldman (@svovaf)
10972
+ * @since 1.0.7
10973
+ *
10974
+ * @return bool
10975
+ */
10976
+ function has_free_plan() {
10977
+ return ! $this->is_only_premium();
10978
+ }
10979
+
10980
+ /**
10981
+ * Displays a license activation dialog box when the user clicks on the "Activate License"
10982
+ * or "Change License" link on the plugins
10983
+ * page.
10984
+ *
10985
+ * @author Leo Fajardo (@leorw)
10986
+ * @since 1.1.9
10987
+ */
10988
+ function _add_license_activation_dialog_box() {
10989
+ $vars = array(
10990
+ 'id' => $this->_module_id,
10991
+ );
10992
+
10993
+ fs_require_template( 'forms/license-activation.php', $vars );
10994
+ fs_require_template( 'forms/resend-key.php', $vars );
10995
+ }
10996
+
10997
+ /**
10998
+ * Displays a subscription cancellation dialog box when the user clicks on the "Deactivate License"
10999
+ * link on the "Account" page or deactivates a plugin and there's an active subscription that is
11000
+ * either associated with a non-lifetime single-site license or non-lifetime multisite license that
11001
+ * is only activated on a single production site.
11002
+ *
11003
+ * @author Leo Fajardo (@leorw)
11004
+ * @since 2.2.1
11005
+ *
11006
+ * @param bool $is_license_deactivation
11007
+ */
11008
+ function _maybe_add_subscription_cancellation_dialog_box( $is_license_deactivation = false ) {
11009
+ if ( fs_is_network_admin() ) {
11010
+ // Subscription cancellation dialog box is currently not supported for multisite networks.
11011
+ return;
11012
+ }
11013
+
11014
+ $license = $this->_get_license();
11015
+
11016
+ /**
11017
+ * 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.
11018
+ *
11019
+ * @author Leo Fajardo (@leorw) (Comment added by Vova Feldman @svovaf)
11020
+ * @since 2.2.1
11021
+ */
11022
+ if ( ! is_object( $license ) ||
11023
+ $license->is_lifetime() ||
11024
+ ( ! $license->is_single_site() && $license->activated > 1 )
11025
+ ) {
11026
+ return;
11027
+ }
11028
+
11029
+ /**
11030
+ * @var FS_Subscription $subscription
11031
+ */
11032
+ $subscription = $this->_get_subscription( $license->id );
11033
+ if ( ! is_object( $subscription ) || ! $subscription->is_active() ) {
11034
+ return;
11035
+ }
11036
+
11037
+ $vars = array(
11038
+ 'id' => $this->_module_id,
11039
+ 'license' => $license,
11040
+ 'has_trial' => $this->is_paid_trial(),
11041
+ 'is_license_deactivation' => $is_license_deactivation,
11042
+ );
11043
+
11044
+ fs_require_template( 'forms/subscription-cancellation.php', $vars );
11045
+ }
11046
+
11047
+ /**
11048
+ * @author Leo Fajardo (@leorw)
11049
+ * @since 2.0.2
11050
+ */
11051
+ function _add_premium_version_upgrade_selection_dialog_box() {
11052
+ $modules_update = get_site_transient( $this->is_theme() ? 'update_themes' : 'update_plugins' );
11053
+ if ( ! isset( $modules_update->response[ $this->_plugin_basename ] ) ) {
11054
+ return;
11055
+ }
11056
+
11057
+ $vars = array(
11058
+ 'id' => $this->_module_id,
11059
+ 'new_version' => is_object( $modules_update->response[ $this->_plugin_basename ] ) ?
11060
+ $modules_update->response[ $this->_plugin_basename ]->new_version :
11061
+ $modules_update->response[ $this->_plugin_basename ]['new_version']
11062
+ );
11063
+
11064
+ fs_require_template( 'forms/premium-versions-upgrade-metadata.php', $vars );
11065
+ fs_require_once_template( 'forms/premium-versions-upgrade-handler.php', $vars );
11066
+ }
11067
+
11068
+ /**
11069
+ * Displays the opt-out dialog box when the user clicks on the "Opt Out" link on the "Plugins"
11070
+ * page.
11071
+ *
11072
+ * @author Leo Fajardo (@leorw)
11073
+ * @since 1.2.1.5
11074
+ */
11075
+ function _add_optout_dialog() {
11076
+ if ( $this->is_theme() ) {
11077
+ $vars = null;
11078
+ fs_require_once_template( '/js/jquery.content-change.php', $vars );
11079
+ }
11080
+
11081
+ $vars = array( 'id' => $this->_module_id );
11082
+ fs_require_template( 'forms/optout.php', $vars );
11083
+ }
11084
+
11085
+ /**
11086
+ * Prepare page to include all required UI and logic for the license activation dialog.
11087
+ *
11088
+ * @author Vova Feldman (@svovaf)
11089
+ * @since 1.2.0
11090
+ */
11091
+ function _add_license_activation() {
11092
+ if ( ! $this->is_user_admin() ) {
11093
+ // Only admins can activate a license.
11094
+ return;
11095
+ }
11096
+
11097
+ if ( ! $this->has_paid_plan() ) {
11098
+ // Module doesn't have any paid plans.
11099
+ return;
11100
+ }
11101
+
11102
+ if ( ! $this->is_premium() ) {
11103
+ // Only add license activation logic to the premium version.
11104
+ return;
11105
+ }
11106
+
11107
+ // Add license activation link and AJAX request handler.
11108
+ if ( self::is_plugins_page() ) {
11109
+ /**
11110
+ * @since 1.2.0 Add license action link only on plugins page.
11111
+ */
11112
+ $this->_add_license_action_link();
11113
+ }
11114
+
11115
+ // Add license activation AJAX callback.
11116
+ $this->add_ajax_action( 'activate_license', array( &$this, '_activate_license_ajax_action' ) );
11117
+
11118
+ // Add resend license AJAX callback.
11119
+ $this->add_ajax_action( 'resend_license_key', array( &$this, '_resend_license_key_ajax_action' ) );
11120
+ }
11121
+
11122
+ /**
11123
+ * @author Leo Fajardo (@leorw)
11124
+ * @since 2.0.2
11125
+ */
11126
+ function _add_premium_version_upgrade_selection() {
11127
+ if ( ! $this->is_user_admin() ) {
11128
+ return;
11129
+ }
11130
+
11131
+ if ( ! $this->is_premium() || $this->has_any_active_valid_license() ) {
11132
+ // This is relevant only to the free versions and premium versions without an active license.
11133
+ return;
11134
+ }
11135
+
11136
+ if ( self::is_updates_page() || ( $this->is_plugin() && self::is_plugins_page() ) ) {
11137
+ $this->_add_premium_version_upgrade_selection_action();
11138
+ }
11139
+ }
11140
+
11141
+ /**
11142
+ * @author Leo Fajardo (@leorw)
11143
+ *
11144
+ * @since 1.1.9
11145
+ * @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).
11146
+ */
11147
+ function _activate_license_ajax_action() {
11148
+ $this->_logger->entrance();
11149
+
11150
+ $this->check_ajax_referer( 'activate_license' );
11151
+
11152
+ $license_key = trim( fs_request_get( 'license_key' ) );
11153
+
11154
+ if ( empty( $license_key ) ) {
11155
+ exit;
11156
+ }
11157
+
11158
+ $plugin_id = fs_request_get( 'module_id', '', 'post' );
11159
+ $fs = ( $plugin_id == $this->_module_id ) ?
11160
+ $this :
11161
+ $this->get_addon_instance( $plugin_id );
11162
+
11163
+ $error = false;
11164
+ $next_page = false;
11165
+
11166
+ $sites = fs_is_network_admin() ?
11167
+ fs_request_get( 'sites', array(), 'post' ) :
11168
+ array();
11169
+
11170
+ $blog_id = fs_request_get( 'blog_id' );
11171
+ $has_valid_blog_id = is_numeric( $blog_id );
11172
+
11173
+ if ( $fs->is_registered() ) {
11174
+ if ( fs_is_network_admin() && ! $has_valid_blog_id ) {
11175
+ // If no specific blog ID was provided, activate the license for all sites in the network.
11176
+ $blog_2_install_map = array();
11177
+ $site_ids = array();
11178
+
11179
+ foreach ( $sites as $site ) {
11180
+ if ( ! isset( $site['blog_id'] ) || ! is_numeric( $site['blog_id'] ) ) {
11181
+ continue;
11182
+ }
11183
+
11184
+ $install = $this->get_install_by_blog_id( $site['blog_id'] );
11185
+
11186
+ if ( is_object( $install ) ) {
11187
+ $blog_2_install_map[ $site['blog_id'] ] = $install;
11188
+ } else {
11189
+ $site_ids[] = $site['blog_id'];
11190
+ }
11191
+ }
11192
+
11193
+ $user = $this->get_current_or_network_user();
11194
+
11195
+ if ( ! empty( $blog_2_install_map ) ) {
11196
+ $result = $this->activate_license_on_many_installs( $user, $license_key, $blog_2_install_map );
11197
+
11198
+ if ( true !== $result ) {
11199
+ $error = FS_Api::is_api_error_object( $result ) ?
11200
+ $result->error->message :
11201
+ var_export( $result, true );
11202
+ }
11203
+ }
11204
+
11205
+ if ( empty( $error ) && ! empty( $site_ids ) ) {
11206
+ $result = $this->activate_license_on_many_sites( $user, $license_key, $site_ids );
11207
+
11208
+ if ( true !== $result ) {
11209
+ $error = FS_Api::is_api_error_object( $result ) ?
11210
+ $result->error->message :
11211
+ var_export( $result, true );
11212
+ }
11213
+ }
11214
+ } else {
11215
+ if ( $has_valid_blog_id ) {
11216
+ /**
11217
+ * If a specific blog ID was provided, activate the license only for the install that is
11218
+ * associated with the given blog ID.
11219
+ *
11220
+ * @author Leo Fajardo (@leorw)
11221
+ */
11222
+ $this->switch_to_blog( $blog_id );
11223
+ }
11224
+
11225
+ $api = $fs->get_api_site_scope();
11226
+
11227
+ $params = array(
11228
+ 'license_key' => $fs->apply_filters( 'license_key', $license_key )
11229
+ );
11230
+
11231
+ $install = $api->call( $fs->add_show_pending( '/' ), 'put', $params );
11232
+
11233
+ if ( FS_Api::is_api_error( $install ) ) {
11234
+ $error = FS_Api::is_api_error_object( $install ) ?
11235
+ $install->error->message :
11236
+ var_export( $install->error, true );
11237
+ } else {
11238
+ $fs->reconnect_locally( $has_valid_blog_id );
11239
+ }
11240
+ }
11241
+
11242
+ if ( empty( $error ) ) {
11243
+ $this->network_upgrade_mode_completed();
11244
+
11245
+ $fs->_sync_license( true, $has_valid_blog_id );
11246
+
11247
+ $next_page = $fs->is_addon() ?
11248
+ $fs->get_parent_instance()->get_account_url() :
11249
+ $fs->get_account_url();
11250
+ }
11251
+ } else {
11252
+ $next_page = $fs->opt_in(
11253
+ false,
11254
+ false,
11255
+ false,
11256
+ $license_key,
11257
+ false,
11258
+ false,
11259
+ false,
11260
+ fs_request_get_bool( 'is_marketing_allowed', null ),
11261
+ $sites
11262
+ );
11263
+
11264
+ if ( isset( $next_page->error ) ) {
11265
+ $error = $next_page->error;
11266
+ } else {
11267
+ if ( fs_is_network_admin() ) {
11268
+ /**
11269
+ * Get the list of sites that were just opted-in (and license activated).
11270
+ * This is an optimization for the next part below saving some DB queries.
11271
+ */
11272
+ $connected_sites = array();
11273
+ foreach ( $sites as $site ) {
11274
+ if ( isset( $site['blog_id'] ) && is_numeric( $site['blog_id'] ) ) {
11275
+ $connected_sites[ $site['blog_id'] ] = true;
11276
+ }
11277
+ }
11278
+
11279
+ $all_sites = self::get_sites();
11280
+ $pending_sites = array();
11281
+
11282
+ /**
11283
+ * 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.
11284
+ *
11285
+ * @author Vova Feldman (@svovaf)
11286
+ */
11287
+ foreach ( $all_sites as $site ) {
11288
+ $blog_id = self::get_site_blog_id( $site );
11289
+
11290
+ if ( isset( $connected_sites[ $blog_id ] ) ) {
11291
+ // Site was just connected.
11292
+ continue;
11293
+ }
11294
+
11295
+ if ( $this->is_installed_on_site( $blog_id ) ) {
11296
+ // Site was already connected before.
11297
+ continue;
11298
+ }
11299
+
11300
+ if ( $this->is_site_delegated_connection( $blog_id ) ) {
11301
+ // Site's connection was delegated.
11302
+ continue;
11303
+ }
11304
+
11305
+ if ( $this->is_anonymous_site( $blog_id ) ) {
11306
+ // Site connection was already skipped.
11307
+ continue;
11308
+ }
11309
+
11310
+ $pending_sites[] = self::get_site_info( $site );
11311
+ }
11312
+
11313
+ if ( ! empty( $pending_sites ) ) {
11314
+ if ( $this->is_freemium() ) {
11315
+ $this->skip_connection( $pending_sites );
11316
+ } else {
11317
+ $this->delegate_connection( $pending_sites );
11318
+ }
11319
+ }
11320
+ }
11321
+ }
11322
+ }
11323
+
11324
+ if ( false === $error && true === $this->_storage->require_license_activation ) {
11325
+ $this->_storage->require_license_activation = false;
11326
+ }
11327
+
11328
+ $result = array(
11329
+ 'success' => ( false === $error )
11330
+ );
11331
+
11332
+ if ( false !== $error ) {
11333
+ $result['error'] = $error;
11334
+ } else {
11335
+ $result['next_page'] = $next_page;
11336
+ }
11337
+
11338
+ echo json_encode( $result );
11339
+
11340
+ exit;
11341
+ }
11342
+
11343
+ /**
11344
+ * @author Leo Fajardo (@leorw)
11345
+ * @since 1.2.3.1
11346
+ */
11347
+ function _network_activate_ajax_action() {
11348
+ $this->_logger->entrance();
11349
+
11350
+ $this->check_ajax_referer( 'network_activate' );
11351
+
11352
+ $plugin_id = fs_request_get( 'module_id', '', 'post' );
11353
+ $fs = ( $plugin_id == $this->_module_id ) ?
11354
+ $this :
11355
+ $this->get_addon_instance( $plugin_id );
11356
+
11357
+ $error = false;
11358
+
11359
+ $sites = fs_request_get( 'sites', array(), 'post' );
11360
+ if ( is_array( $sites ) && ! empty( $sites ) ) {
11361
+ $sites_by_action = array(
11362
+ 'allow' => array(),
11363
+ 'delegate' => array(),
11364
+ 'skip' => array()
11365
+ );
11366
+
11367
+ foreach ( $sites as $site ) {
11368
+ $sites_by_action[ $site['action'] ][] = $site;
11369
+ }
11370
+
11371
+ $total_sites = count( $sites );
11372
+ $total_sites_to_delegate = count( $sites_by_action['delegate'] );
11373
+
11374
+ $next_page = '';
11375
+ if ( $total_sites === $total_sites_to_delegate &&
11376
+ ! $this->is_network_upgrade_mode()
11377
+ ) {
11378
+ $this->delegate_connection();
11379
+ } else {
11380
+ if ( ! empty( $sites_by_action['delegate'] ) ) {
11381
+ $this->delegate_connection( $sites_by_action['delegate'] );
11382
+ }
11383
+
11384
+ if ( ! empty( $sites_by_action['skip'] ) ) {
11385
+ $this->skip_connection( $sites_by_action['skip'] );
11386
+ }
11387
+
11388
+ if ( ! empty( $sites_by_action['allow'] ) ) {
11389
+ if ( ! $fs->is_registered() || ! $this->_is_network_active ) {
11390
+ $next_page = $fs->opt_in(
11391
+ false,
11392
+ false,
11393
+ false,
11394
+ false,
11395
+ false,
11396
+ false,
11397
+ false,
11398
+ fs_request_get_bool( 'is_marketing_allowed', null ),
11399
+ $sites_by_action['allow']
11400
+ );
11401
+ } else {
11402
+ $next_page = $fs->install_with_user(
11403
+ $this->get_network_user(),
11404
+ false,
11405
+ false,
11406
+ false,
11407
+ true,
11408
+ $sites_by_action['allow']
11409
+ );
11410
+ }
11411
+
11412
+ if ( is_object( $next_page ) && isset( $next_page->error ) ) {
11413
+ $error = $next_page->error;
11414
+ }
11415
+ }
11416
+ }
11417
+
11418
+ if ( empty( $next_page ) ) {
11419
+ $next_page = $this->get_after_activation_url( 'after_network_activation_url' );
11420
+ }
11421
+ } else {
11422
+ $error = $this->get_text_inline( 'Invalid site details collection.', 'invalid_site_details_collection' );
11423
+ }
11424
+
11425
+ $result = array(
11426
+ 'success' => ( false === $error )
11427
+ );
11428
+
11429
+ if ( false !== $error ) {
11430
+ $result['error'] = $error;
11431
+ } else {
11432
+ $result['next_page'] = $next_page;
11433
+ }
11434
+
11435
+ echo json_encode( $result );
11436
+
11437
+ exit;
11438
+ }
11439
+
11440
+ /**
11441
+ * Billing update AJAX callback.
11442
+ *
11443
+ * @author Vova Feldman (@svovaf)
11444
+ * @since 1.2.1.5
11445
+ */
11446
+ function _update_billing_ajax_action() {
11447
+ $this->_logger->entrance();
11448
+
11449
+ $this->check_ajax_referer( 'update_billing' );
11450
+
11451
+ if ( ! $this->is_user_admin() ) {
11452
+ // Only for admins.
11453
+ self::shoot_ajax_failure();
11454
+ }
11455
+
11456
+ $billing = fs_request_get( 'billing' );
11457
+
11458
+ $api = $this->get_api_user_scope();
11459
+ $result = $api->call( '/billing.json', 'put', array_merge( $billing, array(
11460
+ 'plugin_id' => $this->get_parent_id(),
11461
+ ) ) );
11462
+
11463
+ if ( ! $this->is_api_result_entity( $result ) ) {
11464
+ self::shoot_ajax_failure();
11465
+ }
11466
+
11467
+ // Purge cached billing.
11468
+ $this->get_api_user_scope()->purge_cache( 'billing.json' );
11469
+
11470
+ self::shoot_ajax_success();
11471
+ }
11472
+
11473
+ /**
11474
+ * Trial start for anonymous users (AJAX callback).
11475
+ *
11476
+ * @author Vova Feldman (@svovaf)
11477
+ * @since 1.2.1.5
11478
+ */
11479
+ function _start_trial_ajax_action() {
11480
+ $this->_logger->entrance();
11481
+
11482
+ $this->check_ajax_referer( 'start_trial' );
11483
+
11484
+ if ( ! $this->is_user_admin() ) {
11485
+ // Only for admins.
11486
+ self::shoot_ajax_failure();
11487
+ }
11488
+
11489
+ $trial_data = fs_request_get( 'trial' );
11490
+
11491
+ $next_page = $this->opt_in(
11492
+ false,
11493
+ false,
11494
+ false,
11495
+ false,
11496
+ false,
11497
+ $trial_data['plan_id']
11498
+ );
11499
+
11500
+ if ( is_object( $next_page ) && $this->is_api_error( $next_page ) ) {
11501
+ self::shoot_ajax_failure(
11502
+ isset( $next_page->error ) ?
11503
+ $next_page->error->message :
11504
+ var_export( $next_page, true )
11505
+ );
11506
+ }
11507
+
11508
+ $this->shoot_ajax_success( array(
11509
+ 'next_page' => $next_page,
11510
+ ) );
11511
+ }
11512
+
11513
+ /**
11514
+ * @author Leo Fajardo (@leorw)
11515
+ * @since 1.2.0
11516
+ */
11517
+ function _resend_license_key_ajax_action() {
11518
+ $this->_logger->entrance();
11519
+
11520
+ $this->check_ajax_referer( 'resend_license_key' );
11521
+
11522
+ $email_address = sanitize_email( trim( fs_request_get( 'email', '', 'post' ) ) );
11523
+
11524
+ if ( empty( $email_address ) ) {
11525
+ exit;
11526
+ }
11527
+
11528
+ $error = false;
11529
+
11530
+ $api = $this->get_api_plugin_scope();
11531
+ $result = $api->call( '/licenses/resend.json', 'post',
11532
+ array(
11533
+ 'email' => $email_address,
11534
+ 'url' => home_url(),
11535
+ )
11536
+ );
11537
+
11538
+ if ( is_object( $result ) && isset( $result->error ) ) {
11539
+ $error = $result->error;
11540
+
11541
+ if ( in_array( $error->code, array( 'invalid_email', 'no_user' ) ) ) {
11542
+ $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' );
11543
+ } else if ( 'no_license' === $error->code ) {
11544
+ $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' );
11545
+ } else {
11546
+ $error = $error->message;
11547
+ }
11548
+ }
11549
+
11550
+ $licenses = array(
11551
+ 'success' => ( false === $error )
11552
+ );
11553
+
11554
+ if ( false !== $error ) {
11555
+ $licenses['error'] = sprintf( '%s... %s', $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ), strtolower( $error ) );
11556
+ }
11557
+
11558
+ echo json_encode( $licenses );
11559
+
11560
+ exit;
11561
+ }
11562
+
11563
+ /**
11564
+ * @author Vova Feldman (@svovaf)
11565
+ * @since 1.2.1.8
11566
+ *
11567
+ * @var string
11568
+ */
11569
+ private static $_pagenow;
11570
+
11571
+ /**
11572
+ * Get current page or the referer if executing a WP AJAX request.
11573
+ *
11574
+ * @author Vova Feldman (@svovaf)
11575
+ * @since 1.2.1.8
11576
+ *
11577
+ * @return string
11578
+ */
11579
+ static function get_current_page() {
11580
+ if ( ! isset( self::$_pagenow ) ) {
11581
+ global $pagenow;
11582
+ if ( empty( $pagenow ) && is_admin() && is_multisite() ) {
11583
+ /**
11584
+ * It appears that `$pagenow` is not yet initialized in some network admin pages when this method
11585
+ * is called, so initialize it here using some pieces of code from `wp-includes/vars.php`.
11586
+ *
11587
+ * @author Leo Fajardo (@leorw)
11588
+ * @since 2.2.3
11589
+ */
11590
+ if ( is_network_admin() ) {
11591
+ preg_match( '#/wp-admin/network/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches );
11592
+ } else if ( is_user_admin() ) {
11593
+ preg_match( '#/wp-admin/user/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches );
11594
+ } else {
11595
+ preg_match( '#/wp-admin/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches );
11596
+ }
11597
+
11598
+ $pagenow = $self_matches[1];
11599
+ $pagenow = trim( $pagenow, '/' );
11600
+ $pagenow = preg_replace( '#\?.*?$#', '', $pagenow );
11601
+ if ( '' === $pagenow || 'index' === $pagenow || 'index.php' === $pagenow ) {
11602
+ $pagenow = 'index.php';
11603
+ } else {
11604
+ preg_match( '#(.*?)(/|$)#', $pagenow, $self_matches );
11605
+ $pagenow = strtolower( $self_matches[1] );
11606
+ if ( '.php' !== substr($pagenow, -4, 4) )
11607
+ $pagenow .= '.php'; // for Options +Multiviews: /wp-admin/themes/index.php (themes.php is queried)
11608
+ }
11609
+ }
11610
+
11611
+ self::$_pagenow = $pagenow;
11612
+
11613
+ if ( self::is_ajax() &&
11614
+ 'admin-ajax.php' === $pagenow
11615
+ ) {
11616
+ $referer = fs_get_raw_referer();
11617
+
11618
+ if ( is_string( $referer ) ) {
11619
+ $parts = explode( '?', $referer );
11620
+
11621
+ self::$_pagenow = basename( $parts[0] );
11622
+ }
11623
+ }
11624
+ }
11625
+
11626
+ return self::$_pagenow;
11627
+ }
11628
+
11629
+ /**
11630
+ * Helper method to check if user in the plugins page.
11631
+ *
11632
+ * @author Vova Feldman (@svovaf)
11633
+ * @since 1.2.1.5
11634
+ *
11635
+ * @return bool
11636
+ */
11637
+ static function is_plugins_page() {
11638
+ return ( 'plugins.php' === self::get_current_page() );
11639
+ }
11640
+
11641
+ /**
11642
+ * @author Leo Fajardo (@leorw)
11643
+ * @since 2.2.3
11644
+ *
11645
+ * @return bool
11646
+ */
11647
+ static function is_plugin_install_page() {
11648
+ return ( 'plugin-install.php' === self::get_current_page() );
11649
+ }
11650
+
11651
+ /**
11652
+ * @author Leo Fajardo (@leorw)
11653
+ * @since 2.0.2
11654
+ *
11655
+ * @return bool
11656
+ */
11657
+ static function is_updates_page() {
11658
+ return ( 'update-core.php' === self::get_current_page() );
11659
+ }
11660
+
11661
+ /**
11662
+ * Helper method to check if user in the themes page.
11663
+ *
11664
+ * @author Vova Feldman (@svovaf)
11665
+ * @since 1.2.2.6
11666
+ *
11667
+ * @return bool
11668
+ */
11669
+ static function is_themes_page() {
11670
+ return ( 'themes.php' === self::get_current_page() );
11671
+ }
11672
+
11673
+ #----------------------------------------------------------------------------------
11674
+ #region Affiliation
11675
+ #----------------------------------------------------------------------------------
11676
+
11677
+ /**
11678
+ * @author Leo Fajardo (@leorw)
11679
+ * @since 1.2.3
11680
+ *
11681
+ * @return bool
11682
+ */
11683
+ function has_affiliate_program() {
11684
+ if ( ! is_object( $this->_plugin ) ) {
11685
+ return false;
11686
+ }
11687
+
11688
+ return $this->_plugin->has_affiliate_program();
11689
+ }
11690
+
11691
+ /**
11692
+ * @author Leo Fajardo (@leorw)
11693
+ * @since 1.2.4
11694
+ */
11695
+ private function fetch_affiliate_terms() {
11696
+ if ( ! is_object( $this->plugin_affiliate_terms ) ) {
11697
+ $plugins_api = $this->get_api_plugin_scope();
11698
+ $affiliate_terms = $plugins_api->get( '/aff.json?type=affiliation', false );
11699
+
11700
+ if ( ! $this->is_api_result_entity( $affiliate_terms ) ) {
11701
+ return;
11702
+ }
11703
+
11704
+ $this->plugin_affiliate_terms = new FS_AffiliateTerms( $affiliate_terms );
11705
+ }
11706
+ }
11707
+
11708
+ /**
11709
+ * @author Leo Fajardo (@leorw)
11710
+ * @since 1.2.4
11711
+ */
11712
+ private function fetch_affiliate_and_custom_terms() {
11713
+ if ( ! empty( $this->_storage->affiliate_application_data ) ) {
11714
+ $application_data = $this->_storage->affiliate_application_data;
11715
+ $flush = ( ! isset( $application_data['status'] ) || 'pending' === $application_data['status'] );
11716
+
11717
+ $users_api = $this->get_api_user_scope();
11718
+ $result = $users_api->get( "/plugins/{$this->_plugin->id}/aff/{$this->plugin_affiliate_terms->id}/affiliates.json", $flush );
11719
+ if ( $this->is_api_result_object( $result, 'affiliates' ) ) {
11720
+ if ( ! empty( $result->affiliates ) ) {
11721
+ $affiliate = new FS_Affiliate( $result->affiliates[0] );
11722
+
11723
+ if ( ! isset( $application_data['status'] ) || $application_data['status'] !== $affiliate->status ) {
11724
+ $application_data['status'] = $affiliate->status;
11725
+ $this->_storage->affiliate_application_data = $application_data;
11726
+ }
11727
+
11728
+ if ( $affiliate->is_using_custom_terms ) {
11729
+ $affiliate_terms = $users_api->get( "/plugins/{$this->_plugin->id}/affiliates/{$affiliate->id}/aff/{$affiliate->custom_affiliate_terms_id}.json", $flush );
11730
+ if ( $this->is_api_result_entity( $affiliate_terms ) ) {
11731
+ $this->custom_affiliate_terms = new FS_AffiliateTerms( $affiliate_terms );
11732
+ }
11733
+ }
11734
+
11735
+ $this->affiliate = $affiliate;
11736
+ }
11737
+ }
11738
+ }
11739
+ }
11740
+
11741
+ /**
11742
+ * @author Leo Fajardo (@leorw)
11743
+ * @since 1.2.3
11744
+ */
11745
+ private function fetch_affiliate_and_terms() {
11746
+ $this->_logger->entrance();
11747
+
11748
+ $this->fetch_affiliate_terms();
11749
+ $this->fetch_affiliate_and_custom_terms();
11750
+ }
11751
+
11752
+ /**
11753
+ * @author Leo Fajardo (@leorw)
11754
+ * @since 1.2.3
11755
+ *
11756
+ * @return FS_Affiliate
11757
+ */
11758
+ function get_affiliate() {
11759
+ return $this->affiliate;
11760
+ }
11761
+
11762
+
11763
+ /**
11764
+ * @author Leo Fajardo (@leorw)
11765
+ * @since 1.2.3
11766
+ *
11767
+ * @return FS_AffiliateTerms
11768
+ */
11769
+ function get_affiliate_terms() {
11770
+ return is_object( $this->custom_affiliate_terms ) ?
11771
+ $this->custom_affiliate_terms :
11772
+ $this->plugin_affiliate_terms;
11773
+ }
11774
+
11775
+ /**
11776
+ * @author Leo Fajardo (@leorw)
11777
+ * @since 1.2.3
11778
+ */
11779
+ function _submit_affiliate_application() {
11780
+ $this->_logger->entrance();
11781
+
11782
+ $this->check_ajax_referer( 'submit_affiliate_application' );
11783
+
11784
+ if ( ! $this->is_user_admin() ) {
11785
+ // Only for admins.
11786
+ self::shoot_ajax_failure();
11787
+ }
11788
+
11789
+ $affiliate = fs_request_get( 'affiliate' );
11790
+
11791
+ if ( empty( $affiliate['promotion_methods'] ) ) {
11792
+ unset( $affiliate['promotion_methods'] );
11793
+ }
11794
+
11795
+ if ( ! empty( $affiliate['additional_domains'] ) ) {
11796
+ $affiliate['additional_domains'] = array_unique( $affiliate['additional_domains'] );
11797
+ }
11798
+
11799
+ if ( ! $this->is_registered() ) {
11800
+ // Opt in but don't track usage.
11801
+ $next_page = $this->opt_in(
11802
+ false,
11803
+ false,
11804
+ false,
11805
+ false,
11806
+ false,
11807
+ false,
11808
+ true
11809
+ );
11810
+
11811
+ if ( is_object( $next_page ) && $this->is_api_error( $next_page ) ) {
11812
+ self::shoot_ajax_failure(
11813
+ isset( $next_page->error ) ?
11814
+ $next_page->error->message :
11815
+ var_export( $next_page, true )
11816
+ );
11817
+ } else if ( $this->is_pending_activation() ) {
11818
+ self::shoot_ajax_failure( $this->get_text_inline( 'Account is pending activation.', 'account-is-pending-activation' ) );
11819
+ }
11820
+ }
11821
+
11822
+ $this->fetch_affiliate_terms();
11823
+
11824
+ $api = $this->get_api_user_scope();
11825
+ $result = $api->call(
11826
+ ( "/plugins/{$this->_plugin->id}/aff/{$this->plugin_affiliate_terms->id}/affiliates.json" ),
11827
+ 'post',
11828
+ $affiliate
11829
+ );
11830
+
11831
+ if ( $this->is_api_error( $result ) ) {
11832
+ self::shoot_ajax_failure(
11833
+ isset( $result->error ) ?
11834
+ $result->error->message :
11835
+ var_export( $result, true )
11836
+ );
11837
+ } else {
11838
+ if ( $this->_admin_notices->has_sticky( 'affiliate_program' ) ) {
11839
+ $this->_admin_notices->remove_sticky( 'affiliate_program' );
11840
+ }
11841
+
11842
+ $affiliate_application_data = array(
11843
+ 'status' => 'pending',
11844
+ 'stats_description' => $affiliate['stats_description'],
11845
+ 'promotion_method_description' => $affiliate['promotion_method_description'],
11846
+ );
11847
+
11848
+ if ( ! empty( $affiliate['promotion_methods'] ) ) {
11849
+ $affiliate_application_data['promotion_methods'] = $affiliate['promotion_methods'];
11850
+ }
11851
+
11852
+ if ( ! empty( $affiliate['domain'] ) ) {
11853
+ $affiliate_application_data['domain'] = $affiliate['domain'];
11854
+ }
11855
+
11856
+ if ( ! empty( $affiliate['additional_domains'] ) ) {
11857
+ $affiliate_application_data['additional_domains'] = $affiliate['additional_domains'];
11858
+ }
11859
+
11860
+ $this->_storage->affiliate_application_data = $affiliate_application_data;
11861
+ }
11862
+
11863
+ // Purge cached affiliate.
11864
+ $api->purge_cache( 'affiliate.json' );
11865
+
11866
+ self::shoot_ajax_success( $result );
11867
+ }
11868
+
11869
+ /**
11870
+ * @author Leo Fajardo (@leorw)
11871
+ * @since 1.2.3
11872
+ *
11873
+ * @return array|null
11874
+ */
11875
+ function get_affiliate_application_data() {
11876
+ if ( empty( $this->_storage->affiliate_application_data ) ) {
11877
+ return null;
11878
+ }
11879
+
11880
+ return $this->_storage->affiliate_application_data;
11881
+ }
11882
+
11883
+ #endregion Affiliation ------------------------------------------------------------
11884
+
11885
+ #----------------------------------------------------------------------------------
11886
+ #region URL Generators
11887
+ #----------------------------------------------------------------------------------
11888
+
11889
+ /**
11890
+ * Alias to pricing_url().
11891
+ *
11892
+ * @author Vova Feldman (@svovaf)
11893
+ * @since 1.0.2
11894
+ *
11895
+ * @uses pricing_url()
11896
+ *
11897
+ * @param string $period Billing cycle
11898
+ * @param bool $is_trial
11899
+ *
11900
+ * @return string
11901
+ */
11902
+ function get_upgrade_url( $period = WP_FS__PERIOD_ANNUALLY, $is_trial = false ) {
11903
+ return $this->pricing_url( $period, $is_trial );
11904
+ }
11905
+
11906
+ /**
11907
+ * @author Vova Feldman (@svovaf)
11908
+ * @since 1.0.9
11909
+ *
11910
+ * @uses get_upgrade_url()
11911
+ *
11912
+ * @return string
11913
+ */
11914
+ function get_trial_url() {
11915
+ return $this->get_upgrade_url( WP_FS__PERIOD_ANNUALLY, true );
11916
+ }
11917
+
11918
+ /**
11919
+ * @author Leo Fajardo (@leorw)
11920
+ * @since 2.1.4
11921
+ *
11922
+ * @param string $new_version
11923
+ *
11924
+ * @return string
11925
+ */
11926
+ function version_upgrade_checkout_link( $new_version ) {
11927
+ if ( ! is_object( $this->_license ) ) {
11928
+ $url = $this->pricing_url();
11929
+
11930
+ $purchase_license_text = $this->get_text_inline( 'Buy a license now', 'buy-license-now' );
11931
+ } else {
11932
+ $subscription = $this->_get_subscription( $this->_license->id );
11933
+
11934
+ $url = $this->checkout_url(
11935
+ is_object( $subscription ) ?
11936
+ ( 1 == $subscription->billing_cycle ? WP_FS__PERIOD_MONTHLY : WP_FS__PERIOD_ANNUALLY ) :
11937
+ WP_FS__PERIOD_LIFETIME,
11938
+ false,
11939
+ array( 'licenses' => $this->_license->quota )
11940
+ );
11941
+
11942
+ $purchase_license_text = $this->get_text_inline( 'Renew your license now', 'renew-license-now' );
11943
+ }
11944
+
11945
+ return sprintf(
11946
+ $this->get_text_inline( '%s to access version %s security & feature updates, and support.', 'x-for-updates-and-support' ),
11947
+ sprintf( '<a href="%s">%s</a>', $url, $purchase_license_text ),
11948
+ $new_version
11949
+ );
11950
+ }
11951
+
11952
+ /**
11953
+ * Plugin's pricing URL.
11954
+ *
11955
+ * @author Vova Feldman (@svovaf)
11956
+ * @since 1.0.4
11957
+ *
11958
+ * @param string $billing_cycle Billing cycle
11959
+ *
11960
+ * @param bool $is_trial
11961
+ *
11962
+ * @return string
11963
+ */
11964
+ function pricing_url( $billing_cycle = WP_FS__PERIOD_ANNUALLY, $is_trial = false ) {
11965
+ $this->_logger->entrance();
11966
+
11967
+ $params = array(
11968
+ 'billing_cycle' => $billing_cycle
11969
+ );
11970
+
11971
+ if ( $is_trial ) {
11972
+ $params['trial'] = 'true';
11973
+ }
11974
+
11975
+ if ( $this->is_addon() ) {
11976
+ return $this->_parent->addon_url( $this->_slug );
11977
+ }
11978
+
11979
+ return $this->_get_admin_page_url( 'pricing', $params );
11980
+ }
11981
+
11982
+ /**
11983
+ * Checkout page URL.
11984
+ *
11985
+ * @author Vova Feldman (@svovaf)
11986
+ * @since 1.0.6
11987
+ *
11988
+ * @param string $billing_cycle Billing cycle
11989
+ * @param bool $is_trial
11990
+ * @param array $extra (optional) Extra parameters, override other query params.
11991
+ *
11992
+ * @return string
11993
+ */
11994
+ function checkout_url(
11995
+ $billing_cycle = WP_FS__PERIOD_ANNUALLY,
11996
+ $is_trial = false,
11997
+ $extra = array()
11998
+ ) {
11999
+ $this->_logger->entrance();
12000
+
12001
+ $params = array(
12002
+ 'checkout' => 'true',
12003
+ 'billing_cycle' => $billing_cycle,
12004
+ );
12005
+
12006
+ if ( $is_trial ) {
12007
+ $params['trial'] = 'true';
12008
+ }
12009
+
12010
+ /**
12011
+ * Params in extra override other params.
12012
+ */
12013
+ $params = array_merge( $params, $extra );
12014
+
12015
+ return $this->_get_admin_page_url( 'pricing', $params );
12016
+ }
12017
+
12018
+ /**
12019
+ * Add-on checkout URL.
12020
+ *
12021
+ * @author Vova Feldman (@svovaf)
12022
+ * @since 1.1.7
12023
+ *
12024
+ * @param number $addon_id
12025
+ * @param number $pricing_id
12026
+ * @param string $billing_cycle
12027
+ * @param bool $is_trial
12028
+ *
12029
+ * @return string
12030
+ */
12031
+ function addon_checkout_url(
12032
+ $addon_id,
12033
+ $pricing_id,
12034
+ $billing_cycle = WP_FS__PERIOD_ANNUALLY,
12035
+ $is_trial = false
12036
+ ) {
12037
+ return $this->checkout_url( $billing_cycle, $is_trial, array(
12038
+ 'plugin_id' => $addon_id,
12039
+ 'pricing_id' => $pricing_id,
12040
+ ) );
12041
+ }
12042
+
12043
+ #endregion
12044
+
12045
+ #endregion ------------------------------------------------------------------
12046
+
12047
+ /**
12048
+ * Check if plugin has any add-ons.
12049
+ *
12050
+ * @author Vova Feldman (@svovaf)
12051
+ * @since 1.0.5
12052
+ *
12053
+ * @since 1.1.7.3 Base logic only on the parameter provided by the developer in the init function.
12054
+ *
12055
+ * @return bool
12056
+ */
12057
+ function has_addons() {
12058
+ $this->_logger->entrance();
12059
+
12060
+ return $this->_has_addons;
12061
+ }
12062
+
12063
+ /**
12064
+ * Check if plugin can work in anonymous mode.
12065
+ *
12066
+ * @author Vova Feldman (@svovaf)
12067
+ * @since 1.0.9
12068
+ *
12069
+ * @return bool
12070
+ *
12071
+ * @deprecated Please use is_enable_anonymous() instead.
12072
+ */
12073
+ function enable_anonymous() {
12074
+ return $this->_enable_anonymous;
12075
+ }
12076
+
12077
+ /**
12078
+ * Check if plugin can work in anonymous mode.
12079
+ *
12080
+ * @author Vova Feldman (@svovaf)
12081
+ * @since 1.1.9
12082
+ *
12083
+ * @return bool
12084
+ */
12085
+ function is_enable_anonymous() {
12086
+ return $this->_enable_anonymous;
12087
+ }
12088
+
12089
+ /**
12090
+ * Check if plugin is premium only (no free plans).
12091
+ *
12092
+ * @author Vova Feldman (@svovaf)
12093
+ * @since 1.1.9
12094
+ *
12095
+ * @return bool
12096
+ */
12097
+ function is_only_premium() {
12098
+ return $this->_is_premium_only;
12099
+ }
12100
+
12101
+ /**
12102
+ * Checks if the plugin's type is "plugin". The other type is "theme".
12103
+ *
12104
+ * @author Leo Fajardo (@leorw)
12105
+ * @since 1.2.2
12106
+ *
12107
+ * @return bool
12108
+ */
12109
+ function is_plugin() {
12110
+ return ( WP_FS__MODULE_TYPE_PLUGIN === $this->_module_type );
12111
+ }
12112
+
12113
+ /**
12114
+ * @author Leo Fajardo (@leorw)
12115
+ * @since 1.2.2
12116
+ *
12117
+ * @return string
12118
+ */
12119
+ function get_module_type() {
12120
+ if ( ! isset( $this->_module_type ) ) {
12121
+ $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array() );
12122
+ $this->_module_type = $id_slug_type_path_map[ $this->_module_id ]['type'];
12123
+ }
12124
+
12125
+ return $this->_module_type;
12126
+ }
12127
+
12128
+ /**
12129
+ * @author Leo Fajardo (@leorw)
12130
+ * @since 1.2.2
12131
+ *
12132
+ * @return string
12133
+ */
12134
+ function get_plugin_main_file_path() {
12135
+ return $this->_plugin_main_file_path;
12136
+ }
12137
+
12138
+ /**
12139
+ * Check if module has a premium code version.
12140
+ *
12141
+ * Serviceware module might be freemium without any
12142
+ * premium code version, where the paid features
12143
+ * are all part of the service.
12144
+ *
12145
+ * @author Vova Feldman (@svovaf)
12146
+ * @since 1.2.1.6
12147
+ *
12148
+ * @return bool
12149
+ */
12150
+ function has_premium_version() {
12151
+ return $this->_has_premium_version;
12152
+ }
12153
+
12154
+ /**
12155
+ * Check if feature supported with current site's plan.
12156
+ *
12157
+ * @author Vova Feldman (@svovaf)
12158
+ * @since 1.0.1
12159
+ *
12160
+ * @todo IMPLEMENT
12161
+ *
12162
+ * @param number $feature_id
12163
+ *
12164
+ * @throws Exception
12165
+ */
12166
+ function is_feature_supported( $feature_id ) {
12167
+ throw new Exception( 'not implemented' );
12168
+ }
12169
+
12170
+ /**
12171
+ * @author Vova Feldman (@svovaf)
12172
+ * @since 1.0.1
12173
+ *
12174
+ * @return bool Is running in SSL/HTTPS
12175
+ */
12176
+ function is_ssl() {
12177
+ return WP_FS__IS_HTTPS;
12178
+ }
12179
+
12180
+ /**
12181
+ * @author Vova Feldman (@svovaf)
12182
+ * @since 1.0.9
12183
+ *
12184
+ * @return bool Is running in AJAX call.
12185
+ *
12186
+ * @link http://wordpress.stackexchange.com/questions/70676/how-to-check-if-i-am-in-admin-ajax
12187
+ */
12188
+ static function is_ajax() {
12189
+ return ( defined( 'DOING_AJAX' ) && DOING_AJAX );
12190
+ }
12191
+
12192
+ /**
12193
+ * Check if it's an AJAX call targeted for the current module.
12194
+ *
12195
+ * @author Vova Feldman (@svovaf)
12196
+ * @since 1.2.0
12197
+ *
12198
+ * @param array|string $actions Collection of AJAX actions.
12199
+ *
12200
+ * @return bool
12201
+ */
12202
+ function is_ajax_action( $actions ) {
12203
+ // Verify it's an ajax call.
12204
+ if ( ! self::is_ajax() ) {
12205
+ return false;
12206
+ }
12207
+
12208
+ // Verify the call is relevant for the plugin.
12209
+ if ( $this->_module_id != fs_request_get( 'module_id' ) ) {
12210
+ return false;
12211
+ }
12212
+
12213
+ // Verify it's one of the specified actions.
12214
+ if ( is_string( $actions ) ) {
12215
+ $actions = explode( ',', $actions );
12216
+ }
12217
+
12218
+ if ( is_array( $actions ) && 0 < count( $actions ) ) {
12219
+ $ajax_action = fs_request_get( 'action' );
12220
+
12221
+ foreach ( $actions as $action ) {
12222
+ if ( $ajax_action === $this->get_action_tag( $action ) ) {
12223
+ return true;
12224
+ }
12225
+ }
12226
+ }
12227
+
12228
+ return false;
12229
+ }
12230
+
12231
+ /**
12232
+ * Check if it's an AJAX call targeted for current request.
12233
+ *
12234
+ * @author Vova Feldman (@svovaf)
12235
+ * @since 1.2.0
12236
+ *
12237
+ * @param array|string $actions Collection of AJAX actions.
12238
+ * @param number|null $module_id
12239
+ *
12240
+ * @return bool
12241
+ */
12242
+ static function is_ajax_action_static( $actions, $module_id = null ) {
12243
+ // Verify it's an ajax call.
12244
+ if ( ! self::is_ajax() ) {
12245
+ return false;
12246
+ }
12247
+
12248
+
12249
+ if ( ! empty( $module_id ) ) {
12250
+ // Verify the call is relevant for the plugin.
12251
+ if ( $module_id != fs_request_get( 'module_id' ) ) {
12252
+ return false;
12253
+ }
12254
+ }
12255
+
12256
+ // Verify it's one of the specified actions.
12257
+ if ( is_string( $actions ) ) {
12258
+ $actions = explode( ',', $actions );
12259
+ }
12260
+
12261
+ if ( is_array( $actions ) && 0 < count( $actions ) ) {
12262
+ $ajax_action = fs_request_get( 'action' );
12263
+
12264
+ foreach ( $actions as $action ) {
12265
+ if ( $ajax_action === self::get_ajax_action_static( $action, $module_id ) ) {
12266
+ return true;
12267
+ }
12268
+ }
12269
+ }
12270
+
12271
+ return false;
12272
+ }
12273
+
12274
+ /**
12275
+ * @author Vova Feldman (@svovaf)
12276
+ * @since 1.1.7
12277
+ *
12278
+ * @return bool
12279
+ */
12280
+ static function is_cron() {
12281
+ return ( defined( 'DOING_CRON' ) && DOING_CRON );
12282
+ }
12283
+
12284
+ /**
12285
+ * Check if a real user is visiting the admin dashboard.
12286
+ *
12287
+ * @author Vova Feldman (@svovaf)
12288
+ * @since 1.1.7
12289
+ *
12290
+ * @return bool
12291
+ */
12292
+ function is_user_in_admin() {
12293
+ return is_admin() && ! self::is_ajax() && ! self::is_cron();
12294
+ }
12295
+
12296
+ /**
12297
+ * Check if a real user is in the customizer view.
12298
+ *
12299
+ * @author Vova Feldman (@svovaf)
12300
+ * @since 1.2.2.7
12301
+ *
12302
+ * @return bool
12303
+ */
12304
+ static function is_customizer() {
12305
+ return is_customize_preview();
12306
+ }
12307
+
12308
+ /**
12309
+ * Check if running in HTTPS and if site's plan matching the specified plan.
12310
+ *
12311
+ * @param string $plan
12312
+ * @param bool $exact
12313
+ *
12314
+ * @return bool
12315
+ */
12316
+ function is_ssl_and_plan( $plan, $exact = false ) {
12317
+ return ( $this->is_ssl() && $this->is_plan( $plan, $exact ) );
12318
+ }
12319
+
12320
+ /**
12321
+ * Construct plugin's settings page URL.
12322
+ *
12323
+ * @author Vova Feldman (@svovaf)
12324
+ * @since 1.0.4
12325
+ *
12326
+ * @param string $page
12327
+ * @param array $params
12328
+ * @param bool|null $network
12329
+ *
12330
+ * @return string
12331
+ */
12332
+ function _get_admin_page_url( $page = '', $params = array(), $network = null ) {
12333
+ if ( is_null( $network ) ) {
12334
+ $network = (
12335
+ $this->_is_network_active &&
12336
+ ( fs_is_network_admin() || ! $this->is_delegated_connection() )
12337
+ );
12338
+ }
12339
+
12340
+ if ( 0 < count( $params ) ) {
12341
+ foreach ( $params as $k => $v ) {
12342
+ $params[ $k ] = urlencode( $v );
12343
+ }
12344
+ }
12345
+
12346
+ $page_param = $this->_menu->get_slug( $page );
12347
+
12348
+ if ( empty( $page ) &&
12349
+ $this->is_theme() &&
12350
+ // Show the opt-in as an overlay for free wp.org themes or themes without any settings page.
12351
+ ( $this->is_free_wp_org_theme() || ! $this->has_settings_menu() )
12352
+ ) {
12353
+ $params[ $this->get_unique_affix() . '_show_optin' ] = 'true';
12354
+
12355
+ return add_query_arg(
12356
+ $params,
12357
+ $this->admin_url( 'themes.php', 'admin', $network )
12358
+ );
12359
+ }
12360
+
12361
+ if ( ! $this->has_settings_menu() ) {
12362
+ if ( ! empty( $page ) ) {
12363
+ // Module doesn't have a setting page, but since the request is for
12364
+ // a specific Freemius page, use the admin.php path.
12365
+ return add_query_arg( array_merge( $params, array(
12366
+ 'page' => $page_param,
12367
+ ) ), $this->admin_url( 'admin.php', 'admin', $network ) );
12368
+ } else {
12369
+ if ( $this->is_activation_mode() ) {
12370
+ /**
12371
+ * @author Vova Feldman
12372
+ * @since 1.2.1.6
12373
+ *
12374
+ * If plugin doesn't have a settings page, create one for the opt-in screen.
12375
+ */
12376
+ return add_query_arg( array_merge( $params, array(
12377
+ 'page' => $this->_slug,
12378
+ ) ), $this->admin_url( 'admin.php', 'admin', $network ) );
12379
+ } else {
12380
+ // Plugin without a settings page.
12381
+ return add_query_arg(
12382
+ $params,
12383
+ $this->admin_url( 'plugins.php', 'admin', $network )
12384
+ );
12385
+ }
12386
+ }
12387
+ }
12388
+
12389
+ // Module has a submenu settings page.
12390
+ if ( ! $this->_menu->is_top_level() ) {
12391
+ $parent_slug = $this->_menu->get_parent_slug();
12392
+ $menu_file = ( false !== strpos( $parent_slug, '.php' ) ) ?
12393
+ $parent_slug :
12394
+ 'admin.php';
12395
+
12396
+ return add_query_arg( array_merge( $params, array(
12397
+ 'page' => $page_param,
12398
+ ) ), $this->admin_url( $menu_file, 'admin', $network ) );
12399
+ }
12400
+
12401
+ // Module has a top level CPT settings page.
12402
+ if ( $this->_menu->is_cpt() ) {
12403
+ if ( empty( $page ) && $this->is_activation_mode() ) {
12404
+ return add_query_arg( array_merge( $params, array(
12405
+ 'page' => $page_param
12406
+ ) ), $this->admin_url( 'admin.php', 'admin', $network ) );
12407
+ } else {
12408
+ if ( ! empty( $page ) ) {
12409
+ $params['page'] = $page_param;
12410
+ }
12411
+
12412
+ return add_query_arg(
12413
+ $params,
12414
+ $this->admin_url( $this->_menu->get_raw_slug(), 'admin', $network )
12415
+ );
12416
+ }
12417
+ }
12418
+
12419
+ // Module has a custom top level settings page.
12420
+ return add_query_arg( array_merge( $params, array(
12421
+ 'page' => $page_param,
12422
+ ) ), $this->admin_url( 'admin.php', 'admin', $network ) );
12423
+ }
12424
+
12425
+ #--------------------------------------------------------------------------------
12426
+ #region Multisite
12427
+ #--------------------------------------------------------------------------------
12428
+
12429
+ /**
12430
+ * @author Leo Fajardo (@leorw)
12431
+ * @since 2.0.0
12432
+ *
12433
+ * @return bool
12434
+ */
12435
+ function is_network_active() {
12436
+ return $this->_is_network_active;
12437
+ }
12438
+
12439
+ /**
12440
+ * Delegate activation for the given sites in the network (or all sites if `null`) to site admins.
12441
+ *
12442
+ * @author Leo Fajardo (@leorw)
12443
+ * @since 2.0.0
12444
+ *
12445
+ * @param array|null $sites
12446
+ */
12447
+ private function delegate_connection( $sites = null ) {
12448
+ $this->_logger->entrance();
12449
+
12450
+ $this->_admin_notices->remove_sticky( 'connect_account' );
12451
+
12452
+ if ( is_null( $sites ) ) {
12453
+ // All sites delegation.
12454
+ $this->_storage->store( 'is_delegated_connection', true, true, true );
12455
+ } else {
12456
+ // Specified sites delegation.
12457
+ foreach ( $sites as $site ) {
12458
+ $this->delegate_site_connection( $site['blog_id'] );
12459
+ }
12460
+ }
12461
+
12462
+ $this->network_upgrade_mode_completed();
12463
+ }
12464
+
12465
+ /**
12466
+ * Delegate specific network site conncetion to the site admin.
12467
+ *
12468
+ * @author Vova Feldman (@svovaf)
12469
+ * @since 2.0.0
12470
+ *
12471
+ * @param int $blog_id
12472
+ */
12473
+ private function delegate_site_connection( $blog_id ) {
12474
+ $this->_storage->store( 'is_delegated_connection', true, $blog_id, true );
12475
+ }
12476
+
12477
+ /**
12478
+ * Check if super-admin delegated the connection of ALL sites to the site admins.
12479
+ *
12480
+ * @author Vova Feldman (@svovaf)
12481
+ * @since 2.0.0
12482
+ *
12483
+ * @return bool
12484
+ */
12485
+ function is_network_delegated_connection() {
12486
+ if ( ! $this->_is_network_active ) {
12487
+ return false;
12488
+ }
12489
+
12490
+ return $this->_storage->get( 'is_delegated_connection', false, true );
12491
+ }
12492
+
12493
+ /**
12494
+ * @author Leo Fajardo (@leorw)
12495
+ * @since 2.0.0
12496
+ *
12497
+ * @param int $blog_id
12498
+ *
12499
+ * @return bool
12500
+ */
12501
+ function is_site_delegated_connection( $blog_id = 0 ) {
12502
+ if ( ! $this->_is_network_active ) {
12503
+ return false;
12504
+ }
12505
+
12506
+ if ( 0 == $blog_id ) {
12507
+ $blog_id = get_current_blog_id();
12508
+ }
12509
+
12510
+ return $this->_storage->get( 'is_delegated_connection', false, $blog_id );
12511
+ }
12512
+
12513
+ /**
12514
+ * Check if delegated the connection. When running within the the network admin,
12515
+ * and haven't specified the blog ID, checks if network level delegated. If running
12516
+ * within a site admin or specified a blog ID, check if delegated the connection for
12517
+ * the current context site.
12518
+ *
12519
+ * If executed outside the the admin, check if delegated the connection
12520
+ * for the current context site OR the whole network.
12521
+ *
12522
+ * @author Vova Feldman (@svovaf)
12523
+ * @since 2.0.0
12524
+ *
12525
+ * @param int $blog_id If set, checks if network delegated or blog specific delegated.
12526
+ *
12527
+ * @return bool
12528
+ */
12529
+ function is_delegated_connection( $blog_id = 0 ) {
12530
+ if ( ! $this->_is_network_active ) {
12531
+ return false;
12532
+ }
12533
+
12534
+ if ( fs_is_network_admin() && 0 == $blog_id ) {
12535
+ return $this->is_network_delegated_connection();
12536
+ }
12537
+
12538
+ return (
12539
+ $this->is_network_delegated_connection() ||
12540
+ $this->is_site_delegated_connection( $blog_id )
12541
+ );
12542
+ }
12543
+
12544
+ /**
12545
+ * Check if the current module is active for the site.
12546
+ *
12547
+ * @author Vova Feldman (@svovaf)
12548
+ * @since 2.0.0
12549
+ *
12550
+ * @param int $blog_id
12551
+ *
12552
+ * @return bool
12553
+ */
12554
+ function is_active_for_site( $blog_id ) {
12555
+ if ( ! is_multisite() ) {
12556
+ // Not a multisite and this code is executed, means that the plugin is active.
12557
+ return true;
12558
+ }
12559
+
12560
+ if ( $this->is_theme() ) {
12561
+ // All themes are site level activated.
12562
+ return true;
12563
+ }
12564
+
12565
+ if ( $this->_is_network_active ) {
12566
+ // Plugin was network activated so it's active.
12567
+ return true;
12568
+ }
12569
+
12570
+ return in_array( $this->_plugin_basename, (array) get_blog_option( $blog_id, 'active_plugins', array() ) );
12571
+ }
12572
+
12573
+ /**
12574
+ * @author Leo Fajardo (@leorw)
12575
+ * @since 2.0.0
12576
+ *
12577
+ * @return array Active & public sites collection.
12578
+ */
12579
+ static function get_sites() {
12580
+ /**
12581
+ * For consistency with get_blog_list() which only return active public sites.
12582
+ *
12583
+ * @author Vova Feldman (@svovaf)
12584
+ */
12585
+ $args = array(
12586
+ /**
12587
+ * Commented out in order to handle the migration of site options whether the site is public or not.
12588
+ *
12589
+ * @author Leo Fajardo (@leorw)
12590
+ * @since 2.2.1
12591
+ */
12592
+ // 'public' => 1,
12593
+ 'archived' => 0,
12594
+ 'mature' => 0,
12595
+ 'spam' => 0,
12596
+ 'deleted' => 0,
12597
+ );
12598
+
12599
+ if ( function_exists( 'get_sites' ) ) {
12600
+ // For WP 4.6 and above.
12601
+ return get_sites( $args );
12602
+ } else if ( function_exists( 'wp_get_sites' ) ) {
12603
+ // For WP 3.7 to WP 4.5.
12604
+ return wp_get_sites( $args );
12605
+ } else {
12606
+ // For WP 3.6 and below.
12607
+ return get_blog_list( 0, 'all' );
12608
+ }
12609
+ }
12610
+
12611
+ /**
12612
+ * Checks if a given blog is active.
12613
+ *
12614
+ * @author Vova Feldman (@svovaf)
12615
+ * @since 2.0.0
12616
+ *
12617
+ * @param $blog_id
12618
+ *
12619
+ * @return bool
12620
+ */
12621
+ private static function is_site_active( $blog_id ) {
12622
+ global $wpdb;
12623
+
12624
+ $blog_info = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->blogs} WHERE blog_id = %d", $blog_id ) );
12625
+
12626
+ if ( ! is_object( $blog_info ) ) {
12627
+ return false;
12628
+ }
12629
+
12630
+ return (
12631
+ true == $blog_info->public &&
12632
+ false == $blog_info->archived &&
12633
+ false == $blog_info->mature &&
12634
+ false == $blog_info->spam &&
12635
+ false == $blog_info->deleted
12636
+ );
12637
+ }
12638
+
12639
+ /**
12640
+ * Get a mapping between the site addresses to their blog IDs.
12641
+ *
12642
+ * @author Vova Feldman (@svovaf)
12643
+ * @since 2.0.0
12644
+ *
12645
+ * @return array {
12646
+ * @key string Site address without protocol with a trailing slash.
12647
+ * @value int Site's blog ID.
12648
+ * }
12649
+ */
12650
+ private function get_address_to_blog_map() {
12651
+ $sites = self::get_sites();
12652
+
12653
+ // Map site addresses to their blog IDs.
12654
+ $address_to_blog_map = array();
12655
+ foreach ( $sites as $site ) {
12656
+ $blog_id = self::get_site_blog_id( $site );
12657
+ $address = trailingslashit( fs_strip_url_protocol( get_site_url( $blog_id ) ) );
12658
+ $address_to_blog_map[ $address ] = $blog_id;
12659
+ }
12660
+
12661
+ return $address_to_blog_map;
12662
+ }
12663
+
12664
+ /**
12665
+ * Get a mapping between the site addresses to their blog IDs.
12666
+ *
12667
+ * @author Vova Feldman (@svovaf)
12668
+ * @since 2.0.0
12669
+ *
12670
+ * @return array {
12671
+ * @key int Site's blog ID.
12672
+ * @value FS_Site Associated install.
12673
+ * }
12674
+ */
12675
+ function get_blog_install_map() {
12676
+ $sites = self::get_sites();
12677
+
12678
+ // Map site blog ID to its install.
12679
+ $install_map = array();
12680
+
12681
+ foreach ( $sites as $site ) {
12682
+ $blog_id = self::get_site_blog_id( $site );
12683
+ $install = $this->get_install_by_blog_id( $blog_id );
12684
+
12685
+ if ( is_object( $install ) ) {
12686
+ $install_map[ $blog_id ] = $install;
12687
+ }
12688
+ }
12689
+
12690
+ return $install_map;
12691
+ }
12692
+
12693
+ /**
12694
+ * Gets a map of module IDs that the given user has opted-in to.
12695
+ *
12696
+ * @author Leo Fajardo (@leorw)
12697
+ * @since 2.1.0
12698
+ *
12699
+ * @param number $fs_user_id
12700
+ *
12701
+ * @return array {
12702
+ * @key number $plugin_id
12703
+ * @value bool Always true.
12704
+ * }
12705
+ */
12706
+ private static function get_user_opted_in_module_ids_map( $fs_user_id ) {
12707
+ self::$_static_logger->entrance();
12708
+
12709
+ if ( ! is_multisite() ) {
12710
+ $installs = array_merge(
12711
+ self::get_all_sites( WP_FS__MODULE_TYPE_PLUGIN ),
12712
+ self::get_all_sites( WP_FS__MODULE_TYPE_THEME )
12713
+ );
12714
+ } else {
12715
+ $sites = self::get_sites();
12716
+
12717
+ $installs = array();
12718
+ foreach ( $sites as $site ) {
12719
+ $blog_id = self::get_site_blog_id( $site );
12720
+
12721
+ $installs = array_merge(
12722
+ $installs,
12723
+ self::get_all_sites( WP_FS__MODULE_TYPE_PLUGIN, $blog_id ),
12724
+ self::get_all_sites( WP_FS__MODULE_TYPE_THEME, $blog_id )
12725
+ );
12726
+ }
12727
+ }
12728
+
12729
+ $module_ids_map = array();
12730
+ foreach ( $installs as $install ) {
12731
+ if ( is_object( $install ) &&
12732
+ FS_Site::is_valid_id( $install->id ) &&
12733
+ FS_User::is_valid_id( $install->user_id ) &&
12734
+ ( $install->user_id == $fs_user_id )
12735
+ ) {
12736
+ $module_ids_map[ $install->plugin_id ] = true;
12737
+ }
12738
+ }
12739
+
12740
+ return $module_ids_map;
12741
+ }
12742
+
12743
+ /**
12744
+ * @author Leo Fajardo (@leorw)
12745
+ *
12746
+ * @return null|array {
12747
+ * 'install' => FS_Site Module's install,
12748
+ * 'blog_id' => string The associated blog ID.
12749
+ * }
12750
+ */
12751
+ private function find_first_install() {
12752
+ $sites = self::get_sites();
12753
+
12754
+ foreach ( $sites as $site ) {
12755
+ $blog_id = self::get_site_blog_id( $site );
12756
+ $install = $this->get_install_by_blog_id( $blog_id );
12757
+
12758
+ if ( is_object( $install ) ) {
12759
+ return array(
12760
+ 'install' => $install,
12761
+ 'blog_id' => $blog_id
12762
+ );
12763
+ }
12764
+ }
12765
+
12766
+ return null;
12767
+ }
12768
+
12769
+ /**
12770
+ * Switches the Freemius site level context to a specified blog.
12771
+ *
12772
+ * @author Vova Feldman (@svovaf)
12773
+ * @since 2.0.0
12774
+ *
12775
+ * @param int $blog_id
12776
+ * @param FS_Site $install
12777
+ */
12778
+ function switch_to_blog( $blog_id, FS_Site $install = null ) {
12779
+ if ( $blog_id == $this->_context_is_network_or_blog_id ) {
12780
+ return;
12781
+ }
12782
+
12783
+ switch_to_blog( $blog_id );
12784
+ $this->_context_is_network_or_blog_id = $blog_id;
12785
+
12786
+ self::$_accounts->set_site_blog_context( $blog_id );
12787
+ $this->_storage->set_site_blog_context( $blog_id );
12788
+ $this->_storage->set_network_active( $this->_is_network_active, $this->is_delegated_connection( $blog_id ) );
12789
+
12790
+ $this->_site = is_object( $install ) ?
12791
+ $install :
12792
+ $this->get_install_by_blog_id( $blog_id );
12793
+
12794
+ $this->_user = false;
12795
+ $this->_licenses = false;
12796
+ $this->_license = null;
12797
+
12798
+ if ( is_object( $this->_site ) ) {
12799
+ // Try to fetch user from install.
12800
+ $this->_user = self::_get_user_by_id( $this->_site->user_id );
12801
+
12802
+ if ( ! is_object( $this->_user ) &&
12803
+ FS_User::is_valid_id( $this->_storage->prev_user_id )
12804
+ ) {
12805
+ // Try to fetch previously saved user.
12806
+ $this->_user = self::_get_user_by_id( $this->_storage->prev_user_id );
12807
+
12808
+ if ( ! is_object( $this->_user ) ) {
12809
+ // Fallback to network's user.
12810
+ $this->_user = $this->get_network_user();
12811
+ }
12812
+ }
12813
+
12814
+ $all_plugin_licenses = self::get_all_licenses( $this->_module_id );
12815
+
12816
+ if ( ! empty( $all_plugin_licenses ) ) {
12817
+ if ( ! FS_Plugin_License::is_valid_id( $this->_site->license_id ) ) {
12818
+ $this->_license = null;
12819
+ } else {
12820
+ $license_found = false;
12821
+ foreach ( $all_plugin_licenses as $license ) {
12822
+ if ( $license->id == $this->_site->license_id ) {
12823
+ // License found.
12824
+ $this->_license = $license;
12825
+ $license_found = true;
12826
+ break;
12827
+ }
12828
+ }
12829
+
12830
+ if ( $license_found ) {
12831
+ $this->link_license_2_user( $this->_license->id, $this->_user->id );
12832
+ }
12833
+ }
12834
+
12835
+ $this->_licenses = $this->get_user_licenses( $this->_user->id );
12836
+ }
12837
+ }
12838
+
12839
+ unset( $this->_site_api );
12840
+ unset( $this->_user_api );
12841
+ }
12842
+
12843
+ /**
12844
+ * Restore the blog context to the blog that originally loaded the module.
12845
+ *
12846
+ * @author Vova Feldman (@svovaf)
12847
+ * @since 2.0.0
12848
+ */
12849
+ function restore_current_blog() {
12850
+ $this->switch_to_blog( $this->_blog_id );
12851
+ }
12852
+
12853
+ /**
12854
+ * @author Vova Feldman (@svovaf)
12855
+ * @since 2.0.0
12856
+ *
12857
+ * @param array|WP_Site $site
12858
+ *
12859
+ * @return int
12860
+ */
12861
+ static function get_site_blog_id( &$site ) {
12862
+ return ( $site instanceof WP_Site ) ?
12863
+ $site->blog_id :
12864
+ ( is_object( $site ) && isset( $site->userblog_id ) ?
12865
+ $site->userblog_id :
12866
+ $site['blog_id'] );
12867
+ }
12868
+
12869
+ /**
12870
+ * @author Leo Fajardo (@leorw)
12871
+ * @since 2.0.0
12872
+ *
12873
+ * @param array|WP_Site|null $site
12874
+ *
12875
+ * @return array
12876
+ */
12877
+ function get_site_info( $site = null ) {
12878
+ $this->_logger->entrance();
12879
+
12880
+ $switched = false;
12881
+
12882
+ if ( is_null( $site ) ) {
12883
+ $url = get_site_url();
12884
+ $name = get_bloginfo( 'name' );
12885
+ $blog_id = null;
12886
+ } else {
12887
+ $blog_id = self::get_site_blog_id( $site );
12888
+
12889
+ if ( get_current_blog_id() != $blog_id ) {
12890
+ switch_to_blog( $blog_id );
12891
+ $switched = true;
12892
+ }
12893
+
12894
+ if ( $site instanceof WP_Site ) {
12895
+ $url = $site->siteurl;
12896
+ $name = $site->blogname;
12897
+ } else {
12898
+ $url = get_site_url( $blog_id );
12899
+ $name = get_bloginfo( 'name' );
12900
+ }
12901
+ }
12902
+
12903
+ $info = array(
12904
+ 'uid' => $this->get_anonymous_id( $blog_id ),
12905
+ 'url' => $url,
12906
+ 'title' => $name,
12907
+ 'language' => get_bloginfo( 'language' ),
12908
+ 'charset' => get_bloginfo( 'charset' ),
12909
+ );
12910
+
12911
+ if ( is_numeric( $blog_id ) ) {
12912
+ $info['blog_id'] = $blog_id;
12913
+ }
12914
+
12915
+ if ( $switched ) {
12916
+ restore_current_blog();
12917
+ }
12918
+
12919
+ return $info;
12920
+ }
12921
+
12922
+ /**
12923
+ * Load the module's install based on the blog ID.
12924
+ *
12925
+ * @author Vova Feldman (@svovaf)
12926
+ * @since 2.0.0
12927
+ *
12928
+ * @param int|null $blog_id
12929
+ *
12930
+ * @return FS_Site
12931
+ */
12932
+ function get_install_by_blog_id( $blog_id = null ) {
12933
+ $installs = self::get_all_sites( $this->_module_type, $blog_id );
12934
+ $install = isset( $installs[ $this->_slug ] ) ? $installs[ $this->_slug ] : null;
12935
+
12936
+ if ( is_object( $install ) &&
12937
+ is_numeric( $install->id ) &&
12938
+ is_numeric( $install->user_id ) &&
12939
+ FS_Plugin_Plan::is_valid_id( $install->plan_id )
12940
+ ) {
12941
+ // Load site.
12942
+ $install = clone $install;
12943
+ }
12944
+
12945
+ return $install;
12946
+ }
12947
+
12948
+ /**
12949
+ * Check if module is installed on a specified site.
12950
+ *
12951
+ * @author Vova Feldman (@svovaf)
12952
+ * @since 2.0.0
12953
+ *
12954
+ * @param int|null $blog_id
12955
+ *
12956
+ * @return bool
12957
+ */
12958
+ function is_installed_on_site( $blog_id = null ) {
12959
+ $installs = self::get_all_sites( $this->_module_type, $blog_id );
12960
+ $install = isset( $installs[ $this->_slug ] ) ? $installs[ $this->_slug ] : null;
12961
+
12962
+ return (
12963
+ is_object( $install ) &&
12964
+ is_numeric( $install->id ) &&
12965
+ is_numeric( $install->user_id ) &&
12966
+ FS_Plugin_Plan::is_valid_id( $install->plan_id )
12967
+ );
12968
+ }
12969
+
12970
+ /**
12971
+ * Check if super-admin connected at least one site via the network opt-in.
12972
+ *
12973
+ * @author Vova Feldman (@svovaf)
12974
+ * @since 2.0.0
12975
+ *
12976
+ * @return bool
12977
+ */
12978
+ function is_network_registered() {
12979
+ if ( ! $this->_is_network_active ) {
12980
+ return false;
12981
+ }
12982
+
12983
+ return FS_User::is_valid_id( $this->_storage->network_user_id );
12984
+ }
12985
+
12986
+ /**
12987
+ * Returns the main user associated with the network.
12988
+ *
12989
+ * @author Vova Feldman (@svovaf)
12990
+ * @since 2.0.0
12991
+ *
12992
+ * @return FS_User
12993
+ */
12994
+ function get_network_user() {
12995
+ if ( ! $this->_is_network_active ) {
12996
+ return null;
12997
+ }
12998
+
12999
+ return FS_User::is_valid_id( $this->_storage->network_user_id ) ?
13000
+ self::_get_user_by_id( $this->_storage->network_user_id ) :
13001
+ null;
13002
+ }
13003
+
13004
+ /**
13005
+ * Returns the current context user or the network's main user.
13006
+ *
13007
+ * @author Vova Feldman (@svovaf)
13008
+ * @since 2.0.0
13009
+ *
13010
+ * @return FS_User
13011
+ */
13012
+ function get_current_or_network_user() {
13013
+ return ( $this->_user instanceof FS_User ) ?
13014
+ $this->_user :
13015
+ $this->get_network_user();
13016
+ }
13017
+
13018
+ /**
13019
+ * Returns the main install associated with the network.
13020
+ *
13021
+ * @author Vova Feldman (@svovaf)
13022
+ * @since 2.0.0
13023
+ *
13024
+ * @return FS_Site
13025
+ */
13026
+ function get_network_install() {
13027
+ if ( ! $this->_is_network_active ) {
13028
+ return null;
13029
+ }
13030
+
13031
+ return FS_Site::is_valid_id( $this->_storage->network_install_blog_id ) ?
13032
+ $this->get_install_by_blog_id( $this->_storage->network_install_blog_id ) :
13033
+ null;
13034
+ }
13035
+
13036
+ /**
13037
+ * Returns the blog ID that is associated with the main install.
13038
+ *
13039
+ * @author Leo Fajardo (@leorw)
13040
+ * @since 2.0.0
13041
+ *
13042
+ * @return int|null
13043
+ */
13044
+ function get_network_install_blog_id() {
13045
+ if ( ! $this->_is_network_active ) {
13046
+ return null;
13047
+ }
13048
+
13049
+ return FS_Site::is_valid_id( $this->_storage->network_install_blog_id ) ?
13050
+ $this->_storage->network_install_blog_id :
13051
+ null;
13052
+ }
13053
+
13054
+ /**
13055
+ * Returns the current context install or the network's main install.
13056
+ *
13057
+ * @author Vova Feldman (@svovaf)
13058
+ * @since 2.0.0
13059
+ *
13060
+ * @return FS_Site
13061
+ */
13062
+ function get_current_or_network_install() {
13063
+ return ( $this->_site instanceof FS_Site ) ?
13064
+ $this->_site :
13065
+ $this->get_network_install();
13066
+ }
13067
+
13068
+ /**
13069
+ * Check if executing a site level action from the network level admin.
13070
+ *
13071
+ * @author Vova Feldman (@svovaf)
13072
+ * @since 2.0.0
13073
+ *
13074
+ * @return false|int If yes, return the requested blog ID.
13075
+ */
13076
+ private function is_network_level_site_specific_action() {
13077
+ if ( ! $this->_is_network_active ) {
13078
+ return false;
13079
+ }
13080
+
13081
+ if ( ! fs_is_network_admin() ) {
13082
+ return false;
13083
+ }
13084
+
13085
+ $blog_id = fs_request_get( 'blog_id', '' );
13086
+
13087
+ return is_numeric( $blog_id ) ? $blog_id : false;
13088
+ }
13089
+
13090
+ /**
13091
+ * Check if executing an action from the network level admin.
13092
+ *
13093
+ * @author Vova Feldman (@svovaf)
13094
+ * @since 2.0.0
13095
+ *
13096
+ * @return bool
13097
+ */
13098
+ private function is_network_level_action() {
13099
+ return ( $this->_is_network_active && fs_is_network_admin() );
13100
+ }
13101
+
13102
+ /**
13103
+ * Needs to be executed after site deactivation, archive, deletion, or flag as spam.
13104
+ * 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.
13105
+ *
13106
+ * @author Vova Feldman (@svovaf)
13107
+ * @since 2.0.0
13108
+ *
13109
+ * @param int $context_blog_id
13110
+ */
13111
+ private function update_multisite_data_after_site_deactivation( $context_blog_id = 0 ) {
13112
+ $this->_logger->entrance();
13113
+
13114
+ if ( $this->_is_network_active ) {
13115
+ if ( $context_blog_id == $this->_storage->network_install_blog_id ) {
13116
+ $installs_map = $this->get_blog_install_map();
13117
+
13118
+ foreach ( $installs_map as $blog_id => $install ) {
13119
+ /**
13120
+ * @var FS_Site $install
13121
+ */
13122
+ if ( $context_blog_id == $blog_id ) {
13123
+ continue;
13124
+ }
13125
+
13126
+ if ( $install->user_id != $this->_storage->network_user_id ) {
13127
+ continue;
13128
+ }
13129
+
13130
+ // Switch reference to a blog that is opted-in and belong to the same super-admin.
13131
+ $this->_storage->network_install_blog_id = $blog_id;
13132
+ break;
13133
+ }
13134
+ }
13135
+ }
13136
+
13137
+ if ( $this->is_sync_cron_scheduled() &&
13138
+ $context_blog_id == $this->get_sync_cron_blog_id()
13139
+ ) {
13140
+ $this->schedule_sync_cron( WP_FS__SCRIPT_START_TIME, true, $context_blog_id );
13141
+ }
13142
+
13143
+ if ( $this->is_install_sync_scheduled() &&
13144
+ $context_blog_id == $this->get_install_sync_cron_blog_id()
13145
+ ) {
13146
+ $this->schedule_install_sync( $context_blog_id );
13147
+ }
13148
+ }
13149
+
13150
+ /**
13151
+ * Executed after site deactivation, archive, or flag as spam.
13152
+ *
13153
+ * @author Vova Feldman (@svovaf)
13154
+ * @since 2.0.0
13155
+ *
13156
+ * @param int $context_blog_id
13157
+ */
13158
+ public function _after_site_deactivated_callback( $context_blog_id = 0 ) {
13159
+ $this->_logger->entrance();
13160
+
13161
+ $install = $this->get_install_by_blog_id( $context_blog_id );
13162
+
13163
+ if ( ! is_object( $install ) ) {
13164
+ // Site not connected.
13165
+ return;
13166
+ }
13167
+
13168
+ $this->update_multisite_data_after_site_deactivation( $context_blog_id );
13169
+
13170
+ $current_blog_id = get_current_blog_id();
13171
+
13172
+ $this->switch_to_blog( $context_blog_id );
13173
+
13174
+ // Send deactivation event.
13175
+ $this->sync_install( array(
13176
+ 'is_active' => false,
13177
+ ) );
13178
+
13179
+ $this->switch_to_blog( $current_blog_id );
13180
+ }
13181
+
13182
+ /**
13183
+ * Executed after site deletion.
13184
+ *
13185
+ * @author Vova Feldman (@svovaf)
13186
+ * @since 2.0.0
13187
+ *
13188
+ * @param int $context_blog_id
13189
+ * @param bool $drop True if site's database tables should be dropped. Default is false.
13190
+ */
13191
+ public function _after_site_deleted_callback( $context_blog_id = 0, $drop = false ) {
13192
+ $this->_logger->entrance();
13193
+
13194
+ $install = $this->get_install_by_blog_id( $context_blog_id );
13195
+
13196
+ if ( ! is_object( $install ) ) {
13197
+ // Site not connected.
13198
+ return;
13199
+ }
13200
+
13201
+ $this->update_multisite_data_after_site_deactivation( $context_blog_id );
13202
+
13203
+ $current_blog_id = get_current_blog_id();
13204
+
13205
+ $this->switch_to_blog( $context_blog_id );
13206
+
13207
+ if ( $drop ) {
13208
+ // Delete install if dropping site DB.
13209
+ $this->delete_account_event();
13210
+ } else {
13211
+ // Send deactivation event.
13212
+ $this->sync_install( array(
13213
+ 'is_active' => false,
13214
+ ) );
13215
+ }
13216
+
13217
+ $this->switch_to_blog( $current_blog_id );
13218
+ }
13219
+
13220
+ /**
13221
+ * Executed after site re-activation.
13222
+ *
13223
+ * @author Vova Feldman (@svovaf)
13224
+ * @since 2.0.0
13225
+ *
13226
+ * @param int $context_blog_id
13227
+ */
13228
+ public function _after_site_reactivated_callback( $context_blog_id = 0 ) {
13229
+ $this->_logger->entrance();
13230
+
13231
+ $install = $this->get_install_by_blog_id( $context_blog_id );
13232
+
13233
+ if ( ! is_object( $install ) ) {
13234
+ // Site not connected.
13235
+ return;
13236
+ }
13237
+
13238
+ if ( ! self::is_site_active( $context_blog_id ) ) {
13239
+ // Site not yet active (can be in spam mode, archived, deleted...).
13240
+ return;
13241
+ }
13242
+
13243
+ $current_blog_id = get_current_blog_id();
13244
+
13245
+ $this->switch_to_blog( $context_blog_id );
13246
+
13247
+ // Send re-activation event.
13248
+ $this->sync_install( array(
13249
+ 'is_active' => true,
13250
+ ) );
13251
+
13252
+ $this->switch_to_blog( $current_blog_id );
13253
+ }
13254
+
13255
+ #endregion Multisite
13256
+
13257
+ /**
13258
+ * @author Leo Fajardo (@leorw)
13259
+ *
13260
+ * @param string $path
13261
+ * @param string $scheme
13262
+ * @param bool $network
13263
+ *
13264
+ * @return string
13265
+ */
13266
+ private function admin_url( $path = '', $scheme = 'admin', $network = true ) {
13267
+ return ( $this->_is_network_active && $network ) ?
13268
+ network_admin_url( $path, $scheme ) :
13269
+ admin_url( $path, $scheme );
13270
+ }
13271
+
13272
+ /**
13273
+ * Check if currently in a specified admin page.
13274
+ *
13275
+ * @author Vova Feldman (@svovaf)
13276
+ * @since 1.2.2.7
13277
+ *
13278
+ * @param string $page
13279
+ *
13280
+ * @return bool
13281
+ */
13282
+ function is_admin_page( $page ) {
13283
+ return ( $this->_menu->get_slug( $page ) === fs_request_get( 'page', '', 'get' ) );
13284
+ }
13285
+
13286
+ /**
13287
+ * Get module's main admin setting page URL.
13288
+ *
13289
+ * @author Vova Feldman (@svovaf)
13290
+ * @since 1.2.2.7
13291
+ *
13292
+ * @return string
13293
+ */
13294
+ function main_menu_url() {
13295
+ return $this->_menu->main_menu_url();
13296
+ }
13297
+
13298
+ /**
13299
+ * Check if currently on the theme's setting page or
13300
+ * on any of the Freemius added pages (via tabs).
13301
+ *
13302
+ * @author Vova Feldman (@svovaf)
13303
+ * @since 1.2.2.7
13304
+ *
13305
+ * @return bool
13306
+ */
13307
+ function is_theme_settings_page() {
13308
+ return fs_starts_with(
13309
+ fs_request_get( 'page', '', 'get' ),
13310
+ $this->_menu->get_slug()
13311
+ );
13312
+ }
13313
+
13314
+ /**
13315
+ * Plugin's account page + sync license URL.
13316
+ *
13317
+ * @author Vova Feldman (@svovaf)
13318
+ * @since 1.1.9.1
13319
+ *
13320
+ * @param bool|number $plugin_id
13321
+ * @param bool $add_action_nonce
13322
+ * @param array $params
13323
+ *
13324
+ * @return string
13325
+ */
13326
+ function _get_sync_license_url( $plugin_id = false, $add_action_nonce = true, $params = array() ) {
13327
+ if ( is_numeric( $plugin_id ) ) {
13328
+ $params['plugin_id'] = $plugin_id;
13329
+ }
13330
+
13331
+ return $this->get_account_url(
13332
+ $this->get_unique_affix() . '_sync_license',
13333
+ $params,
13334
+ $add_action_nonce
13335
+ );
13336
+ }
13337
+
13338
+ /**
13339
+ * Plugin's account URL.
13340
+ *
13341
+ * @author Vova Feldman (@svovaf)
13342
+ * @since 1.0.4
13343
+ *
13344
+ * @param bool|string $action
13345
+ * @param array $params
13346
+ *
13347
+ * @param bool $add_action_nonce
13348
+ *
13349
+ * @return string
13350
+ */
13351
+ function get_account_url( $action = false, $params = array(), $add_action_nonce = true ) {
13352
+ if ( is_string( $action ) ) {
13353
+ $params['fs_action'] = $action;
13354
+ }
13355
+
13356
+ self::require_pluggable_essentials();
13357
+
13358
+ return ( $add_action_nonce && is_string( $action ) ) ?
13359
+ fs_nonce_url( $this->_get_admin_page_url( 'account', $params ), $action ) :
13360
+ $this->_get_admin_page_url( 'account', $params );
13361
+ }
13362
+
13363
+ /**
13364
+ * @author Vova Feldman (@svovaf)
13365
+ * @since 1.2.0
13366
+ *
13367
+ * @param string $tab
13368
+ * @param bool $action
13369
+ * @param array $params
13370
+ * @param bool $add_action_nonce
13371
+ *
13372
+ * @return string
13373
+ *
13374
+ * @uses get_account_url()
13375
+ */
13376
+ function get_account_tab_url( $tab, $action = false, $params = array(), $add_action_nonce = true ) {
13377
+ $params['tab'] = $tab;
13378
+
13379
+ return $this->get_account_url( $action, $params, $add_action_nonce );
13380
+ }
13381
+
13382
+ /**
13383
+ * Plugin's account URL.
13384
+ *
13385
+ * @author Vova Feldman (@svovaf)
13386
+ * @since 1.0.4
13387
+ *
13388
+ * @param bool|string $topic
13389
+ * @param bool|string $message
13390
+ *
13391
+ * @return string
13392
+ */
13393
+ function contact_url( $topic = false, $message = false ) {
13394
+ $params = array();
13395
+ if ( is_string( $topic ) ) {
13396
+ $params['topic'] = $topic;
13397
+ }
13398
+ if ( is_string( $message ) ) {
13399
+ $params['message'] = $message;
13400
+ }
13401
+
13402
+ if ( $this->is_addon() ) {
13403
+ $params['addon_id'] = $this->get_id();
13404
+
13405
+ return $this->get_parent_instance()->_get_admin_page_url( 'contact', $params );
13406
+ } else {
13407
+ return $this->_get_admin_page_url( 'contact', $params );
13408
+ }
13409
+ }
13410
+
13411
+ /**
13412
+ * Add-on direct info URL.
13413
+ *
13414
+ * @author Vova Feldman (@svovaf)
13415
+ * @since 1.1.0
13416
+ *
13417
+ * @param string $slug
13418
+ *
13419
+ * @return string
13420
+ */
13421
+ function addon_url( $slug ) {
13422
+ return $this->_get_admin_page_url( 'addons', array(
13423
+ 'slug' => $slug
13424
+ ) );
13425
+ }
13426
+
13427
+ /* Logger
13428
+ ------------------------------------------------------------------------------------------------------------------*/
13429
+ /**
13430
+ * @param string $id
13431
+ * @param bool $prefix_slug
13432
+ *
13433
+ * @return FS_Logger
13434
+ */
13435
+ function get_logger( $id = '', $prefix_slug = true ) {
13436
+ return FS_Logger::get_logger( ( $prefix_slug ? $this->_slug : '' ) . ( ( ! $prefix_slug || empty( $id ) ) ? '' : '_' ) . $id );
13437
+ }
13438
+
13439
+ /**
13440
+ * Note: This method is used externally so don't delete it.
13441
+ *
13442
+ * @param $id
13443
+ * @param bool $load_options
13444
+ * @param bool $prefix_slug
13445
+ *
13446
+ * @return FS_Option_Manager
13447
+ */
13448
+ function get_options_manager( $id, $load_options = false, $prefix_slug = true ) {
13449
+ return FS_Option_Manager::get_manager( ( $prefix_slug ? $this->_slug : '' ) . ( ( ! $prefix_slug || empty( $id ) ) ? '' : '_' ) . $id, $load_options );
13450
+ }
13451
+
13452
+ /* Security
13453
+ ------------------------------------------------------------------------------------------------------------------*/
13454
+ private static function _encrypt( $str ) {
13455
+ if ( is_null( $str ) ) {
13456
+ return null;
13457
+ }
13458
+
13459
+ /**
13460
+ * The encrypt/decrypt functions are used to protect
13461
+ * the user from messing up with some of the sensitive
13462
+ * data stored for the module as a JSON in the database.
13463
+ *
13464
+ * I used the same suggested hack by the theme review team.
13465
+ * For more details, look at the function `Base64UrlDecode()`
13466
+ * in `./sdk/FreemiusBase.php`.
13467
+ *
13468
+ * @todo Remove this hack once the base64 error is removed from the Theme Check.
13469
+ *
13470
+ * @author Vova Feldman (@svovaf)
13471
+ * @since 1.2.2
13472
+ */
13473
+ $fn = 'base64' . '_encode';
13474
+
13475
+ return $fn( $str );
13476
+ }
13477
+
13478
+ static function _decrypt( $str ) {
13479
+ if ( is_null( $str ) ) {
13480
+ return null;
13481
+ }
13482
+
13483
+ /**
13484
+ * The encrypt/decrypt functions are used to protect
13485
+ * the user from messing up with some of the sensitive
13486
+ * data stored for the module as a JSON in the database.
13487
+ *
13488
+ * I used the same suggested hack by the theme review team.
13489
+ * For more details, look at the function `Base64UrlDecode()`
13490
+ * in `./sdk/FreemiusBase.php`.
13491
+ *
13492
+ * @todo Remove this hack once the base64 error is removed from the Theme Check.
13493
+ *
13494
+ * @author Vova Feldman (@svovaf)
13495
+ * @since 1.2.2
13496
+ */
13497
+ $fn = 'base64' . '_decode';
13498
+
13499
+ return $fn( $str );
13500
+ }
13501
+
13502
+ /**
13503
+ * @author Vova Feldman (@svovaf)
13504
+ * @since 1.0.5
13505
+ *
13506
+ * @param FS_Entity $entity
13507
+ *
13508
+ * @return FS_Entity Return an encrypted clone entity.
13509
+ */
13510
+ private static function _encrypt_entity( FS_Entity $entity ) {
13511
+ $clone = clone $entity;
13512
+ $props = get_object_vars( $entity );
13513
+
13514
+ foreach ( $props as $key => $val ) {
13515
+ $clone->{$key} = self::_encrypt( $val );
13516
+ }
13517
+
13518
+ return $clone;
13519
+ }
13520
+
13521
+ /**
13522
+ * @author Vova Feldman (@svovaf)
13523
+ * @since 1.0.5
13524
+ *
13525
+ * @param FS_Entity $entity
13526
+ *
13527
+ * @return FS_Entity Return an decrypted clone entity.
13528
+ */
13529
+ private static function decrypt_entity( FS_Entity $entity ) {
13530
+ $clone = clone $entity;
13531
+ $props = get_object_vars( $entity );
13532
+
13533
+ foreach ( $props as $key => $val ) {
13534
+ $clone->{$key} = self::_decrypt( $val );
13535
+ }
13536
+
13537
+ return $clone;
13538
+ }
13539
+
13540
+ /**
13541
+ * Tries to activate account based on POST params.
13542
+ *
13543
+ * @author Vova Feldman (@svovaf)
13544
+ * @since 1.0.2
13545
+ *
13546
+ * @deprecated Not in use, outdated.
13547
+ */
13548
+ function _activate_account() {
13549
+ if ( $this->is_registered() ) {
13550
+ // Already activated.
13551
+ return;
13552
+ }
13553
+
13554
+ self::_clean_admin_content_section();
13555
+
13556
+ if ( fs_request_is_action( 'activate' ) && fs_request_is_post() ) {
13557
+ // check_admin_referer( 'activate_' . $this->_plugin->public_key );
13558
+
13559
+ // Verify matching plugin details.
13560
+ if ( $this->_plugin->id != fs_request_get( 'plugin_id' ) || $this->_slug != fs_request_get( 'plugin_slug' ) ) {
13561
+ return;
13562
+ }
13563
+
13564
+ $user = new FS_User();
13565
+ $user->id = fs_request_get( 'user_id' );
13566
+ $user->public_key = fs_request_get( 'user_public_key' );
13567
+ $user->secret_key = fs_request_get( 'user_secret_key' );
13568
+ $user->email = fs_request_get( 'user_email' );
13569
+ $user->first = fs_request_get( 'user_first' );
13570
+ $user->last = fs_request_get( 'user_last' );
13571
+ $user->is_verified = fs_request_get_bool( 'user_is_verified' );
13572
+
13573
+ $site = new FS_Site();
13574
+ $site->id = fs_request_get( 'install_id' );
13575
+ $site->public_key = fs_request_get( 'install_public_key' );
13576
+ $site->secret_key = fs_request_get( 'install_secret_key' );
13577
+ $site->plan_id = fs_request_get( 'plan_id' );
13578
+
13579
+ $plans = array();
13580
+ $plans_data = json_decode( urldecode( fs_request_get( 'plans' ) ) );
13581
+ foreach ( $plans_data as $p ) {
13582
+ $plan = new FS_Plugin_Plan( $p );
13583
+ if ( $site->plan_id == $plan->id ) {
13584
+ $plan->title = fs_request_get( 'plan_title' );
13585
+ $plan->name = fs_request_get( 'plan_name' );
13586
+ }
13587
+
13588
+ $plans[] = $plan;
13589
+ }
13590
+
13591
+ $this->_set_account( $user, $site, $plans );
13592
+
13593
+ // Reload the page with the keys.
13594
+ fs_redirect( $this->_get_admin_page_url() );
13595
+ }
13596
+ }
13597
+
13598
+ /**
13599
+ * @author Vova Feldman (@svovaf)
13600
+ * @since 1.0.7
13601
+ *
13602
+ * @param string $email
13603
+ *
13604
+ * @return FS_User|false
13605
+ */
13606
+ static function _get_user_by_email( $email ) {
13607
+ self::$_static_logger->entrance();
13608
+
13609
+ $email = trim( strtolower( $email ) );
13610
+
13611
+ $users = self::get_all_users();
13612
+
13613
+ if ( is_array( $users ) ) {
13614
+ foreach ( $users as $user ) {
13615
+ if ( $email === trim( strtolower( $user->email ) ) ) {
13616
+ return $user;
13617
+ }
13618
+ }
13619
+ }
13620
+
13621
+ return false;
13622
+ }
13623
+
13624
+ #----------------------------------------------------------------------------------
13625
+ #region Account (Loading, Updates & Activation)
13626
+ #----------------------------------------------------------------------------------
13627
+
13628
+ /***
13629
+ * Load account information (user + site).
13630
+ *
13631
+ * @author Vova Feldman (@svovaf)
13632
+ * @since 1.0.1
13633
+ */
13634
+ private function _load_account() {
13635
+ $this->_logger->entrance();
13636
+
13637
+ $this->do_action( 'before_account_load' );
13638
+
13639
+ $users = self::get_all_users();
13640
+ $plans = self::get_all_plans( $this->_module_type );
13641
+
13642
+ if ( $this->_logger->is_on() && is_admin() ) {
13643
+ $this->_logger->log( 'users = ' . var_export( $users, true ) );
13644
+ $this->_logger->log( 'plans = ' . var_export( $plans, true ) );
13645
+ }
13646
+
13647
+ $site = fs_is_network_admin() ?
13648
+ $this->get_network_install() :
13649
+ $this->get_install_by_blog_id();
13650
+
13651
+ if ( fs_is_network_admin() &&
13652
+ ! is_object( $site ) &&
13653
+ FS_Site::is_valid_id( $this->_storage->network_install_blog_id )
13654
+ ) {
13655
+ $first_install = $this->find_first_install();
13656
+
13657
+ if ( is_null( $first_install ) ) {
13658
+ unset( $this->_storage->network_install_blog_id );
13659
+ } else {
13660
+ $site = $first_install['install'];
13661
+ $this->_storage->network_install_blog_id = $first_install['blog_id'];
13662
+ }
13663
+ }
13664
+
13665
+ if ( is_object( $site ) &&
13666
+ is_numeric( $site->id ) &&
13667
+ is_numeric( $site->user_id ) &&
13668
+ FS_Plugin_Plan::is_valid_id( $site->plan_id )
13669
+ ) {
13670
+ // Load site.
13671
+ $this->_site = $site;
13672
+
13673
+ // Load plans.
13674
+ $this->_plans = $plans[ $this->_slug ];
13675
+ if ( ! is_array( $this->_plans ) || empty( $this->_plans ) ) {
13676
+ $this->_sync_plans();
13677
+ } else {
13678
+ for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
13679
+ if ( $this->_plans[ $i ] instanceof FS_Plugin_Plan ) {
13680
+ $this->_plans[ $i ] = self::decrypt_entity( $this->_plans[ $i ] );
13681
+ } else {
13682
+ unset( $this->_plans[ $i ] );
13683
+ }
13684
+ }
13685
+ }
13686
+ }
13687
+
13688
+ $user = null;
13689
+ if ( fs_is_network_admin() && $this->_is_network_active ) {
13690
+ $user = $this->get_network_user();
13691
+ }
13692
+
13693
+ if ( is_object( $user ) ) {
13694
+ $this->_user = clone $user;
13695
+ } else if ( $this->_site ) {
13696
+ $user = self::_get_user_by_id( $this->_site->user_id );
13697
+
13698
+ if ( ! is_object( $user ) && FS_User::is_valid_id( $this->_storage->prev_user_id ) ) {
13699
+ /**
13700
+ * Try to load the previous owner. This recovery is used for the following use-case:
13701
+ * 1. Opt-in
13702
+ * 2. Cloning site1 to site2
13703
+ * 3. Ownership switch in site1 (same applies for site2)
13704
+ * 4. Install data sync on site2
13705
+ * 5. Now site2's install is associated with the new owner which does not exists locally.
13706
+ */
13707
+ $user = self::_get_user_by_id( $this->_storage->prev_user_id );
13708
+ }
13709
+
13710
+ if ( ! is_object( $user ) ) {
13711
+ /**
13712
+ * This is a special fault tolerance mechanism to handle a scenario that the user data is missing.
13713
+ */
13714
+ $user = $this->fetch_user_by_install();
13715
+ }
13716
+
13717
+ $this->_user = ( $user instanceof FS_User ) ?
13718
+ clone $user :
13719
+ null;
13720
+ }
13721
+
13722
+ if ( is_object( $this->_user ) ) {
13723
+ // Load licenses.
13724
+ $this->_licenses = $this->get_user_licenses( $this->_user->id );
13725
+ }
13726
+
13727
+ if ( is_object( $this->_site ) ) {
13728
+ $this->_license = $this->_get_license_by_id( $this->_site->license_id );
13729
+
13730
+ if ( $this->_site->version != $this->get_plugin_version() ) {
13731
+ // If stored install version is different than current installed plugin version,
13732
+ // then update plugin version event.
13733
+ $this->update_plugin_version_event();
13734
+ }
13735
+ }
13736
+
13737
+ if ( true === $this->_storage->require_license_activation &&
13738
+ ! fs_request_get_bool( 'require_license', true )
13739
+ ) {
13740
+ $this->_storage->require_license_activation = false;
13741
+ }
13742
+
13743
+ if ( $this->is_theme() ) {
13744
+ $this->_register_account_hooks();
13745
+ }
13746
+ }
13747
+
13748
+ /**
13749
+ * Special user recovery mechanism.
13750
+ *
13751
+ * @author Vova Feldman (@svovaf)
13752
+ * @since 2.0.0
13753
+ *
13754
+ * @return \FS_User|mixed
13755
+ */
13756
+ private function fetch_user_by_install() {
13757
+ $api = $this->get_api_site_scope();
13758
+
13759
+ $uid = $this->get_anonymous_id();
13760
+ $request_path = "/users/{$this->_site->user_id}.json?uid={$uid}";
13761
+
13762
+ $result = $api->get( $request_path, false, WP_FS__TIME_10_MIN_IN_SEC );
13763
+
13764
+ if ( $this->is_api_result_entity( $result ) ) {
13765
+ $user = new FS_User( $result );
13766
+ $this->_user = $user;
13767
+ $this->_store_user();
13768
+
13769
+ return $user;
13770
+ }
13771
+
13772
+ $error_code = FS_Api::get_error_code( $result );
13773
+
13774
+ if ( in_array( $error_code, array( 'invalid_unique_id', 'user_cannot_be_recovered' ) ) ) {
13775
+ /**
13776
+ * Those API errors will continue coming and are not recoverable with the
13777
+ * current site's data. Therefore, extend the API call's cached result to 7 days.
13778
+ */
13779
+ $api->update_cache_expiration( $request_path, WP_FS__TIME_WEEK_IN_SEC );
13780
+ }
13781
+
13782
+ return $result;
13783
+ }
13784
+
13785
+ /**
13786
+ * @author Vova Feldman (@svovaf)
13787
+ * @since 1.0.1
13788
+ *
13789
+ * @param FS_User $user
13790
+ * @param FS_Site $site
13791
+ * @param bool|array $plans
13792
+ */
13793
+ private function _set_account( FS_User $user, FS_Site $site, $plans = false ) {
13794
+ $site->user_id = $user->id;
13795
+
13796
+ $this->_site = $site;
13797
+ $this->_user = $user;
13798
+ if ( false !== $plans ) {
13799
+ $this->_plans = $plans;
13800
+ }
13801
+
13802
+ $this->send_install_update();
13803
+
13804
+ $this->_store_account();
13805
+
13806
+ }
13807
+
13808
+ /**
13809
+ * Get a sanitized array with the WordPress version, SDK version, and PHP version.
13810
+ * Each version is trimmed after the 16th char.
13811
+ *
13812
+ * @author Vova Feldman (@svovaf)
13813
+ * @since 2.2.1
13814
+ *
13815
+ * @return array
13816
+ */
13817
+ private function get_versions() {
13818
+ $versions = array();
13819
+ $versions['platform_version'] = get_bloginfo( 'version' );
13820
+ $versions['sdk_version'] = $this->version;
13821
+ $versions['programming_language_version'] = phpversion();
13822
+
13823
+ foreach ( $versions as $k => $version ) {
13824
+ if ( is_string( $versions[ $k ] ) && ! empty( $versions[ $k ] ) ) {
13825
+ $versions[ $k ] = substr( $versions[ $k ], 0, 16 );
13826
+ }
13827
+ }
13828
+
13829
+ return $versions;
13830
+ }
13831
+
13832
+ /**
13833
+ * @author Vova Feldman (@svovaf)
13834
+ * @since 1.1.7.4
13835
+ *
13836
+ * @param array $override_with
13837
+ * @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.
13838
+ *
13839
+ * @return array
13840
+ */
13841
+ function get_opt_in_params( $override_with = array(), $network_level_or_blog_id = null ) {
13842
+ $this->_logger->entrance();
13843
+
13844
+ $current_user = self::_get_current_wp_user();
13845
+
13846
+ $activation_action = $this->get_unique_affix() . '_activate_new';
13847
+ $return_url = $this->is_anonymous() ?
13848
+ // If skipped already, then return to the account page.
13849
+ $this->get_account_url( $activation_action, array(), false ) :
13850
+ // Return to the module's main page.
13851
+ $this->get_after_activation_url( 'after_connect_url', array( 'fs_action' => $activation_action ) );
13852
+
13853
+ $versions = $this->get_versions();
13854
+
13855
+ $params = array_merge( $versions, array(
13856
+ 'user_firstname' => $current_user->user_firstname,
13857
+ 'user_lastname' => $current_user->user_lastname,
13858
+ 'user_nickname' => $current_user->user_nicename,
13859
+ 'user_email' => $current_user->user_email,
13860
+ 'user_ip' => WP_FS__REMOTE_ADDR,
13861
+ 'plugin_slug' => $this->_slug,
13862
+ 'plugin_id' => $this->get_id(),
13863
+ 'plugin_public_key' => $this->get_public_key(),
13864
+ 'plugin_version' => $this->get_plugin_version(),
13865
+ 'return_url' => fs_nonce_url( $return_url, $activation_action ),
13866
+ 'account_url' => fs_nonce_url( $this->_get_admin_page_url(
13867
+ 'account',
13868
+ array( 'fs_action' => 'sync_user' )
13869
+ ), 'sync_user' ),
13870
+ 'is_premium' => $this->is_premium(),
13871
+ 'is_active' => true,
13872
+ 'is_uninstalled' => false,
13873
+ ) );
13874
+
13875
+ if ( true === $network_level_or_blog_id ) {
13876
+ if ( ! isset( $override_with['sites'] ) ) {
13877
+ $params['sites'] = array();
13878
+
13879
+ $sites = self::get_sites();
13880
+
13881
+ foreach ( $sites as $site ) {
13882
+ $blog_id = self::get_site_blog_id( $site );
13883
+ if ( ! $this->is_site_delegated_connection( $blog_id ) &&
13884
+ ! $this->is_installed_on_site( $blog_id )
13885
+ ) {
13886
+ $params['sites'][] = $this->get_site_info( $site );
13887
+ }
13888
+ }
13889
+ }
13890
+ } else {
13891
+ $site = is_numeric( $network_level_or_blog_id ) ?
13892
+ array( 'blog_id' => $network_level_or_blog_id ) :
13893
+ null;
13894
+
13895
+ $site = $this->get_site_info( $site );
13896
+
13897
+ $params = array_merge( $params, array(
13898
+ 'site_uid' => $site['uid'],
13899
+ 'site_url' => $site['url'],
13900
+ 'site_name' => $site['title'],
13901
+ 'language' => $site['language'],
13902
+ 'charset' => $site['charset'],
13903
+ ) );
13904
+ }
13905
+
13906
+ if ( $this->is_pending_activation() &&
13907
+ ! empty( $this->_storage->pending_license_key )
13908
+ ) {
13909
+ $params['license_key'] = $this->_storage->pending_license_key;
13910
+ }
13911
+
13912
+ if ( WP_FS__SKIP_EMAIL_ACTIVATION && $this->has_secret_key() ) {
13913
+ // Even though rand() is known for its security issues,
13914
+ // the timestamp adds another layer of protection.
13915
+ // It would be very hard for an attacker to get the secret key form here.
13916
+ // Plus, this should never run in production since the secret should never
13917
+ // be included in the production version.
13918
+ $params['ts'] = WP_FS__SCRIPT_START_TIME;
13919
+ $params['salt'] = md5( uniqid( rand() ) );
13920
+ $params['secure'] = md5(
13921
+ $params['ts'] .
13922
+ $params['salt'] .
13923
+ $this->get_secret_key()
13924
+ );
13925
+ }
13926
+
13927
+ return array_merge( $params, $override_with );
13928
+ }
13929
+
13930
+ /**
13931
+ * 1. If successful opt-in or pending activation returns the next page that the user should be redirected to.
13932
+ * 2. If there was an API error, return the API result.
13933
+ *
13934
+ * @author Vova Feldman (@svovaf)
13935
+ * @since 1.1.7.4
13936
+ *
13937
+ * @param string|bool $email
13938
+ * @param string|bool $first
13939
+ * @param string|bool $last
13940
+ * @param string|bool $license_key
13941
+ * @param bool $is_uninstall If "true", this means that the module is currently being uninstalled.
13942
+ * In this case, the user and site info will be sent to the server but no
13943
+ * data will be saved to the WP installation's database.
13944
+ * @param number|bool $trial_plan_id
13945
+ * @param bool $is_disconnected Whether or not to opt in without tracking.
13946
+ * @param null|bool $is_marketing_allowed
13947
+ * @param array $sites If network-level opt-in, an array of containing details of sites.
13948
+ *
13949
+ * @return string|object
13950
+ * @use WP_Error
13951
+ */
13952
+ function opt_in(
13953
+ $email = false,
13954
+ $first = false,
13955
+ $last = false,
13956
+ $license_key = false,
13957
+ $is_uninstall = false,
13958
+ $trial_plan_id = false,
13959
+ $is_disconnected = false,
13960
+ $is_marketing_allowed = null,
13961
+ $sites = array()
13962
+ ) {
13963
+ $this->_logger->entrance();
13964
+
13965
+ if ( false === $email ) {
13966
+ $current_user = self::_get_current_wp_user();
13967
+ $email = $current_user->user_email;
13968
+ }
13969
+
13970
+ /**
13971
+ * @since 1.2.1 If activating with license key, ignore the context-user
13972
+ * since the user will be automatically loaded from the license.
13973
+ */
13974
+ if ( empty( $license_key ) ) {
13975
+ // Clean up pending license if opt-ing in again.
13976
+ $this->_storage->remove( 'pending_license_key' );
13977
+
13978
+ if ( ! $is_uninstall ) {
13979
+ $fs_user = Freemius::_get_user_by_email( $email );
13980
+ if ( is_object( $fs_user ) && ! $this->is_pending_activation() ) {
13981
+ return $this->install_with_current_user(
13982
+ false,
13983
+ $trial_plan_id,
13984
+ $sites
13985
+ );
13986
+ }
13987
+ }
13988
+ }
13989
+
13990
+ $user_info = array();
13991
+ if ( ! empty( $email ) ) {
13992
+ $user_info['user_email'] = $email;
13993
+ }
13994
+ if ( ! empty( $first ) ) {
13995
+ $user_info['user_firstname'] = $first;
13996
+ }
13997
+ if ( ! empty( $last ) ) {
13998
+ $user_info['user_lastname'] = $last;
13999
+ }
14000
+
14001
+ if ( ! empty( $sites ) ) {
14002
+ $is_network = true;
14003
+
14004
+ $user_info['sites'] = $sites;
14005
+ } else {
14006
+ $is_network = false;
14007
+ }
14008
+
14009
+ $params = $this->get_opt_in_params( $user_info, $is_network );
14010
+
14011
+ $filtered_license_key = false;
14012
+ if ( is_string( $license_key ) ) {
14013
+ $filtered_license_key = $this->apply_filters( 'license_key', $license_key );
14014
+ $params['license_key'] = $filtered_license_key;
14015
+ } else if ( FS_Plugin_Plan::is_valid_id( $trial_plan_id ) ) {
14016
+ $params['trial_plan_id'] = $trial_plan_id;
14017
+ }
14018
+
14019
+ if ( $is_uninstall ) {
14020
+ $params['uninstall_params'] = array(
14021
+ 'reason_id' => $this->_storage->uninstall_reason->id,
14022
+ 'reason_info' => $this->_storage->uninstall_reason->info
14023
+ );
14024
+ }
14025
+
14026
+ if ( isset( $params['license_key'] ) ) {
14027
+ $fs_user = Freemius::_get_user_by_email( $email );
14028
+
14029
+ if ( is_object( $fs_user ) ) {
14030
+ /**
14031
+ * If opting in with a context license and the context WP Admin user already opted in
14032
+ * before from the current site, add the user context security params to avoid the
14033
+ * unnecessary email activation when the context license is owned by the same context user.
14034
+ *
14035
+ * @author Leo Fajardo (@leorw)
14036
+ * @since 1.2.3
14037
+ */
14038
+ $params = array_merge( $params, FS_Security::instance()->get_context_params(
14039
+ $fs_user,
14040
+ false,
14041
+ 'install_with_existing_user'
14042
+ ) );
14043
+ }
14044
+ }
14045
+
14046
+ if ( is_bool( $is_marketing_allowed ) ) {
14047
+ $params['is_marketing_allowed'] = $is_marketing_allowed;
14048
+ }
14049
+
14050
+ $params['is_disconnected'] = $is_disconnected;
14051
+ $params['format'] = 'json';
14052
+
14053
+ $request = array(
14054
+ 'method' => 'POST',
14055
+ 'body' => $params,
14056
+ 'timeout' => WP_FS__DEBUG_SDK ? 60 : 30,
14057
+ );
14058
+
14059
+ $url = $this->add_show_pending( WP_FS__ADDRESS . '/action/service/user/install/' );
14060
+ $response = self::safe_remote_post( $url, $request );
14061
+
14062
+ if ( is_wp_error( $response ) ) {
14063
+ /**
14064
+ * @var WP_Error $response
14065
+ */
14066
+ $result = new stdClass();
14067
+
14068
+ $error_code = $response->get_error_code();
14069
+ $error_type = str_replace( ' ', '', ucwords( str_replace( '_', ' ', $error_code ) ) );
14070
+
14071
+ $result->error = (object) array(
14072
+ 'type' => $error_type,
14073
+ 'message' => $response->get_error_message(),
14074
+ 'code' => $error_code,
14075
+ 'http' => 402
14076
+ );
14077
+
14078
+ return $result;
14079
+ }
14080
+
14081
+ // Module is being uninstalled, don't handle the returned data.
14082
+ if ( $is_uninstall ) {
14083
+ return true;
14084
+ }
14085
+
14086
+ /**
14087
+ * 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.
14088
+ *
14089
+ * @author Vova Feldman (@svovaf)
14090
+ * @since 1.2.3
14091
+ * @link https://themes.trac.wordpress.org/ticket/46134#comment:5
14092
+ * @link https://themes.trac.wordpress.org/ticket/46134#comment:9
14093
+ * @link https://themes.trac.wordpress.org/ticket/46134#comment:12
14094
+ * @link https://themes.trac.wordpress.org/ticket/46134#comment:14
14095
+ */
14096
+ $decoded = is_string( $response['body'] ) ?
14097
+ json_decode( $response['body'] ) :
14098
+ null;
14099
+
14100
+ if ( empty( $decoded ) ) {
14101
+ return false;
14102
+ }
14103
+
14104
+ if ( ! $this->is_api_result_object( $decoded ) ) {
14105
+ if ( ! empty( $params['license_key'] ) ) {
14106
+ // Pass the fully entered license key to the failure handler.
14107
+ $params['license_key'] = $license_key;
14108
+ }
14109
+
14110
+ return $is_uninstall ?
14111
+ $decoded :
14112
+ $this->apply_filters( 'after_install_failure', $decoded, $params );
14113
+ } else if ( isset( $decoded->pending_activation ) && $decoded->pending_activation ) {
14114
+ if ( $is_network ) {
14115
+ $site_ids = array();
14116
+ foreach ( $sites as $site ) {
14117
+ $site_ids[] = $site['blog_id'];
14118
+ }
14119
+
14120
+ /**
14121
+ * Store the sites so that they can be installed once the user has clicked on the activation link
14122
+ * in the email.
14123
+ *
14124
+ * @author Leo Fajardo (@leorw)
14125
+ */
14126
+ $this->_storage->pending_sites_info = array(
14127
+ 'blog_ids' => $site_ids,
14128
+ 'license_key' => $license_key,
14129
+ 'trial_plan_id' => $trial_plan_id
14130
+ );
14131
+ }
14132
+
14133
+ // Pending activation, add message.
14134
+ return $this->set_pending_confirmation(
14135
+ ( isset( $decoded->email ) ?
14136
+ $decoded->email :
14137
+ true ),
14138
+ false,
14139
+ $filtered_license_key,
14140
+ ! empty( $params['trial_plan_id'] )
14141
+ );
14142
+ } else if ( isset( $decoded->install_secret_key ) ) {
14143
+ return $this->install_with_new_user(
14144
+ $decoded->user_id,
14145
+ $decoded->user_public_key,
14146
+ $decoded->user_secret_key,
14147
+ ( isset( $decoded->is_marketing_allowed ) && ! is_null( $decoded->is_marketing_allowed ) ?
14148
+ $decoded->is_marketing_allowed :
14149
+ null ),
14150
+ $decoded->install_id,
14151
+ $decoded->install_public_key,
14152
+ $decoded->install_secret_key,
14153
+ false
14154
+ );
14155
+ } else if ( is_array( $decoded->installs ) ) {
14156
+ return $this->install_many_with_new_user(
14157
+ $decoded->user_id,
14158
+ $decoded->user_public_key,
14159
+ $decoded->user_secret_key,
14160
+ ( isset( $decoded->is_marketing_allowed ) && ! is_null( $decoded->is_marketing_allowed ) ?
14161
+ $decoded->is_marketing_allowed :
14162
+ null ),
14163
+ $decoded->installs,
14164
+ false
14165
+ );
14166
+ }
14167
+
14168
+ return $decoded;
14169
+ }
14170
+
14171
+ /**
14172
+ * Set user and site identities.
14173
+ *
14174
+ * @author Vova Feldman (@svovaf)
14175
+ * @since 1.0.9
14176
+ *
14177
+ * @param FS_User $user
14178
+ * @param FS_Site $site
14179
+ * @param bool $redirect
14180
+ * @param bool $auto_install Since 1.2.1.7 If `true` and setting up an account with a valid license, will
14181
+ * redirect (or return a URL) to the account page with a special parameter to
14182
+ * trigger the auto installation processes.
14183
+ *
14184
+ * @return string If redirect is `false`, returns the next page the user should be redirected to.
14185
+ */
14186
+ function setup_account(
14187
+ FS_User $user,
14188
+ FS_Site $site,
14189
+ $redirect = true,
14190
+ $auto_install = false
14191
+ ) {
14192
+ return $this->setup_network_account(
14193
+ $user,
14194
+ array( $site ),
14195
+ $redirect,
14196
+ $auto_install,
14197
+ false
14198
+ );
14199
+ }
14200
+
14201
+ /**
14202
+ * Set user and site identities.
14203
+ *
14204
+ * @author Vova Feldman (@svovaf)
14205
+ * @since 2.0.0
14206
+ *
14207
+ * @param FS_User $user
14208
+ * @param FS_Site[] $installs
14209
+ * @param bool $redirect
14210
+ * @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.
14211
+ * @param bool $is_network_level_opt_in
14212
+ *
14213
+ * @return string If redirect is `false`, returns the next page the user should be redirected to.
14214
+ */
14215
+ function setup_network_account(
14216
+ FS_User $user,
14217
+ array $installs,
14218
+ $redirect = true,
14219
+ $auto_install = false,
14220
+ $is_network_level_opt_in = true
14221
+ ) {
14222
+ $first_install = $installs[0];
14223
+
14224
+ $this->_user = $user;
14225
+ $this->_site = $first_install;
14226
+
14227
+ $this->_sync_plans();
14228
+
14229
+ if ( $this->_storage->handle_gdpr_admin_notice &&
14230
+ $this->should_handle_gdpr_admin_notice() &&
14231
+ FS_GDPR_Manager::instance()->should_show_opt_in_notice()
14232
+ ) {
14233
+ /**
14234
+ * Clear user lock after an opt-in.
14235
+ */
14236
+ require_once WP_FS__DIR_INCLUDES . '/class-fs-user-lock.php';
14237
+ FS_User_Lock::instance()->unlock();
14238
+ }
14239
+
14240
+ if ( 1 < count( $installs ) ) {
14241
+ // Only network level opt-in can have more than one install.
14242
+ $is_network_level_opt_in = true;
14243
+ }
14244
+ // $is_network_level_opt_in = self::is_ajax_action_static( 'network_activate', $this->_module_id );
14245
+ // If Freemius was OFF before, turn it on.
14246
+ $this->turn_on();
14247
+
14248
+ if ( ! $this->_is_network_active || ! $is_network_level_opt_in ) {
14249
+ $this->_set_account( $user, $first_install );
14250
+
14251
+ $this->do_action( 'after_account_connection', $user, $first_install );
14252
+ } else {
14253
+ $this->_store_user();
14254
+
14255
+ // Map site addresses to their blog IDs.
14256
+ $address_to_blog_map = $this->get_address_to_blog_map();
14257
+
14258
+ $first_blog_id = null;
14259
+ $blog_2_install_map = array();
14260
+ foreach ( $installs as $install ) {
14261
+ $address = trailingslashit( fs_strip_url_protocol( $install->url ) );
14262
+ $blog_id = $address_to_blog_map[ $address ];
14263
+
14264
+ $this->_store_site( true, $blog_id, $install );
14265
+
14266
+ if ( is_null( $first_blog_id ) ) {
14267
+ $first_blog_id = $blog_id;
14268
+ }
14269
+
14270
+ $blog_2_install_map[ $blog_id ] = $install;
14271
+ }
14272
+
14273
+ if ( ! FS_User::is_valid_id( $this->_storage->network_user_id ) ||
14274
+ ! is_object( self::_get_user_by_id( $this->_storage->network_user_id ) )
14275
+ ) {
14276
+ // Store network user.
14277
+ $this->_storage->network_user_id = $this->_user->id;
14278
+ }
14279
+
14280
+ if ( ! FS_Site::is_valid_id( $this->_storage->network_install_blog_id ) ) {
14281
+ $this->_storage->network_install_blog_id = $first_blog_id;
14282
+ }
14283
+
14284
+ if ( count( $installs ) === count( $address_to_blog_map ) ) {
14285
+ // Super-admin opted-in for all sites in the network.
14286
+ $this->_storage->is_network_connected = true;
14287
+ }
14288
+
14289
+ $this->_store_licenses( false );
14290
+
14291
+ self::$_accounts->store();
14292
+
14293
+ // Don't sync the installs data on network upgrade
14294
+ if ( ! $this->network_upgrade_mode_completed() ) {
14295
+ $this->send_installs_update();
14296
+ }
14297
+
14298
+ // Switch install context back to the first install.
14299
+ $this->_site = $first_install;
14300
+
14301
+ $current_blog = get_current_blog_id();
14302
+
14303
+ foreach ( $blog_2_install_map as $blog_id => $install ) {
14304
+ $this->switch_to_blog( $blog_id );
14305
+
14306
+ $this->do_action( 'after_account_connection', $user, $install );
14307
+ }
14308
+
14309
+ $this->switch_to_blog( $current_blog );
14310
+
14311
+ $this->do_action( 'after_network_account_connection', $user, $blog_2_install_map );
14312
+ }
14313
+
14314
+ if ( is_numeric( $first_install->license_id ) ) {
14315
+ $this->_license = $this->_get_license_by_id( $first_install->license_id );
14316
+ }
14317
+
14318
+ $this->_admin_notices->remove_sticky( 'connect_account' );
14319
+
14320
+ if ( $this->is_pending_activation() || ! $this->has_settings_menu() ) {
14321
+ // Remove pending activation sticky notice (if still exist).
14322
+ $this->_admin_notices->remove_sticky( 'activation_pending' );
14323
+
14324
+ // Remove plugin from pending activation mode.
14325
+ unset( $this->_storage->is_pending_activation );
14326
+
14327
+ if ( ! $this->is_paying_or_trial() ) {
14328
+ $this->_admin_notices->add_sticky(
14329
+ sprintf( $this->get_text_inline( '%s activation was successfully completed.', 'plugin-x-activation-message' ), '<b>' . $this->get_plugin_name() . '</b>' ),
14330
+ 'activation_complete'
14331
+ );
14332
+ }
14333
+ }
14334
+
14335
+ if ( $this->is_paying_or_trial() ) {
14336
+ if ( ! $this->is_premium() ||
14337
+ ! $this->has_premium_version() ||
14338
+ ! $this->has_settings_menu()
14339
+ ) {
14340
+ if ( $this->is_paying() ) {
14341
+ $this->_admin_notices->add_sticky(
14342
+ sprintf(
14343
+ $this->get_text_inline( 'Your account was successfully activated with the %s plan.', 'activation-with-plan-x-message' ),
14344
+ $this->get_plan_title()
14345
+ ) . $this->get_complete_upgrade_instructions(),
14346
+ 'plan_upgraded',
14347
+ $this->get_text_x_inline( 'Yee-haw', 'interjection expressing joy or exuberance', 'yee-haw' ) . '!'
14348
+ );
14349
+ } else {
14350
+ $trial_plan = $this->get_trial_plan();
14351
+
14352
+ $this->_admin_notices->add_sticky(
14353
+ sprintf(
14354
+ $this->get_text_inline( 'Your trial has been successfully started.', 'trial-started-message' ),
14355
+ '<i>' . $this->get_plugin_name() . '</i>'
14356
+ ) . $this->get_complete_upgrade_instructions( $trial_plan->title ),
14357
+ 'trial_started',
14358
+ $this->get_text_x_inline( 'Yee-haw', 'interjection expressing joy or exuberance', 'yee-haw' ) . '!'
14359
+ );
14360
+ }
14361
+ }
14362
+
14363
+ $this->_admin_notices->remove_sticky( array(
14364
+ 'trial_promotion',
14365
+ ) );
14366
+ }
14367
+
14368
+ $plugin_id = fs_request_get( 'plugin_id', false );
14369
+
14370
+ // Store activation time ONLY for plugins & themes (not add-ons).
14371
+ if ( ! is_numeric( $plugin_id ) || ( $plugin_id == $this->_plugin->id ) ) {
14372
+ if ( empty( $this->_storage->activation_timestamp ) ) {
14373
+ $this->_storage->activation_timestamp = WP_FS__SCRIPT_START_TIME;
14374
+ }
14375
+ }
14376
+
14377
+ $next_page = '';
14378
+
14379
+ $extra = array();
14380
+ if ( $auto_install ) {
14381
+ $extra['auto_install'] = 'true';
14382
+ }
14383
+
14384
+ if ( is_numeric( $plugin_id ) ) {
14385
+ /**
14386
+ * @author Leo Fajardo (@leorw)
14387
+ * @since 1.2.1.6
14388
+ *
14389
+ * Also sync the license after an anonymous user subscribes.
14390
+ */
14391
+ if ( $this->is_anonymous() || $plugin_id != $this->_plugin->id ) {
14392
+ // Add-on was installed - sync license right after install.
14393
+ $next_page = $this->_get_sync_license_url( $plugin_id, true, $extra );
14394
+ }
14395
+ } else {
14396
+ /**
14397
+ * @author Vova Feldman (@svovaf)
14398
+ * @since 1.1.9 If site installed with a valid license, sync license.
14399
+ */
14400
+ if ( $this->is_paying() ) {
14401
+ $this->_sync_plugin_license(
14402
+ true,
14403
+ // Installs data is already synced in the beginning of this method directly or via _set_account().
14404
+ false
14405
+ );
14406
+ }
14407
+
14408
+ // Reload the page with the keys.
14409
+ $next_page = $this->is_anonymous() ?
14410
+ // If user previously skipped, redirect to account page.
14411
+ $this->get_account_url( false, $extra ) :
14412
+ $this->get_after_activation_url( 'after_connect_url', array(), $is_network_level_opt_in );
14413
+ }
14414
+
14415
+ if ( ! empty( $next_page ) && $redirect ) {
14416
+ fs_redirect( $next_page );
14417
+ }
14418
+
14419
+ return $next_page;
14420
+ }
14421
+
14422
+ /**
14423
+ * Install plugin with new user information after approval.
14424
+ *
14425
+ * @author Vova Feldman (@svovaf)
14426
+ * @since 1.0.7
14427
+ */
14428
+ function _install_with_new_user() {
14429
+ $this->_logger->entrance();
14430
+
14431
+ if ( $this->is_registered() ) {
14432
+ return;
14433
+ }
14434
+
14435
+ if ( ( $this->is_plugin() && fs_request_is_action( $this->get_unique_affix() . '_activate_new' ) ) ||
14436
+ // @todo This logic should be improved because it's executed on every load of a theme.
14437
+ $this->is_theme()
14438
+ ) {
14439
+ // check_admin_referer( $this->_slug . '_activate_new' );
14440
+
14441
+ if ( fs_request_has( 'user_secret_key' ) ) {
14442
+ if ( fs_is_network_admin() && isset( $this->_storage->pending_sites_info ) ) {
14443
+ $pending_sites_info = $this->_storage->pending_sites_info;
14444
+
14445
+ $this->install_many_pending_with_user(
14446
+ fs_request_get( 'user_id' ),
14447
+ fs_request_get( 'user_public_key' ),
14448
+ fs_request_get( 'user_secret_key' ),
14449
+ fs_request_get_bool( 'is_marketing_allowed', null ),
14450
+ $pending_sites_info['blog_ids'],
14451
+ $pending_sites_info['license_key'],
14452
+ $pending_sites_info['trial_plan_id']
14453
+ );
14454
+ } else {
14455
+ $this->install_with_new_user(
14456
+ fs_request_get( 'user_id' ),
14457
+ fs_request_get( 'user_public_key' ),
14458
+ fs_request_get( 'user_secret_key' ),
14459
+ fs_request_get_bool( 'is_marketing_allowed', null ),
14460
+ fs_request_get( 'install_id' ),
14461
+ fs_request_get( 'install_public_key' ),
14462
+ fs_request_get( 'install_secret_key' ),
14463
+ true,
14464
+ fs_request_get_bool( 'auto_install' )
14465
+ );
14466
+ }
14467
+ } else if ( fs_request_has( 'pending_activation' ) ) {
14468
+ $this->set_pending_confirmation( fs_request_get( 'user_email' ), true );
14469
+ }
14470
+ }
14471
+ }
14472
+
14473
+ /**
14474
+ * @author Vova Feldman (@svovaf)
14475
+ * @since 2.0.0
14476
+ *
14477
+ * @param number $id
14478
+ * @param string $public_key
14479
+ * @param string $secret_key
14480
+ *
14481
+ * @return \FS_User
14482
+ */
14483
+ private function setup_user( $id, $public_key, $secret_key ) {
14484
+ $user = self::_get_user_by_id( $id );
14485
+
14486
+ if ( is_object( $user ) ) {
14487
+ $this->_user = $user;
14488
+ } else {
14489
+ $user = new FS_User();
14490
+ $user->id = $id;
14491
+ $user->public_key = $public_key;
14492
+ $user->secret_key = $secret_key;
14493
+
14494
+ $this->_user = $user;
14495
+ $user_result = $this->get_api_user_scope()->get();
14496
+ $user = new FS_User( $user_result );
14497
+
14498
+ $this->_user = $user;
14499
+ $this->_store_user();
14500
+ }
14501
+
14502
+ return $user;
14503
+ }
14504
+
14505
+ /**
14506
+ * Install plugin with new user.
14507
+ *
14508
+ * @author Vova Feldman (@svovaf)
14509
+ * @since 1.1.7.4
14510
+ *
14511
+ * @param number $user_id
14512
+ * @param string $user_public_key
14513
+ * @param string $user_secret_key
14514
+ * @param bool|null $is_marketing_allowed
14515
+ * @param number $install_id
14516
+ * @param string $install_public_key
14517
+ * @param string $install_secret_key
14518
+ * @param bool $redirect
14519
+ * @param bool $auto_install Since 1.2.1.7 If `true` and setting up an account with a valid license, will
14520
+ * redirect (or return a URL) to the account page with a special parameter to
14521
+ * trigger the auto installation processes.
14522
+ *
14523
+ * @return string If redirect is `false`, returns the next page the user should be redirected to.
14524
+ */
14525
+ private function install_with_new_user(
14526
+ $user_id,
14527
+ $user_public_key,
14528
+ $user_secret_key,
14529
+ $is_marketing_allowed,
14530
+ $install_id,
14531
+ $install_public_key,
14532
+ $install_secret_key,
14533
+ $redirect = true,
14534
+ $auto_install = false
14535
+ ) {
14536
+ /**
14537
+ * This method is also executed after opting in with a license key since the
14538
+ * license can be potentially associated with a different owner.
14539
+ *
14540
+ * @since 2.0.0
14541
+ */
14542
+ $user = self::_get_user_by_id( $user_id );
14543
+
14544
+ if ( ! is_object( $user ) ) {
14545
+ $user = new FS_User();
14546
+ $user->id = $user_id;
14547
+ $user->public_key = $user_public_key;
14548
+ $user->secret_key = $user_secret_key;
14549
+
14550
+ $this->_user = $user;
14551
+ $user_result = $this->get_api_user_scope()->get();
14552
+ $user = new FS_User( $user_result );
14553
+ }
14554
+
14555
+ $this->_user = $user;
14556
+
14557
+ $site = new FS_Site();
14558
+ $site->id = $install_id;
14559
+ $site->public_key = $install_public_key;
14560
+ $site->secret_key = $install_secret_key;
14561
+
14562
+ $this->_site = $site;
14563
+ $site_result = $this->get_api_site_scope()->get();
14564
+ $site = new FS_Site( $site_result );
14565
+ $this->_site = $site;
14566
+
14567
+ if ( ! is_null( $is_marketing_allowed ) ) {
14568
+ $this->disable_opt_in_notice_and_lock_user();
14569
+ }
14570
+
14571
+ return $this->setup_account(
14572
+ $this->_user,
14573
+ $this->_site,
14574
+ $redirect,
14575
+ $auto_install
14576
+ );
14577
+ }
14578
+
14579
+ /**
14580
+ * Install plugin with user.
14581
+ *
14582
+ * @author Leo Fajardo (@leorw)
14583
+ * @since 2.0.0
14584
+ *
14585
+ * @param number $user_id
14586
+ * @param string $user_public_key
14587
+ * @param string $user_secret_key
14588
+ * @param bool|null $is_marketing_allowed
14589
+ * @param array $site_ids
14590
+ * @param bool $license_key
14591
+ * @param bool $trial_plan_id
14592
+ * @param bool $redirect
14593
+ *
14594
+ * @return string If redirect is `false`, returns the next page the user should be redirected to.
14595
+ */
14596
+ private function install_many_pending_with_user(
14597
+ $user_id,
14598
+ $user_public_key,
14599
+ $user_secret_key,
14600
+ $is_marketing_allowed,
14601
+ $site_ids,
14602
+ $license_key = false,
14603
+ $trial_plan_id = false,
14604
+ $redirect = true
14605
+ ) {
14606
+ $user = $this->setup_user( $user_id, $user_public_key, $user_secret_key );
14607
+
14608
+ if ( ! is_null( $is_marketing_allowed ) ) {
14609
+ $this->disable_opt_in_notice_and_lock_user();
14610
+ }
14611
+
14612
+ $sites = array();
14613
+ foreach ( $site_ids as $site_id ) {
14614
+ $sites[] = $this->get_site_info( array( 'blog_id' => $site_id ) );
14615
+ }
14616
+
14617
+ $this->install_with_user( $user, $license_key, $trial_plan_id, $redirect, true, $sites );
14618
+ }
14619
+
14620
+ /**
14621
+ * Multi-site install with a new user.
14622
+ *
14623
+ * @author Vova Feldman (@svovaf)
14624
+ * @since 2.0.0
14625
+ *
14626
+ * @param number $user_id
14627
+ * @param string $user_public_key
14628
+ * @param string $user_secret_key
14629
+ * @param bool|null $is_marketing_allowed
14630
+ * @param object[] $installs
14631
+ * @param bool $redirect
14632
+ * @param bool $auto_install Since 1.2.1.7 If `true` and setting up an account with a valid license, will
14633
+ * redirect (or return a URL) to the account page with a special parameter to
14634
+ * trigger the auto installation processes.
14635
+ *
14636
+ * @return string If redirect is `false`, returns the next page the user should be redirected to.
14637
+ */
14638
+ private function install_many_with_new_user(
14639
+ $user_id,
14640
+ $user_public_key,
14641
+ $user_secret_key,
14642
+ $is_marketing_allowed,
14643
+ array $installs,
14644
+ $redirect = true,
14645
+ $auto_install = false
14646
+ ) {
14647
+ $this->setup_user( $user_id, $user_public_key, $user_secret_key );
14648
+
14649
+ if ( ! is_null( $is_marketing_allowed ) ) {
14650
+ $this->disable_opt_in_notice_and_lock_user();
14651
+ }
14652
+
14653
+ $install_ids = array();
14654
+
14655
+ foreach ( $installs as $install ) {
14656
+ $install_ids[] = $install->id;
14657
+ }
14658
+
14659
+ $left = count( $install_ids );
14660
+ $offset = 0;
14661
+
14662
+ $installs = array();
14663
+ while ( $left > 0 ) {
14664
+ $result = $this->get_api_user_scope()->get( "/plugins/{$this->_module_id}/installs.json?ids=" . implode( ',', array_slice( $install_ids, $offset, 25 ) ) );
14665
+
14666
+ if ( ! $this->is_api_result_object( $result, 'installs' ) ) {
14667
+ // @todo Handle API error.
14668
+ }
14669
+
14670
+ $installs = array_merge( $installs, $result->installs );
14671
+
14672
+ $left -= 25;
14673
+ }
14674
+
14675
+ foreach ( $installs as &$install ) {
14676
+ $install = new FS_Site( $install );
14677
+ }
14678
+
14679
+ return $this->setup_network_account(
14680
+ $this->_user,
14681
+ $installs,
14682
+ $redirect,
14683
+ $auto_install
14684
+ );
14685
+ }
14686
+
14687
+ /**
14688
+ * @author Vova Feldman (@svovaf)
14689
+ * @since 1.1.7.4
14690
+ *
14691
+ * @param string|bool $email
14692
+ * @param bool $redirect
14693
+ * @param string|bool $license_key Since 1.2.1.5
14694
+ * @param bool $is_pending_trial Since 1.2.1.5
14695
+ *
14696
+ * @return string Since 1.2.1.5 if $redirect is `false`, return the pending activation page.
14697
+ */
14698
+ private function set_pending_confirmation(
14699
+ $email = false,
14700
+ $redirect = true,
14701
+ $license_key = false,
14702
+ $is_pending_trial = false
14703
+ ) {
14704
+ if ( $this->_ignore_pending_mode ) {
14705
+ /**
14706
+ * If explicitly asked to ignore pending mode, set to anonymous mode
14707
+ * if require confirmation before finalizing the opt-in.
14708
+ *
14709
+ * @author Vova Feldman
14710
+ * @since 1.2.1.6
14711
+ */
14712
+ $this->skip_connection( null, fs_is_network_admin() );
14713
+ } else {
14714
+ // Install must be activated via email since
14715
+ // user with the same email already exist.
14716
+ $this->_storage->is_pending_activation = true;
14717
+ $this->_add_pending_activation_notice( $email, $is_pending_trial );
14718
+ }
14719
+
14720
+ if ( ! empty( $license_key ) ) {
14721
+ $this->_storage->pending_license_key = $license_key;
14722
+ }
14723
+
14724
+ // Remove the opt-in sticky notice.
14725
+ $this->_admin_notices->remove_sticky( array(
14726
+ 'connect_account',
14727
+ 'trial_promotion',
14728
+ ) );
14729
+
14730
+ $next_page = $this->get_after_activation_url( 'after_pending_connect_url' );
14731
+
14732
+ // Reload the page with with pending activation message.
14733
+ if ( $redirect ) {
14734
+ fs_redirect( $next_page );
14735
+ }
14736
+
14737
+ return $next_page;
14738
+ }
14739
+
14740
+ /**
14741
+ * Install plugin with current logged WP user info.
14742
+ *
14743
+ * @author Vova Feldman (@svovaf)
14744
+ * @since 1.0.7
14745
+ */
14746
+ function _install_with_current_user() {
14747
+ $this->_logger->entrance();
14748
+
14749
+ if ( $this->is_registered() ) {
14750
+ return;
14751
+ }
14752
+
14753
+ if ( fs_request_is_action( $this->get_unique_affix() . '_activate_existing' ) && fs_request_is_post() ) {
14754
+ // check_admin_referer( 'activate_existing_' . $this->_plugin->public_key );
14755
+
14756
+ /**
14757
+ * @author Vova Feldman (@svovaf)
14758
+ * @since 1.1.9 Add license key if given.
14759
+ */
14760
+ $license_key = fs_request_get( 'license_secret_key' );
14761
+
14762
+ $this->install_with_current_user( $license_key );
14763
+ }
14764
+ }
14765
+
14766
+
14767
+ /**
14768
+ * @author Vova Feldman (@svovaf)
14769
+ * @since 1.1.7.4
14770
+ *
14771
+ * @param string|bool $license_key
14772
+ * @param number|bool $trial_plan_id
14773
+ * @param array $sites Since 2.0.0
14774
+ * @param bool $redirect
14775
+ *
14776
+ * @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.
14777
+ */
14778
+ private function install_with_current_user(
14779
+ $license_key = false,
14780
+ $trial_plan_id = false,
14781
+ $sites = array(),
14782
+ $redirect = true
14783
+ ) {
14784
+ // Get current logged WP user.
14785
+ $current_user = self::_get_current_wp_user();
14786
+
14787
+ // Find the relevant FS user by the email.
14788
+ $user = self::_get_user_by_email( $current_user->user_email );
14789
+
14790
+ return $this->install_with_user( $user, $license_key, $trial_plan_id, $redirect, true, $sites );
14791
+ }
14792
+
14793
+ /**
14794
+ * @author Vova Feldman (@svovaf)
14795
+ * @since 2.0.0
14796
+ *
14797
+ * @param \FS_User $user
14798
+ * @param string|bool $license_key
14799
+ * @param number|bool $trial_plan_id
14800
+ * @param bool $redirect
14801
+ * @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.
14802
+ * @param array $sites Since 2.0.0. If not empty, should be a collection of site details for the bulk install API request.
14803
+ *
14804
+ * @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.
14805
+ */
14806
+ private function install_with_user(
14807
+ FS_User $user,
14808
+ $license_key = false,
14809
+ $trial_plan_id = false,
14810
+ $redirect = true,
14811
+ $setup_account = true,
14812
+ $sites = array()
14813
+ ) {
14814
+ // We have to set the user before getting user scope API handler.
14815
+ $this->_user = $user;
14816
+
14817
+ // Install the plugin.
14818
+ $result = $this->create_installs_with_user(
14819
+ $user,
14820
+ $license_key,
14821
+ $trial_plan_id,
14822
+ $sites,
14823
+ $redirect
14824
+ );
14825
+
14826
+ if ( ! $this->is_api_result_entity( $result ) &&
14827
+ ! $this->is_api_result_object( $result, 'installs' )
14828
+ ) {
14829
+ // @todo Handler potential API error of the $result
14830
+ }
14831
+
14832
+ if ( empty( $sites ) ) {
14833
+ $site = new FS_Site( $result );
14834
+ $this->_site = $site;
14835
+
14836
+ if ( ! $setup_account ) {
14837
+ $this->_store_site();
14838
+
14839
+ $this->sync_plan_if_not_exist( $site->plan_id );
14840
+
14841
+ if ( ! empty( $license_key ) && FS_Plugin_License::is_valid_id( $site->license_id ) ) {
14842
+ $this->sync_license_if_not_exist( $site->license_id, $license_key );
14843
+ }
14844
+
14845
+ $this->_admin_notices->remove_sticky( 'connect_account', false );
14846
+
14847
+ return $site;
14848
+ }
14849
+
14850
+ return $this->setup_account( $this->_user, $this->_site, $redirect );
14851
+ } else {
14852
+ $installs = array();
14853
+ foreach ( $result->installs as $install ) {
14854
+ $installs[] = new FS_Site( $install );
14855
+ }
14856
+
14857
+ return $this->setup_network_account(
14858
+ $user,
14859
+ $installs,
14860
+ $redirect
14861
+ );
14862
+ }
14863
+ }
14864
+
14865
+ /**
14866
+ * Initiate an API request to create a collection of installs.
14867
+ *
14868
+ * @author Vova Feldman (@svovaf)
14869
+ * @since 2.0.0
14870
+ *
14871
+ * @param \FS_User $user
14872
+ * @param bool $license_key
14873
+ * @param bool $trial_plan_id
14874
+ * @param array $sites
14875
+ * @param bool $redirect
14876
+ * @param bool $silent
14877
+ *
14878
+ * @return object|mixed
14879
+ */
14880
+ private function create_installs_with_user(
14881
+ FS_User $user,
14882
+ $license_key = false,
14883
+ $trial_plan_id = false,
14884
+ $sites = array(),
14885
+ $redirect = false,
14886
+ $silent = false
14887
+ ) {
14888
+ $extra_install_params = array(
14889
+ 'uid' => $this->get_anonymous_id(),
14890
+ 'is_disconnected' => false,
14891
+ );
14892
+
14893
+ if ( ! empty( $license_key ) ) {
14894
+ $extra_install_params['license_key'] = $this->apply_filters( 'license_key', $license_key );
14895
+ } else if ( FS_Plugin_Plan::is_valid_id( $trial_plan_id ) ) {
14896
+ $extra_install_params['trial_plan_id'] = $trial_plan_id;
14897
+ }
14898
+
14899
+ if ( ! empty( $sites ) ) {
14900
+ $extra_install_params['sites'] = $sites;
14901
+ }
14902
+
14903
+ $args = $this->get_install_data_for_api( $extra_install_params, false, false );
14904
+
14905
+ // Install the plugin.
14906
+ $result = $this->get_api_user_scope_by_user( $user )->call(
14907
+ "/plugins/{$this->get_id()}/installs.json",
14908
+ 'post',
14909
+ $args
14910
+ );
14911
+
14912
+ if ( ! $this->is_api_result_entity( $result ) &&
14913
+ ! $this->is_api_result_object( $result, 'installs' )
14914
+ ) {
14915
+ if ( ! empty( $args['license_key'] ) ) {
14916
+ // Pass full the fully entered license key to the failure handler.
14917
+ $args['license_key'] = $license_key;
14918
+ }
14919
+
14920
+ $result = $this->apply_filters( 'after_install_failure', $result, $args );
14921
+
14922
+ if ( ! $silent ) {
14923
+ $this->_admin_notices->add(
14924
+ sprintf( $this->get_text_inline( 'Couldn\'t activate %s.', 'could-not-activate-x' ), $this->get_plugin_name() ) . ' ' .
14925
+ $this->get_text_inline( 'Please contact us with the following message:', 'contact-us-with-error-message' ) . ' ' . '<b>' . $result->error->message . '</b>',
14926
+ $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
14927
+ 'error'
14928
+ );
14929
+ }
14930
+
14931
+ if ( $redirect ) {
14932
+ /**
14933
+ * We set the user before getting the user scope API handler, so the user became temporarily
14934
+ * registered (`is_registered() = true`). Since the API returned an error and we will redirect,
14935
+ * we have to set the user to `null`, otherwise, the user will be redirected to the wrong
14936
+ * activation page based on the return value of `is_registered()`. In addition, in case the
14937
+ * context plugin doesn't have a settings menu and the default page is the `Plugins` page,
14938
+ * misleading plugin activation errors will be shown on the `Plugins` page.
14939
+ *
14940
+ * @author Leo Fajardo (@leorw)
14941
+ */
14942
+ $this->_user = null;
14943
+
14944
+ fs_redirect( $this->get_activation_url( array( 'error' => $result->error->message ) ) );
14945
+ }
14946
+ }
14947
+
14948
+ return $result;
14949
+ }
14950
+
14951
+ /**
14952
+ * Tries to activate add-on account based on parent plugin info.
14953
+ *
14954
+ * @author Vova Feldman (@svovaf)
14955
+ * @since 1.0.6
14956
+ *
14957
+ * @param Freemius $parent_fs
14958
+ */
14959
+ private function _activate_addon_account( Freemius $parent_fs ) {
14960
+ if ( $this->is_registered() ) {
14961
+ // Already activated.
14962
+ return;
14963
+ }
14964
+
14965
+ // Activate add-on with parent plugin credentials.
14966
+ $addon_install = $parent_fs->get_api_site_scope()->call(
14967
+ "/addons/{$this->_plugin->id}/installs.json",
14968
+ 'post',
14969
+ $this->get_install_data_for_api( array(
14970
+ 'uid' => $this->get_anonymous_id(),
14971
+ ), false, false )
14972
+ );
14973
+
14974
+ if ( isset( $addon_install->error ) ) {
14975
+ $this->_admin_notices->add(
14976
+ sprintf( $this->get_text_inline( 'Couldn\'t activate %s.', 'could-not-activate-x' ), $this->get_plugin_name() ) . ' ' .
14977
+ $this->get_text_inline( 'Please contact us with the following message:', 'contact-us-with-error-message' ) . ' ' . '<b>' . $addon_install->error->message . '</b>',
14978
+ $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
14979
+ 'error'
14980
+ );
14981
+
14982
+ return;
14983
+ }
14984
+
14985
+ // Get user information based on parent's plugin.
14986
+ $user = $parent_fs->get_user();
14987
+
14988
+ // First of all, set site and user info - otherwise we won't
14989
+ // be able to invoke API calls.
14990
+ $this->_site = new FS_Site( $addon_install );
14991
+ $this->_user = $user;
14992
+
14993
+ // Sync add-on plans.
14994
+ $this->_sync_plans();
14995
+
14996
+ // Get site's current plan.
14997
+ //$this->_site->plan = $this->_get_plan_by_id( $this->_site->plan->id );
14998
+
14999
+ $this->_set_account( $user, $this->_site );
15000
+
15001
+ // Sync licenses.
15002
+ $this->_sync_licenses();
15003
+
15004
+ // Try to activate premium license.
15005
+ $this->_activate_license( true );
15006
+ }
15007
+
15008
+ /**
15009
+ * Tries to activate parent account based on add-on's info.
15010
+ *
15011
+ * @author Vova Feldman (@svovaf)
15012
+ * @since 1.2.2.7
15013
+ *
15014
+ * @param Freemius $parent_fs
15015
+ */
15016
+ private function activate_parent_account( Freemius $parent_fs ) {
15017
+ if ( ! $this->is_addon() ) {
15018
+ // This is not an add-on.
15019
+ return;
15020
+ }
15021
+
15022
+ if ( $parent_fs->is_registered() ) {
15023
+ // Already activated.
15024
+ return;
15025
+ }
15026
+
15027
+ // Activate parent with add-on's user credentials.
15028
+ $parent_install = $this->get_api_user_scope()->call(
15029
+ "/plugins/{$parent_fs->_plugin->id}/installs.json",
15030
+ 'post',
15031
+ $parent_fs->get_install_data_for_api( array(
15032
+ 'uid' => $parent_fs->get_anonymous_id(),
15033
+ ), false, false )
15034
+ );
15035
+
15036
+ if ( isset( $parent_install->error ) ) {
15037
+ $this->_admin_notices->add(
15038
+ sprintf( $this->get_text_inline( 'Couldn\'t activate %s.', 'could-not-activate-x' ), $this->get_plugin_name() ) . ' ' .
15039
+ $this->get_text_inline( 'Please contact us with the following message:', 'contact-us-with-error-message' ) . ' ' . '<b>' . $parent_install->error->message . '</b>',
15040
+ $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
15041
+ 'error'
15042
+ );
15043
+
15044
+ return;
15045
+ }
15046
+
15047
+ $parent_fs->_admin_notices->remove_sticky( 'connect_account' );
15048
+
15049
+ if ( $parent_fs->is_pending_activation() ) {
15050
+ $parent_fs->_admin_notices->remove_sticky( 'activation_pending' );
15051
+
15052
+ unset( $parent_fs->_storage->is_pending_activation );
15053
+ }
15054
+
15055
+ // Get user information based on parent's plugin.
15056
+ $user = $this->get_user();
15057
+
15058
+ // First of all, set site info - otherwise we won't
15059
+ // be able to invoke API calls.
15060
+ $parent_fs->_site = new FS_Site( $parent_install );
15061
+ $parent_fs->_user = $user;
15062
+
15063
+ // Sync add-on plans.
15064
+ $parent_fs->_sync_plans();
15065
+
15066
+ $parent_fs->_set_account( $user, $parent_fs->_site );
15067
+ }
15068
+
15069
+ #endregion
15070
+
15071
+ #----------------------------------------------------------------------------------
15072
+ #region Admin Menu Items
15073
+ #----------------------------------------------------------------------------------
15074
+
15075
+ private $_menu_items = array();
15076
+
15077
+ /**
15078
+ * @author Vova Feldman (@svovaf)
15079
+ * @since 1.2.1.8
15080
+ *
15081
+ * @return array
15082
+ */
15083
+ function get_menu_items() {
15084
+ return $this->_menu_items;
15085
+ }
15086
+
15087
+ /**
15088
+ * @author Vova Feldman (@svovaf)
15089
+ * @since 1.0.7
15090
+ *
15091
+ * @return string
15092
+ */
15093
+ function get_menu_slug() {
15094
+ return $this->_menu->get_slug();
15095
+ }
15096
+
15097
+ /**
15098
+ * @author Vova Feldman (@svovaf)
15099
+ * @since 1.0.9
15100
+ */
15101
+ function _prepare_admin_menu() {
15102
+ // if ( ! $this->is_on() ) {
15103
+ // return;
15104
+ // }
15105
+
15106
+ /**
15107
+ * When running from a site admin with a network activated module and the connection
15108
+ * was NOT delegated and the user still haven't skipped or opted-in, then hide the
15109
+ * site level settings.
15110
+ *
15111
+ * @author Vova Feldman (@svovaf)
15112
+ * @since 2.0.0
15113
+ */
15114
+ $should_hide_site_admin_settings = (
15115
+ $this->_is_network_active &&
15116
+ ! fs_is_network_admin() &&
15117
+ ! $this->is_delegated_connection() &&
15118
+ ! $this->is_anonymous() &&
15119
+ ! $this->is_registered()
15120
+ );
15121
+
15122
+ if ( ( ! $this->has_api_connectivity() && ! $this->is_enable_anonymous() ) ||
15123
+ $should_hide_site_admin_settings
15124
+ ) {
15125
+ $this->_menu->remove_menu_item( $should_hide_site_admin_settings );
15126
+ } else {
15127
+ $this->do_action( fs_is_network_admin() ?
15128
+ 'before_network_admin_menu_init' :
15129
+ 'before_admin_menu_init'
15130
+ );
15131
+
15132
+ $this->add_menu_action();
15133
+
15134
+ $this->add_network_menu_when_missing();
15135
+
15136
+ $this->add_submenu_items();
15137
+ }
15138
+ }
15139
+
15140
+ /**
15141
+ * Admin dashboard menu items modifications.
15142
+ *
15143
+ * NOTE: admin_menu action executed before admin_init.
15144
+ *
15145
+ * @author Vova Feldman (@svovaf)
15146
+ * @since 1.0.7
15147
+ *
15148
+ */
15149
+ private function add_menu_action() {
15150
+ if ( $this->is_activation_mode() ) {
15151
+ if ( $this->is_plugin() || ( $this->has_settings_menu() && ! $this->is_free_wp_org_theme() ) ) {
15152
+ $this->override_plugin_menu_with_activation();
15153
+ } else {
15154
+ /**
15155
+ * Handle theme opt-in when the opt-in form shows as a dialog box in the themes page.
15156
+ */
15157
+ if ( fs_request_is_action( $this->get_unique_affix() . '_activate_existing' ) ) {
15158
+ add_action( 'load-themes.php', array( &$this, '_install_with_current_user' ) );
15159
+ } else if ( fs_request_is_action( $this->get_unique_affix() . '_activate_new' ) ||
15160
+ fs_request_get_bool( 'pending_activation' )
15161
+ ) {
15162
+ add_action( 'load-themes.php', array( &$this, '_install_with_new_user' ) );
15163
+ }
15164
+ }
15165
+ } else {
15166
+ if ( ! $this->is_registered() ) {
15167
+ // If not registered try to install user.
15168
+ if ( fs_request_is_action( $this->get_unique_affix() . '_activate_new' ) ) {
15169
+ $this->_install_with_new_user();
15170
+ }
15171
+ } else if (
15172
+ fs_request_is_action( 'sync_user' ) &&
15173
+ ( ! $this->has_settings_menu() || $this->is_free_wp_org_theme() )
15174
+ ) {
15175
+ $this->_handle_account_user_sync();
15176
+ }
15177
+ }
15178
+ }
15179
+
15180
+ /**
15181
+ * @author Vova Feldman (@svovaf)
15182
+ * @since 1.0.1
15183
+ */
15184
+ function _redirect_on_clicked_menu_link() {
15185
+ $this->_logger->entrance();
15186
+
15187
+ $page = fs_request_get('page');
15188
+ $page = is_string($page) ? strtolower($page) : '';
15189
+
15190
+ $this->_logger->log( 'page = ' . $page );
15191
+
15192
+ foreach ( $this->_menu_items as $priority => $items ) {
15193
+ foreach ( $items as $item ) {
15194
+ if ( isset( $item['url'] ) ) {
15195
+ if ( $page === $this->_menu->get_slug( strtolower( $item['menu_slug'] ) ) ) {
15196
+ $this->_logger->log( 'Redirecting to ' . $item['url'] );
15197
+
15198
+ fs_redirect( $item['url'] );
15199
+ }
15200
+ }
15201
+ }
15202
+ }
15203
+ }
15204
+
15205
+ /**
15206
+ * Remove plugin's all admin menu items & pages, and replace with activation page.
15207
+ *
15208
+ * @author Vova Feldman (@svovaf)
15209
+ * @since 1.0.1
15210
+ */
15211
+ private function override_plugin_menu_with_activation() {
15212
+ $this->_logger->entrance();
15213
+
15214
+ $hook = false;
15215
+
15216
+ if ( ! $this->has_settings_menu() ) {
15217
+ // Add the opt-in page without a menu item.
15218
+ $hook = FS_Admin_Menu_Manager::add_subpage(
15219
+ null,
15220
+ $this->get_plugin_name(),
15221
+ $this->get_plugin_name(),
15222
+ 'manage_options',
15223
+ $this->_slug,
15224
+ array( &$this, '_connect_page_render' )
15225
+ );
15226
+ } else if ( $this->_menu->is_top_level() ) {
15227
+ if ( $this->_menu->is_override_exact() ) {
15228
+ // Make sure the current page is matching the activation page.
15229
+ if ( ! $this->is_matching_url( $this->get_activation_url() ) ) {
15230
+ return;
15231
+ }
15232
+ }
15233
+
15234
+ $hook = $this->_menu->override_menu_item( array( &$this, '_connect_page_render' ) );
15235
+
15236
+ if ( false === $hook ) {
15237
+ // Create new menu item just for the opt-in.
15238
+ $hook = FS_Admin_Menu_Manager::add_page(
15239
+ $this->get_plugin_name(),
15240
+ $this->get_plugin_name(),
15241
+ 'manage_options',
15242
+ $this->_menu->get_slug(),
15243
+ array( &$this, '_connect_page_render' )
15244
+ );
15245
+ }
15246
+ } else {
15247
+ $menus = array( $this->_menu->get_parent_slug() );
15248
+
15249
+ if ( $this->_menu->is_override_exact() ) {
15250
+ // Make sure the current page is matching the activation page.
15251
+ if ( ! $this->is_matching_url( $this->get_activation_url() ) ) {
15252
+ return;
15253
+ }
15254
+ }
15255
+
15256
+ foreach ( $menus as $parent_slug ) {
15257
+ $hook = $this->_menu->override_submenu_action(
15258
+ $parent_slug,
15259
+ $this->_menu->get_raw_slug(),
15260
+ array( &$this, '_connect_page_render' )
15261
+ );
15262
+
15263
+ if ( false !== $hook ) {
15264
+ // Found plugin's submenu item.
15265
+ break;
15266
+ }
15267
+ }
15268
+ }
15269
+
15270
+ if ( $this->is_activation_page() ) {
15271
+ // Clean admin page from distracting content.
15272
+ self::_clean_admin_content_section();
15273
+ }
15274
+
15275
+ if ( false !== $hook ) {
15276
+ if ( fs_request_is_action( $this->get_unique_affix() . '_activate_existing' ) ) {
15277
+ $this->_install_with_current_user();
15278
+ } else if ( fs_request_is_action( $this->get_unique_affix() . '_activate_new' ) ) {
15279
+ $this->_install_with_new_user();
15280
+ }
15281
+ }
15282
+ }
15283
+
15284
+ /**
15285
+ * If a plugin was network activated and connected but don't have a network
15286
+ * level settings, then add an artificial menu item for the Account and other
15287
+ * Freemius settings.
15288
+ *
15289
+ * @author Vova Feldman (@svovaf)
15290
+ * @since 2.0.0
15291
+ */
15292
+ private function add_network_menu_when_missing() {
15293
+ $this->_logger->entrance();
15294
+
15295
+ if ( ! $this->_is_network_active ) {
15296
+ // Plugin wasn't activated on the network level.
15297
+ return;
15298
+ }
15299
+
15300
+ if ( ! fs_is_network_admin() ) {
15301
+ // The context is not the network admin.
15302
+ return;
15303
+ }
15304
+
15305
+ if ( $this->_menu->has_network_menu() ) {
15306
+ // Plugin already has a network level menu.
15307
+ return;
15308
+ }
15309
+
15310
+ if ( $this->is_network_activation_mode() ) {
15311
+ /**
15312
+ * Do not add during activation mode, otherwise, there will be duplicate menus while the opt-in
15313
+ * screen is being shown.
15314
+ *
15315
+ * @author Leo Fajardo (@leorw)
15316
+ */
15317
+ return;
15318
+ }
15319
+
15320
+ if ( ! WP_FS__SHOW_NETWORK_EVEN_WHEN_DELEGATED ) {
15321
+ if ( $this->is_network_delegated_connection() ) {
15322
+ // Super-admin delegated the connection to the site admins.
15323
+ return;
15324
+ }
15325
+ }
15326
+
15327
+ if ( ! $this->_menu->has_menu() || $this->_menu->is_top_level() ) {
15328
+ $this->_dynamically_added_top_level_page_hook_name = $this->_menu->add_page_and_update(
15329
+ $this->get_plugin_name(),
15330
+ $this->get_plugin_name(),
15331
+ 'manage_options',
15332
+ $this->_menu->has_menu() ? $this->_menu->get_slug() : $this->_slug
15333
+ );
15334
+ } else {
15335
+ $this->_menu->add_subpage_and_update(
15336
+ $this->_menu->get_parent_slug(),
15337
+ $this->get_plugin_name(),
15338
+ $this->get_plugin_name(),
15339
+ 'manage_options',
15340
+ $this->_menu->get_slug()
15341
+ );
15342
+ }
15343
+ }
15344
+
15345
+ /**
15346
+ * @author Leo Fajardo (@leorw)
15347
+ * @since 1.2.1
15348
+ *
15349
+ * return string
15350
+ */
15351
+ function get_top_level_menu_capability() {
15352
+ global $menu;
15353
+
15354
+ $top_level_menu_slug = $this->get_top_level_menu_slug();
15355
+
15356
+ foreach ( $menu as $menu_info ) {
15357
+ /**
15358
+ * The second element in the menu info array is the capability/role that has access to the menu and the
15359
+ * third element is the menu slug.
15360
+ */
15361
+ if ( $menu_info[2] === $top_level_menu_slug ) {
15362
+ return $menu_info[1];
15363
+ }
15364
+ }
15365
+
15366
+ return 'read';
15367
+ }
15368
+
15369
+ /**
15370
+ * @author Vova Feldman (@svovaf)
15371
+ * @since 1.0.0
15372
+ *
15373
+ * @return string
15374
+ */
15375
+ private function get_top_level_menu_slug() {
15376
+ return ( $this->is_addon() ?
15377
+ $this->get_parent_instance()->_menu->get_top_level_menu_slug() :
15378
+ $this->_menu->get_top_level_menu_slug() );
15379
+ }
15380
+
15381
+ /**
15382
+ * @author Vova Feldman (@svovaf)
15383
+ * @since 1.2.2.7
15384
+ *
15385
+ * @return string
15386
+ */
15387
+ function get_pricing_cta_label() {
15388
+ $label = $this->get_text_inline( 'Upgrade', 'upgrade' );
15389
+
15390
+ if ( $this->is_in_trial_promotion() &&
15391
+ ! $this->is_paying_or_trial()
15392
+ ) {
15393
+ // If running a trial promotion, modify the pricing to load the trial.
15394
+ $label = $this->get_text_inline( 'Start Trial', 'start-trial' );
15395
+ } else if ( $this->is_paying() ) {
15396
+ $label = $this->get_text_inline( 'Pricing', 'pricing' );
15397
+ }
15398
+
15399
+ return $label;
15400
+ }
15401
+
15402
+ /**
15403
+ * @author Vova Feldman (@svovaf)
15404
+ * @since 1.2.2.7
15405
+ *
15406
+ * @return bool
15407
+ */
15408
+ function is_pricing_page_visible() {
15409
+ return (
15410
+ // Has at least one paid plan.
15411
+ $this->has_paid_plan() &&
15412
+ // Didn't ask to hide the pricing page.
15413
+ $this->is_page_visible( 'pricing' ) &&
15414
+ // Don't have a valid active license or has more than one plan.
15415
+ ( ! $this->is_paying() || ! $this->is_single_plan() )
15416
+ );
15417
+ }
15418
+
15419
+ /**
15420
+ * Add default Freemius menu items.
15421
+ *
15422
+ * @author Vova Feldman (@svovaf)
15423
+ * @since 1.0.0
15424
+ * @since 1.2.2.7 Also add submenu items when running in a free .org theme so the tabs will be visible.
15425
+ */
15426
+ private function add_submenu_items() {
15427
+ $this->_logger->entrance();
15428
+
15429
+ $is_activation_mode = $this->is_activation_mode();
15430
+
15431
+ if ( $this->is_addon() ) {
15432
+ // No submenu items for add-ons.
15433
+ $add_submenu_items = false;
15434
+ } else if ( $this->is_free_wp_org_theme() && ! fs_is_network_admin() ) {
15435
+ // Also add submenu items when running in a free .org theme so the tabs will be visible.
15436
+ $add_submenu_items = true;
15437
+ } else if ( $is_activation_mode && ! $this->is_free_wp_org_theme() ) {
15438
+ $add_submenu_items = false;
15439
+ } else if ( fs_is_network_admin() ) {
15440
+ /**
15441
+ * Add submenu items to network level when plugin was network
15442
+ * activated and the super-admin did NOT delegated the connection
15443
+ * of all sites to site admins.
15444
+ */
15445
+ $add_submenu_items = (
15446
+ $this->_is_network_active &&
15447
+ ( WP_FS__SHOW_NETWORK_EVEN_WHEN_DELEGATED ||
15448
+ ! $this->is_network_delegated_connection() )
15449
+ );
15450
+ } else {
15451
+ $add_submenu_items = ( ! $this->_is_network_active || $this->is_delegated_connection() );
15452
+ }
15453
+
15454
+ if ( $add_submenu_items ) {
15455
+ if ( $this->has_affiliate_program() ) {
15456
+ // Add affiliation page.
15457
+ $this->add_submenu_item(
15458
+ $this->get_text_inline( 'Affiliation', 'affiliation' ),
15459
+ array( &$this, '_affiliation_page_render' ),
15460
+ $this->get_plugin_name() . ' &ndash; ' . $this->get_text_inline( 'Affiliation', 'affiliation' ),
15461
+ 'manage_options',
15462
+ 'affiliation',
15463
+ 'Freemius::_clean_admin_content_section',
15464
+ WP_FS__DEFAULT_PRIORITY,
15465
+ $this->is_submenu_item_visible( 'affiliation' )
15466
+ );
15467
+ }
15468
+ }
15469
+
15470
+ if ( $add_submenu_items ||
15471
+ ( $is_activation_mode &&
15472
+ $this->is_only_premium() &&
15473
+ $this->is_admin_page( 'account' ) &&
15474
+ fs_request_is_action( $this->get_unique_affix() . '_sync_license' )
15475
+ )
15476
+ ) {
15477
+ if ( ! WP_FS__DEMO_MODE && $this->is_registered() ) {
15478
+ $show_account = (
15479
+ $this->is_submenu_item_visible( 'account' ) &&
15480
+ /**
15481
+ * @since 1.2.2.7 Don't show the Account for free WP.org themes without any paid plans.
15482
+ */
15483
+ ( ! $this->is_free_wp_org_theme() || $this->has_paid_plan() )
15484
+ );
15485
+
15486
+ // Add user account page.
15487
+ $this->add_submenu_item(
15488
+ $this->get_text_inline( 'Account', 'account' ),
15489
+ array( &$this, '_account_page_render' ),
15490
+ $this->get_plugin_name() . ' &ndash; ' . $this->get_text_inline( 'Account', 'account' ),
15491
+ 'manage_options',
15492
+ 'account',
15493
+ array( &$this, '_account_page_load' ),
15494
+ WP_FS__DEFAULT_PRIORITY,
15495
+ ( $add_submenu_items && $show_account )
15496
+ );
15497
+ }
15498
+ }
15499
+
15500
+ if ( $add_submenu_items ) {
15501
+ // Add contact page.
15502
+ $this->add_submenu_item(
15503
+ $this->get_text_inline( 'Contact Us', 'contact-us' ),
15504
+ array( &$this, '_contact_page_render' ),
15505
+ $this->get_plugin_name() . ' &ndash; ' . $this->get_text_inline( 'Contact Us', 'contact-us' ),
15506
+ 'manage_options',
15507
+ 'contact',
15508
+ 'Freemius::_clean_admin_content_section',
15509
+ WP_FS__DEFAULT_PRIORITY,
15510
+ $this->is_submenu_item_visible( 'contact' )
15511
+ );
15512
+
15513
+ if ( $this->has_addons() ) {
15514
+ $this->add_submenu_item(
15515
+ $this->get_text_inline( 'Add-Ons', 'add-ons' ),
15516
+ array( &$this, '_addons_page_render' ),
15517
+ $this->get_plugin_name() . ' &ndash; ' . $this->get_text_inline( 'Add-Ons', 'add-ons' ),
15518
+ 'manage_options',
15519
+ 'addons',
15520
+ array( &$this, '_addons_page_load' ),
15521
+ WP_FS__LOWEST_PRIORITY - 1,
15522
+ $this->is_submenu_item_visible( 'addons' )
15523
+ );
15524
+ }
15525
+ }
15526
+
15527
+ if ( $add_submenu_items ||
15528
+ ( $is_activation_mode && $this->is_only_premium() && $this->is_admin_page( 'pricing' ) )
15529
+ ) {
15530
+ if ( ! WP_FS__DEMO_MODE ) {
15531
+ $show_pricing = (
15532
+ $this->is_submenu_item_visible( 'pricing' ) &&
15533
+ $this->is_pricing_page_visible()
15534
+ );
15535
+
15536
+ $pricing_cta_text = $this->get_pricing_cta_label();
15537
+ $pricing_class = 'upgrade-mode';
15538
+ if ( $show_pricing ) {
15539
+ if ( $this->is_in_trial_promotion() &&
15540
+ ! $this->is_paying_or_trial()
15541
+ ) {
15542
+ // If running a trial promotion, modify the pricing to load the trial.
15543
+ $pricing_class = 'trial-mode';
15544
+ } else if ( $this->is_paying() ) {
15545
+ $pricing_class = '';
15546
+ }
15547
+ }
15548
+
15549
+ // Add upgrade/pricing page.
15550
+ $this->add_submenu_item(
15551
+ $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' ) ),
15552
+ array( &$this, '_pricing_page_render' ),
15553
+ $this->get_plugin_name() . ' &ndash; ' . $this->get_text_x_inline( 'Pricing', 'noun', 'pricing' ),
15554
+ 'manage_options',
15555
+ 'pricing',
15556
+ 'Freemius::_clean_admin_content_section',
15557
+ WP_FS__LOWEST_PRIORITY,
15558
+ ( $add_submenu_items && $show_pricing ),
15559
+ $pricing_class
15560
+ );
15561
+ }
15562
+ }
15563
+
15564
+ if ( ! $is_activation_mode || ( true !== $this->_storage->require_license_activation ) ) {
15565
+ /**
15566
+ * Add the other menu items if there are any when not in activation mode or license activation is not
15567
+ * required (license activation is required for registered or anonymous users after activating the
15568
+ * premium version when the site is not in trial mode or there's no active valid license).
15569
+ *
15570
+ * @author Leo Fajardo (@leorw)
15571
+ * @since 2.2.1
15572
+ */
15573
+ if ( 0 < count( $this->_menu_items ) ) {
15574
+ if ( ! $this->_menu->is_top_level() ) {
15575
+ fs_enqueue_local_style( 'fs_common', '/admin/common.css' );
15576
+
15577
+ // Append submenu items right after the plugin's submenu item.
15578
+ $this->order_sub_submenu_items();
15579
+ } else {
15580
+ // Append submenu items.
15581
+ $this->embed_submenu_items();
15582
+ }
15583
+ }
15584
+ }
15585
+ }
15586
+
15587
+ /**
15588
+ * Moved the actual submenu item additions to a separated function,
15589
+ * in order to support sub-submenu items when the plugin's settings
15590
+ * only have a submenu and not top-level menu item.
15591
+ *
15592
+ * @author Vova Feldman (@svovaf)
15593
+ * @since 1.1.4
15594
+ */
15595
+ private function embed_submenu_items() {
15596
+ $item_template = $this->_menu->is_top_level() ?
15597
+ '<span class="fs-submenu-item %s %s %s">%s</span>' :
15598
+ '<span class="fs-submenu-item fs-sub %s %s %s">%s</span>';
15599
+
15600
+ $top_level_menu_capability = $this->get_top_level_menu_capability();
15601
+
15602
+ ksort( $this->_menu_items );
15603
+
15604
+ $is_first_submenu_item = true;
15605
+
15606
+ foreach ( $this->_menu_items as $priority => $items ) {
15607
+ foreach ( $items as $item ) {
15608
+ $capability = ( ! empty( $item['capability'] ) ? $item['capability'] : $top_level_menu_capability );
15609
+
15610
+ $menu_item = sprintf(
15611
+ $item_template,
15612
+ $this->get_unique_affix(),
15613
+ $item['menu_slug'],
15614
+ ! empty( $item['class'] ) ? $item['class'] : '',
15615
+ $item['menu_title']
15616
+ );
15617
+
15618
+ $top_level_menu_slug = $this->get_top_level_menu_slug();
15619
+ $menu_slug = $this->_menu->get_slug( $item['menu_slug'] );
15620
+
15621
+ if ( ! isset( $item['url'] ) ) {
15622
+ $hook = FS_Admin_Menu_Manager::add_subpage(
15623
+ $item['show_submenu'] ?
15624
+ $top_level_menu_slug :
15625
+ null,
15626
+ $item['page_title'],
15627
+ $menu_item,
15628
+ $capability,
15629
+ $menu_slug,
15630
+ $item['render_function']
15631
+ );
15632
+
15633
+ if ( false !== $item['before_render_function'] ) {
15634
+ add_action( "load-$hook", $item['before_render_function'] );
15635
+ }
15636
+ } else {
15637
+ FS_Admin_Menu_Manager::add_subpage(
15638
+ $item['show_submenu'] ?
15639
+ $top_level_menu_slug :
15640
+ null,
15641
+ $item['page_title'],
15642
+ $menu_item,
15643
+ $capability,
15644
+ $menu_slug,
15645
+ array( $this, '' )
15646
+ );
15647
+ }
15648
+
15649
+ if ( $item['show_submenu'] && $is_first_submenu_item ) {
15650
+ if ( $this->_is_network_active && ! empty( $this->_dynamically_added_top_level_page_hook_name ) ) {
15651
+ /**
15652
+ * If the top-level menu has been dynamically created, remove the first submenu item that
15653
+ * WordPress automatically creates when there's no submenu item whose slug matches the
15654
+ * parent's. In the following example, the `Awesome Plugin` submenu item will be removed.
15655
+ *
15656
+ * Awesome Plugin
15657
+ * - Awesome Plugin <-- we want to remove this since there's no real setting page for the top-level
15658
+ *
15659
+ * @author Leo Fajardo (@leorw)
15660
+ */
15661
+ remove_submenu_page( $top_level_menu_slug, $top_level_menu_slug );
15662
+ }
15663
+
15664
+ $is_first_submenu_item = false;
15665
+ }
15666
+ }
15667
+ }
15668
+ }
15669
+
15670
+ /**
15671
+ * Re-order the submenu items so all Freemius added new submenu items
15672
+ * are added right after the plugin's settings submenu item.
15673
+ *
15674
+ * @author Vova Feldman (@svovaf)
15675
+ * @since 1.1.4
15676
+ */
15677
+ private function order_sub_submenu_items() {
15678
+ global $submenu;
15679
+
15680
+ $menu_slug = $this->_menu->get_top_level_menu_slug();
15681
+
15682
+ /**
15683
+ * Before "admin_menu" fires, WordPress will loop over the default submenus and remove pages for which the user
15684
+ * does not have permissions. So in case a plugin does not have top-level menu but does have submenus under any
15685
+ * of the default menus, only users that have the right role can access its sub-submenus (Account, Contact Us,
15686
+ * Support Forum, etc.) since $submenu[ $menu_slug ] will be empty if the user doesn't have permission.
15687
+ *
15688
+ * In case a plugin does not have submenus under any of the default menus but does have submenus under the menu
15689
+ * of another plugin, only users that have the right role can access its sub-submenus since we will use the
15690
+ * capability needed to access the parent menu as the capability for the submenus that we will add.
15691
+ */
15692
+ if ( empty( $submenu[ $menu_slug ] ) ) {
15693
+ return;
15694
+ }
15695
+
15696
+ $top_level_menu = &$submenu[ $menu_slug ];
15697
+
15698
+ $all_submenu_items_after = array();
15699
+
15700
+ $found_submenu_item = false;
15701
+
15702
+ foreach ( $top_level_menu as $submenu_id => $meta ) {
15703
+ if ( $found_submenu_item ) {
15704
+ // Remove all submenu items after the plugin's submenu item.
15705
+ $all_submenu_items_after[] = $meta;
15706
+ unset( $top_level_menu[ $submenu_id ] );
15707
+ }
15708
+
15709
+ if ( $this->_menu->get_raw_slug() === $meta[2] ) {
15710
+ // Found the submenu item, put all below.
15711
+ $found_submenu_item = true;
15712
+ continue;
15713
+ }
15714
+ }
15715
+
15716
+ // Embed all plugin's new submenu items.
15717
+ $this->embed_submenu_items();
15718
+
15719
+ // Start with specially high number to make sure it's appended.
15720
+ $i = max( 10000, max( array_keys( $top_level_menu ) ) + 1 );
15721
+ foreach ( $all_submenu_items_after as $meta ) {
15722
+ $top_level_menu[ $i ] = $meta;
15723
+ $i ++;
15724
+ }
15725
+
15726
+ // Sort submenu items.
15727
+ ksort( $top_level_menu );
15728
+ }
15729
+
15730
+ /**
15731
+ * Helper method to return the module's support forum URL.
15732
+ *
15733
+ * @author Vova Feldman (@svovaf)
15734
+ * @since 1.2.2.7
15735
+ *
15736
+ * @return string
15737
+ */
15738
+ function get_support_forum_url() {
15739
+ return $this->apply_filters( 'support_forum_url', "https://wordpress.org/support/{$this->_module_type}/{$this->_slug}" );
15740
+ }
15741
+
15742
+ /**
15743
+ * Displays the Support Forum link when enabled.
15744
+ *
15745
+ * Can be filtered like so:
15746
+ *
15747
+ * function _fs_show_support_menu( $is_visible, $menu_id ) {
15748
+ * if ( 'support' === $menu_id ) {
15749
+ * return _fs->is_registered();
15750
+ * }
15751
+ * return $is_visible;
15752
+ * }
15753
+ * _fs()->add_filter('is_submenu_visible', '_fs_show_support_menu', 10, 2);
15754
+ *
15755
+ */
15756
+ function _add_default_submenu_items() {
15757
+ if ( ! $this->is_on() ) {
15758
+ return;
15759
+ }
15760
+
15761
+ if ( ! $this->is_activation_mode() &&
15762
+ ( ( $this->_is_network_active && fs_is_network_admin() ) ||
15763
+ ( ! $this->_is_network_active && is_admin() ) )
15764
+ ) {
15765
+ $this->add_submenu_link_item(
15766
+ $this->apply_filters( 'support_forum_submenu', $this->get_text_inline( 'Support Forum', 'support-forum' ) ),
15767
+ $this->get_support_forum_url(),
15768
+ 'wp-support-forum',
15769
+ null,
15770
+ 50,
15771
+ $this->is_submenu_item_visible( 'support' )
15772
+ );
15773
+ }
15774
+ }
15775
+
15776
+ /**
15777
+ * @author Vova Feldman (@svovaf)
15778
+ * @since 1.0.1
15779
+ *
15780
+ * @param string $menu_title
15781
+ * @param callable $render_function
15782
+ * @param bool|string $page_title
15783
+ * @param string $capability
15784
+ * @param bool|string $menu_slug
15785
+ * @param bool|callable $before_render_function
15786
+ * @param int $priority
15787
+ * @param bool $show_submenu
15788
+ * @param string $class Since 1.2.1.5 can add custom classes to menu items.
15789
+ */
15790
+ function add_submenu_item(
15791
+ $menu_title,
15792
+ $render_function,
15793
+ $page_title = false,
15794
+ $capability = 'manage_options',
15795
+ $menu_slug = false,
15796
+ $before_render_function = false,
15797
+ $priority = WP_FS__DEFAULT_PRIORITY,
15798
+ $show_submenu = true,
15799
+ $class = ''
15800
+ ) {
15801
+ $this->_logger->entrance( 'Title = ' . $menu_title );
15802
+
15803
+ if ( $this->is_addon() ) {
15804
+ $parent_fs = $this->get_parent_instance();
15805
+
15806
+ if ( is_object( $parent_fs ) ) {
15807
+ $parent_fs->add_submenu_item(
15808
+ $menu_title,
15809
+ $render_function,
15810
+ $page_title,
15811
+ $capability,
15812
+ $menu_slug,
15813
+ $before_render_function,
15814
+ $priority,
15815
+ $show_submenu,
15816
+ $class
15817
+ );
15818
+
15819
+ return;
15820
+ }
15821
+ }
15822
+
15823
+ if ( ! isset( $this->_menu_items[ $priority ] ) ) {
15824
+ $this->_menu_items[ $priority ] = array();
15825
+ }
15826
+
15827
+ $this->_menu_items[ $priority ][] = array(
15828
+ 'page_title' => is_string( $page_title ) ? $page_title : $menu_title,
15829
+ 'menu_title' => $menu_title,
15830
+ 'capability' => $capability,
15831
+ 'menu_slug' => is_string( $menu_slug ) ? $menu_slug : strtolower( $menu_title ),
15832
+ 'render_function' => $render_function,
15833
+ 'before_render_function' => $before_render_function,
15834
+ 'show_submenu' => $show_submenu,
15835
+ 'class' => $class,
15836
+ );
15837
+ }
15838
+
15839
+ /**
15840
+ * @author Vova Feldman (@svovaf)
15841
+ * @since 1.0.1
15842
+ *
15843
+ * @param string $menu_title
15844
+ * @param string $url
15845
+ * @param bool $menu_slug
15846
+ * @param string $capability
15847
+ * @param int $priority
15848
+ * @param bool $show_submenu
15849
+ */
15850
+ function add_submenu_link_item(
15851
+ $menu_title,
15852
+ $url,
15853
+ $menu_slug = false,
15854
+ $capability = 'read',
15855
+ $priority = WP_FS__DEFAULT_PRIORITY,
15856
+ $show_submenu = true
15857
+ ) {
15858
+ $this->_logger->entrance( 'Title = ' . $menu_title . '; Url = ' . $url );
15859
+
15860
+ if ( $this->is_addon() ) {
15861
+ $parent_fs = $this->get_parent_instance();
15862
+
15863
+ if ( is_object( $parent_fs ) ) {
15864
+ $parent_fs->add_submenu_link_item(
15865
+ $menu_title,
15866
+ $url,
15867
+ $menu_slug,
15868
+ $capability,
15869
+ $priority,
15870
+ $show_submenu
15871
+ );
15872
+
15873
+ return;
15874
+ }
15875
+ }
15876
+
15877
+ if ( ! isset( $this->_menu_items[ $priority ] ) ) {
15878
+ $this->_menu_items[ $priority ] = array();
15879
+ }
15880
+
15881
+ $this->_menu_items[ $priority ][] = array(
15882
+ 'menu_title' => $menu_title,
15883
+ 'capability' => $capability,
15884
+ 'menu_slug' => is_string( $menu_slug ) ? $menu_slug : strtolower( $menu_title ),
15885
+ 'url' => $url,
15886
+ 'page_title' => $menu_title,
15887
+ 'render_function' => 'fs_dummy',
15888
+ 'before_render_function' => '',
15889
+ 'show_submenu' => $show_submenu,
15890
+ );
15891
+ }
15892
+
15893
+ #endregion ------------------------------------------------------------------
15894
+
15895
+
15896
+ #--------------------------------------------------------------------------------
15897
+ #region Actions / Hooks / Filters
15898
+ #--------------------------------------------------------------------------------
15899
+
15900
+ /**
15901
+ * @author Vova Feldman (@svovaf)
15902
+ * @since 1.1.7
15903
+ *
15904
+ * @param string $tag
15905
+ *
15906
+ * @return string
15907
+ */
15908
+ public function get_action_tag( $tag ) {
15909
+ return self::get_action_tag_static( $tag, $this->_slug, $this->is_plugin() );
15910
+ }
15911
+
15912
+ /**
15913
+ * @author Vova Feldman (@svovaf)
15914
+ * @since 1.2.1.6
15915
+ *
15916
+ * @param string $tag
15917
+ * @param string $slug
15918
+ * @param bool $is_plugin
15919
+ *
15920
+ * @return string
15921
+ */
15922
+ static function get_action_tag_static( $tag, $slug = '', $is_plugin = true ) {
15923
+ $action = "fs_{$tag}";
15924
+
15925
+ if ( ! empty( $slug ) ) {
15926
+ $action .= '_' . self::get_module_unique_affix( $slug, $is_plugin );
15927
+ }
15928
+
15929
+ return $action;
15930
+ }
15931
+
15932
+ /**
15933
+ * Returns a string that can be used to generate a unique action name,
15934
+ * option name, HTML element ID, or HTML element class.
15935
+ *
15936
+ * @author Leo Fajardo (@leorw)
15937
+ * @since 1.2.2
15938
+ *
15939
+ * @return string
15940
+ */
15941
+ public function get_unique_affix() {
15942
+ return self::get_module_unique_affix( $this->_slug, $this->is_plugin() );
15943
+ }
15944
+
15945
+ /**
15946
+ * Returns a string that can be used to generate a unique action name,
15947
+ * option name, HTML element ID, or HTML element class.
15948
+ *
15949
+ * @author Vova Feldman (@svovaf)
15950
+ * @since 1.2.2.5
15951
+ *
15952
+ * @param string $slug
15953
+ * @param bool $is_plugin
15954
+ *
15955
+ * @return string
15956
+ */
15957
+ static function get_module_unique_affix( $slug, $is_plugin = true ) {
15958
+ $affix = $slug;
15959
+
15960
+ if ( ! $is_plugin ) {
15961
+ $affix .= '-' . WP_FS__MODULE_TYPE_THEME;
15962
+ }
15963
+
15964
+ return $affix;
15965
+ }
15966
+
15967
+ /**
15968
+ * @author Vova Feldman (@svovaf)
15969
+ * @since 1.2.1
15970
+ * @since 1.2.2.5 The AJAX action names are based on the module ID, not like the non-AJAX actions that are
15971
+ * based on the slug for backward compatibility.
15972
+ *
15973
+ * @param string $tag
15974
+ *
15975
+ * @return string
15976
+ */
15977
+ function get_ajax_action( $tag ) {
15978
+ return self::get_ajax_action_static( $tag, $this->_module_id );
15979
+ }
15980
+
15981
+ /**
15982
+ * @author Vova Feldman (@svovaf)
15983
+ * @since 1.2.1.7
15984
+ *
15985
+ * @param string $tag
15986
+ *
15987
+ * @return string
15988
+ */
15989
+ function get_ajax_security( $tag ) {
15990
+ return wp_create_nonce( $this->get_ajax_action( $tag ) );
15991
+ }
15992
+
15993
+ /**
15994
+ * @author Vova Feldman (@svovaf)
15995
+ * @since 1.2.1.7
15996
+ *
15997
+ * @param string $tag
15998
+ */
15999
+ function check_ajax_referer( $tag ) {
16000
+ check_ajax_referer( $this->get_ajax_action( $tag ), 'security' );
16001
+ }
16002
+
16003
+ /**
16004
+ * @author Vova Feldman (@svovaf)
16005
+ * @since 1.2.1.6
16006
+ * @since 1.2.2.5 The AJAX action names are based on the module ID, not like the non-AJAX actions that are
16007
+ * based on the slug for backward compatibility.
16008
+ *
16009
+ * @param string $tag
16010
+ * @param number|null $module_id
16011
+ *
16012
+ * @return string
16013
+ */
16014
+ private static function get_ajax_action_static( $tag, $module_id = null ) {
16015
+ $action = "fs_{$tag}";
16016
+
16017
+ if ( ! empty( $module_id ) ) {
16018
+ $action .= "_{$module_id}";
16019
+ }
16020
+
16021
+ return $action;
16022
+ }
16023
+
16024
+ /**
16025
+ * Do action, specific for the current context plugin.
16026
+ *
16027
+ * @author Vova Feldman (@svovaf)
16028
+ * @since 1.0.1
16029
+ *
16030
+ * @param string $tag The name of the action to be executed.
16031
+ * @param mixed $arg,... Optional. Additional arguments which are passed on to the
16032
+ * functions hooked to the action. Default empty.
16033
+ *
16034
+ * @uses do_action()
16035
+ */
16036
+ function do_action( $tag, $arg = '' ) {
16037
+ $this->_logger->entrance( $tag );
16038
+
16039
+ $args = func_get_args();
16040
+
16041
+ call_user_func_array( 'do_action', array_merge(
16042
+ array( $this->get_action_tag( $tag ) ),
16043
+ array_slice( $args, 1 ) )
16044
+ );
16045
+ }
16046
+
16047
+ /**
16048
+ * Add action, specific for the current context plugin.
16049
+ *
16050
+ * @author Vova Feldman (@svovaf)
16051
+ * @since 1.0.1
16052
+ *
16053
+ * @param string $tag
16054
+ * @param callable $function_to_add
16055
+ * @param int $priority
16056
+ * @param int $accepted_args
16057
+ *
16058
+ * @uses add_action()
16059
+ */
16060
+ function add_action(
16061
+ $tag,
16062
+ $function_to_add,
16063
+ $priority = WP_FS__DEFAULT_PRIORITY,
16064
+ $accepted_args = 1
16065
+ ) {
16066
+ $this->_logger->entrance( $tag );
16067
+
16068
+ add_action( $this->get_action_tag( $tag ), $function_to_add, $priority, $accepted_args );
16069
+ }
16070
+
16071
+ /**
16072
+ * Add AJAX action, specific for the current context plugin.
16073
+ *
16074
+ * @author Vova Feldman (@svovaf)
16075
+ * @since 1.2.1
16076
+ *
16077
+ * @param string $tag
16078
+ * @param callable $function_to_add
16079
+ * @param int $priority
16080
+ *
16081
+ * @uses add_action()
16082
+ *
16083
+ * @return bool True if action added, false if no need to add the action since the AJAX call isn't matching.
16084
+ */
16085
+ function add_ajax_action(
16086
+ $tag,
16087
+ $function_to_add,
16088
+ $priority = WP_FS__DEFAULT_PRIORITY
16089
+ ) {
16090
+ $this->_logger->entrance( $tag );
16091
+
16092
+ return self::add_ajax_action_static(
16093
+ $tag,
16094
+ $function_to_add,
16095
+ $priority,
16096
+ $this->_module_id
16097
+ );
16098
+ }
16099
+
16100
+ /**
16101
+ * Add AJAX action.
16102
+ *
16103
+ * @author Vova Feldman (@svovaf)
16104
+ * @since 1.2.1.6
16105
+ *
16106
+ * @param string $tag
16107
+ * @param callable $function_to_add
16108
+ * @param int $priority
16109
+ * @param number|null $module_id
16110
+ *
16111
+ * @return bool True if action added, false if no need to add the action since the AJAX call isn't matching.
16112
+ * @uses add_action()
16113
+ *
16114
+ */
16115
+ static function add_ajax_action_static(
16116
+ $tag,
16117
+ $function_to_add,
16118
+ $priority = WP_FS__DEFAULT_PRIORITY,
16119
+ $module_id = null
16120
+ ) {
16121
+ self::$_static_logger->entrance( $tag );
16122
+
16123
+ if ( ! self::is_ajax_action_static( $tag, $module_id ) ) {
16124
+ return false;
16125
+ }
16126
+
16127
+ add_action(
16128
+ 'wp_ajax_' . self::get_ajax_action_static( $tag, $module_id ),
16129
+ $function_to_add,
16130
+ $priority,
16131
+ 0
16132
+ );
16133
+
16134
+ self::$_static_logger->info( "$tag AJAX callback action added." );
16135
+
16136
+ return true;
16137
+ }
16138
+
16139
+ /**
16140
+ * Send a JSON response back to an Ajax request.
16141
+ *
16142
+ * @author Vova Feldman (@svovaf)
16143
+ * @since 1.2.1.5
16144
+ *
16145
+ * @param mixed $response
16146
+ */
16147
+ static function shoot_ajax_response( $response ) {
16148
+ wp_send_json( $response );
16149
+ }
16150
+
16151
+ /**
16152
+ * Send a JSON response back to an Ajax request, indicating success.
16153
+ *
16154
+ * @author Vova Feldman (@svovaf)
16155
+ * @since 1.2.1.5
16156
+ *
16157
+ * @param mixed $data Data to encode as JSON, then print and exit.
16158
+ */
16159
+ static function shoot_ajax_success( $data = null ) {
16160
+ wp_send_json_success( $data );
16161
+ }
16162
+
16163
+ /**
16164
+ * Send a JSON response back to an Ajax request, indicating failure.
16165
+ *
16166
+ * @author Vova Feldman (@svovaf)
16167
+ * @since 1.2.1.5
16168
+ *
16169
+ * @param mixed $error Optional error message.
16170
+ */
16171
+ static function shoot_ajax_failure( $error = '' ) {
16172
+ $result = array( 'success' => false );
16173
+ if ( ! empty( $error ) ) {
16174
+ $result['error'] = $error;
16175
+ }
16176
+
16177
+ wp_send_json( $result );
16178
+ }
16179
+
16180
+ /**
16181
+ * Apply filter, specific for the current context plugin.
16182
+ *
16183
+ * @author Vova Feldman (@svovaf)
16184
+ * @since 1.0.9
16185
+ *
16186
+ * @param string $tag The name of the filter hook.
16187
+ * @param mixed $value The value on which the filters hooked to `$tag` are applied on.
16188
+ *
16189
+ * @return mixed The filtered value after all hooked functions are applied to it.
16190
+ *
16191
+ * @uses apply_filters()
16192
+ */
16193
+ function apply_filters( $tag, $value ) {
16194
+ $this->_logger->entrance( $tag );
16195
+
16196
+ $args = func_get_args();
16197
+ array_unshift( $args, $this->get_unique_affix() );
16198
+
16199
+ return call_user_func_array( 'fs_apply_filter', $args );
16200
+ }
16201
+
16202
+ /**
16203
+ * Add filter, specific for the current context plugin.
16204
+ *
16205
+ * @author Vova Feldman (@svovaf)
16206
+ * @since 1.0.9
16207
+ *
16208
+ * @param string $tag
16209
+ * @param callable $function_to_add
16210
+ * @param int $priority
16211
+ * @param int $accepted_args
16212
+ *
16213
+ * @uses add_filter()
16214
+ */
16215
+ function add_filter( $tag, $function_to_add, $priority = WP_FS__DEFAULT_PRIORITY, $accepted_args = 1 ) {
16216
+ $this->_logger->entrance( $tag );
16217
+
16218
+ add_filter( $this->get_action_tag( $tag ), $function_to_add, $priority, $accepted_args );
16219
+ }
16220
+
16221
+ /**
16222
+ * Check if has filter.
16223
+ *
16224
+ * @author Vova Feldman (@svovaf)
16225
+ * @since 1.1.4
16226
+ *
16227
+ * @param string $tag
16228
+ * @param callable|bool $function_to_check Optional. The callback to check for. Default false.
16229
+ *
16230
+ * @return false|int
16231
+ *
16232
+ * @uses has_filter()
16233
+ */
16234
+ function has_filter( $tag, $function_to_check = false ) {
16235
+ $this->_logger->entrance( $tag );
16236
+
16237
+ return has_filter( $this->get_action_tag( $tag ), $function_to_check );
16238
+ }
16239
+
16240
+ #endregion
16241
+
16242
+ /**
16243
+ * Override default i18n text phrases.
16244
+ *
16245
+ * @author Vova Feldman (@svovaf)
16246
+ * @since 1.1.6
16247
+ *
16248
+ * @param string[] string $key_value
16249
+ *
16250
+ * @uses fs_override_i18n()
16251
+ */
16252
+ function override_i18n( $key_value ) {
16253
+ fs_override_i18n( $key_value, $this->_slug );
16254
+ }
16255
+
16256
+ /* Account Page
16257
+ ------------------------------------------------------------------------------------------------------------------*/
16258
+ /**
16259
+ * Update site information.
16260
+ *
16261
+ * @author Vova Feldman (@svovaf)
16262
+ * @since 1.0.1
16263
+ *
16264
+ * @param bool $store Flush to Database if true.
16265
+ * @param null|int $network_level_or_blog_id Since 2.0.0
16266
+ * @param \FS_Site $site Since 2.0.0
16267
+ */
16268
+ private function _store_site( $store = true, $network_level_or_blog_id = null, FS_Site $site = null ) {
16269
+ $this->_logger->entrance();
16270
+
16271
+ if ( empty( $this->_site->id ) ) {
16272
+ $this->_logger->error( "Empty install ID, can't store site." );
16273
+
16274
+ return;
16275
+ }
16276
+
16277
+ $site_clone = is_object( $site ) ? $site : $this->_site;
16278
+ $encrypted_site = clone $site_clone;
16279
+
16280
+ $sites = self::get_all_sites( $this->_module_type, $network_level_or_blog_id );
16281
+
16282
+ $prev_stored_user_id = $this->_storage->get( 'prev_user_id', false, $network_level_or_blog_id );
16283
+
16284
+ if ( empty( $prev_stored_user_id ) &&
16285
+ $this->_user->id != $this->_site->user_id
16286
+ ) {
16287
+ /**
16288
+ * Store the current user ID as the previous user ID so that the previous user can be used
16289
+ * as the install's owner while the new owner's details are not yet available.
16290
+ *
16291
+ * This will be executed only in the `replica` site. For example, there are 2 sites, namely `original`
16292
+ * and `replica`, then an ownership change was initiated and completed in the `original`, the `replica`
16293
+ * will be using the previous user until it is updated again (e.g.: until the next clone of `original`
16294
+ * into `replica`.
16295
+ *
16296
+ * @author Leo Fajardo (@leorw)
16297
+ */
16298
+ $this->_storage->store( 'prev_user_id', $sites[ $this->_slug ]->user_id, $network_level_or_blog_id );
16299
+ }
16300
+
16301
+ $sites[ $this->_slug ] = $encrypted_site;
16302
+
16303
+ $this->set_account_option( 'sites', $sites, $store, $network_level_or_blog_id );
16304
+ }
16305
+
16306
+ /**
16307
+ * Update plugin's plans information.
16308
+ *
16309
+ * @author Vova Feldman (@svovaf)
16310
+ * @since 1.0.2
16311
+ *
16312
+ * @param bool $store Flush to Database if true.
16313
+ */
16314
+ private function _store_plans( $store = true ) {
16315
+ $this->_logger->entrance();
16316
+
16317
+ $plans = self::get_all_plans( $this->_module_type );
16318
+
16319
+ // Copy plans.
16320
+ $encrypted_plans = array();
16321
+ for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
16322
+ $encrypted_plans[] = self::_encrypt_entity( $this->_plans[ $i ] );
16323
+ }
16324
+
16325
+ $plans[ $this->_slug ] = $encrypted_plans;
16326
+
16327
+ $this->set_account_option( 'plans', $plans, $store );
16328
+ }
16329
+
16330
+ /**
16331
+ * Update user's plugin licenses.
16332
+ *
16333
+ * @author Vova Feldman (@svovaf)
16334
+ * @since 1.0.5
16335
+ *
16336
+ * @param bool $store
16337
+ * @param number|bool $module_id
16338
+ * @param FS_Plugin_License[] $licenses
16339
+ */
16340
+ private function _store_licenses( $store = true, $module_id = false, $licenses = array() ) {
16341
+ $this->_logger->entrance();
16342
+
16343
+ $all_licenses = self::get_all_licenses();
16344
+
16345
+ if ( ! FS_Plugin::is_valid_id( $module_id ) ) {
16346
+ $module_id = $this->_module_id;
16347
+
16348
+ $user_licenses = is_array( $this->_licenses ) ?
16349
+ $this->_licenses :
16350
+ array();
16351
+
16352
+ if ( empty( $user_licenses ) ) {
16353
+ // If the context user doesn't have any license, don't update the licenses collection.
16354
+ return;
16355
+ }
16356
+
16357
+ $new_user_licenses_map = array();
16358
+ foreach ( $user_licenses as $user_license ) {
16359
+ $new_user_licenses_map[ $user_license->id ] = $user_license;
16360
+ }
16361
+
16362
+ self::store_user_id_license_ids_map( array_keys( $new_user_licenses_map ), $this->_module_id, $this->_user->id );
16363
+
16364
+ // Update user licenses.
16365
+ $licenses_to_update_count = count( $new_user_licenses_map );
16366
+ foreach ( $all_licenses[ $module_id ] as $key => $license ) {
16367
+ if ( 0 === $licenses_to_update_count ) {
16368
+ break;
16369
+ }
16370
+
16371
+ if ( isset( $new_user_licenses_map[ $license->id ] ) ) {
16372
+ // Update license.
16373
+ $all_licenses[ $module_id ][ $key ] = $new_user_licenses_map[ $license->id ];
16374
+ unset( $new_user_licenses_map[ $license->id ] );
16375
+
16376
+ $licenses_to_update_count --;
16377
+ }
16378
+ }
16379
+
16380
+ if ( ! empty( $new_user_licenses_map ) ) {
16381
+ // Add new licenses.
16382
+ $all_licenses[ $module_id ] = array_merge( array_values( $new_user_licenses_map ), $all_licenses[ $module_id ] );
16383
+ }
16384
+
16385
+ $licenses = $all_licenses[ $module_id ];
16386
+ }
16387
+
16388
+ if ( ! isset( $all_licenses[ $module_id ] ) ) {
16389
+ $all_licenses[ $module_id ] = array();
16390
+ }
16391
+
16392
+ $all_licenses[ $module_id ] = $licenses;
16393
+
16394
+ self::$_accounts->set_option( 'all_licenses', $all_licenses, $store );
16395
+ }
16396
+
16397
+ /**
16398
+ * Update user information.
16399
+ *
16400
+ * @author Vova Feldman (@svovaf)
16401
+ * @since 1.0.1
16402
+ *
16403
+ * @param bool $store Flush to Database if true.
16404
+ */
16405
+ private function _store_user( $store = true ) {
16406
+ $this->_logger->entrance();
16407
+
16408
+ if ( empty( $this->_user->id ) ) {
16409
+ $this->_logger->error( "Empty user ID, can't store user." );
16410
+
16411
+ return;
16412
+ }
16413
+
16414
+ $users = self::get_all_users();
16415
+ $users[ $this->_user->id ] = $this->_user;
16416
+ self::$_accounts->set_option( 'users', $users, $store );
16417
+ }
16418
+
16419
+ /**
16420
+ * Update new updates information.
16421
+ *
16422
+ * @author Vova Feldman (@svovaf)
16423
+ * @since 1.0.4
16424
+ *
16425
+ * @param FS_Plugin_Tag|null $update
16426
+ * @param bool $store Flush to Database if true.
16427
+ * @param bool|number $plugin_id
16428
+ */
16429
+ private function _store_update( $update, $store = true, $plugin_id = false ) {
16430
+ $this->_logger->entrance();
16431
+
16432
+ if ( $update instanceof FS_Plugin_Tag ) {
16433
+ $update->updated = time();
16434
+ }
16435
+
16436
+ if ( ! is_numeric( $plugin_id ) ) {
16437
+ $plugin_id = $this->_plugin->id;
16438
+ }
16439
+
16440
+ $updates = self::get_all_updates();
16441
+ $updates[ $plugin_id ] = $update;
16442
+ self::$_accounts->set_option( 'updates', $updates, $store );
16443
+ }
16444
+
16445
+ /**
16446
+ * Update new updates information.
16447
+ *
16448
+ * @author Vova Feldman (@svovaf)
16449
+ * @since 1.0.6
16450
+ *
16451
+ * @param FS_Plugin[] $plugin_addons
16452
+ * @param bool $store Flush to Database if true.
16453
+ */
16454
+ private function _store_addons( $plugin_addons, $store = true ) {
16455
+ $this->_logger->entrance();
16456
+
16457
+ $addons = self::get_all_addons();
16458
+ $addons[ $this->_plugin->id ] = $plugin_addons;
16459
+ self::$_accounts->set_option( 'addons', $addons, $store );
16460
+ }
16461
+
16462
+ /**
16463
+ * Delete plugin's associated add-ons.
16464
+ *
16465
+ * @author Vova Feldman (@svovaf)
16466
+ * @since 1.0.8
16467
+ *
16468
+ * @param bool $store
16469
+ *
16470
+ * @return bool
16471
+ */
16472
+ private function _delete_account_addons( $store = true ) {
16473
+ $all_addons = self::get_all_account_addons();
16474
+
16475
+ if ( ! isset( $all_addons[ $this->_plugin->id ] ) ) {
16476
+ return false;
16477
+ }
16478
+
16479
+ unset( $all_addons[ $this->_plugin->id ] );
16480
+
16481
+ self::$_accounts->set_option( 'account_addons', $all_addons, $store );
16482
+
16483
+ return true;
16484
+ }
16485
+
16486
+ /**
16487
+ * Update account add-ons list.
16488
+ *
16489
+ * @author Vova Feldman (@svovaf)
16490
+ * @since 1.0.6
16491
+ *
16492
+ * @param FS_Plugin[] $addons
16493
+ * @param bool $store Flush to Database if true.
16494
+ */
16495
+ private function _store_account_addons( $addons, $store = true ) {
16496
+ $this->_logger->entrance();
16497
+
16498
+ $all_addons = self::get_all_account_addons();
16499
+ $all_addons[ $this->_plugin->id ] = $addons;
16500
+ self::$_accounts->set_option( 'account_addons', $all_addons, $store );
16501
+ }
16502
+
16503
+ /**
16504
+ * Store account params in the Database.
16505
+ *
16506
+ * @author Vova Feldman (@svovaf)
16507
+ * @since 1.0.1
16508
+ *
16509
+ * @param null|int $blog_id Since 2.0.0
16510
+ */
16511
+ private function _store_account( $blog_id = null ) {
16512
+ $this->_logger->entrance();
16513
+
16514
+ $this->_store_site( false, $blog_id );
16515
+ $this->_store_user( false );
16516
+ $this->_store_plans( false );
16517
+ $this->_store_licenses( false );
16518
+
16519
+ self::$_accounts->store( $blog_id );
16520
+ }
16521
+
16522
+ /**
16523
+ * Sync user's information.
16524
+ *
16525
+ * @author Vova Feldman (@svovaf)
16526
+ * @since 1.0.3
16527
+ * @uses FS_Api
16528
+ */
16529
+ private function _handle_account_user_sync() {
16530
+ $this->_logger->entrance();
16531
+
16532
+ $api = $this->get_api_user_scope();
16533
+
16534
+ // Get user's information.
16535
+ $user = $api->get( '/', true );
16536
+
16537
+ if ( isset( $user->id ) ) {
16538
+ $this->_user->first = $user->first;
16539
+ $this->_user->last = $user->last;
16540
+ $this->_user->email = $user->email;
16541
+
16542
+ $is_menu_item_account_visible = $this->is_submenu_item_visible( 'account' );
16543
+
16544
+ if ( $user->is_verified &&
16545
+ ( ! isset( $this->_user->is_verified ) || false === $this->_user->is_verified )
16546
+ ) {
16547
+ $this->_user->is_verified = true;
16548
+
16549
+ $this->do_action( 'account_email_verified', $user->email );
16550
+
16551
+ $this->_admin_notices->add(
16552
+ $this->get_text_inline( 'Your email has been successfully verified - you are AWESOME!', 'email-verified-message' ),
16553
+ $this->get_text_x_inline( 'Right on', 'a positive response', 'right-on' ) . '!',
16554
+ 'success',
16555
+ // Make admin sticky if account menu item is invisible,
16556
+ // since the page will be auto redirected to the plugin's
16557
+ // main settings page, and the non-sticky message
16558
+ // will disappear.
16559
+ ! $is_menu_item_account_visible,
16560
+ 'email_verified'
16561
+ );
16562
+ }
16563
+
16564
+ // Flush user details to DB.
16565
+ $this->_store_user();
16566
+
16567
+ $this->do_action( 'after_account_user_sync', $user );
16568
+
16569
+ /**
16570
+ * If account menu item is hidden, redirect to plugin's main settings page.
16571
+ *
16572
+ * @author Vova Feldman (@svovaf)
16573
+ * @since 1.1.6
16574
+ *
16575
+ * @link https://github.com/Freemius/wordpress-sdk/issues/6
16576
+ */
16577
+ if ( ! $is_menu_item_account_visible ) {
16578
+ fs_redirect( $this->_get_admin_page_url() );
16579
+ }
16580
+ }
16581
+ }
16582
+
16583
+ /**
16584
+ * @author Vova Feldman (@svovaf)
16585
+ * @since 1.0.9
16586
+ * @uses FS_Api
16587
+ *
16588
+ * @param number|bool $license_id
16589
+ *
16590
+ * @return FS_Subscription|object|bool
16591
+ */
16592
+ private function _fetch_site_license_subscription( $license_id = false ) {
16593
+ $this->_logger->entrance();
16594
+ $api = $this->get_api_site_scope();
16595
+
16596
+ if ( ! is_numeric( $license_id ) ) {
16597
+ $license_id = $this->_license->id;
16598
+ }
16599
+
16600
+ $result = $api->get( "/licenses/{$license_id}/subscriptions.json", true );
16601
+
16602
+ return ! isset( $result->error ) ?
16603
+ ( ( is_array( $result->subscriptions ) && 0 < count( $result->subscriptions ) ) ?
16604
+ new FS_Subscription( $result->subscriptions[0] ) :
16605
+ false
16606
+ ) :
16607
+ $result;
16608
+ }
16609
+
16610
+ /**
16611
+ * @author Vova Feldman (@svovaf)
16612
+ * @since 1.0.4
16613
+ * @uses FS_Api
16614
+ *
16615
+ * @param number|bool $plan_id
16616
+ *
16617
+ * @return FS_Plugin_Plan|object
16618
+ */
16619
+ private function _fetch_site_plan( $plan_id = false ) {
16620
+ $this->_logger->entrance();
16621
+ $api = $this->get_api_site_scope();
16622
+
16623
+ if ( ! is_numeric( $plan_id ) ) {
16624
+ $plan_id = $this->_site->plan_id;
16625
+ }
16626
+
16627
+ $plan = $api->get( "/plans/{$plan_id}.json", true );
16628
+
16629
+ return ! isset( $plan->error ) ? new FS_Plugin_Plan( $plan ) : $plan;
16630
+ }
16631
+
16632
+ /**
16633
+ * @author Vova Feldman (@svovaf)
16634
+ * @since 1.0.5
16635
+ * @uses FS_Api
16636
+ *
16637
+ * @return FS_Plugin_Plan[]|object
16638
+ */
16639
+ private function _fetch_plugin_plans() {
16640
+ $this->_logger->entrance();
16641
+ $api = $this->get_current_or_network_user_api_scope();
16642
+
16643
+ /**
16644
+ * @since 1.2.3 When running in DEV mode, retrieve pending plans as well.
16645
+ */
16646
+ $result = $api->get( $this->add_show_pending( "/plugins/{$this->_module_id}/plans.json" ), true );
16647
+
16648
+ if ( $this->is_api_result_object( $result, 'plans' ) && is_array( $result->plans ) ) {
16649
+ for ( $i = 0, $len = count( $result->plans ); $i < $len; $i ++ ) {
16650
+ $result->plans[ $i ] = new FS_Plugin_Plan( $result->plans[ $i ] );
16651
+ }
16652
+
16653
+ $result = $result->plans;
16654
+ }
16655
+
16656
+ return $result;
16657
+ }
16658
+
16659
+ /**
16660
+ * @author Vova Feldman (@svovaf)
16661
+ * @since 2.0.0
16662
+ *
16663
+ * @param number $plan_id
16664
+ *
16665
+ * @return \FS_Plugin_Plan|object
16666
+ */
16667
+ private function fetch_plan_by_id( $plan_id ) {
16668
+ $this->_logger->entrance();
16669
+ $api = $this->get_current_or_network_user_api_scope();
16670
+
16671
+ $result = $api->get( "/plugins/{$this->_module_id}/plans/{$plan_id}.json", true );
16672
+
16673
+ return $this->is_api_result_entity( $result ) ?
16674
+ new FS_Plugin_Plan( $result ) :
16675
+ $result;
16676
+ }
16677
+
16678
+ /**
16679
+ * @author Vova Feldman (@svovaf)
16680
+ * @since 1.0.5
16681
+ * @uses FS_Api
16682
+ *
16683
+ * @param number|bool $plugin_id
16684
+ * @param number|bool $site_license_id
16685
+ * @param array $foreign_licenses @since 2.0.0. This is used by network-activated plugins.
16686
+ * @param number|null $blog_id
16687
+ *
16688
+ * @return FS_Plugin_License[]|object
16689
+ */
16690
+ private function _fetch_licenses(
16691
+ $plugin_id = false,
16692
+ $site_license_id = false,
16693
+ $foreign_licenses = array(),
16694
+ $blog_id = null
16695
+ ) {
16696
+ $this->_logger->entrance();
16697
+
16698
+ $api = $this->get_api_user_scope();
16699
+
16700
+ if ( ! is_numeric( $plugin_id ) ) {
16701
+ $plugin_id = $this->_plugin->id;
16702
+ }
16703
+
16704
+ $user_licenses_endpoint = "/plugins/{$plugin_id}/licenses.json";
16705
+ if ( ! empty ( $foreign_licenses ) ) {
16706
+ $foreign_licenses = array(
16707
+ // Prefix with `+` to tell the server to include foreign licenses in the licenses collection.
16708
+ 'ids' => ( urlencode( '+' ) . implode( ',', $foreign_licenses['ids'] ) ),
16709
+ 'license_keys' => implode( ',', array_map( 'urlencode', $foreign_licenses['license_keys'] ) )
16710
+ );
16711
+
16712
+ $user_licenses_endpoint = add_query_arg( $foreign_licenses, $user_licenses_endpoint );
16713
+ }
16714
+
16715
+ $result = $api->get( $user_licenses_endpoint, true );
16716
+
16717
+ $is_site_license_synced = false;
16718
+
16719
+ $api_errors = array();
16720
+
16721
+ if ( $this->is_api_result_object( $result, 'licenses' ) &&
16722
+ is_array( $result->licenses )
16723
+ ) {
16724
+ for ( $i = 0, $len = count( $result->licenses ); $i < $len; $i ++ ) {
16725
+ $result->licenses[ $i ] = new FS_Plugin_License( $result->licenses[ $i ] );
16726
+
16727
+ if ( ( ! $is_site_license_synced ) && is_numeric( $site_license_id ) ) {
16728
+ $is_site_license_synced = ( $site_license_id == $result->licenses[ $i ]->id );
16729
+ }
16730
+ }
16731
+
16732
+ $result = $result->licenses;
16733
+ } else {
16734
+ $api_errors[] = $result;
16735
+ $result = array();
16736
+ }
16737
+
16738
+ if ( ! $is_site_license_synced ) {
16739
+ if ( ! is_null( $blog_id ) ) {
16740
+ /**
16741
+ * If blog ID is not null, the request is for syncing of the license of a single site via the
16742
+ * network-level "Account" page.
16743
+ *
16744
+ * @author Leo Fajardo (@leorw)
16745
+ */
16746
+ $this->switch_to_blog( $blog_id );
16747
+ }
16748
+
16749
+ $api = $this->get_api_site_scope();
16750
+
16751
+ if ( is_numeric( $site_license_id ) ) {
16752
+ // Try to retrieve a foreign license that is linked to the install.
16753
+ $api_result = $api->call( '/licenses.json' );
16754
+
16755
+ if ( $this->is_api_result_object( $api_result, 'licenses' ) &&
16756
+ is_array( $api_result->licenses )
16757
+ ) {
16758
+ $licenses = $api_result->licenses;
16759
+
16760
+ if ( ! empty( $licenses ) ) {
16761
+ $result[] = new FS_Plugin_License( $licenses[0] );
16762
+ }
16763
+ } else {
16764
+ $api_errors[] = $api_result;
16765
+ }
16766
+ } else if ( is_object( $this->_license ) ) {
16767
+ $is_license_in_result = false;
16768
+ if ( ! empty( $result ) ) {
16769
+ foreach ( $result as $license ) {
16770
+ if ( $license->id == $this->_license->id ) {
16771
+ $is_license_in_result = true;
16772
+ break;
16773
+ }
16774
+ }
16775
+ }
16776
+
16777
+ if ( ! $is_license_in_result ) {
16778
+ // Fetch foreign license by ID and license key.
16779
+ $license = $api->get( "/licenses/{$this->_license->id}.json?license_key=" .
16780
+ urlencode( $this->_license->secret_key ) );
16781
+
16782
+ if ( $this->is_api_result_entity( $license ) ) {
16783
+ $result[] = new FS_Plugin_License( $license );
16784
+ } else {
16785
+ $api_errors[] = $license;
16786
+ }
16787
+ }
16788
+ }
16789
+
16790
+ if ( ! is_null( $blog_id ) ) {
16791
+ $this->switch_to_blog( $this->_storage->network_install_blog_id );
16792
+ }
16793
+ }
16794
+
16795
+ if ( is_array( $result ) && 0 < count( $result ) ) {
16796
+ // If found at least one license, return license collection even if there are errors.
16797
+ return $result;
16798
+ }
16799
+
16800
+ if ( ! empty( $api_errors ) ) {
16801
+ // If found any errors and no licenses, return first error.
16802
+ return $api_errors[0];
16803
+ }
16804
+
16805
+ // Fallback to empty licenses list.
16806
+ return $result;
16807
+ }
16808
+
16809
+ /**
16810
+ * @author Vova Feldman (@svovaf)
16811
+ * @since 2.0.0
16812
+ *
16813
+ * @param number $license_id
16814
+ * @param string $license_key
16815
+ *
16816
+ * @return \FS_Plugin_License|object
16817
+ */
16818
+ private function fetch_license_by_key( $license_id, $license_key ) {
16819
+ $this->_logger->entrance();
16820
+
16821
+ $api = $this->get_current_or_network_user_api_scope();
16822
+
16823
+ $result = $api->get( "/licenses/{$license_id}.json?license_key=" . urlencode( $license_key ) );
16824
+
16825
+ return $this->is_api_result_entity( $result ) ?
16826
+ new FS_Plugin_License( $result ) :
16827
+ $result;
16828
+ }
16829
+
16830
+ /**
16831
+ * @author Vova Feldman (@svovaf)
16832
+ * @since 1.2.0
16833
+ * @uses FS_Api
16834
+ *
16835
+ * @param number|bool $plugin_id
16836
+ * @param bool $flush
16837
+ *
16838
+ * @return FS_Payment[]|object
16839
+ */
16840
+ function _fetch_payments( $plugin_id = false, $flush = false ) {
16841
+ $this->_logger->entrance();
16842
+
16843
+ $api = $this->get_api_user_scope();
16844
+
16845
+ if ( ! is_numeric( $plugin_id ) ) {
16846
+ $plugin_id = $this->_plugin->id;
16847
+ }
16848
+
16849
+ $result = $api->get( "/plugins/{$plugin_id}/payments.json?include_addons=true", $flush );
16850
+
16851
+ if ( ! isset( $result->error ) ) {
16852
+ for ( $i = 0, $len = count( $result->payments ); $i < $len; $i ++ ) {
16853
+ $result->payments[ $i ] = new FS_Payment( $result->payments[ $i ] );
16854
+ }
16855
+ $result = $result->payments;
16856
+ }
16857
+
16858
+ return $result;
16859
+ }
16860
+
16861
+ /**
16862
+ * @author Vova Feldman (@svovaf)
16863
+ * @since 1.2.1.5
16864
+ * @uses FS_Api
16865
+ *
16866
+ * @param bool $flush
16867
+ *
16868
+ * @return \FS_Billing|mixed
16869
+ */
16870
+ function _fetch_billing( $flush = false ) {
16871
+ require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-billing.php';
16872
+
16873
+ $billing = $this->get_api_user_scope()->get( 'billing.json', $flush );
16874
+
16875
+ if ( $this->is_api_result_entity( $billing ) ) {
16876
+ $billing = new FS_Billing( $billing );
16877
+ }
16878
+
16879
+ return $billing;
16880
+ }
16881
+
16882
+ /**
16883
+ * @author Vova Feldman (@svovaf)
16884
+ * @since 1.0.5
16885
+ *
16886
+ * @param FS_Plugin_License[] $licenses
16887
+ * @param number $module_id
16888
+ */
16889
+ private function _update_licenses( $licenses, $module_id ) {
16890
+ $this->_logger->entrance();
16891
+
16892
+ if ( is_array( $licenses ) ) {
16893
+ for ( $i = 0, $len = count( $licenses ); $i < $len; $i ++ ) {
16894
+ $licenses[ $i ]->updated = time();
16895
+ }
16896
+ }
16897
+
16898
+ $this->_store_licenses( true, $module_id, $licenses );
16899
+ }
16900
+
16901
+ /**
16902
+ * @author Vova Feldman (@svovaf)
16903
+ * @since 1.0.4
16904
+ *
16905
+ * @param bool|number $plugin_id
16906
+ * @param bool $flush Since 1.1.7.3
16907
+ * @param int $expiration Since 1.2.2.7
16908
+ * @param bool|string $newer_than Since 2.2.1
16909
+ *
16910
+ * @return object|false New plugin tag info if exist.
16911
+ */
16912
+ private function _fetch_newer_version( $plugin_id = false, $flush = true, $expiration = WP_FS__TIME_24_HOURS_IN_SEC, $newer_than = false ) {
16913
+ $latest_tag = $this->_fetch_latest_version( $plugin_id, $flush, $expiration, $newer_than );
16914
+
16915
+ if ( ! is_object( $latest_tag ) ) {
16916
+ return false;
16917
+ }
16918
+
16919
+ // Check if version is actually newer.
16920
+ $has_new_version =
16921
+ // If it's an non-installed add-on then always return latest.
16922
+ ( $this->_is_addon_id( $plugin_id ) && ! $this->is_addon_activated( $plugin_id ) ) ||
16923
+ // Compare versions.
16924
+ version_compare( $this->get_plugin_version(), $latest_tag->version, '<' );
16925
+
16926
+ $this->_logger->departure( $has_new_version ? 'Found newer plugin version ' . $latest_tag->version : 'No new version' );
16927
+
16928
+ return $has_new_version ? $latest_tag : false;
16929
+ }
16930
+
16931
+ /**
16932
+ * @author Vova Feldman (@svovaf)
16933
+ * @since 1.0.5
16934
+ *
16935
+ * @param bool|number $plugin_id
16936
+ * @param bool $flush Since 1.1.7.3
16937
+ * @param int $expiration Since 1.2.2.7
16938
+ * @param bool|string $newer_than Since 2.2.1
16939
+ *
16940
+ * @return bool|FS_Plugin_Tag
16941
+ */
16942
+ function get_update( $plugin_id = false, $flush = true, $expiration = WP_FS__TIME_24_HOURS_IN_SEC, $newer_than = false ) {
16943
+ $this->_logger->entrance();
16944
+
16945
+ if ( ! is_numeric( $plugin_id ) ) {
16946
+ $plugin_id = $this->_plugin->id;
16947
+ }
16948
+
16949
+ $this->check_updates( true, $plugin_id, $flush, $expiration, $newer_than );
16950
+ $updates = $this->get_all_updates();
16951
+
16952
+ return isset( $updates[ $plugin_id ] ) && is_object( $updates[ $plugin_id ] ) ? $updates[ $plugin_id ] : false;
16953
+ }
16954
+
16955
+ /**
16956
+ * Check if site assigned with active license.
16957
+ *
16958
+ * @author Vova Feldman (@svovaf)
16959
+ * @since 1.0.6
16960
+ *
16961
+ * @deprecated Please use has_active_valid_license() instead because license can be cancelled.
16962
+ */
16963
+ function has_active_license() {
16964
+ return (
16965
+ is_object( $this->_license ) &&
16966
+ is_numeric( $this->_license->id ) &&
16967
+ ! $this->_license->is_expired()
16968
+ );
16969
+ }
16970
+
16971
+ /**
16972
+ * Check if site assigned with active & valid (not expired) license.
16973
+ *
16974
+ * @author Vova Feldman (@svovaf)
16975
+ * @since 1.2.1
16976
+ */
16977
+ function has_active_valid_license() {
16978
+ return self::is_active_valid_license( $this->_license );
16979
+ }
16980
+
16981
+ /**
16982
+ * Check if a given license is active & valid (not expired).
16983
+ *
16984
+ * @author Vova Feldman (@svovaf)
16985
+ * @since 2.1.3
16986
+ *
16987
+ * @param FS_Plugin_License $license
16988
+ *
16989
+ * @return bool
16990
+ */
16991
+ private static function is_active_valid_license( $license ) {
16992
+ return (
16993
+ is_object( $license ) &&
16994
+ FS_Plugin_License::is_valid_id( $license->id ) &&
16995
+ $license->is_active() &&
16996
+ $license->is_valid()
16997
+ );
16998
+ }
16999
+
17000
+ /**
17001
+ * Checks if there's any site that is associated with an active & valid license.
17002
+ * This logic is used to determine if the admin can download the premium code base from a network level admin.
17003
+ *
17004
+ * @author Vova Feldman (@svovaf)
17005
+ * @since 2.1.3
17006
+ *
17007
+ * @return bool
17008
+ */
17009
+ function has_any_active_valid_license() {
17010
+ if ( ! fs_is_network_admin() ) {
17011
+ return $this->has_active_valid_license();
17012
+ }
17013
+
17014
+ $installs = $this->get_blog_install_map();
17015
+ $all_plugin_licenses = self::get_all_licenses( $this->_module_id );
17016
+
17017
+ foreach ( $installs as $blog_id => $install ) {
17018
+ if ( ! FS_Plugin_License::is_valid_id( $install->license_id ) ) {
17019
+ continue;
17020
+ }
17021
+
17022
+ foreach ( $all_plugin_licenses as $license ) {
17023
+ if ( $license->id == $install->license_id ) {
17024
+ if ( self::is_active_valid_license( $license ) ) {
17025
+ return true;
17026
+ }
17027
+ }
17028
+ }
17029
+ }
17030
+
17031
+ return false;
17032
+ }
17033
+
17034
+ /**
17035
+ * Check if site assigned with license with enabled features.
17036
+ *
17037
+ * @author Vova Feldman (@svovaf)
17038
+ * @since 1.0.6
17039
+ *
17040
+ * @return bool
17041
+ */
17042
+ function has_features_enabled_license() {
17043
+ return (
17044
+ is_object( $this->_license ) &&
17045
+ is_numeric( $this->_license->id ) &&
17046
+ $this->_license->is_features_enabled()
17047
+ );
17048
+ }
17049
+
17050
+ /**
17051
+ * Check if user is a trial or have feature enabled license.
17052
+ *
17053
+ * @author Vova Feldman (@svovaf)
17054
+ * @since 1.1.7
17055
+ *
17056
+ * @return bool
17057
+ */
17058
+ function can_use_premium_code() {
17059
+ return $this->is_trial() || $this->has_features_enabled_license();
17060
+ }
17061
+
17062
+ /**
17063
+ * Checks if the current user can activate plugins or switch themes. Note that this method should only be used
17064
+ * after the `init` action is triggered because it is using `current_user_can()` which is only functional after
17065
+ * the context user is authenticated.
17066
+ *
17067
+ * @author Leo Fajardo (@leorw)
17068
+ * @since 1.2.2
17069
+ *
17070
+ * @return bool
17071
+ */
17072
+ function is_user_admin() {
17073
+ /**
17074
+ * Require a super-admin when network activated, running from the network level OR if
17075
+ * running from the site level but not delegated the opt-in.
17076
+ *
17077
+ * @author Vova Feldman (@svovaf)
17078
+ * @since 2.0.0
17079
+ */
17080
+ if ( $this->_is_network_active &&
17081
+ ( fs_is_network_admin() || ! $this->is_delegated_connection() )
17082
+ ) {
17083
+ return is_super_admin();
17084
+ }
17085
+
17086
+ return ( $this->is_plugin() && current_user_can( is_multisite() ? 'manage_options' : 'activate_plugins' ) )
17087
+ || ( $this->is_theme() && current_user_can( 'switch_themes' ) );
17088
+ }
17089
+
17090
+ /**
17091
+ * Sync site's plan.
17092
+ *
17093
+ * @author Vova Feldman (@svovaf)
17094
+ * @since 1.0.3
17095
+ *
17096
+ * @uses FS_Api
17097
+ *
17098
+ * @param bool $background Hints the method if it's a background sync. If false, it means that was initiated by
17099
+ * the admin.
17100
+ * @param bool $is_context_single_site @since 2.0.0. This is used when syncing a license for a single install from the
17101
+ * network-level "Account" page.
17102
+ * @param int|null $current_blog_id @since 2.2.3. This is passed from the `execute_cron` method and used by the
17103
+ * `_sync_plugin_license` method in order to switch to the previous blog when sending
17104
+ * updates for a single site in case `execute_cron` has switched to a different blog.
17105
+ */
17106
+ private function _sync_license( $background = false, $is_context_single_site = false, $current_blog_id = null ) {
17107
+ $this->_logger->entrance();
17108
+
17109
+ $plugin_id = fs_request_get( 'plugin_id', $this->get_id() );
17110
+
17111
+ $is_addon_sync = ( ! $this->_plugin->is_addon() && $plugin_id != $this->get_id() );
17112
+
17113
+ if ( $is_addon_sync ) {
17114
+ $this->_sync_addon_license( $plugin_id, $background );
17115
+ } else {
17116
+ $this->_sync_plugin_license( $background, true, $is_context_single_site, $current_blog_id );
17117
+ }
17118
+
17119
+ $this->do_action( 'after_account_plan_sync', $this->get_plan_name() );
17120
+ }
17121
+
17122
+ /**
17123
+ * Sync plugin's add-on license.
17124
+ *
17125
+ * @author Vova Feldman (@svovaf)
17126
+ * @since 1.0.6
17127
+ * @uses FS_Api
17128
+ *
17129
+ * @param number $addon_id
17130
+ * @param bool $background
17131
+ */
17132
+ private function _sync_addon_license( $addon_id, $background ) {
17133
+ $this->_logger->entrance();
17134
+
17135
+ if ( $this->is_addon_activated( $addon_id ) ) {
17136
+ // If already installed, use add-on sync.
17137
+ $fs_addon = self::get_instance_by_id( $addon_id );
17138
+ $fs_addon->_sync_license( $background );
17139
+
17140
+ return;
17141
+ }
17142
+
17143
+ // Validate add-on exists.
17144
+ $addon = $this->get_addon( $addon_id );
17145
+
17146
+ if ( ! is_object( $addon ) ) {
17147
+ return;
17148
+ }
17149
+
17150
+ // Add add-on into account add-ons.
17151
+ $account_addons = $this->get_account_addons();
17152
+ if ( ! is_array( $account_addons ) ) {
17153
+ $account_addons = array();
17154
+ }
17155
+ $account_addons[] = $addon->id;
17156
+ $account_addons = array_unique( $account_addons );
17157
+ $this->_store_account_addons( $account_addons );
17158
+
17159
+ // Load add-on licenses.
17160
+ $licenses = $this->_fetch_licenses( $addon->id );
17161
+
17162
+ // Sync add-on licenses.
17163
+ if ( $this->is_array_instanceof( $licenses, 'FS_Plugin_License' ) ) {
17164
+ $this->_update_licenses( $licenses, $addon->id );
17165
+
17166
+ if ( ! $this->is_addon_installed( $addon->id ) && FS_License_Manager::has_premium_license( $licenses ) ) {
17167
+ $plans_result = $this->get_api_site_or_plugin_scope()->get( $this->add_show_pending( "/addons/{$addon_id}/plans.json" ) );
17168
+
17169
+ if ( ! isset( $plans_result->error ) ) {
17170
+ $plans = array();
17171
+ foreach ( $plans_result->plans as $plan ) {
17172
+ $plans[] = new FS_Plugin_Plan( $plan );
17173
+ }
17174
+
17175
+ $this->_admin_notices->add_sticky(
17176
+ sprintf(
17177
+ ( FS_Plan_Manager::instance()->has_free_plan( $plans ) ?
17178
+ $this->get_text_inline( 'Your %s Add-on plan was successfully upgraded.', 'addon-successfully-upgraded-message' ) :
17179
+ /* translators: %s:product name, e.g. Facebook add-on was successfully... */
17180
+ $this->get_text_inline( '%s Add-on was successfully purchased.', 'addon-successfully-purchased-message' ) ),
17181
+ $addon->title
17182
+ ) . ' ' . $this->get_latest_download_link(
17183
+ $this->get_text_inline( 'Download the latest version', 'download-latest-version' ),
17184
+ $addon_id
17185
+ ),
17186
+ 'addon_plan_upgraded_' . $addon->slug,
17187
+ $this->get_text_x_inline( 'Yee-haw', 'interjection expressing joy or exuberance', 'yee-haw' ) . '!'
17188
+ );
17189
+ }
17190
+ }
17191
+ }
17192
+ }
17193
+
17194
+ /**
17195
+ * Sync site's plugin plan.
17196
+ *
17197
+ * @author Vova Feldman (@svovaf)
17198
+ * @since 1.0.6
17199
+ * @uses FS_Api
17200
+ *
17201
+ * @param bool $background Hints the method if it's a background sync. If false, it means that was initiated by the admin.
17202
+ * @param bool $send_installs_update Since 2.0.0
17203
+ * @param bool $is_context_single_site Since 2.0.0. This is used when sending an update for a single install and
17204
+ * syncing its license from the network-level "Account" page (e.g.: after
17205
+ * activating a license only for the single install).
17206
+ * @param int|null $current_blog_id Since 2.2.3. This is passed from the `execute_cron` method so that it
17207
+ * can be used here to switch to the previous blog in case `execute_cron`
17208
+ * has switched to a different blog.
17209
+ */
17210
+ private function _sync_plugin_license(
17211
+ $background = false,
17212
+ $send_installs_update = true,
17213
+ $is_context_single_site = false,
17214
+ $current_blog_id = null
17215
+ ) {
17216
+ $this->_logger->entrance();
17217
+
17218
+ $plan_change = 'none';
17219
+
17220
+ $is_site_level_sync = ( $is_context_single_site || fs_is_blog_admin() || ! $this->_is_network_active );
17221
+
17222
+ if ( ! $send_installs_update ) {
17223
+ $site = $this->_site;
17224
+ } else {
17225
+ /**
17226
+ * Sync site info.
17227
+ *
17228
+ * @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.
17229
+ */
17230
+ if ( $is_site_level_sync ) {
17231
+ /**
17232
+ * Switch to the previous blog since `execute_cron` may have switched to a different blog.
17233
+ *
17234
+ * @author Leo Fajardo (@leorw)
17235
+ * @since 2.2.3
17236
+ */
17237
+ if ( is_numeric( $current_blog_id ) ) {
17238
+ $this->switch_to_blog( $current_blog_id );
17239
+ }
17240
+
17241
+ $result = $this->send_install_update( array(), true );
17242
+ $is_valid = $this->is_api_result_entity( $result );
17243
+ } else {
17244
+ $result = $this->send_installs_update( array(), true );
17245
+ $is_valid = $this->is_api_result_object( $result, 'installs' );
17246
+ }
17247
+
17248
+ if ( ! $is_valid ) {
17249
+ if ( $is_context_single_site ) {
17250
+ // Switch back to the main blog so that the following logic will have the right entities.
17251
+ $this->switch_to_blog( $this->_storage->network_install_blog_id );
17252
+ }
17253
+
17254
+ // Show API messages only if not background sync or if paying customer.
17255
+ if ( ! $background || $this->is_paying() ) {
17256
+ // Try to ping API to see if not blocked.
17257
+ if ( ! FS_Api::test() ) {
17258
+ /**
17259
+ * Failed to ping API - blocked!
17260
+ *
17261
+ * @author Vova Feldman (@svovaf)
17262
+ * @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.
17263
+ */
17264
+ $api = $this->get_api_site_scope();
17265
+
17266
+ if ( ! self::$_global_admin_notices->has_sticky( 'api_blocked' ) ) {
17267
+ self::$_global_admin_notices->add(
17268
+ sprintf(
17269
+ $this->get_text_x_inline( 'Your server is blocking the access to Freemius\' API, which is crucial for %1s synchronization. Please contact your host to whitelist %2s', '%1s - plugin title, %2s - API domain', 'server-blocking-access' ),
17270
+ $this->get_plugin_name(),
17271
+ '<a href="' . $api->get_url() . '" target="_blank">' . $api->get_url() . '</a>'
17272
+ ) . '<br> ' . $this->get_text_inline( 'Error received from the server:', 'server-error-message' ) . var_export( $result->error, true ),
17273
+ $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
17274
+ 'error',
17275
+ $background,
17276
+ 'api_blocked'
17277
+ );
17278
+ }
17279
+ } else {
17280
+ // Authentication params are broken.
17281
+ $this->_admin_notices->add(
17282
+ $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' ),
17283
+ $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
17284
+ 'error'
17285
+ );
17286
+ }
17287
+ }
17288
+
17289
+ // No reason to continue with license sync while there are API issues.
17290
+ return;
17291
+ }
17292
+
17293
+ if ( $is_site_level_sync ) {
17294
+ $site = new FS_Site( $result );
17295
+ } else {
17296
+ // Map site addresses to their blog IDs.
17297
+ $address_to_blog_map = $this->get_address_to_blog_map();
17298
+
17299
+ // Find the current context install.
17300
+ $site = null;
17301
+ foreach ( $result->installs as $install ) {
17302
+ if ( $install->id == $this->_site->id ) {
17303
+ $site = new FS_Site( $install );
17304
+ } else {
17305
+ $address = trailingslashit( fs_strip_url_protocol( $install->url ) );
17306
+ $blog_id = $address_to_blog_map[ $address ];
17307
+
17308
+ $this->_store_site( true, $blog_id, new FS_Site( $install ) );
17309
+ }
17310
+ }
17311
+ }
17312
+
17313
+ // Sync plans.
17314
+ $this->_sync_plans();
17315
+ }
17316
+
17317
+ // Remove sticky API connectivity message.
17318
+ self::$_global_admin_notices->remove_sticky( 'api_blocked' );
17319
+
17320
+ if ( ! $this->has_paid_plan() ) {
17321
+ $this->_site = $site;
17322
+ $this->_store_site(
17323
+ true,
17324
+ $is_site_level_sync ?
17325
+ null :
17326
+ $this->get_network_install_blog_id()
17327
+ );
17328
+ } else {
17329
+ $context_blog_id = 0;
17330
+
17331
+ if ( $is_context_single_site ) {
17332
+ $context_blog_id = get_current_blog_id();
17333
+
17334
+ // Switch back to the main blog in order to properly sync the license.
17335
+ $this->switch_to_blog( $this->_storage->network_install_blog_id );
17336
+ }
17337
+
17338
+ /**
17339
+ * Sync licenses. Pass the site's license ID so that the foreign licenses will be fetched if the license
17340
+ * associated with that ID is not included in the user's licenses collection.
17341
+ */
17342
+ $this->_sync_licenses(
17343
+ $site->license_id,
17344
+ ( $is_context_single_site ?
17345
+ $context_blog_id :
17346
+ null
17347
+ )
17348
+ );
17349
+
17350
+ if ( $is_context_single_site ) {
17351
+ $this->switch_to_blog( $context_blog_id );
17352
+ }
17353
+
17354
+ // Check if plan / license changed.
17355
+ if ( $site->plan_id != $this->_site->plan_id ||
17356
+ // Check if trial started.
17357
+ $site->trial_plan_id != $this->_site->trial_plan_id ||
17358
+ $site->trial_ends != $this->_site->trial_ends ||
17359
+ // Check if license changed.
17360
+ $site->license_id != $this->_site->license_id
17361
+ ) {
17362
+ if ( $site->is_trial() && ( ! $this->_site->is_trial() || $site->trial_ends != $this->_site->trial_ends ) ) {
17363
+ // New trial started.
17364
+ $this->_site = $site;
17365
+ $plan_change = 'trial_started';
17366
+
17367
+ // For trial with subscription use-case.
17368
+ $new_license = is_null( $site->license_id ) ? null : $this->_get_license_by_id( $site->license_id );
17369
+
17370
+ if ( is_object( $new_license ) && $new_license->is_valid() ) {
17371
+ $this->_site = $site;
17372
+ $this->_update_site_license( $new_license );
17373
+ $this->_store_licenses();
17374
+
17375
+ $this->_sync_site_subscription( $this->_license );
17376
+ }
17377
+ } else if ( $this->_site->is_trial() && ! $site->is_trial() && ! is_numeric( $site->license_id ) ) {
17378
+ // Was in trial, but now trial expired and no license ID.
17379
+ // New trial started.
17380
+ $this->_site = $site;
17381
+ $plan_change = 'trial_expired';
17382
+ } else {
17383
+ $is_free = $this->is_free_plan();
17384
+
17385
+ // Make sure license exist and not expired.
17386
+ $new_license = is_null( $site->license_id ) ?
17387
+ null :
17388
+ $this->_get_license_by_id( $site->license_id );
17389
+
17390
+ if ( $is_free && is_null( $new_license ) && $this->has_any_license() && $this->_license->is_cancelled ) {
17391
+ // License cancelled.
17392
+ $this->_site = $site;
17393
+ $this->_update_site_license( $new_license );
17394
+ $this->_store_licenses();
17395
+
17396
+ $plan_change = 'cancelled';
17397
+ } else if ( $is_free && ( ( ! is_object( $new_license ) || $new_license->is_expired() ) ) ) {
17398
+ // The license is expired, so ignore upgrade method.
17399
+ $this->_site = $site;
17400
+ } else {
17401
+ // License changed.
17402
+ $this->_site = $site;
17403
+
17404
+ /**
17405
+ * IMPORTANT:
17406
+ * 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.
17407
+ *
17408
+ * @author Vova Feldman (@svovaf)
17409
+ * @since 2.0.0
17410
+ */
17411
+ $this->_update_site_license( $new_license );
17412
+
17413
+ if ( ! $is_context_single_site &&
17414
+ fs_is_network_admin() &&
17415
+ $this->_is_network_active &&
17416
+ $new_license->quota > 1 &&
17417
+ get_blog_count() > 1
17418
+ ) {
17419
+ // See if license can activated on all sites.
17420
+ if ( ! $this->try_activate_license_on_network( $this->_user, $new_license ) ) {
17421
+ if ( ! fs_request_get_bool( 'auto_install' ) ) {
17422
+ // Open the license activation dialog box on the account page.
17423
+ add_action( 'admin_footer', array(
17424
+ &$this,
17425
+ '_open_license_activation_dialog_box'
17426
+ ) );
17427
+ }
17428
+ }
17429
+ }
17430
+
17431
+ $this->_store_licenses();
17432
+
17433
+ $plan_change = $is_free ?
17434
+ 'upgraded' :
17435
+ ( is_object( $new_license ) ?
17436
+ 'changed' :
17437
+ 'downgraded' );
17438
+ }
17439
+ }
17440
+
17441
+ // Store updated site info.
17442
+ $this->_store_site(
17443
+ true,
17444
+ $is_site_level_sync ?
17445
+ null :
17446
+ $this->get_network_install_blog_id()
17447
+ );
17448
+ } else {
17449
+ if ( is_object( $this->_license ) && $this->_license->is_expired() ) {
17450
+ if ( ! $this->has_features_enabled_license() ) {
17451
+ $this->_deactivate_license();
17452
+ $plan_change = 'downgraded';
17453
+ } else {
17454
+ $plan_change = 'expired';
17455
+ }
17456
+ }
17457
+
17458
+ if ( is_numeric( $site->license_id ) && is_object( $this->_license ) ) {
17459
+ $this->_sync_site_subscription( $this->_license );
17460
+ }
17461
+ }
17462
+ }
17463
+
17464
+ $hmm_text = $this->get_text_x_inline( 'Hmm', 'something somebody says when they are thinking about what you have just said.', 'hmm' ) . '...';
17465
+
17466
+ if ( $this->has_paid_plan() ) {
17467
+ switch ( $plan_change ) {
17468
+ case 'none':
17469
+ if ( ! $background && is_admin() ) {
17470
+ $plan = $this->is_trial() ?
17471
+ $this->get_trial_plan() :
17472
+ $this->get_plan();
17473
+
17474
+ if ( $plan->is_free() ) {
17475
+ $this->_admin_notices->add(
17476
+ sprintf(
17477
+ $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' ),
17478
+ '<i><b>' . $plan->title . ( $this->is_trial() ? ' ' . $this->get_text_x_inline( 'Trial', 'trial period', 'trial' ) : '' ) . '</b></i>'
17479
+ ) . ' ' . sprintf(
17480
+ '<a href="%s">%s</a>',
17481
+ $this->contact_url(
17482
+ 'bug',
17483
+ 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' ),
17484
+ strtoupper( $plan->name )
17485
+ )
17486
+ ),
17487
+ $this->get_text_inline( 'Please contact us here', 'contact-us-here' )
17488
+ ),
17489
+ $hmm_text
17490
+ );
17491
+ }
17492
+ }
17493
+ break;
17494
+ case 'upgraded':
17495
+ $this->_admin_notices->add_sticky(
17496
+ sprintf(
17497
+ $this->get_text_inline( 'Your plan was successfully upgraded.', 'plan-upgraded-message' ),
17498
+ '<i>' . $this->get_plugin_name() . '</i>'
17499
+ ) . $this->get_complete_upgrade_instructions(),
17500
+ 'plan_upgraded',
17501
+ $this->get_text_x_inline( 'Yee-haw', 'interjection expressing joy or exuberance', 'yee-haw' ) . '!'
17502
+ );
17503
+
17504
+ $this->_admin_notices->remove_sticky( array(
17505
+ 'trial_started',
17506
+ 'trial_promotion',
17507
+ 'trial_expired',
17508
+ 'activation_complete',
17509
+ 'license_expired',
17510
+ ) );
17511
+ break;
17512
+ case 'changed':
17513
+ $this->_admin_notices->add_sticky(
17514
+ sprintf(
17515
+ $this->get_text_inline( 'Your plan was successfully changed to %s.', 'plan-changed-to-x-message' ),
17516
+ $this->get_plan_title()
17517
+ ),
17518
+ 'plan_changed'
17519
+ );
17520
+
17521
+ $this->_admin_notices->remove_sticky( array(
17522
+ 'trial_started',
17523
+ 'trial_promotion',
17524
+ 'trial_expired',
17525
+ 'activation_complete',
17526
+ ) );
17527
+ break;
17528
+ case 'downgraded':
17529
+ $this->_admin_notices->add_sticky(
17530
+ ($this->has_free_plan() ?
17531
+ 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 ) :
17532
+ /* translators: %1$s: product title; %2$s, %3$s: wrapping HTML anchor element; %4$s: 'plugin', 'theme', or 'add-on'. */
17533
+ 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) ) ),
17534
+ 'license_expired',
17535
+ $hmm_text
17536
+ );
17537
+ $this->_admin_notices->remove_sticky( 'plan_upgraded' );
17538
+ break;
17539
+ case 'cancelled':
17540
+ $this->_admin_notices->add(
17541
+ $this->get_text_inline( 'Your license has been cancelled. If you think it\'s a mistake, please contact support.', 'license-cancelled' ) . ' ' .
17542
+ sprintf(
17543
+ '<a href="%s">%s</a>',
17544
+ $this->contact_url( 'bug' ),
17545
+ $this->get_text_inline( 'Please contact us here', 'contact-us-here' )
17546
+ ),
17547
+ $hmm_text,
17548
+ 'error'
17549
+ );
17550
+ $this->_admin_notices->remove_sticky( 'plan_upgraded' );
17551
+ break;
17552
+ case 'expired':
17553
+ $this->_admin_notices->add_sticky(
17554
+ 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 ),
17555
+ 'license_expired',
17556
+ $hmm_text
17557
+ );
17558
+ $this->_admin_notices->remove_sticky( 'plan_upgraded' );
17559
+ break;
17560
+ case 'trial_started':
17561
+ $this->_admin_notices->add_sticky(
17562
+ sprintf(
17563
+ $this->get_text_inline( 'Your trial has been successfully started.', 'trial-started-message' ),
17564
+ '<i>' . $this->get_plugin_name() . '</i>'
17565
+ ) . $this->get_complete_upgrade_instructions( $this->get_trial_plan()->title ),
17566
+ 'trial_started',
17567
+ $this->get_text_x_inline( 'Yee-haw', 'interjection expressing joy or exuberance', 'yee-haw' ) . '!'
17568
+ );
17569
+
17570
+ $this->_admin_notices->remove_sticky( array(
17571
+ 'trial_promotion',
17572
+ ) );
17573
+ break;
17574
+ case 'trial_expired':
17575
+ $this->_admin_notices->add_sticky(
17576
+ ($this->has_free_plan() ?
17577
+ $this->get_text_inline( 'Your free trial has expired. You can still continue using all our free features.', 'trial-expired-message' ) :
17578
+ /* translators: %1$s: product title; %2$s, %3$s: wrapping HTML anchor element; %4$s: 'plugin', 'theme', or 'add-on'. */
17579
+ 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))),
17580
+ 'trial_expired',
17581
+ $hmm_text
17582
+ );
17583
+ $this->_admin_notices->remove_sticky( array(
17584
+ 'trial_started',
17585
+ 'trial_promotion',
17586
+ 'plan_upgraded',
17587
+ ) );
17588
+ break;
17589
+ }
17590
+ }
17591
+
17592
+ if ( 'none' !== $plan_change ) {
17593
+ $this->do_action( 'after_license_change', $plan_change, $this->get_plan() );
17594
+ }
17595
+ }
17596
+
17597
+ /**
17598
+ * Include the required JS at the footer of the admin to trigger the license activation dialog box.
17599
+ *
17600
+ * @author Vova Feldman (@svovaf)
17601
+ * @since 2.0.0
17602
+ */
17603
+ public function _open_license_activation_dialog_box() {
17604
+ $vars = array( 'license_id' => $this->_site->license_id );
17605
+ fs_require_once_template( 'js/open-license-activation.php', $vars );
17606
+ }
17607
+
17608
+ /**
17609
+ * @author Vova Feldman (@svovaf)
17610
+ * @since 1.0.5
17611
+ *
17612
+ * @param bool $background
17613
+ */
17614
+ protected function _activate_license( $background = false ) {
17615
+ $this->_logger->entrance();
17616
+
17617
+ $license_id = fs_request_get( 'license_id' );
17618
+
17619
+ if ( is_object( $this->_site ) &&
17620
+ FS_Plugin_License::is_valid_id( $license_id ) &&
17621
+ $license_id == $this->_site->license_id
17622
+ ) {
17623
+ // License is already activated.
17624
+ return;
17625
+ }
17626
+
17627
+ $premium_license = FS_Plugin_License::is_valid_id( $license_id ) ?
17628
+ $this->_get_license_by_id( $license_id ) :
17629
+ $this->_get_available_premium_license();
17630
+
17631
+ if ( ! is_object( $premium_license ) ) {
17632
+ return;
17633
+ }
17634
+
17635
+ if ( ! is_object( $this->_site ) ) {
17636
+ // Not yet opted-in.
17637
+ $user = $this->get_current_or_network_user();
17638
+ if ( ! is_object( $user ) ) {
17639
+ $user = self::_get_user_by_id( $premium_license->user_id );
17640
+ }
17641
+
17642
+ if ( is_object( $user ) ) {
17643
+ $this->install_with_user( $user, $premium_license->secret_key, false, false, false );
17644
+ } else {
17645
+ $this->opt_in(
17646
+ false,
17647
+ false,
17648
+ false,
17649
+ $premium_license->secret_key
17650
+ );
17651
+
17652
+ return;
17653
+ }
17654
+ }
17655
+
17656
+
17657
+ /**
17658
+ * If the premium license is already associated with the install, just
17659
+ * update the license reference (activation is not required).
17660
+ *
17661
+ * @since 1.1.9
17662
+ */
17663
+ if ( $premium_license->id == $this->_site->license_id ) {
17664
+ // License is already activated.
17665
+ $this->_update_site_license( $premium_license );
17666
+ $this->_store_account();
17667
+
17668
+ return;
17669
+ }
17670
+
17671
+ if ( $this->_site->user_id != $premium_license->user_id ) {
17672
+ $api_request_params = array( 'license_key' => $premium_license->secret_key );
17673
+ } else {
17674
+ $api_request_params = array();
17675
+ }
17676
+
17677
+ $api = $this->get_api_site_scope();
17678
+ $license = $api->call( "/licenses/{$premium_license->id}.json", 'put', $api_request_params );
17679
+
17680
+ if ( ! $this->is_api_result_entity( $license ) ) {
17681
+ if ( ! $background ) {
17682
+ $this->_admin_notices->add( sprintf(
17683
+ '%s %s',
17684
+ $this->get_text_inline( 'It looks like the license could not be activated.', 'license-activation-failed-message' ),
17685
+ ( is_object( $license ) && isset( $license->error ) ?
17686
+ $license->error->message :
17687
+ sprintf( '%s<br><code>%s</code>',
17688
+ $this->get_text_inline( 'Error received from the server:', 'server-error-message' ),
17689
+ var_export( $license, true )
17690
+ )
17691
+ )
17692
+ ),
17693
+ $this->get_text_x_inline( 'Hmm', 'something somebody says when they are thinking about what you have just said.', 'hmm' ) . '...',
17694
+ 'error'
17695
+ );
17696
+ }
17697
+
17698
+ return;
17699
+ }
17700
+
17701
+ $premium_license = new FS_Plugin_License( $license );
17702
+
17703
+ // Updated site plan.
17704
+ $site = $this->get_api_site_scope()->get( '/', true );
17705
+ if ( $this->is_api_result_entity( $site ) ) {
17706
+ $this->_site = new FS_Site( $site );
17707
+ }
17708
+ $this->_update_site_license( $premium_license );
17709
+
17710
+ $this->_store_account();
17711
+
17712
+ if ( ! $background ) {
17713
+ $this->_admin_notices->add_sticky(
17714
+ $this->get_text_inline( 'Your license was successfully activated.', 'license-activated-message' ) .
17715
+ $this->get_complete_upgrade_instructions(),
17716
+ 'license_activated',
17717
+ $this->get_text_x_inline( 'Yee-haw', 'interjection expressing joy or exuberance', 'yee-haw' ) . '!'
17718
+ );
17719
+ }
17720
+
17721
+ $this->_admin_notices->remove_sticky( array(
17722
+ 'trial_promotion',
17723
+ 'license_expired',
17724
+ ) );
17725
+ }
17726
+
17727
+ /**
17728
+ * @author Vova Feldman (@svovaf)
17729
+ * @since 1.0.5
17730
+ *
17731
+ * @param bool $show_notice
17732
+ */
17733
+ protected function _deactivate_license( $show_notice = true ) {
17734
+ $this->_logger->entrance();
17735
+
17736
+ $hmm_text = $this->get_text_x_inline( 'Hmm', 'something somebody says when they are thinking about what you have just said.', 'hmm' ) . '...';
17737
+
17738
+ if ( ! FS_Plugin_License::is_valid_id( $this->_site->license_id ) ) {
17739
+ $this->_admin_notices->add(
17740
+ 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() ),
17741
+ $hmm_text
17742
+ );
17743
+
17744
+ return;
17745
+ }
17746
+
17747
+ $api = $this->get_api_site_scope();
17748
+ $license = $api->call( "/licenses/{$this->_site->license_id}.json", 'delete' );
17749
+
17750
+ $this->handle_license_deactivation_result( $license, $hmm_text, $show_notice );
17751
+ }
17752
+
17753
+ /**
17754
+ * @author Leo Fajardo (@leorw)
17755
+ * @since 2.2.1
17756
+ *
17757
+ * @param FS_Plugin_License $license
17758
+ * @param bool|string $hmm_text
17759
+ * @param bool $show_notice
17760
+ */
17761
+ private function handle_license_deactivation_result( $license, $hmm_text = false, $show_notice = true ) {
17762
+ if ( isset( $license->error ) ) {
17763
+ $this->_admin_notices->add(
17764
+ $this->get_text_inline( 'It looks like the license deactivation failed.', 'license-deactivation-failed-message' ) . '<br> ' .
17765
+ $this->get_text_inline( 'Error received from the server:', 'server-error-message' ) . ' ' . var_export( $license->error, true ),
17766
+ $hmm_text,
17767
+ 'error'
17768
+ );
17769
+
17770
+ return;
17771
+ }
17772
+
17773
+ // Update license cache.
17774
+ if ( is_array( $this->_licenses ) ) {
17775
+ for ( $i = 0, $len = count( $this->_licenses ); $i < $len; $i ++ ) {
17776
+ if ( $license->id == $this->_licenses[ $i ]->id ) {
17777
+ $this->_licenses[ $i ] = new FS_Plugin_License( $license );
17778
+ }
17779
+ }
17780
+ }
17781
+
17782
+ // Update site plan to default.
17783
+ $this->_sync_plans();
17784
+ $this->_site->plan_id = $this->_plans[0]->id;
17785
+ // Unlink license from site.
17786
+ $this->_update_site_license( null );
17787
+
17788
+ $this->_store_account();
17789
+
17790
+ if ( $show_notice ) {
17791
+ $this->_admin_notices->add(
17792
+ sprintf( $this->get_text_inline( 'Your license was successfully deactivated, you are back to the %s plan.', 'license-deactivation-message' ), $this->get_plan_title() ),
17793
+ $this->get_text_inline( 'O.K', 'ok' )
17794
+ );
17795
+ }
17796
+
17797
+ $this->_admin_notices->remove_sticky( array(
17798
+ 'plan_upgraded',
17799
+ 'license_activated',
17800
+ ) );
17801
+ }
17802
+
17803
+ /**
17804
+ * Site plan downgrade.
17805
+ *
17806
+ * @author Vova Feldman (@svovaf)
17807
+ * @since 1.0.4
17808
+ *
17809
+ * @return object
17810
+ *
17811
+ * @uses FS_Api
17812
+ */
17813
+ private function _downgrade_site() {
17814
+ $this->_logger->entrance();
17815
+
17816
+ $deactivate_license = fs_request_get_bool( 'deactivate_license' );
17817
+
17818
+ $api = $this->get_api_site_scope();
17819
+ $site = $api->call( 'downgrade.json', 'put', array( 'deactivate_license' => $deactivate_license ) );
17820
+
17821
+ $plan_downgraded = false;
17822
+ $plan = false;
17823
+ if ( $this->is_api_result_entity( $site ) ) {
17824
+ $prev_plan_id = $this->_site->plan_id;
17825
+
17826
+ // Update new site plan id.
17827
+ $this->_site->plan_id = $site->plan_id;
17828
+
17829
+ $plan = $this->get_plan();
17830
+ $subscription = $this->_sync_site_subscription( $this->_license );
17831
+
17832
+ // Plan downgraded if plan was changed or subscription was cancelled.
17833
+ $plan_downgraded = ( $plan instanceof FS_Plugin_Plan && $prev_plan_id != $plan->id ) ||
17834
+ ( is_object( $subscription ) && ! isset( $subscription->error ) && ! $subscription->is_active() );
17835
+ } else {
17836
+ // handle different error cases.
17837
+ $this->handle_license_deactivation_result(
17838
+ $site,
17839
+ $this->get_text_x_inline( 'Hmm', 'something somebody says when they are thinking about what you have just said.', 'hmm' ) . '...'
17840
+ );
17841
+ }
17842
+
17843
+ if ( ! $plan_downgraded ) {
17844
+ return (object) array(
17845
+ 'error' => (object) array(
17846
+ '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' )
17847
+ )
17848
+ );
17849
+ }
17850
+
17851
+ // Remove previous sticky message about upgrade (if exist).
17852
+ $this->_admin_notices->remove_sticky( 'plan_upgraded' );
17853
+
17854
+ $this->_admin_notices->add(
17855
+ sprintf( $this->get_text_inline( 'Your subscription was successfully cancelled. Your %s plan license will expire in %s.', 'plan-x-downgraded-message' ),
17856
+ $plan->title,
17857
+ human_time_diff( time(), strtotime( $this->_license->expiration ) )
17858
+ )
17859
+ );
17860
+
17861
+ // Store site updates.
17862
+ $this->_store_site();
17863
+
17864
+ if ( $deactivate_license &&
17865
+ ! FS_Plugin_License::is_valid_id( $site->license_id )
17866
+ ) {
17867
+ if ( $this->_site->is_localhost() ) {
17868
+ $this->_license->activated_local = max( 0, $this->_license->activated_local - 1 );
17869
+ } else {
17870
+ $this->_license->activated = max( 0, $this->_license->activated - 1 );
17871
+ }
17872
+
17873
+ // Handle successful license deactivation result.
17874
+ $this->handle_license_deactivation_result( $this->_license );
17875
+ }
17876
+
17877
+ return $site;
17878
+ }
17879
+
17880
+ /**
17881
+ * @author Vova Feldman (@svovaf)
17882
+ * @since 1.1.8.1
17883
+ *
17884
+ * @param bool|string $plan_name
17885
+ *
17886
+ * @return bool If trial was successfully started.
17887
+ */
17888
+ function start_trial( $plan_name = false ) {
17889
+ $this->_logger->entrance();
17890
+
17891
+ // Alias.
17892
+ $oops_text = $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...';
17893
+
17894
+ if ( $this->is_trial() ) {
17895
+ // Already in trial mode.
17896
+ $this->_admin_notices->add(
17897
+ sprintf( $this->get_text_inline( 'You are already running the %s in a trial mode.', 'in-trial-mode' ), $this->_module_type ),
17898
+ $oops_text,
17899
+ 'error'
17900
+ );
17901
+
17902
+ return false;
17903
+ }
17904
+
17905
+ if ( $this->_site->is_trial_utilized() ) {
17906
+ // Trial was already utilized.
17907
+ $this->_admin_notices->add(
17908
+ $this->get_text_inline( 'You already utilized a trial before.', 'trial-utilized' ),
17909
+ $oops_text,
17910
+ 'error'
17911
+ );
17912
+
17913
+ return false;
17914
+ }
17915
+
17916
+ if ( false !== $plan_name ) {
17917
+ $plan = $this->get_plan_by_name( $plan_name );
17918
+
17919
+ if ( false === $plan ) {
17920
+ // Plan doesn't exist.
17921
+ $this->_admin_notices->add(
17922
+ sprintf( $this->get_text_inline( 'Plan %s do not exist, therefore, can\'t start a trial.', 'trial-plan-x-not-exist' ), $plan_name ),
17923
+ $oops_text,
17924
+ 'error'
17925
+ );
17926
+
17927
+ return false;
17928
+ }
17929
+
17930
+ if ( ! $plan->has_trial() ) {
17931
+ // Plan doesn't exist.
17932
+ $this->_admin_notices->add(
17933
+ sprintf( $this->get_text_inline( 'Plan %s does not support a trial period.', 'plan-x-no-trial' ), $plan_name ),
17934
+ $oops_text,
17935
+ 'error'
17936
+ );
17937
+
17938
+ return false;
17939
+ }
17940
+ } else {
17941
+ if ( ! $this->has_trial_plan() ) {
17942
+ // None of the plans have a trial.
17943
+ $this->_admin_notices->add(
17944
+ sprintf( $this->get_text_inline( 'None of the %s\'s plans supports a trial period.', 'no-trials' ), $this->_module_type ),
17945
+ $oops_text,
17946
+ 'error'
17947
+ );
17948
+
17949
+ return false;
17950
+ }
17951
+
17952
+ $plans_with_trial = FS_Plan_Manager::instance()->get_trial_plans( $this->_plans );
17953
+
17954
+ $plan = $plans_with_trial[0];
17955
+ }
17956
+
17957
+ $api = $this->get_api_site_scope();
17958
+ $plan = $api->call( "plans/{$plan->id}/trials.json", 'post' );
17959
+
17960
+ if ( ! $this->is_api_result_entity( $plan ) ) {
17961
+ // Some API error while trying to start the trial.
17962
+ $this->_admin_notices->add(
17963
+ sprintf( $this->get_text_inline( 'Unexpected API error. Please contact the %s\'s author with the following error.', 'unexpected-api-error' ), $this->_module_type )
17964
+ . ' ' . var_export( $plan, true ),
17965
+ $oops_text,
17966
+ 'error'
17967
+ );
17968
+
17969
+ return false;
17970
+ }
17971
+
17972
+ // Sync license.
17973
+ $this->_sync_license();
17974
+
17975
+ return $this->is_trial();
17976
+ }
17977
+
17978
+ /**
17979
+ * Cancel site trial.
17980
+ *
17981
+ * @author Vova Feldman (@svovaf)
17982
+ * @since 1.0.9
17983
+ *
17984
+ * @return object
17985
+ *
17986
+ * @uses FS_Api
17987
+ */
17988
+ private function _cancel_trial() {
17989
+ $this->_logger->entrance();
17990
+
17991
+ if ( ! $this->is_trial() ) {
17992
+ return (object) array(
17993
+ 'error' => (object) array(
17994
+ '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' )
17995
+ )
17996
+ );
17997
+ }
17998
+
17999
+ $trial_plan = $this->get_trial_plan();
18000
+
18001
+ $api = $this->get_api_site_scope();
18002
+ $site = $api->call( 'trials.json', 'delete' );
18003
+
18004
+ $trial_cancelled = false;
18005
+
18006
+ if ( $this->is_api_result_entity( $site ) ) {
18007
+ $prev_trial_ends = $this->_site->trial_ends;
18008
+
18009
+ if ( $this->is_paid_trial() ) {
18010
+ $this->_license->expiration = $site->trial_ends;
18011
+ $this->_license->is_cancelled = true;
18012
+ $this->_update_site_license( $this->_license );
18013
+ $this->_store_licenses();
18014
+
18015
+ // Clear subscription reference.
18016
+ $this->_sync_site_subscription( null );
18017
+ }
18018
+
18019
+ // Update site info.
18020
+ $this->_site = new FS_Site( $site );
18021
+
18022
+ $trial_cancelled = ( $prev_trial_ends != $site->trial_ends );
18023
+ } else {
18024
+ // @todo handle different error cases.
18025
+ }
18026
+
18027
+ if ( ! $trial_cancelled ) {
18028
+ return (object) array(
18029
+ 'error' => (object) array(
18030
+ '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' )
18031
+ )
18032
+ );
18033
+ }
18034
+
18035
+ // Remove previous sticky messages about upgrade or trial (if exist).
18036
+ $this->_admin_notices->remove_sticky( array(
18037
+ 'trial_started',
18038
+ 'trial_promotion',
18039
+ 'plan_upgraded',
18040
+ ) );
18041
+
18042
+ // Store site updates.
18043
+ $this->_store_site();
18044
+
18045
+ if ( ! $this->is_addon() ||
18046
+ ! $this->deactivate_premium_only_addon_without_license( true )
18047
+ ) {
18048
+ $this->_admin_notices->add(
18049
+ sprintf( $this->get_text_inline( 'Your %s free trial was successfully cancelled.', 'trial-cancel-message' ), $trial_plan->title )
18050
+ );
18051
+ }
18052
+
18053
+ return $site;
18054
+ }
18055
+
18056
+ /**
18057
+ * @author Vova Feldman (@svovaf)
18058
+ * @since 1.0.6
18059
+ *
18060
+ * @param bool|number $plugin_id
18061
+ *
18062
+ * @return bool
18063
+ */
18064
+ private function _is_addon_id( $plugin_id ) {
18065
+ return is_numeric( $plugin_id ) && ( $this->get_id() != $plugin_id );
18066
+ }
18067
+
18068
+ /**
18069
+ * Check if user eligible to download premium version updates.
18070
+ *
18071
+ * @author Vova Feldman (@svovaf)
18072
+ * @since 1.0.6
18073
+ *
18074
+ * @return bool
18075
+ */
18076
+ private function _can_download_premium() {
18077
+ return $this->has_any_active_valid_license() ||
18078
+ ( $this->is_trial() && ! $this->get_trial_plan()->is_free() );
18079
+ }
18080
+
18081
+ /**
18082
+ *
18083
+ * @author Vova Feldman (@svovaf)
18084
+ * @since 1.0.6
18085
+ *
18086
+ * @param bool|number $addon_id
18087
+ * @param string $type "json" or "zip"
18088
+ *
18089
+ * @return string
18090
+ */
18091
+ private function _get_latest_version_endpoint( $addon_id = false, $type = 'json' ) {
18092
+
18093
+ $is_addon = $this->_is_addon_id( $addon_id );
18094
+
18095
+ $is_premium = null;
18096
+ if ( ! $is_addon ) {
18097
+ $is_premium = ( $this->is_premium() || $this->_can_download_premium() );
18098
+ } else if ( $this->is_addon_activated( $addon_id ) ) {
18099
+ $fs_addon = self::get_instance_by_id( $addon_id );
18100
+ $is_premium = ( $fs_addon->is_premium() || $fs_addon->_can_download_premium() );
18101
+ }
18102
+
18103
+ // If add-on, then append add-on ID.
18104
+ $endpoint = ( $is_addon ? "/addons/$addon_id" : '' ) .
18105
+ '/updates/latest.' . $type;
18106
+
18107
+ // If add-on and not yet activated, try to fetch based on server licensing.
18108
+ if ( is_bool( $is_premium ) ) {
18109
+ $endpoint = add_query_arg( 'is_premium', json_encode( $is_premium ), $endpoint );
18110
+ }
18111
+
18112
+ if ( $this->has_secret_key() ) {
18113
+ $endpoint = add_query_arg( 'type', 'all', $endpoint );
18114
+ }
18115
+
18116
+ return $endpoint;
18117
+ }
18118
+
18119
+ /**
18120
+ * @author Vova Feldman (@svovaf)
18121
+ * @since 1.0.4
18122
+ *
18123
+ * @param bool|number $addon_id
18124
+ * @param bool $flush Since 1.1.7.3
18125
+ * @param int $expiration Since 1.2.2.7
18126
+ * @param bool|string $newer_than Since 2.2.1
18127
+ * @param bool|string $fetch_readme Since 2.2.1
18128
+ *
18129
+ * @return object|false Plugin latest tag info.
18130
+ */
18131
+ function _fetch_latest_version(
18132
+ $addon_id = false,
18133
+ $flush = true,
18134
+ $expiration = WP_FS__TIME_24_HOURS_IN_SEC,
18135
+ $newer_than = false,
18136
+ $fetch_readme = true
18137
+ ) {
18138
+ $this->_logger->entrance();
18139
+
18140
+ $switch_to_blog_id = null;
18141
+
18142
+ /**
18143
+ * @since 1.1.7.3 Check for plugin updates from Freemius only if opted-in.
18144
+ * @since 1.1.7.4 Also check updates for add-ons.
18145
+ */
18146
+ if ( ! $this->is_registered() &&
18147
+ ! $this->_is_addon_id( $addon_id )
18148
+ ) {
18149
+ if ( ! is_multisite() ) {
18150
+ return false;
18151
+ }
18152
+
18153
+ $installs_map = $this->get_blog_install_map();
18154
+
18155
+ foreach ( $installs_map as $blog_id => $install ) {
18156
+ /**
18157
+ * @var FS_Site $install
18158
+ */
18159
+ if ( $install->is_trial() ) {
18160
+ $switch_to_blog_id = $blog_id;
18161
+ break;
18162
+ }
18163
+
18164
+ if ( FS_Plugin_License::is_valid_id( $install->license_id ) ) {
18165
+ $license = $this->get_license_by_id( $install->license_id );
18166
+
18167
+ if ( is_object( $license ) && $license->is_features_enabled() ) {
18168
+ $switch_to_blog_id = $blog_id;
18169
+ break;
18170
+ }
18171
+ }
18172
+ }
18173
+
18174
+ if ( is_null( $switch_to_blog_id ) ) {
18175
+ return false;
18176
+ }
18177
+ }
18178
+
18179
+ $current_blog_id = is_numeric( $switch_to_blog_id ) ?
18180
+ get_current_blog_id() :
18181
+ 0;
18182
+
18183
+ if ( is_numeric( $switch_to_blog_id ) ) {
18184
+ $this->switch_to_blog( $switch_to_blog_id );
18185
+ }
18186
+
18187
+ $latest_version_endpoint = $this->_get_latest_version_endpoint( $addon_id, 'json' );
18188
+
18189
+ if ( ! empty( $newer_than ) ) {
18190
+ $latest_version_endpoint = add_query_arg( 'newer_than', $newer_than, $latest_version_endpoint );
18191
+ }
18192
+
18193
+ if ( true === $fetch_readme ) {
18194
+ $latest_version_endpoint = add_query_arg( 'readme', 'true', $latest_version_endpoint );
18195
+ }
18196
+
18197
+ $tag = $this->get_api_site_or_plugin_scope()->get(
18198
+ $latest_version_endpoint,
18199
+ $flush,
18200
+ $expiration
18201
+ );
18202
+
18203
+ if ( is_numeric( $switch_to_blog_id ) ) {
18204
+ $this->switch_to_blog( $current_blog_id );
18205
+ }
18206
+
18207
+ $latest_version = ( is_object( $tag ) && isset( $tag->version ) ) ? $tag->version : 'couldn\'t get';
18208
+
18209
+ $this->_logger->departure( 'Latest version ' . $latest_version );
18210
+
18211
+ return ( is_object( $tag ) && isset( $tag->version ) ) ? $tag : false;
18212
+ }
18213
+
18214
+ #----------------------------------------------------------------------------------
18215
+ #region Download Plugin
18216
+ #----------------------------------------------------------------------------------
18217
+
18218
+ /**
18219
+ * Download latest plugin version, based on plan.
18220
+ *
18221
+ * Not like _download_latest(), this will redirect the page
18222
+ * to secure download url to prevent dual download (from FS to WP server,
18223
+ * and then from WP server to the client / browser).
18224
+ *
18225
+ * @author Vova Feldman (@svovaf)
18226
+ * @since 1.0.9
18227
+ *
18228
+ * @param bool|number $plugin_id
18229
+ *
18230
+ * @uses FS_Api
18231
+ * @uses wp_redirect()
18232
+ */
18233
+ private function download_latest_directly( $plugin_id = false ) {
18234
+ $this->_logger->entrance();
18235
+
18236
+ wp_redirect( $this->get_latest_download_api_url( $plugin_id ) );
18237
+ }
18238
+
18239
+ /**
18240
+ * Get latest plugin FS API download URL.
18241
+ *
18242
+ * @author Vova Feldman (@svovaf)
18243
+ * @since 1.0.9
18244
+ *
18245
+ * @param bool|number $plugin_id
18246
+ *
18247
+ * @return string
18248
+ */
18249
+ private function get_latest_download_api_url( $plugin_id = false ) {
18250
+ $this->_logger->entrance();
18251
+
18252
+ return $this->get_api_site_scope()->get_signed_url(
18253
+ $this->_get_latest_version_endpoint( $plugin_id, 'zip' )
18254
+ );
18255
+ }
18256
+
18257
+ /**
18258
+ * Get payment invoice URL.
18259
+ *
18260
+ * @author Vova Feldman (@svovaf)
18261
+ * @since 1.2.0
18262
+ *
18263
+ * @param bool|number $payment_id
18264
+ *
18265
+ * @return string
18266
+ */
18267
+ function _get_invoice_api_url( $payment_id = false ) {
18268
+ $this->_logger->entrance();
18269
+
18270
+ return $this->get_api_user_scope()->get_signed_url(
18271
+ "/payments/{$payment_id}/invoice.pdf"
18272
+ );
18273
+ }
18274
+
18275
+ /**
18276
+ * Get latest plugin download link.
18277
+ *
18278
+ * @author Vova Feldman (@svovaf)
18279
+ * @since 1.0.9
18280
+ *
18281
+ * @param string $label
18282
+ * @param bool|number $plugin_id
18283
+ *
18284
+ * @return string
18285
+ */
18286
+ private function get_latest_download_link( $label, $plugin_id = false ) {
18287
+ return sprintf(
18288
+ '<a target="_blank" href="%s">%s</a>',
18289
+ $this->_get_latest_download_local_url( $plugin_id ),
18290
+ $label
18291
+ );
18292
+ }
18293
+
18294
+ /**
18295
+ * Get latest plugin download local URL.
18296
+ *
18297
+ * @author Vova Feldman (@svovaf)
18298
+ * @since 1.0.9
18299
+ *
18300
+ * @param bool|number $plugin_id
18301
+ *
18302
+ * @return string
18303
+ */
18304
+ function _get_latest_download_local_url( $plugin_id = false ) {
18305
+ // Add timestamp to protect from caching.
18306
+ $params = array( 'ts' => WP_FS__SCRIPT_START_TIME );
18307
+
18308
+ if ( ! empty( $plugin_id ) ) {
18309
+ $params['plugin_id'] = $plugin_id;
18310
+ } else if ( $this->is_addon() ) {
18311
+ $params['plugin_id'] = $this->get_id();
18312
+ }
18313
+
18314
+ $fs = $this->is_addon() ?
18315
+ $this->get_parent_instance() :
18316
+ $this;
18317
+
18318
+ return $fs->get_account_url( 'download_latest', $params );
18319
+ }
18320
+
18321
+ #endregion Download Plugin ------------------------------------------------------------------
18322
+
18323
+ /**
18324
+ * @author Vova Feldman (@svovaf)
18325
+ * @since 1.0.4
18326
+ *
18327
+ * @uses FS_Api
18328
+ *
18329
+ * @param bool $background Hints the method if it's a background updates check. If false, it means that
18330
+ * was initiated by the admin.
18331
+ * @param bool|number $plugin_id
18332
+ * @param bool $flush Since 1.1.7.3
18333
+ * @param int $expiration Since 1.2.2.7
18334
+ * @param bool|string $newer_than Since 2.2.1
18335
+ */
18336
+ private function check_updates(
18337
+ $background = false,
18338
+ $plugin_id = false,
18339
+ $flush = true,
18340
+ $expiration = WP_FS__TIME_24_HOURS_IN_SEC,
18341
+ $newer_than = false
18342
+ ) {
18343
+ $this->_logger->entrance();
18344
+
18345
+ // Check if there's a newer version for download.
18346
+ $new_version = $this->_fetch_newer_version( $plugin_id, $flush, $expiration, $newer_than );
18347
+
18348
+ $update = null;
18349
+ if ( is_object( $new_version ) ) {
18350
+ $update = new FS_Plugin_Tag( $new_version );
18351
+
18352
+ if ( ! $background ) {
18353
+ $this->_admin_notices->add(
18354
+ sprintf(
18355
+ /* translators: %s: Numeric version number (e.g. '2.1.9' */
18356
+ $this->get_text_inline( 'Version %s was released.', 'version-x-released' ) . ' ' . $this->get_text_inline( 'Please download %s.', 'please-download-x' ),
18357
+ $update->version,
18358
+ sprintf(
18359
+ '<a href="%s" target="_blank">%s</a>',
18360
+ $this->get_account_url( 'download_latest' ),
18361
+ sprintf(
18362
+ /* translators: %s: plan name (e.g. latest "Professional" version) */
18363
+ $this->get_text_inline( 'the latest %s version here', 'latest-x-version' ),
18364
+ $this->get_plan_title()
18365
+ )
18366
+ )
18367
+ ),
18368
+ $this->get_text_inline( 'New', 'new' ) . '!'
18369
+ );
18370
+ }
18371
+ } else if ( false === $new_version && ! $background ) {
18372
+ $this->_admin_notices->add(
18373
+ $this->get_text_inline( 'Seems like you got the latest release.', 'you-have-latest' ),
18374
+ $this->get_text_inline( 'You are all good!', 'you-are-good' )
18375
+ );
18376
+ }
18377
+
18378
+ $this->_store_update( $update, true, $plugin_id );
18379
+ }
18380
+
18381
+ /**
18382
+ * @author Vova Feldman (@svovaf)
18383
+ * @since 1.0.4
18384
+ *
18385
+ * @param bool $flush Since 1.1.7.3 add 24 hour cache by default.
18386
+ *
18387
+ * @return FS_Plugin[]
18388
+ *
18389
+ * @uses FS_Api
18390
+ */
18391
+ private function sync_addons( $flush = false ) {
18392
+ $this->_logger->entrance();
18393
+
18394
+ $api = $this->get_api_site_or_plugin_scope();
18395
+
18396
+ $path = $this->add_show_pending( '/addons.json?enriched=true' );
18397
+
18398
+ /**
18399
+ * @since 1.2.1
18400
+ *
18401
+ * If there's a cached version of the add-ons and not asking
18402
+ * for a flush, just use the currently stored add-ons.
18403
+ */
18404
+ if ( ! $flush && $api->is_cached( $path ) ) {
18405
+ $addons = self::get_all_addons();
18406
+
18407
+ return $addons[ $this->_plugin->id ];
18408
+ }
18409
+
18410
+ $result = $api->get( $path, $flush );
18411
+
18412
+ $addons = array();
18413
+ if ( $this->is_api_result_object( $result, 'plugins' ) &&
18414
+ is_array( $result->plugins )
18415
+ ) {
18416
+ for ( $i = 0, $len = count( $result->plugins ); $i < $len; $i ++ ) {
18417
+ $addons[ $i ] = new FS_Plugin( $result->plugins[ $i ] );
18418
+ }
18419
+
18420
+ $this->_store_addons( $addons, true );
18421
+ }
18422
+
18423
+ return $addons;
18424
+ }
18425
+
18426
+ /**
18427
+ * Handle user email update.
18428
+ *
18429
+ * @author Vova Feldman (@svovaf)
18430
+ * @since 1.0.3
18431
+ * @uses FS_Api
18432
+ *
18433
+ * @param string $new_email
18434
+ *
18435
+ * @return object
18436
+ */
18437
+ private function update_email( $new_email ) {
18438
+ $this->_logger->entrance();
18439
+
18440
+
18441
+ $api = $this->get_api_user_scope();
18442
+ $user = $api->call( "?plugin_id={$this->_plugin->id}&fields=id,email,is_verified", 'put', array(
18443
+ 'email' => $new_email,
18444
+ 'after_email_confirm_url' => $this->_get_admin_page_url(
18445
+ 'account',
18446
+ array( 'fs_action' => 'sync_user' )
18447
+ ),
18448
+ ) );
18449
+
18450
+ if ( ! isset( $user->error ) ) {
18451
+ $this->_user->email = $user->email;
18452
+ $this->_user->is_verified = $user->is_verified;
18453
+ $this->_store_user();
18454
+ } else {
18455
+ // handle different error cases.
18456
+
18457
+ }
18458
+
18459
+ return $user;
18460
+ }
18461
+
18462
+ #----------------------------------------------------------------------------------
18463
+ #region API Error Handling
18464
+ #----------------------------------------------------------------------------------
18465
+
18466
+ /**
18467
+ * @author Vova Feldman (@svovaf)
18468
+ * @since 1.1.1
18469
+ *
18470
+ * @param mixed $result
18471
+ *
18472
+ * @return bool Is API result contains an error.
18473
+ */
18474
+ private function is_api_error( $result ) {
18475
+ return FS_Api::is_api_error( $result );
18476
+ }
18477
+
18478
+ /**
18479
+ * Checks if given API result is a non-empty and not an error object.
18480
+ *
18481
+ * @author Vova Feldman (@svovaf)
18482
+ * @since 1.2.1.5
18483
+ *
18484
+ * @param mixed $result
18485
+ * @param string|null $required_property Optional property we want to verify that is set.
18486
+ *
18487
+ * @return bool
18488
+ */
18489
+ function is_api_result_object( $result, $required_property = null ) {
18490
+ return FS_Api::is_api_result_object( $result, $required_property );
18491
+ }
18492
+
18493
+ /**
18494
+ * Checks if given API result is a non-empty entity object with non-empty ID.
18495
+ *
18496
+ * @author Vova Feldman (@svovaf)
18497
+ * @since 1.2.1.5
18498
+ *
18499
+ * @param mixed $result
18500
+ *
18501
+ * @return bool
18502
+ */
18503
+ private function is_api_result_entity( $result ) {
18504
+ return FS_Api::is_api_result_entity( $result );
18505
+ }
18506
+
18507
+ #endregion
18508
+
18509
+ /**
18510
+ * Make sure a given argument is an array of a specific type.
18511
+ *
18512
+ * @author Vova Feldman (@svovaf)
18513
+ * @since 1.2.1.5
18514
+ *
18515
+ * @param mixed $array
18516
+ * @param string $class
18517
+ *
18518
+ * @return bool
18519
+ */
18520
+ private function is_array_instanceof( $array, $class ) {
18521
+ return ( is_array( $array ) && ( empty( $array ) || $array[0] instanceof $class ) );
18522
+ }
18523
+
18524
+ /**
18525
+ * Start install ownership change.
18526
+ *
18527
+ * @author Vova Feldman (@svovaf)
18528
+ * @since 1.1.1
18529
+ * @uses FS_Api
18530
+ *
18531
+ * @param string $candidate_email
18532
+ *
18533
+ * @return bool Is ownership change successfully initiated.
18534
+ */
18535
+ private function init_change_owner( $candidate_email ) {
18536
+ $this->_logger->entrance();
18537
+
18538
+ $api = $this->get_api_site_scope();
18539
+ $result = $api->call( "/users/{$this->_user->id}.json", 'put', array(
18540
+ 'email' => $candidate_email,
18541
+ 'after_confirm_url' => $this->_get_admin_page_url(
18542
+ 'account',
18543
+ array( 'fs_action' => 'change_owner' )
18544
+ ),
18545
+ ) );
18546
+
18547
+ return ! $this->is_api_error( $result );
18548
+ }
18549
+
18550
+ /**
18551
+ * Handle install ownership change.
18552
+ *
18553
+ * @author Vova Feldman (@svovaf)
18554
+ * @since 1.1.1
18555
+ * @uses FS_Api
18556
+ *
18557
+ * @return bool Was ownership change successfully complete.
18558
+ */
18559
+ private function complete_change_owner() {
18560
+ $this->_logger->entrance();
18561
+
18562
+ $site_result = $this->get_api_site_scope( true )->get();
18563
+ $site = new FS_Site( $site_result );
18564
+ $this->_site = $site;
18565
+
18566
+ $user = new FS_User();
18567
+ $user->id = fs_request_get( 'user_id' );
18568
+
18569
+ // Validate install's user and given user.
18570
+ if ( $user->id != $this->_site->user_id ) {
18571
+ return false;
18572
+ }
18573
+
18574
+ $user->public_key = fs_request_get( 'user_public_key' );
18575
+ $user->secret_key = fs_request_get( 'user_secret_key' );
18576
+
18577
+ // Fetch new user information.
18578
+ $this->_user = $user;
18579
+ $user_result = $this->get_api_user_scope( true )->get();
18580
+ $user = new FS_User( $user_result );
18581
+ $this->_user = $user;
18582
+
18583
+ $this->_set_account( $user, $site );
18584
+
18585
+ return true;
18586
+ }
18587
+
18588
+ /**
18589
+ * Handle user name update.
18590
+ *
18591
+ * @author Vova Feldman (@svovaf)
18592
+ * @since 1.0.9
18593
+ * @uses FS_Api
18594
+ *
18595
+ * @return object
18596
+ */
18597
+ private function update_user_name() {
18598
+ $this->_logger->entrance();
18599
+ $name = fs_request_get( 'fs_user_name_' . $this->get_unique_affix(), '' );
18600
+
18601
+ $api = $this->get_api_user_scope();
18602
+ $user = $api->call( "?plugin_id={$this->_plugin->id}&fields=id,first,last", 'put', array(
18603
+ 'name' => $name,
18604
+ ) );
18605
+
18606
+ if ( ! isset( $user->error ) ) {
18607
+ $this->_user->first = $user->first;
18608
+ $this->_user->last = $user->last;
18609
+ $this->_store_user();
18610
+ } else {
18611
+ // handle different error cases.
18612
+
18613
+ }
18614
+
18615
+ return $user;
18616
+ }
18617
+
18618
+ /**
18619
+ * Verify user email.
18620
+ *
18621
+ * @author Vova Feldman (@svovaf)
18622
+ * @since 1.0.3
18623
+ * @uses FS_Api
18624
+ */
18625
+ private function verify_email() {
18626
+ $this->_handle_account_user_sync();
18627
+
18628
+ if ( $this->_user->is_verified() ) {
18629
+ return;
18630
+ }
18631
+
18632
+ $api = $this->get_api_site_scope();
18633
+ $result = $api->call( "/users/{$this->_user->id}/verify.json", 'put', array(
18634
+ 'after_email_confirm_url' => $this->_get_admin_page_url(
18635
+ 'account',
18636
+ array( 'fs_action' => 'sync_user' )
18637
+ )
18638
+ ) );
18639
+
18640
+ if ( ! isset( $result->error ) ) {
18641
+ $this->_admin_notices->add( sprintf(
18642
+ $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' ),
18643
+ sprintf( '<a href="mailto:%1s">%2s</a>', esc_url( $this->_user->email ), $this->_user->email )
18644
+ ) );
18645
+ } else {
18646
+ // handle different error cases.
18647
+
18648
+ }
18649
+ }
18650
+
18651
+ /**
18652
+ * @author Vova Feldman (@svovaf)
18653
+ * @since 1.1.2
18654
+ *
18655
+ * @param array $params
18656
+ * @param bool|null $network
18657
+ *
18658
+ * @return string
18659
+ */
18660
+ function get_activation_url( $params = array(), $network = null ) {
18661
+ if ( $this->is_addon() && $this->has_free_plan() ) {
18662
+ /**
18663
+ * @author Vova Feldman (@svovaf)
18664
+ * @since 1.2.1.7 Add-on's activation is the parent's module activation.
18665
+ */
18666
+ return $this->get_parent_instance()->get_activation_url( $params );
18667
+ }
18668
+
18669
+ return $this->apply_filters( 'connect_url', $this->_get_admin_page_url( '', $params, $network ) );
18670
+ }
18671
+
18672
+ /**
18673
+ * @author Vova Feldman (@svovaf)
18674
+ * @since 1.2.1.5
18675
+ *
18676
+ * @param array $params
18677
+ *
18678
+ * @return string
18679
+ */
18680
+ function get_reconnect_url( $params = array() ) {
18681
+ $params['fs_action'] = 'reset_anonymous_mode';
18682
+ $params['fs_unique_affix'] = $this->get_unique_affix();
18683
+
18684
+ return $this->get_activation_url( $params );
18685
+ }
18686
+
18687
+ /**
18688
+ * Get the URL of the page that should be loaded after the user connect
18689
+ * or skip in the opt-in screen.
18690
+ *
18691
+ * @author Vova Feldman (@svovaf)
18692
+ * @since 1.1.3
18693
+ *
18694
+ * @param string $filter Filter name.
18695
+ * @param array $params Since 1.2.2.7
18696
+ * @param bool|null $network
18697
+ *
18698
+ * @return string
18699
+ */
18700
+ function get_after_activation_url( $filter, $params = array(), $network = null ) {
18701
+ if ( $this->is_free_wp_org_theme() &&
18702
+ ( fs_request_has( 'pending_activation' ) ||
18703
+ // For cases when the first time path is set, even though it's a WP.org theme.
18704
+ fs_request_get_bool( $this->get_unique_affix() . '_show_optin' ) )
18705
+ ) {
18706
+ $first_time_path = '';
18707
+ } else {
18708
+ $first_time_path = $this->_menu->get_first_time_path();
18709
+ }
18710
+
18711
+ if ( $this->_is_network_active &&
18712
+ fs_is_network_admin() &&
18713
+ ! $this->_menu->has_network_menu() &&
18714
+ $this->is_network_registered()
18715
+ ) {
18716
+ $target_url = $this->get_account_url();
18717
+ } else {
18718
+ // Default plugin's page.
18719
+ $target_url = $this->_get_admin_page_url( '', array(), $network );
18720
+ }
18721
+
18722
+ return add_query_arg( $params, $this->apply_filters(
18723
+ $filter,
18724
+ empty( $first_time_path ) ?
18725
+ $target_url :
18726
+ $first_time_path
18727
+ ) );
18728
+ }
18729
+
18730
+ /**
18731
+ * Handle account page updates / edits / actions.
18732
+ *
18733
+ * @author Vova Feldman (@svovaf)
18734
+ * @since 1.0.2
18735
+ *
18736
+ */
18737
+ private function _handle_account_edits() {
18738
+ if ( ! $this->is_user_admin() ) {
18739
+ return;
18740
+ }
18741
+
18742
+ $action = fs_get_action();
18743
+
18744
+ if ( empty( $action ) ) {
18745
+ return;
18746
+ }
18747
+
18748
+ $plugin_id = fs_request_get( 'plugin_id', $this->get_id() );
18749
+ $install_id = fs_request_get( 'install_id', '' );
18750
+
18751
+ // Alias.
18752
+ $oops_text = $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...';
18753
+
18754
+ $is_network_action = $this->is_network_level_action();
18755
+ $blog_id = $this->is_network_level_site_specific_action();
18756
+
18757
+ if ( is_numeric( $blog_id ) ) {
18758
+ $this->switch_to_blog( $blog_id );
18759
+ } else {
18760
+ $blog_id = '';
18761
+ }
18762
+
18763
+ switch ( $action ) {
18764
+ case 'opt_in':
18765
+ check_admin_referer( trim( "{$action}:{$blog_id}:{$install_id}", ':' ) );
18766
+
18767
+ if ( $plugin_id == $this->get_id() ) {
18768
+ if ( $is_network_action && ! empty( $blog_id ) ) {
18769
+ if ( ! $this->is_registered() ) {
18770
+ $this->install_with_user(
18771
+ $this->get_network_user(),
18772
+ false,
18773
+ false,
18774
+ false,
18775
+ false
18776
+ );
18777
+
18778
+ $this->_admin_notices->add(
18779
+ $this->get_text_inline( 'Site successfully opted in.', 'successful-opt-in' ),
18780
+ $this->get_text_inline( 'Awesome', 'awesome' )
18781
+ );
18782
+ }
18783
+ }
18784
+ }
18785
+ break;
18786
+
18787
+ case 'toggle_tracking':
18788
+ check_admin_referer( trim( "{$action}:{$blog_id}:{$install_id}", ':' ) );
18789
+
18790
+ if ( $plugin_id == $this->get_id() ) {
18791
+ if ( $is_network_action && ! empty( $blog_id ) ) {
18792
+ if ( $this->is_registered() ) {
18793
+ if ( $this->is_tracking_prohibited() ) {
18794
+ if ( $this->allow_site_tracking() ) {
18795
+ $this->_admin_notices->add(
18796
+ 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 ),
18797
+ $this->get_text_inline( 'Thank you!', 'thank-you' )
18798
+ );
18799
+ }
18800
+ } else {
18801
+ if ( $this->stop_site_tracking() ) {
18802
+ $this->_admin_notices->add(
18803
+ sprintf(
18804
+ $this->get_text_inline( 'We will no longer be sending any usage data of %s on %s to %s.', 'opted-out-successfully' ),
18805
+ $this->get_plugin_title(),
18806
+ fs_strip_url_protocol( get_site_url( $blog_id ) ),
18807
+ sprintf(
18808
+ '<a href="%s" target="_blank">%s</a>',
18809
+ 'https://freemius.com',
18810
+ 'freemius.com'
18811
+ )
18812
+ )
18813
+ );
18814
+ }
18815
+ }
18816
+ }
18817
+ }
18818
+ }
18819
+
18820
+ break;
18821
+
18822
+ case 'delete_account':
18823
+ check_admin_referer( trim( "{$action}:{$blog_id}:{$install_id}", ':' ) );
18824
+
18825
+ if ( $plugin_id == $this->get_id() ) {
18826
+ if ( $is_network_action && empty( $blog_id ) ) {
18827
+ $this->delete_network_account_event();
18828
+ } else {
18829
+ $this->delete_account_event();
18830
+ }
18831
+
18832
+ // Clear user and site.
18833
+ $this->_site = null;
18834
+ $this->_user = null;
18835
+
18836
+ $this->maybe_set_slug_and_network_menu_exists_flag();
18837
+
18838
+ fs_redirect( $this->get_activation_url() );
18839
+ } else {
18840
+ if ( $this->is_addon_activated( $plugin_id ) ) {
18841
+ $fs_addon = self::get_instance_by_id( $plugin_id );
18842
+ $fs_addon->delete_account_event();
18843
+
18844
+ fs_redirect( $this->_get_admin_page_url( 'account' ) );
18845
+ }
18846
+ }
18847
+
18848
+ return;
18849
+
18850
+ case 'downgrade_account':
18851
+ if ( is_numeric( $blog_id ) ) {
18852
+ check_admin_referer( trim( "{$action}:{$blog_id}:{$install_id}", ':' ) );
18853
+ } else {
18854
+ check_admin_referer( $action );
18855
+ }
18856
+
18857
+ $switch_to_network_install_blog_after_cancellation = (
18858
+ is_numeric( $blog_id ) &&
18859
+ $plugin_id == $this->get_id() &&
18860
+ ! $this->is_trial()
18861
+ );
18862
+
18863
+ $result = $this->cancel_subscription_or_trial( $plugin_id );
18864
+ if ( $this->is_api_error( $result ) ) {
18865
+ $this->_admin_notices->add(
18866
+ $result->error->message,
18867
+ $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
18868
+ 'error'
18869
+ );
18870
+ }
18871
+
18872
+ if ( $switch_to_network_install_blog_after_cancellation ) {
18873
+ $this->switch_to_blog( $this->_storage->network_install_blog_id );
18874
+ }
18875
+
18876
+ return;
18877
+
18878
+ case 'activate_license':
18879
+ check_admin_referer( trim( "{$action}:{$blog_id}:{$install_id}", ':' ) );
18880
+
18881
+ $fs = $this;
18882
+ if ( $plugin_id != $this->get_id() ) {
18883
+ $fs = $this->is_addon_activated( $plugin_id ) ?
18884
+ self::get_instance_by_id( $plugin_id ) :
18885
+ null;
18886
+ }
18887
+
18888
+ if ( is_object( $fs ) ) {
18889
+ $fs->_activate_license();
18890
+ }
18891
+
18892
+ return;
18893
+
18894
+ case 'deactivate_license':
18895
+ check_admin_referer( trim( "{$action}:{$blog_id}:{$install_id}", ':' ) );
18896
+
18897
+ if ( $plugin_id == $this->get_id() ) {
18898
+ $this->_deactivate_license();
18899
+
18900
+ if ( $this->is_only_premium() ) {
18901
+ // Clear user and site.
18902
+ $this->_site = null;
18903
+ $this->_user = null;
18904
+
18905
+ if ( ! $is_network_action ) {
18906
+ fs_redirect( $this->get_activation_url() );
18907
+ } else if ( is_numeric( $blog_id ) ) {
18908
+ $this->switch_to_blog( $this->_storage->network_install_blog_id );
18909
+ }
18910
+ }
18911
+ } else {
18912
+ if ( $this->is_addon_activated( $plugin_id ) ) {
18913
+ $fs_addon = self::get_instance_by_id( $plugin_id );
18914
+ $fs_addon->_deactivate_license();
18915
+ }
18916
+ }
18917
+
18918
+ return;
18919
+
18920
+ case 'check_updates':
18921
+ check_admin_referer( $action );
18922
+ $this->check_updates();
18923
+
18924
+ return;
18925
+
18926
+ case 'change_owner':
18927
+ $state = fs_request_get( 'state', 'init' );
18928
+ switch ( $state ) {
18929
+ case 'init':
18930
+ $candidate_email = fs_request_get( 'candidate_email', '' );
18931
+
18932
+ if ( $this->init_change_owner( $candidate_email ) ) {
18933
+ $this->_admin_notices->add( sprintf( $this->get_text_inline( 'Please check your mailbox, you should receive an email via %s to confirm the ownership change. From security reasons, you must confirm the change within the next 15 min. If you cannot find the email, please check your spam folder.', 'change-owner-request-sent-x' ), '<b>' . $this->_user->email . '</b>' ) );
18934
+ }
18935
+ break;
18936
+ case 'owner_confirmed':
18937
+ $candidate_email = fs_request_get( 'candidate_email', '' );
18938
+
18939
+ $this->_admin_notices->add( sprintf( $this->get_text_inline( 'Thanks for confirming the ownership change. An email was just sent to %s for final approval.', 'change-owner-request_owner-confirmed' ), '<b>' . $candidate_email . '</b>' ) );
18940
+ break;
18941
+ case 'candidate_confirmed':
18942
+ if ( $this->complete_change_owner() ) {
18943
+ $this->_admin_notices->add_sticky(
18944
+ sprintf( $this->get_text_inline( '%s is the new owner of the account.', 'change-owner-request_candidate-confirmed' ), '<b>' . $this->_user->email . '</b>' ),
18945
+ 'ownership_changed',
18946
+ $this->get_text_x_inline( 'Congrats', 'as congratulations', 'congrats' ) . '!'
18947
+ );
18948
+ } else {
18949
+ // @todo Handle failed ownership change message.
18950
+ }
18951
+ break;
18952
+ }
18953
+
18954
+ return;
18955
+
18956
+ case 'update_email':
18957
+ check_admin_referer( 'update_email' );
18958
+
18959
+ $new_email = fs_request_get( 'fs_email_' . $this->get_unique_affix(), '' );
18960
+ $result = $this->update_email( $new_email );
18961
+
18962
+ if ( isset( $result->error ) ) {
18963
+ switch ( $result->error->code ) {
18964
+ case 'user_exist':
18965
+ $this->_admin_notices->add(
18966
+ $this->get_text_inline( 'Sorry, we could not complete the email update. Another user with the same email is already registered.', 'user-exist-message' ) . ' ' .
18967
+ 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 . '</b>' ) .
18968
+ sprintf(
18969
+ '<a style="margin-left: 10px;" href="%s"><button class="button button-primary">%s &nbsp;&#10140;</button></a>',
18970
+ $this->get_account_url( 'change_owner', array(
18971
+ 'state' => 'init',
18972
+ 'candidate_email' => $new_email
18973
+ ) ),
18974
+ $this->get_text_inline( 'Change Ownership', 'change-ownership' )
18975
+ ),
18976
+ $oops_text,
18977
+ 'error'
18978
+ );
18979
+ break;
18980
+ }
18981
+ } else {
18982
+ $this->_admin_notices->add( $this->get_text_inline( 'Your email was successfully updated. You should receive an email with confirmation instructions in few moments.', 'email-updated-message' ) );
18983
+ }
18984
+
18985
+ return;
18986
+
18987
+ case 'update_user_name':
18988
+ check_admin_referer( 'update_user_name' );
18989
+
18990
+ $result = $this->update_user_name();
18991
+
18992
+ if ( isset( $result->error ) ) {
18993
+ $this->_admin_notices->add(
18994
+ $this->get_text_inline( 'Please provide your full name.', 'name-update-failed-message' ),
18995
+ $oops_text,
18996
+ 'error'
18997
+ );
18998
+ } else {
18999
+ $this->_admin_notices->add( $this->get_text_inline( 'Your name was successfully updated.', 'name-updated-message' ) );
19000
+ }
19001
+
19002
+ return;
19003
+
19004
+ #region Actions that might be called from external links (e.g. email)
19005
+
19006
+ case 'cancel_trial':
19007
+ $result = $this->cancel_subscription_or_trial( $plugin_id );
19008
+ if ( $this->is_api_error( $result ) ) {
19009
+ $this->_admin_notices->add(
19010
+ $result->error->message,
19011
+ $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
19012
+ 'error'
19013
+ );
19014
+ }
19015
+
19016
+ return;
19017
+
19018
+ case 'verify_email':
19019
+ $this->verify_email();
19020
+
19021
+ return;
19022
+
19023
+ case 'sync_user':
19024
+ $this->_handle_account_user_sync();
19025
+
19026
+ return;
19027
+
19028
+ case $this->get_unique_affix() . '_sync_license':
19029
+ $this->_sync_license();
19030
+
19031
+ return;
19032
+
19033
+ case 'download_latest':
19034
+ $this->download_latest_directly( $plugin_id );
19035
+
19036
+ return;
19037
+
19038
+ #endregion
19039
+ }
19040
+
19041
+ if ( WP_FS__IS_POST_REQUEST ) {
19042
+ $properties = array( 'site_secret_key', 'site_id', 'site_public_key' );
19043
+ foreach ( $properties as $p ) {
19044
+ if ( 'update_' . $p === $action ) {
19045
+ check_admin_referer( $action );
19046
+
19047
+ $this->_logger->log( $action );
19048
+
19049
+ $site_property = substr( $p, strlen( 'site_' ) );
19050
+ $site_property_value = fs_request_get( 'fs_' . $p . '_' . $this->get_unique_affix(), '' );
19051
+ $this->get_site()->{$site_property} = $site_property_value;
19052
+
19053
+ // Store account after modification.
19054
+ $this->_store_site();
19055
+
19056
+ $this->do_action( 'account_property_edit', 'site', $site_property, $site_property_value );
19057
+
19058
+ $this->_admin_notices->add( sprintf(
19059
+ /* translators: %s: User's account property (e.g. email address, name) */
19060
+ $this->get_text_inline( 'You have successfully updated your %s.', 'x-updated' ),
19061
+ '<b>' . str_replace( '_', ' ', $p ) . '</b>'
19062
+ ) );
19063
+
19064
+ return;
19065
+ }
19066
+ }
19067
+ }
19068
+ }
19069
+
19070
+ /**
19071
+ * Account page resources load.
19072
+ *
19073
+ * @author Vova Feldman (@svovaf)
19074
+ * @since 1.0.6
19075
+ */
19076
+ function _account_page_load() {
19077
+ $this->_logger->entrance();
19078
+
19079
+ $this->_logger->info( var_export( $_REQUEST, true ) );
19080
+
19081
+ fs_enqueue_local_style( 'fs_account', '/admin/account.css' );
19082
+
19083
+ if ( $this->has_addons() ) {
19084
+ wp_enqueue_script( 'plugin-install' );
19085
+ add_thickbox();
19086
+
19087
+ function fs_addons_body_class( $classes ) {
19088
+ $classes .= ' plugins-php';
19089
+
19090
+ return $classes;
19091
+ }
19092
+
19093
+ add_filter( 'admin_body_class', 'fs_addons_body_class' );
19094
+ }
19095
+
19096
+ if ( $this->has_paid_plan() &&
19097
+ ! $this->has_any_license() &&
19098
+ ! $this->is_sync_executed() &&
19099
+ $this->is_tracking_allowed()
19100
+ ) {
19101
+ /**
19102
+ * If no licenses found and no sync job was executed during the last 24 hours,
19103
+ * just execute the sync job right away (blocking execution).
19104
+ *
19105
+ * @since 1.1.7.3
19106
+ */
19107
+ $this->run_manual_sync();
19108
+ }
19109
+
19110
+ $this->_handle_account_edits();
19111
+
19112
+ $this->do_action( 'account_page_load_before_departure' );
19113
+ }
19114
+
19115
+ /**
19116
+ * Renders the "Affiliation" page.
19117
+ *
19118
+ * @author Leo Fajardo (@leorw)
19119
+ * @since 1.2.3
19120
+ */
19121
+ function _affiliation_page_render() {
19122
+ $this->_logger->entrance();
19123
+
19124
+ $this->fetch_affiliate_and_terms();
19125
+
19126
+ fs_enqueue_local_style( 'fs_affiliation', '/admin/affiliation.css' );
19127
+
19128
+ $vars = array( 'id' => $this->_module_id );
19129
+ echo $this->apply_filters( "/forms/affiliation.php", fs_get_template( '/forms/affiliation.php', $vars ) );
19130
+ }
19131
+
19132
+
19133
+ /**
19134
+ * Render account page.
19135
+ *
19136
+ * @author Vova Feldman (@svovaf)
19137
+ * @since 1.0.0
19138
+ */
19139
+ function _account_page_render() {
19140
+ $this->_logger->entrance();
19141
+
19142
+ $template = 'account.php';
19143
+ $vars = array( 'id' => $this->_module_id );
19144
+
19145
+ /**
19146
+ * Added filter to the template to allow developers wrapping the template
19147
+ * in custom HTML (e.g. within a wizard/tabs).
19148
+ *
19149
+ * @author Vova Feldman (@svovaf)
19150
+ * @since 1.2.1.6
19151
+ */
19152
+ echo $this->apply_filters( "templates/{$template}", fs_get_template( $template, $vars ) );
19153
+ }
19154
+
19155
+ /**
19156
+ * Render account connect page.
19157
+ *
19158
+ * @author Vova Feldman (@svovaf)
19159
+ * @since 1.0.7
19160
+ */
19161
+ function _connect_page_render() {
19162
+ $this->_logger->entrance();
19163
+
19164
+ $vars = array( 'id' => $this->_module_id );
19165
+
19166
+ /**
19167
+ * Added filter to the template to allow developers wrapping the template
19168
+ * in custom HTML (e.g. within a wizard/tabs).
19169
+ *
19170
+ * @author Vova Feldman (@svovaf)
19171
+ * @since 1.2.1.6
19172
+ */
19173
+ echo $this->apply_filters( 'templates/connect.php', fs_get_template( 'connect.php', $vars ) );
19174
+ }
19175
+
19176
+ /**
19177
+ * Load required resources before add-ons page render.
19178
+ *
19179
+ * @author Vova Feldman (@svovaf)
19180
+ * @since 1.0.6
19181
+ */
19182
+ function _addons_page_load() {
19183
+ $this->_logger->entrance();
19184
+
19185
+ fs_enqueue_local_style( 'fs_addons', '/admin/add-ons.css' );
19186
+
19187
+ wp_enqueue_script( 'plugin-install' );
19188
+ add_thickbox();
19189
+
19190
+ function fs_addons_body_class( $classes ) {
19191
+ $classes .= ' plugins-php';
19192
+
19193
+ return $classes;
19194
+ }
19195
+
19196
+ add_filter( 'admin_body_class', 'fs_addons_body_class' );
19197
+
19198
+ if ( ! $this->is_registered() && $this->is_org_repo_compliant() ) {
19199
+ $this->_admin_notices->add(
19200
+ sprintf( $this->get_text_inline( 'Just letting you know that the add-ons information of %s is being pulled from an external server.', 'addons-info-external-message' ), '<b>' . $this->get_plugin_name() . '</b>' ),
19201
+ $this->get_text_x_inline( 'Heads up', 'advance notice of something that will need attention.', 'heads-up' ),
19202
+ 'update-nag'
19203
+ );
19204
+ }
19205
+ }
19206
+
19207
+ /**
19208
+ * Render add-ons page.
19209
+ *
19210
+ * @author Vova Feldman (@svovaf)
19211
+ * @since 1.0.6
19212
+ */
19213
+ function _addons_page_render() {
19214
+ $this->_logger->entrance();
19215
+
19216
+ $vars = array( 'id' => $this->_module_id );
19217
+
19218
+ /**
19219
+ * Added filter to the template to allow developers wrapping the template
19220
+ * in custom HTML (e.g. within a wizard/tabs).
19221
+ *
19222
+ * @author Vova Feldman (@svovaf)
19223
+ * @since 1.2.1.6
19224
+ */
19225
+ echo $this->apply_filters( 'templates/add-ons.php', fs_get_template( 'add-ons.php', $vars ) );
19226
+ }
19227
+
19228
+ /* Pricing & Upgrade
19229
+ ------------------------------------------------------------------------------------------------------------------*/
19230
+ /**
19231
+ * Render pricing page.
19232
+ *
19233
+ * @author Vova Feldman (@svovaf)
19234
+ * @since 1.0.0
19235
+ */
19236
+ function _pricing_page_render() {
19237
+ $this->_logger->entrance();
19238
+
19239
+ $vars = array( 'id' => $this->_module_id );
19240
+
19241
+ if ( 'true' === fs_request_get( 'checkout', false ) ) {
19242
+ echo $this->apply_filters( 'templates/checkout.php', fs_get_template( 'checkout.php', $vars ) );
19243
+ } else {
19244
+ echo $this->apply_filters( 'templates/pricing.php', fs_get_template( 'pricing.php', $vars ) );
19245
+ }
19246
+ }
19247
+
19248
+ #----------------------------------------------------------------------------------
19249
+ #region Contact Us
19250
+ #----------------------------------------------------------------------------------
19251
+
19252
+ /**
19253
+ * Render contact-us page.
19254
+ *
19255
+ * @author Vova Feldman (@svovaf)
19256
+ * @since 1.0.3
19257
+ */
19258
+ function _contact_page_render() {
19259
+ $this->_logger->entrance();
19260
+
19261
+ $vars = array( 'id' => $this->_module_id );
19262
+
19263
+ /**
19264
+ * Added filter to the template to allow developers wrapping the template
19265
+ * in custom HTML (e.g. within a wizard/tabs).
19266
+ *
19267
+ * @author Vova Feldman (@svovaf)
19268
+ * @since 2.1.3
19269
+ */
19270
+ echo $this->apply_filters( 'templates/contact.php', fs_get_template( 'contact.php', $vars ) );
19271
+ }
19272
+
19273
+ #endregion ------------------------------------------------------------------------
19274
+
19275
+ /**
19276
+ * Hide all admin notices to prevent distractions.
19277
+ *
19278
+ * @author Vova Feldman (@svovaf)
19279
+ * @since 1.0.3
19280
+ *
19281
+ * @uses remove_all_actions()
19282
+ */
19283
+ private static function _hide_admin_notices() {
19284
+ remove_all_actions( 'admin_notices' );
19285
+ remove_all_actions( 'network_admin_notices' );
19286
+ remove_all_actions( 'all_admin_notices' );
19287
+ remove_all_actions( 'user_admin_notices' );
19288
+ }
19289
+
19290
+ static function _clean_admin_content_section_hook() {
19291
+ self::_hide_admin_notices();
19292
+
19293
+ // Hide footer.
19294
+ echo '<style>#wpfooter { display: none !important; }</style>';
19295
+ }
19296
+
19297
+ /**
19298
+ * Attach to admin_head hook to hide all admin notices.
19299
+ *
19300
+ * @author Vova Feldman (@svovaf)
19301
+ * @since 1.0.3
19302
+ */
19303
+ static function _clean_admin_content_section() {
19304
+ add_action( 'admin_head', 'Freemius::_clean_admin_content_section_hook' );
19305
+ }
19306
+
19307
+ /* CSS & JavaScript
19308
+ ------------------------------------------------------------------------------------------------------------------*/
19309
+ /* function _enqueue_script($handle, $src) {
19310
+ $url = plugins_url( substr( WP_FS__DIR_JS, strlen( $this->_plugin_dir_path ) ) . '/assets/js/' . $src );
19311
+
19312
+ $this->_logger->entrance( 'script = ' . $url );
19313
+
19314
+ wp_enqueue_script( $handle, $url );
19315
+ }*/
19316
+
19317
+ /* SDK
19318
+ ------------------------------------------------------------------------------------------------------------------*/
19319
+ private $_user_api;
19320
+
19321
+ /**
19322
+ *
19323
+ * @author Vova Feldman (@svovaf)
19324
+ * @since 1.0.2
19325
+ *
19326
+ * @param bool $flush
19327
+ *
19328
+ * @return FS_Api
19329
+ */
19330
+ private function get_api_user_scope( $flush = false ) {
19331
+ if ( ! isset( $this->_user_api ) || $flush ) {
19332
+ $this->_user_api = $this->get_api_user_scope_by_user( $this->_user );
19333
+ }
19334
+
19335
+ return $this->_user_api;
19336
+ }
19337
+
19338
+ /**
19339
+ * @author Vova Feldman (@svovaf)
19340
+ * @since 2.0.0
19341
+ *
19342
+ * @param \FS_User $user
19343
+ *
19344
+ * @return \FS_Api
19345
+ */
19346
+ private function get_api_user_scope_by_user( FS_User $user ) {
19347
+ return FS_Api::instance(
19348
+ $this->_module_id,
19349
+ 'user',
19350
+ $user->id,
19351
+ $user->public_key,
19352
+ ! $this->is_live(),
19353
+ $user->secret_key
19354
+ );
19355
+ }
19356
+
19357
+ /**
19358
+ *
19359
+ * @author Leo Fajardo (@leorw)
19360
+ * @since 2.0.0
19361
+ *
19362
+ * @param bool $flush
19363
+ *
19364
+ * @return FS_Api
19365
+ */
19366
+ private function get_current_or_network_user_api_scope( $flush = false ) {
19367
+ if ( ! $this->_is_network_active ||
19368
+ ( isset( $this->_user ) && $this->_user instanceof FS_User )
19369
+ ) {
19370
+ return $this->get_api_user_scope( $flush );
19371
+ }
19372
+
19373
+ $user = $this->get_current_or_network_user();
19374
+
19375
+ $this->_user_api = FS_Api::instance(
19376
+ $this->_module_id,
19377
+ 'user',
19378
+ $user->id,
19379
+ $user->public_key,
19380
+ ! $this->is_live(),
19381
+ $user->secret_key
19382
+ );
19383
+
19384
+ return $this->_user_api;
19385
+ }
19386
+
19387
+ private $_site_api;
19388
+
19389
+ /**
19390
+ *
19391
+ * @author Vova Feldman (@svovaf)
19392
+ * @since 1.0.2
19393
+ *
19394
+ * @param bool $flush
19395
+ *
19396
+ * @return FS_Api
19397
+ */
19398
+ private function get_api_site_scope( $flush = false ) {
19399
+ if ( ! isset( $this->_site_api ) || $flush ) {
19400
+ $this->_site_api = FS_Api::instance(
19401
+ $this->_module_id,
19402
+ 'install',
19403
+ $this->_site->id,
19404
+ $this->_site->public_key,
19405
+ ! $this->is_live(),
19406
+ $this->_site->secret_key
19407
+ );
19408
+ }
19409
+
19410
+ return $this->_site_api;
19411
+ }
19412
+
19413
+ private $_plugin_api;
19414
+
19415
+ /**
19416
+ * Get plugin public API scope.
19417
+ *
19418
+ * @author Vova Feldman (@svovaf)
19419
+ * @since 1.0.7
19420
+ *
19421
+ * @return FS_Api
19422
+ */
19423
+ function get_api_plugin_scope() {
19424
+ if ( ! isset( $this->_plugin_api ) ) {
19425
+ $this->_plugin_api = FS_Api::instance(
19426
+ $this->_module_id,
19427
+ 'plugin',
19428
+ $this->_plugin->id,
19429
+ $this->_plugin->public_key,
19430
+ ! $this->is_live()
19431
+ );
19432
+ }
19433
+
19434
+ return $this->_plugin_api;
19435
+ }
19436
+
19437
+ /**
19438
+ * Get site API scope object (fallback to public plugin scope when not registered).
19439
+ *
19440
+ * @author Vova Feldman (@svovaf)
19441
+ * @since 1.0.7
19442
+ *
19443
+ * @return FS_Api
19444
+ */
19445
+ function get_api_site_or_plugin_scope() {
19446
+ return $this->is_registered() ?
19447
+ $this->get_api_site_scope() :
19448
+ $this->get_api_plugin_scope();
19449
+ }
19450
+
19451
+ /**
19452
+ * Show trial promotional notice (if any trial exist).
19453
+ *
19454
+ * @author Vova Feldman (@svovaf)
19455
+ * @since 1.0.9
19456
+ *
19457
+ * @param FS_Plugin_Plan[] $plans
19458
+ */
19459
+ function _check_for_trial_plans( $plans ) {
19460
+ /**
19461
+ * For some reason core's do_action() flattens arrays when it has a single object item. Therefore, we need to restructure the array as expected.
19462
+ *
19463
+ * @author Vova Feldman (@svovaf)
19464
+ * @since 2.1.2
19465
+ */
19466
+ if ( ! is_array( $plans ) && is_object( $plans ) ) {
19467
+ $plans = array( $plans );
19468
+ }
19469
+
19470
+ $this->_storage->has_trial_plan = FS_Plan_Manager::instance()->has_trial_plan( $plans );
19471
+ }
19472
+
19473
+ /**
19474
+ * During trial promotion the "upgrade" submenu item turns to
19475
+ * "start trial" to encourage the trial. Since we want to keep
19476
+ * the same menu item handler and there's no robust way to
19477
+ * add new arguments to the menu item link's querystring,
19478
+ * use JavaScript to find the menu item and update the href of
19479
+ * the link.
19480
+ *
19481
+ * @author Vova Feldman (@svovaf)
19482
+ * @since 1.2.1.5
19483
+ */
19484
+ function _fix_start_trial_menu_item_url() {
19485
+ $template_args = array( 'id' => $this->_module_id );
19486
+ fs_require_template( 'add-trial-to-pricing.php', $template_args );
19487
+ }
19488
+
19489
+ /**
19490
+ * Check if module is currently in a trial promotion mode.
19491
+ *
19492
+ * @author Vova Feldman (@svovaf)
19493
+ * @since 1.2.2.7
19494
+ *
19495
+ * @return bool
19496
+ */
19497
+ function is_in_trial_promotion() {
19498
+ return $this->_admin_notices->has_sticky( 'trial_promotion' );
19499
+ }
19500
+
19501
+ /**
19502
+ * Show trial promotional notice (if any trial exist).
19503
+ *
19504
+ * @author Vova Feldman (@svovaf)
19505
+ * @since 1.0.9
19506
+ *
19507
+ * @return bool If trial notice added.
19508
+ */
19509
+ function _add_trial_notice() {
19510
+ if ( ! $this->is_user_admin() ) {
19511
+ return false;
19512
+ }
19513
+
19514
+ if ( ! $this->is_user_in_admin() ) {
19515
+ return false;
19516
+ }
19517
+
19518
+ if ( $this->_is_network_active ) {
19519
+ if ( fs_is_network_admin() ) {
19520
+ // Network level trial is disabled at the moment.
19521
+ return false;
19522
+ }
19523
+
19524
+ if ( ! $this->is_delegated_connection() ) {
19525
+ // Only delegated sites should support trials.
19526
+ return false;
19527
+ }
19528
+ }
19529
+
19530
+ // Check if trial message is already shown.
19531
+ if ( $this->is_in_trial_promotion() ) {
19532
+ add_action( 'admin_footer', array( &$this, '_fix_start_trial_menu_item_url' ) );
19533
+
19534
+ $this->_menu->add_counter_to_menu_item( 1, 'fs-trial' );
19535
+
19536
+ return false;
19537
+ }
19538
+
19539
+ if ( $this->is_premium() && ! WP_FS__DEV_MODE ) {
19540
+ // Don't show trial if running the premium code, unless running in DEV mode.
19541
+ return false;
19542
+ }
19543
+
19544
+ if ( ! $this->has_trial_plan() ) {
19545
+ // No plans with trial.
19546
+ return false;
19547
+ }
19548
+
19549
+ if ( ! $this->apply_filters( 'show_trial', true ) ) {
19550
+ // Developer explicitly asked not to show the trial promo.
19551
+ return false;
19552
+ }
19553
+
19554
+ if ( $this->is_registered() ) {
19555
+ // Check if trial already utilized.
19556
+ if ( $this->_site->is_trial_utilized() ) {
19557
+ return false;
19558
+ }
19559
+
19560
+ if ( $this->is_paying_or_trial() ) {
19561
+ // Don't show trial if paying or already in trial.
19562
+ return false;
19563
+ }
19564
+ }
19565
+
19566
+ if ( $this->is_activation_mode() || $this->is_pending_activation() ) {
19567
+ // If not yet opted-in/skipped, or pending activation, don't show trial.
19568
+ return false;
19569
+ }
19570
+
19571
+ $last_time_trial_promotion_shown = $this->_storage->get( 'trial_promotion_shown', false );
19572
+ $was_promotion_shown_before = ( false !== $last_time_trial_promotion_shown );
19573
+
19574
+ // Show promotion if never shown before and 24 hours after initial activation with FS.
19575
+ if ( ! $was_promotion_shown_before &&
19576
+ $this->_storage->install_timestamp > ( time() - $this->apply_filters( 'show_first_trial_after_n_sec', WP_FS__TIME_24_HOURS_IN_SEC ) )
19577
+ ) {
19578
+ return false;
19579
+ }
19580
+
19581
+ // OR if promotion was shown before, try showing it every 30 days.
19582
+ if ( $was_promotion_shown_before &&
19583
+ $this->apply_filters( 'reshow_trial_after_every_n_sec', 30 * WP_FS__TIME_24_HOURS_IN_SEC ) > time() - $last_time_trial_promotion_shown
19584
+ ) {
19585
+ return false;
19586
+ }
19587
+
19588
+ $trial_period = $this->_trial_days;
19589
+ $require_payment = $this->_is_trial_require_payment;
19590
+ $trial_url = $this->get_trial_url();
19591
+ $plans_string = strtolower( $this->get_text_inline( 'Awesome', 'awesome' ) );
19592
+
19593
+ if ( $this->is_registered() ) {
19594
+ // If opted-in, override trial with up to date data from API.
19595
+ $trial_plans = FS_Plan_Manager::instance()->get_trial_plans( $this->_plans );
19596
+ $trial_plans_count = count( $trial_plans );
19597
+
19598
+ if ( 0 === $trial_plans_count ) {
19599
+ // If there's no plans with a trial just exit.
19600
+ return false;
19601
+ }
19602
+
19603
+ /**
19604
+ * @var FS_Plugin_Plan $paid_plan
19605
+ */
19606
+ $paid_plan = $trial_plans[0];
19607
+ $require_payment = $paid_plan->is_require_subscription;
19608
+ $trial_period = $paid_plan->trial_period;
19609
+
19610
+ $total_paid_plans = count( $this->_plans ) - ( FS_Plan_Manager::instance()->has_free_plan( $this->_plans ) ? 1 : 0 );
19611
+
19612
+ if ( $total_paid_plans !== $trial_plans_count ) {
19613
+ // Not all paid plans have a trial - generate a string of those that have it.
19614
+ for ( $i = 0; $i < $trial_plans_count; $i ++ ) {
19615
+ $plans_string .= sprintf(
19616
+ ' <a href="%s">%s</a>',
19617
+ $trial_url,
19618
+ $trial_plans[ $i ]->title
19619
+ );
19620
+
19621
+ if ( $i < $trial_plans_count - 2 ) {
19622
+ $plans_string .= ', ';
19623
+ } else if ( $i == $trial_plans_count - 2 ) {
19624
+ $plans_string .= ' and ';
19625
+ }
19626
+ }
19627
+ }
19628
+ }
19629
+
19630
+ $message = sprintf(
19631
+ $this->get_text_x_inline( 'Hey', 'exclamation', 'hey' ) . '! ' . $this->get_text_inline( 'How do you like %s so far? Test all our %s premium features with a %d-day free trial.', 'trial-x-promotion-message' ),
19632
+ sprintf( '<b>%s</b>', $this->get_plugin_name() ),
19633
+ $plans_string,
19634
+ $trial_period
19635
+ );
19636
+
19637
+ // "No Credit-Card Required" or "No Commitment for N Days".
19638
+ $cc_string = $require_payment ?
19639
+ sprintf( $this->get_text_inline( 'No commitment for %s days - cancel anytime!', 'no-commitment-for-x-days' ), $trial_period ) :
19640
+ $this->get_text_inline( 'No credit card required', 'no-cc-required' ) . '!';
19641
+
19642
+
19643
+ // Start trial button.
19644
+ $button = ' ' . sprintf(
19645
+ '<a style="margin-left: 10px; vertical-align: super;" href="%s"><button class="button button-primary">%s &nbsp;&#10140;</button></a>',
19646
+ $trial_url,
19647
+ $this->get_text_x_inline( 'Start free trial', 'call to action', 'start-free-trial' )
19648
+ );
19649
+
19650
+ $this->_admin_notices->add_sticky(
19651
+ $this->apply_filters( 'trial_promotion_message', "{$message} {$cc_string} {$button}" ),
19652
+ 'trial_promotion',
19653
+ '',
19654
+ 'promotion'
19655
+ );
19656
+
19657
+ $this->_storage->trial_promotion_shown = WP_FS__SCRIPT_START_TIME;
19658
+
19659
+ return true;
19660
+ }
19661
+
19662
+ /**
19663
+ * Lets users/customers know that the product has an affiliate program.
19664
+ *
19665
+ * @author Leo Fajardo (@leorw)
19666
+ * @since 1.2.2.11
19667
+ *
19668
+ * @return bool Returns true if the notice has been added.
19669
+ */
19670
+ function _add_affiliate_program_notice() {
19671
+ if ( ! $this->is_user_admin() ) {
19672
+ return false;
19673
+ }
19674
+
19675
+ if ( ! $this->is_user_in_admin() ) {
19676
+ return false;
19677
+ }
19678
+
19679
+ // Check if the notice is already shown.
19680
+ if ( $this->_admin_notices->has_sticky( 'affiliate_program' ) ) {
19681
+ return false;
19682
+ }
19683
+
19684
+ if (
19685
+ // Product has no affiliate program.
19686
+ ! $this->has_affiliate_program() ||
19687
+ // User has applied for an affiliate account.
19688
+ ! empty( $this->_storage->affiliate_application_data )
19689
+ ) {
19690
+ return false;
19691
+ }
19692
+
19693
+ if ( ! $this->apply_filters( 'show_affiliate_program_notice', true ) ) {
19694
+ // Developer explicitly asked not to show the notice about the affiliate program.
19695
+ return false;
19696
+ }
19697
+
19698
+ if ( $this->is_activation_mode() || $this->is_pending_activation() ) {
19699
+ // If not yet opted in/skipped, or pending activation, don't show the notice.
19700
+ return false;
19701
+ }
19702
+
19703
+ $last_time_notice_was_shown = $this->_storage->get( 'affiliate_program_notice_shown', false );
19704
+ $was_notice_shown_before = ( false !== $last_time_notice_was_shown );
19705
+
19706
+ /**
19707
+ * Do not show the notice if it was already shown before or less than 30 days have passed since the initial
19708
+ * activation with FS.
19709
+ */
19710
+ if ( $was_notice_shown_before ||
19711
+ $this->_storage->install_timestamp > ( time() - ( WP_FS__TIME_24_HOURS_IN_SEC * 30 ) )
19712
+ ) {
19713
+ return false;
19714
+ }
19715
+
19716
+ if ( ! $this->is_paying() &&
19717
+ FS_Plugin::AFFILIATE_MODERATION_CUSTOMERS == $this->_plugin->affiliate_moderation
19718
+ ) {
19719
+ // If the user is not a customer and the affiliate program is only for customers, don't show the notice.
19720
+ return false;
19721
+ }
19722
+
19723
+ $message = sprintf(
19724
+ $this->get_text_inline( 'Hey there, did you know that %s has an affiliate program? If you like the %s you can become our ambassador and earn some cash!', 'become-an-ambassador-admin-notice' ),
19725
+ sprintf( '<strong>%s</strong>', $this->get_plugin_name() ),
19726
+ $this->get_module_label( true )
19727
+ );
19728
+
19729
+ // HTML code for the "Learn more..." button.
19730
+ $button = ' ' . sprintf(
19731
+ '<a style="display: block; margin-top: 10px;" href="%s"><button class="button button-primary">%s &nbsp;&#10140;</button></a>',
19732
+ $this->_get_admin_page_url( 'affiliation' ),
19733
+ $this->get_text_inline( 'Learn more', 'learn-more' ) . '...'
19734
+ );
19735
+
19736
+ $this->_admin_notices->add_sticky(
19737
+ $this->apply_filters( 'affiliate_program_notice', "{$message} {$button}" ),
19738
+ 'affiliate_program',
19739
+ '',
19740
+ 'promotion'
19741
+ );
19742
+
19743
+ $this->_storage->affiliate_program_notice_shown = WP_FS__SCRIPT_START_TIME;
19744
+
19745
+ return true;
19746
+ }
19747
+
19748
+ /**
19749
+ * @author Vova Feldman (@svovaf)
19750
+ * @since 1.2.1.5
19751
+ */
19752
+ function _enqueue_common_css() {
19753
+ if ( $this->has_paid_plan() && ! $this->is_paying() ) {
19754
+ // Add basic CSS for admin-notices and menu-item colors.
19755
+ fs_enqueue_local_style( 'fs_common', '/admin/common.css' );
19756
+ }
19757
+ }
19758
+
19759
+ /**
19760
+ * @author Leo Fajardo (@leorw)
19761
+ * @since 1.2.2
19762
+ */
19763
+ function _show_theme_activation_optin_dialog() {
19764
+ fs_enqueue_local_style( 'fs_connect', '/admin/connect.css' );
19765
+
19766
+ add_action( 'admin_footer-themes.php', array( &$this, '_add_fs_theme_activation_dialog' ) );
19767
+ }
19768
+
19769
+ /**
19770
+ * @author Leo Fajardo (@leorw)
19771
+ * @since 1.2.2
19772
+ */
19773
+ function _add_fs_theme_activation_dialog() {
19774
+ $vars = array( 'id' => $this->_module_id );
19775
+ fs_require_once_template( 'connect.php', $vars );
19776
+ }
19777
+
19778
+ /* Action Links
19779
+ ------------------------------------------------------------------------------------------------------------------*/
19780
+ private $_action_links_hooked = false;
19781
+ private $_action_links = array();
19782
+
19783
+ /**
19784
+ * Hook to plugin action links filter.
19785
+ *
19786
+ * @author Vova Feldman (@svovaf)
19787
+ * @since 1.0.0
19788
+ */
19789
+ private function hook_plugin_action_links() {
19790
+ $this->_logger->entrance();
19791
+
19792
+ $this->_action_links_hooked = true;
19793
+
19794
+ $this->_logger->log( 'Adding action links hooks.' );
19795
+
19796
+ // Add action link to settings page.
19797
+ add_filter( 'plugin_action_links_' . $this->_plugin_basename, array(
19798
+ &$this,
19799
+ '_modify_plugin_action_links_hook'
19800
+ ), WP_FS__DEFAULT_PRIORITY, 2 );
19801
+ add_filter( 'network_admin_plugin_action_links_' . $this->_plugin_basename, array(
19802
+ &$this,
19803
+ '_modify_plugin_action_links_hook'
19804
+ ), WP_FS__DEFAULT_PRIORITY, 2 );
19805
+ }
19806
+
19807
+ /**
19808
+ * Add plugin action link.
19809
+ *
19810
+ * @author Vova Feldman (@svovaf)
19811
+ * @since 1.0.0
19812
+ *
19813
+ * @param $label
19814
+ * @param $url
19815
+ * @param bool $external
19816
+ * @param int $priority
19817
+ * @param bool $key
19818
+ */
19819
+ function add_plugin_action_link( $label, $url, $external = false, $priority = WP_FS__DEFAULT_PRIORITY, $key = false ) {
19820
+ $this->_logger->entrance();
19821
+
19822
+ if ( ! isset( $this->_action_links[ $priority ] ) ) {
19823
+ $this->_action_links[ $priority ] = array();
19824
+ }
19825
+
19826
+ if ( false === $key ) {
19827
+ $key = preg_replace( "/[^A-Za-z0-9 ]/", '', strtolower( $label ) );
19828
+ }
19829
+
19830
+ $this->_action_links[ $priority ][] = array(
19831
+