debug
9 years ago
entities
9 years ago
managers
9 years ago
sdk
9 years ago
supplements
9 years ago
class-freemius-abstract.php
9 years ago
class-freemius.php
9 years ago
class-fs-api.php
9 years ago
class-fs-logger.php
9 years ago
class-fs-plugin-updater.php
9 years ago
class-fs-security.php
9 years ago
fs-core-functions.php
9 years ago
fs-essential-functions.php
9 years ago
fs-plugin-info-dialog.php
9 years ago
i18n.php
9 years ago
index.php
9 years ago
l10n.php
9 years ago
class-freemius-abstract.php
554 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @package Freemius |
| 4 | * @copyright Copyright (c) 2015, Freemius, Inc. |
| 5 | * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 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 registered with Freemius by connecting his account. |
| 32 | * |
| 33 | * @since 1.0.1 |
| 34 | * @return bool |
| 35 | */ |
| 36 | abstract function is_registered(); |
| 37 | |
| 38 | /** |
| 39 | * Check if the user skipped connecting the account with Freemius. |
| 40 | * |
| 41 | * @since 1.0.7 |
| 42 | * |
| 43 | * @return bool |
| 44 | */ |
| 45 | abstract function is_anonymous(); |
| 46 | |
| 47 | /** |
| 48 | * Check if the user currently in activation mode. |
| 49 | * |
| 50 | * @since 1.0.7 |
| 51 | * |
| 52 | * @return bool |
| 53 | */ |
| 54 | abstract function is_activation_mode(); |
| 55 | |
| 56 | #endregion |
| 57 | |
| 58 | #---------------------------------------------------------------------------------- |
| 59 | #region Usage Tracking |
| 60 | #---------------------------------------------------------------------------------- |
| 61 | |
| 62 | /** |
| 63 | * Returns TRUE if the user opted-in and didn't disconnect (opt-out). |
| 64 | * |
| 65 | * @author Leo Fajardo (@leorw) |
| 66 | * @since 1.2.1.5 |
| 67 | * |
| 68 | * @return bool |
| 69 | */ |
| 70 | abstract function is_tracking_allowed(); |
| 71 | |
| 72 | /** |
| 73 | * Returns TRUE if the user never opted-in or manually opted-out. |
| 74 | * |
| 75 | * @author Vova Feldman (@svovaf) |
| 76 | * @since 1.2.1.5 |
| 77 | * |
| 78 | * @return bool |
| 79 | */ |
| 80 | function is_tracking_prohibited() { |
| 81 | return ! $this->is_registered() || ! $this->is_tracking_allowed(); |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Opt-out from usage tracking. |
| 86 | * |
| 87 | * Note: This will not delete the account information but will stop all tracking. |
| 88 | * |
| 89 | * Returns: |
| 90 | * 1. FALSE - If the user never opted-in. |
| 91 | * 2. TRUE - If successfully opted-out. |
| 92 | * 3. object - API Result on failure. |
| 93 | * |
| 94 | * @author Leo Fajardo (@leorw) |
| 95 | * @since 1.2.1.5 |
| 96 | * |
| 97 | * @return bool|object |
| 98 | */ |
| 99 | abstract function stop_tracking(); |
| 100 | |
| 101 | /** |
| 102 | * Opt-in back into usage tracking. |
| 103 | * |
| 104 | * Note: This will only work if the user opted-in previously. |
| 105 | * |
| 106 | * Returns: |
| 107 | * 1. FALSE - If the user never opted-in. |
| 108 | * 2. TRUE - If successfully opted-in back to usage tracking. |
| 109 | * 3. object - API result on failure. |
| 110 | * |
| 111 | * @author Leo Fajardo (@leorw) |
| 112 | * @since 1.2.1.5 |
| 113 | * |
| 114 | * @return bool|object |
| 115 | */ |
| 116 | abstract function allow_tracking(); |
| 117 | |
| 118 | #endregion |
| 119 | |
| 120 | #---------------------------------------------------------------------------------- |
| 121 | #region Permissions |
| 122 | #---------------------------------------------------------------------------------- |
| 123 | |
| 124 | /** |
| 125 | * Check if plugin must be WordPress.org compliant. |
| 126 | * |
| 127 | * @since 1.0.7 |
| 128 | * |
| 129 | * @return bool |
| 130 | */ |
| 131 | abstract function is_org_repo_compliant(); |
| 132 | |
| 133 | /** |
| 134 | * Check if plugin is allowed to install executable files. |
| 135 | * |
| 136 | * @author Vova Feldman (@svovaf) |
| 137 | * @since 1.0.5 |
| 138 | * |
| 139 | * @return bool |
| 140 | */ |
| 141 | function is_allowed_to_install() { |
| 142 | return ( $this->is_premium() || ! $this->is_org_repo_compliant() ); |
| 143 | } |
| 144 | |
| 145 | #endregion |
| 146 | |
| 147 | /** |
| 148 | * Check if user in trial or in free plan (not paying). |
| 149 | * |
| 150 | * @author Vova Feldman (@svovaf) |
| 151 | * @since 1.0.4 |
| 152 | * |
| 153 | * @return bool |
| 154 | */ |
| 155 | function is_not_paying() { |
| 156 | return ( $this->is_trial() || $this->is_free_plan() ); |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * Check if the user has an activated and valid paid license on current plugin's install. |
| 161 | * |
| 162 | * @since 1.0.9 |
| 163 | * |
| 164 | * @return bool |
| 165 | */ |
| 166 | abstract function is_paying(); |
| 167 | |
| 168 | /** |
| 169 | * Check if the user is paying or in trial. |
| 170 | * |
| 171 | * @since 1.0.9 |
| 172 | * |
| 173 | * @return bool |
| 174 | */ |
| 175 | function is_paying_or_trial() { |
| 176 | return ( $this->is_paying() || $this->is_trial() ); |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * Check if user in a trial or have feature enabled license. |
| 181 | * |
| 182 | * @author Vova Feldman (@svovaf) |
| 183 | * @since 1.1.7 |
| 184 | * |
| 185 | * @return bool |
| 186 | */ |
| 187 | abstract function can_use_premium_code(); |
| 188 | |
| 189 | #---------------------------------------------------------------------------------- |
| 190 | #region Premium Only |
| 191 | #---------------------------------------------------------------------------------- |
| 192 | |
| 193 | /** |
| 194 | * All logic wrapped in methods with "__premium_only()" suffix will be only |
| 195 | * included in the premium code. |
| 196 | * |
| 197 | * Example: |
| 198 | * if ( freemius()->is__premium_only() ) { |
| 199 | * ... |
| 200 | * } |
| 201 | */ |
| 202 | |
| 203 | /** |
| 204 | * Returns true when running premium plugin code. |
| 205 | * |
| 206 | * @since 1.0.9 |
| 207 | * |
| 208 | * @return bool |
| 209 | */ |
| 210 | function is__premium_only() { |
| 211 | return $this->is_premium(); |
| 212 | } |
| 213 | |
| 214 | /** |
| 215 | * Check if the user has an activated and valid paid license on current plugin's install. |
| 216 | * |
| 217 | * @since 1.0.9 |
| 218 | * |
| 219 | * @return bool |
| 220 | * |
| 221 | */ |
| 222 | function is_paying__premium_only() { |
| 223 | return ( $this->is__premium_only() && $this->is_paying() ); |
| 224 | } |
| 225 | |
| 226 | /** |
| 227 | * All code wrapped in this statement will be only included in the premium code. |
| 228 | * |
| 229 | * @since 1.0.9 |
| 230 | * |
| 231 | * @param string $plan Plan name. |
| 232 | * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans. |
| 233 | * |
| 234 | * @return bool |
| 235 | */ |
| 236 | function is_plan__premium_only( $plan, $exact = false ) { |
| 237 | return ( $this->is_premium() && $this->is_plan( $plan, $exact ) ); |
| 238 | } |
| 239 | |
| 240 | /** |
| 241 | * Check if plan matches active license' plan or active trial license' plan. |
| 242 | * |
| 243 | * All code wrapped in this statement will be only included in the premium code. |
| 244 | * |
| 245 | * @since 1.0.9 |
| 246 | * |
| 247 | * @param string $plan Plan name. |
| 248 | * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans. |
| 249 | * |
| 250 | * @return bool |
| 251 | */ |
| 252 | function is_plan_or_trial__premium_only( $plan, $exact = false ) { |
| 253 | return ( $this->is_premium() && $this->is_plan_or_trial( $plan, $exact ) ); |
| 254 | } |
| 255 | |
| 256 | /** |
| 257 | * Check if the user is paying or in trial. |
| 258 | * |
| 259 | * All code wrapped in this statement will be only included in the premium code. |
| 260 | * |
| 261 | * @since 1.0.9 |
| 262 | * |
| 263 | * @return bool |
| 264 | */ |
| 265 | function is_paying_or_trial__premium_only() { |
| 266 | return $this->is_premium() && $this->is_paying_or_trial(); |
| 267 | } |
| 268 | |
| 269 | /** |
| 270 | * Check if the user has an activated and valid paid license on current plugin's install. |
| 271 | * |
| 272 | * @since 1.0.4 |
| 273 | * |
| 274 | * @return bool |
| 275 | * |
| 276 | * @deprecated Method name is confusing since it's not clear from the name the code will be removed. |
| 277 | * @using Alias to is_paying__premium_only() |
| 278 | */ |
| 279 | function is_paying__fs__() { |
| 280 | return $this->is_paying__premium_only(); |
| 281 | } |
| 282 | |
| 283 | /** |
| 284 | * Check if user in a trial or have feature enabled license. |
| 285 | * |
| 286 | * All code wrapped in this statement will be only included in the premium code. |
| 287 | * |
| 288 | * @author Vova Feldman (@svovaf) |
| 289 | * @since 1.1.9 |
| 290 | * |
| 291 | * @return bool |
| 292 | */ |
| 293 | function can_use_premium_code__premium_only() { |
| 294 | return $this->is_premium() && $this->can_use_premium_code(); |
| 295 | } |
| 296 | |
| 297 | #endregion |
| 298 | |
| 299 | #---------------------------------------------------------------------------------- |
| 300 | #region Trial |
| 301 | #---------------------------------------------------------------------------------- |
| 302 | |
| 303 | /** |
| 304 | * Check if the user in a trial. |
| 305 | * |
| 306 | * @since 1.0.3 |
| 307 | * |
| 308 | * @return bool |
| 309 | */ |
| 310 | abstract function is_trial(); |
| 311 | |
| 312 | /** |
| 313 | * Check if trial already utilized. |
| 314 | * |
| 315 | * @since 1.0.9 |
| 316 | * |
| 317 | * @return bool |
| 318 | */ |
| 319 | abstract function is_trial_utilized(); |
| 320 | |
| 321 | #endregion |
| 322 | |
| 323 | #---------------------------------------------------------------------------------- |
| 324 | #region Plans |
| 325 | #---------------------------------------------------------------------------------- |
| 326 | |
| 327 | /** |
| 328 | * Check if plugin using the free plan. |
| 329 | * |
| 330 | * @since 1.0.4 |
| 331 | * |
| 332 | * @return bool |
| 333 | */ |
| 334 | abstract function is_free_plan(); |
| 335 | |
| 336 | /** |
| 337 | * @since 1.0.2 |
| 338 | * |
| 339 | * @param string $plan Plan name. |
| 340 | * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans. |
| 341 | * |
| 342 | * @return bool |
| 343 | */ |
| 344 | abstract function is_plan( $plan, $exact = false ); |
| 345 | |
| 346 | /** |
| 347 | * Check if plan based on trial. If not in trial mode, should return false. |
| 348 | * |
| 349 | * @since 1.0.9 |
| 350 | * |
| 351 | * @param string $plan Plan name. |
| 352 | * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans. |
| 353 | * |
| 354 | * @return bool |
| 355 | */ |
| 356 | abstract function is_trial_plan( $plan, $exact = false ); |
| 357 | |
| 358 | /** |
| 359 | * Check if plan matches active license' plan or active trial license' plan. |
| 360 | * |
| 361 | * @since 1.0.9 |
| 362 | * |
| 363 | * @param string $plan Plan name. |
| 364 | * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans. |
| 365 | * |
| 366 | * @return bool |
| 367 | */ |
| 368 | function is_plan_or_trial( $plan, $exact = false ) { |
| 369 | return $this->is_plan( $plan, $exact ) || |
| 370 | $this->is_trial_plan( $plan, $exact ); |
| 371 | } |
| 372 | |
| 373 | /** |
| 374 | * Check if plugin has any paid plans. |
| 375 | * |
| 376 | * @author Vova Feldman (@svovaf) |
| 377 | * @since 1.0.7 |
| 378 | * |
| 379 | * @return bool |
| 380 | */ |
| 381 | abstract function has_paid_plan(); |
| 382 | |
| 383 | /** |
| 384 | * Check if plugin has any free plan, or is it premium only. |
| 385 | * |
| 386 | * Note: If no plans configured, assume plugin is free. |
| 387 | * |
| 388 | * @author Vova Feldman (@svovaf) |
| 389 | * @since 1.0.7 |
| 390 | * |
| 391 | * @return bool |
| 392 | */ |
| 393 | abstract function has_free_plan(); |
| 394 | |
| 395 | /** |
| 396 | * Check if plugin is premium only (no free plans). |
| 397 | * |
| 398 | * NOTE: is__premium_only() is very different method, don't get confused. |
| 399 | * |
| 400 | * @author Vova Feldman (@svovaf) |
| 401 | * @since 1.1.9 |
| 402 | * |
| 403 | * @return bool |
| 404 | */ |
| 405 | abstract function is_only_premium(); |
| 406 | |
| 407 | /** |
| 408 | * Check if module has a premium code version. |
| 409 | * |
| 410 | * Serviceware module might be freemium without any |
| 411 | * premium code version, where the paid features |
| 412 | * are all part of the service. |
| 413 | * |
| 414 | * @author Vova Feldman (@svovaf) |
| 415 | * @since 1.2.1.6 |
| 416 | * |
| 417 | * @return bool |
| 418 | */ |
| 419 | abstract function has_premium_version(); |
| 420 | |
| 421 | /** |
| 422 | * Check if module has any release on Freemius, |
| 423 | * or all plugin's code is on WordPress.org (Serviceware). |
| 424 | * |
| 425 | * @return bool |
| 426 | */ |
| 427 | function has_release_on_freemius() { |
| 428 | return ! $this->is_org_repo_compliant() || |
| 429 | $this->has_premium_version(); |
| 430 | } |
| 431 | |
| 432 | /** |
| 433 | * Checks if it's a freemium plugin. |
| 434 | * |
| 435 | * @author Vova Feldman (@svovaf) |
| 436 | * @since 1.1.9 |
| 437 | * |
| 438 | * @return bool |
| 439 | */ |
| 440 | function is_freemium() { |
| 441 | return $this->has_paid_plan() && |
| 442 | $this->has_free_plan(); |
| 443 | } |
| 444 | |
| 445 | #endregion |
| 446 | |
| 447 | /** |
| 448 | * Check if running payments in sandbox mode. |
| 449 | * |
| 450 | * @since 1.0.4 |
| 451 | * |
| 452 | * @return bool |
| 453 | */ |
| 454 | abstract function is_payments_sandbox(); |
| 455 | |
| 456 | /** |
| 457 | * Check if running test vs. live plugin. |
| 458 | * |
| 459 | * @since 1.0.5 |
| 460 | * |
| 461 | * @return bool |
| 462 | */ |
| 463 | abstract function is_live(); |
| 464 | |
| 465 | /** |
| 466 | * Check if running premium plugin code. |
| 467 | * |
| 468 | * @since 1.0.5 |
| 469 | * |
| 470 | * @return bool |
| 471 | */ |
| 472 | abstract function is_premium(); |
| 473 | |
| 474 | /** |
| 475 | * Get upgrade URL. |
| 476 | * |
| 477 | * @author Vova Feldman (@svovaf) |
| 478 | * @since 1.0.2 |
| 479 | * |
| 480 | * @param string $period Billing cycle. |
| 481 | * |
| 482 | * @return string |
| 483 | */ |
| 484 | abstract function get_upgrade_url( $period = WP_FS__PERIOD_ANNUALLY ); |
| 485 | |
| 486 | /** |
| 487 | * Check if Freemius was first added in a plugin update. |
| 488 | * |
| 489 | * @author Vova Feldman (@svovaf) |
| 490 | * @since 1.1.5 |
| 491 | * |
| 492 | * @return bool |
| 493 | */ |
| 494 | function is_plugin_update() { |
| 495 | return ! $this->is_plugin_new_install(); |
| 496 | } |
| 497 | |
| 498 | /** |
| 499 | * Check if Freemius was part of the plugin when the user installed it first. |
| 500 | * |
| 501 | * @author Vova Feldman (@svovaf) |
| 502 | * @since 1.1.5 |
| 503 | * |
| 504 | * @return bool |
| 505 | */ |
| 506 | abstract function is_plugin_new_install(); |
| 507 | |
| 508 | #---------------------------------------------------------------------------------- |
| 509 | #region Marketing |
| 510 | #---------------------------------------------------------------------------------- |
| 511 | |
| 512 | /** |
| 513 | * Check if current user purchased any other plugins before. |
| 514 | * |
| 515 | * @author Vova Feldman (@svovaf) |
| 516 | * @since 1.0.9 |
| 517 | * |
| 518 | * @return bool |
| 519 | */ |
| 520 | abstract function has_purchased_before(); |
| 521 | |
| 522 | /** |
| 523 | * Check if current user classified as an agency. |
| 524 | * |
| 525 | * @author Vova Feldman (@svovaf) |
| 526 | * @since 1.0.9 |
| 527 | * |
| 528 | * @return bool |
| 529 | */ |
| 530 | abstract function is_agency(); |
| 531 | |
| 532 | /** |
| 533 | * Check if current user classified as a developer. |
| 534 | * |
| 535 | * @author Vova Feldman (@svovaf) |
| 536 | * @since 1.0.9 |
| 537 | * |
| 538 | * @return bool |
| 539 | */ |
| 540 | abstract function is_developer(); |
| 541 | |
| 542 | /** |
| 543 | * Check if current user classified as a business. |
| 544 | * |
| 545 | * @author Vova Feldman (@svovaf) |
| 546 | * @since 1.0.9 |
| 547 | * |
| 548 | * @return bool |
| 549 | */ |
| 550 | abstract function is_business(); |
| 551 | |
| 552 | #endregion |
| 553 | } |
| 554 |