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