entities
10 years ago
managers
10 years ago
sdk
10 years ago
class-freemius-abstract.php
10 years ago
class-freemius.php
10 years ago
class-fs-api.php
10 years ago
class-fs-logger.php
10 years ago
class-fs-plugin-updater.php
10 years ago
class-fs-security.php
10 years ago
fs-core-functions.php
10 years ago
fs-plugin-functions.php
10 years ago
i18n.php
10 years ago
class-freemius-abstract.php
382 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 | if ( ! defined( 'ABSPATH' ) ) { |
| 9 | exit; |
| 10 | } |
| 11 | |
| 12 | |
| 13 | /** |
| 14 | * - Each instance of Freemius class represents a single plugin |
| 15 | * install by a single user (the installer of the plugin). |
| 16 | * |
| 17 | * - Each website can only have one install of the same plugin. |
| 18 | * |
| 19 | * - Install entity is only created after a user connects his account with Freemius. |
| 20 | * |
| 21 | * Class Freemius_Abstract |
| 22 | */ |
| 23 | abstract class Freemius_Abstract { |
| 24 | |
| 25 | #region Identity ------------------------------------------------------------------ |
| 26 | |
| 27 | /** |
| 28 | * Check if user registered with Freemius by connecting his account. |
| 29 | * |
| 30 | * @since 1.0.1 |
| 31 | * @return bool |
| 32 | */ |
| 33 | abstract function is_registered(); |
| 34 | |
| 35 | /** |
| 36 | * Check if the user skipped connecting the account with Freemius. |
| 37 | * |
| 38 | * @since 1.0.7 |
| 39 | * |
| 40 | * @return bool |
| 41 | */ |
| 42 | abstract function is_anonymous(); |
| 43 | |
| 44 | /** |
| 45 | * Check if the user currently in activation mode. |
| 46 | * |
| 47 | * @since 1.0.7 |
| 48 | * |
| 49 | * @return bool |
| 50 | */ |
| 51 | abstract function is_activation_mode(); |
| 52 | |
| 53 | #endregion Identity ------------------------------------------------------------------ |
| 54 | |
| 55 | #region Permissions ------------------------------------------------------------------ |
| 56 | |
| 57 | /** |
| 58 | * Check if plugin must be WordPress.org compliant. |
| 59 | * |
| 60 | * @since 1.0.7 |
| 61 | * |
| 62 | * @return bool |
| 63 | */ |
| 64 | abstract function is_org_repo_compliant(); |
| 65 | |
| 66 | /** |
| 67 | * Check if plugin is allowed to install executable files. |
| 68 | * |
| 69 | * @author Vova Feldman (@svovaf) |
| 70 | * @since 1.0.5 |
| 71 | * |
| 72 | * @return bool |
| 73 | */ |
| 74 | function is_allowed_to_install() { |
| 75 | return ( $this->is_premium() || ! $this->is_org_repo_compliant() ); |
| 76 | } |
| 77 | |
| 78 | #endregion Permissions ------------------------------------------------------------------ |
| 79 | |
| 80 | /** |
| 81 | * Check if user in trial or in free plan (not paying). |
| 82 | * |
| 83 | * @author Vova Feldman (@svovaf) |
| 84 | * @since 1.0.4 |
| 85 | * |
| 86 | * @return bool |
| 87 | */ |
| 88 | function is_not_paying() { |
| 89 | return ( $this->is_trial() || $this->is_free_plan() ); |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Check if the user has an activated and valid paid license on current plugin's install. |
| 94 | * |
| 95 | * @since 1.0.9 |
| 96 | * |
| 97 | * @return bool |
| 98 | */ |
| 99 | abstract function is_paying(); |
| 100 | |
| 101 | /** |
| 102 | * Check if the user is paying or in trial. |
| 103 | * |
| 104 | * @since 1.0.9 |
| 105 | * |
| 106 | * @return bool |
| 107 | */ |
| 108 | function is_paying_or_trial() { |
| 109 | return ( $this->is_paying() || $this->is_trial() ); |
| 110 | } |
| 111 | |
| 112 | #region Premium Only ------------------------------------------------------------------ |
| 113 | |
| 114 | /** |
| 115 | * All logic wrapped in methods with "__premium_only()" suffix will be only |
| 116 | * included in the premium code. |
| 117 | * |
| 118 | * Example: |
| 119 | * if ( freemius()->is__premium_only() ) { |
| 120 | * ... |
| 121 | * } |
| 122 | */ |
| 123 | |
| 124 | /** |
| 125 | * Returns true when running premium plugin code. |
| 126 | * |
| 127 | * @since 1.0.9 |
| 128 | * |
| 129 | * @return bool |
| 130 | */ |
| 131 | function is__premium_only() { |
| 132 | return $this->is_premium(); |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * Check if the user has an activated and valid paid license on current plugin's install. |
| 137 | * |
| 138 | * @since 1.0.9 |
| 139 | * |
| 140 | * @return bool |
| 141 | * |
| 142 | */ |
| 143 | function is_paying__premium_only() { |
| 144 | return ( $this->is__premium_only() && $this->is_paying() ); |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * All code wrapped in this statement will be only included in the premium code. |
| 149 | * |
| 150 | * @since 1.0.9 |
| 151 | * |
| 152 | * @param string $plan Plan name |
| 153 | * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans. |
| 154 | * |
| 155 | * @return bool |
| 156 | */ |
| 157 | function is_plan__premium_only( $plan, $exact = false ) { |
| 158 | return ( $this->is_premium() && $this->is_plan( $plan, $exact ) ); |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * Check if plan matches active license' plan or active trial license' plan. |
| 163 | * |
| 164 | * All code wrapped in this statement will be only included in the premium code. |
| 165 | * |
| 166 | * @since 1.0.9 |
| 167 | * |
| 168 | * @param string $plan Plan name |
| 169 | * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans. |
| 170 | * |
| 171 | * @return bool |
| 172 | */ |
| 173 | function is_plan_or_trial__premium_only( $plan, $exact = false ) { |
| 174 | return ( $this->is_premium() && $this->is_plan_or_trial( $plan, $exact ) ); |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * Check if the user is paying or in trial. |
| 179 | * |
| 180 | * All code wrapped in this statement will be only included in the premium code. |
| 181 | * |
| 182 | * @since 1.0.9 |
| 183 | * |
| 184 | * @return bool |
| 185 | */ |
| 186 | function is_paying_or_trial__premium_only() { |
| 187 | return $this->is_premium() && $this->is_paying_or_trial(); |
| 188 | } |
| 189 | |
| 190 | /** |
| 191 | * Check if the user has an activated and valid paid license on current plugin's install. |
| 192 | * |
| 193 | * @since 1.0.4 |
| 194 | * |
| 195 | * @return bool |
| 196 | * |
| 197 | * @deprecated Method name is confusing since it's not clear from the name the code will be removed. |
| 198 | * @using Alias to is_paying__premium_only() |
| 199 | */ |
| 200 | function is_paying__fs__() { |
| 201 | return $this->is_paying__premium_only(); |
| 202 | } |
| 203 | |
| 204 | #endregion Premium Only ------------------------------------------------------------------ |
| 205 | |
| 206 | #region Trial ------------------------------------------------------------------ |
| 207 | |
| 208 | /** |
| 209 | * Check if the user in a trial. |
| 210 | * |
| 211 | * @since 1.0.3 |
| 212 | * |
| 213 | * @return bool |
| 214 | */ |
| 215 | abstract function is_trial(); |
| 216 | |
| 217 | /** |
| 218 | * Check if trial already utilized. |
| 219 | * |
| 220 | * @since 1.0.9 |
| 221 | * |
| 222 | * @return bool |
| 223 | */ |
| 224 | abstract function is_trial_utilized(); |
| 225 | |
| 226 | #endregion Trial ------------------------------------------------------------------ |
| 227 | |
| 228 | #region Plans ------------------------------------------------------------------ |
| 229 | |
| 230 | /** |
| 231 | * Check if plugin using the free plan. |
| 232 | * |
| 233 | * @since 1.0.4 |
| 234 | * |
| 235 | * @return bool |
| 236 | */ |
| 237 | abstract function is_free_plan(); |
| 238 | |
| 239 | /** |
| 240 | * @since 1.0.2 |
| 241 | * |
| 242 | * @param string $plan Plan name |
| 243 | * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans. |
| 244 | * |
| 245 | * @return bool |
| 246 | */ |
| 247 | abstract function is_plan( $plan, $exact = false ); |
| 248 | |
| 249 | /** |
| 250 | * Check if plan based on trial. If not in trial mode, should return false. |
| 251 | * |
| 252 | * @since 1.0.9 |
| 253 | * |
| 254 | * @param string $plan Plan name |
| 255 | * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans. |
| 256 | * |
| 257 | * @return bool |
| 258 | */ |
| 259 | abstract function is_trial_plan( $plan, $exact = false ); |
| 260 | |
| 261 | /** |
| 262 | * Check if plan matches active license' plan or active trial license' plan. |
| 263 | * |
| 264 | * @since 1.0.9 |
| 265 | * |
| 266 | * @param string $plan Plan name |
| 267 | * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans. |
| 268 | * |
| 269 | * @return bool |
| 270 | */ |
| 271 | function is_plan_or_trial( $plan, $exact = false ) { |
| 272 | return $this->is_plan( $plan, $exact ) || |
| 273 | $this->is_trial_plan( $plan, $exact ); |
| 274 | } |
| 275 | |
| 276 | /** |
| 277 | * Check if plugin has any paid plans. |
| 278 | * |
| 279 | * @author Vova Feldman (@svovaf) |
| 280 | * @since 1.0.7 |
| 281 | * |
| 282 | * @return bool |
| 283 | */ |
| 284 | abstract function has_paid_plan(); |
| 285 | |
| 286 | /** |
| 287 | * Check if plugin has any free plan, or is it premium only. |
| 288 | * |
| 289 | * Note: If no plans configured, assume plugin is free. |
| 290 | * |
| 291 | * @author Vova Feldman (@svovaf) |
| 292 | * @since 1.0.7 |
| 293 | * |
| 294 | * @return bool |
| 295 | */ |
| 296 | abstract function has_free_plan(); |
| 297 | |
| 298 | #endregion Plans ------------------------------------------------------------------ |
| 299 | |
| 300 | /** |
| 301 | * Check if running payments in sandbox mode. |
| 302 | * |
| 303 | * @since 1.0.4 |
| 304 | * |
| 305 | * @return bool |
| 306 | */ |
| 307 | abstract function is_payments_sandbox(); |
| 308 | |
| 309 | /** |
| 310 | * Check if running test vs. live plugin. |
| 311 | * |
| 312 | * @since 1.0.5 |
| 313 | * |
| 314 | * @return bool |
| 315 | */ |
| 316 | abstract function is_live(); |
| 317 | |
| 318 | /** |
| 319 | * Check if running premium plugin code. |
| 320 | * |
| 321 | * @since 1.0.5 |
| 322 | * |
| 323 | * @return bool |
| 324 | */ |
| 325 | abstract function is_premium(); |
| 326 | |
| 327 | /** |
| 328 | * Get upgrade URL. |
| 329 | * |
| 330 | * @author Vova Feldman (@svovaf) |
| 331 | * @since 1.0.2 |
| 332 | * |
| 333 | * @param string $period Billing cycle |
| 334 | * |
| 335 | * @return string |
| 336 | */ |
| 337 | abstract function get_upgrade_url( $period = WP_FS__PERIOD_ANNUALLY ); |
| 338 | |
| 339 | #region Marketing ------------------------------------------------------------------ |
| 340 | |
| 341 | /** |
| 342 | * Check if current user purchased any other plugins before. |
| 343 | * |
| 344 | * @author Vova Feldman (@svovaf) |
| 345 | * @since 1.0.9 |
| 346 | * |
| 347 | * @return bool |
| 348 | */ |
| 349 | abstract function has_purchased_before(); |
| 350 | |
| 351 | /** |
| 352 | * Check if current user classified as an agency. |
| 353 | * |
| 354 | * @author Vova Feldman (@svovaf) |
| 355 | * @since 1.0.9 |
| 356 | * |
| 357 | * @return bool |
| 358 | */ |
| 359 | abstract function is_agency(); |
| 360 | |
| 361 | /** |
| 362 | * Check if current user classified as a developer. |
| 363 | * |
| 364 | * @author Vova Feldman (@svovaf) |
| 365 | * @since 1.0.9 |
| 366 | * |
| 367 | * @return bool |
| 368 | */ |
| 369 | abstract function is_developer(); |
| 370 | |
| 371 | /** |
| 372 | * Check if current user classified as a business. |
| 373 | * |
| 374 | * @author Vova Feldman (@svovaf) |
| 375 | * @since 1.0.9 |
| 376 | * |
| 377 | * @return bool |
| 378 | */ |
| 379 | abstract function is_business(); |
| 380 | |
| 381 | #endregion ------------------------------------------------------------------ |
| 382 | } |