PluginProbe ʕ •ᴥ•ʔ
Code Manager / 1.0.3
Code Manager v1.0.3
1.0.48 1.0.47 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 1.0.25 1.0.26 1.0.27 1.0.28 1.0.3 1.0.30 1.0.31 1.0.32 1.0.33 1.0.34 1.0.35 1.0.36 1.0.37 1.0.38 1.0.39 1.0.4 1.0.40 1.0.41 1.0.42 1.0.43 1.0.44 1.0.45 1.0.46 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9
code-manager / freemius / includes / class-freemius-abstract.php
code-manager / freemius / includes Last commit date
customizer 5 years ago debug 5 years ago entities 5 years ago managers 5 years ago sdk 5 years ago supplements 5 years ago class-freemius-abstract.php 5 years ago class-freemius.php 5 years ago class-fs-admin-notices.php 5 years ago class-fs-api.php 5 years ago class-fs-logger.php 5 years ago class-fs-options.php 5 years ago class-fs-plugin-updater.php 5 years ago class-fs-security.php 5 years ago class-fs-storage.php 5 years ago class-fs-user-lock.php 5 years ago fs-core-functions.php 5 years ago fs-essential-functions.php 5 years ago fs-plugin-info-dialog.php 5 years ago i18n.php 5 years ago index.php 5 years ago l10n.php 5 years ago
class-freemius-abstract.php
597 lines
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 }