/freemius/includes/managers/class-fs-plan-manager.php

  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.6 
  7. */ 
  8.  
  9. if ( ! defined( 'ABSPATH' ) ) { 
  10. exit; 
  11.  
  12. class FS_Plan_Manager { 
  13. /** 
  14. * @var FS_Plan_Manager 
  15. */ 
  16. private static $_instance; 
  17.  
  18. /** 
  19. * @return FS_Plan_Manager 
  20. */ 
  21. static function instance() { 
  22. if ( ! isset( self::$_instance ) ) { 
  23. self::$_instance = new FS_Plan_Manager(); 
  24.  
  25. return self::$_instance; 
  26.  
  27. private function __construct() { 
  28.  
  29. /** 
  30. * @param FS_Plugin_License[] $licenses 
  31. * 
  32. * @return bool 
  33. */ 
  34. function has_premium_license( $licenses ) { 
  35. if ( is_array( $licenses ) ) { 
  36. /** 
  37. * @var FS_Plugin_License[] $licenses 
  38. */ 
  39. foreach ( $licenses as $license ) { 
  40. if ( ! $license->is_utilized() && $license->is_features_enabled() ) { 
  41. return true; 
  42.  
  43. return false; 
  44.  
  45. /** 
  46. * Check if plugin has any paid plans. 
  47. * 
  48. * @author Vova Feldman (@svovaf) 
  49. * @since 1.0.7 
  50. * 
  51. * @param FS_Plugin_Plan[] $plans 
  52. * 
  53. * @return bool 
  54. */ 
  55. function has_paid_plan( $plans ) { 
  56. if ( ! is_array( $plans ) || 0 === count( $plans ) ) { 
  57. return false; 
  58.  
  59. /** 
  60. * @var FS_Plugin_Plan[] $plans 
  61. */ 
  62. for ( $i = 0, $len = count( $plans ); $i < $len; $i ++ ) { 
  63. if ( ! $plans[ $i ]->is_free() ) { 
  64. return true; 
  65.  
  66. return false; 
  67.  
  68. /** 
  69. * Check if plugin has any free plan, or is it premium only. 
  70. * 
  71. * Note: If no plans configured, assume plugin is free. 
  72. * 
  73. * @author Vova Feldman (@svovaf) 
  74. * @since 1.0.7 
  75. * 
  76. * @param FS_Plugin_Plan[] $plans 
  77. * 
  78. * @return bool 
  79. */ 
  80. function has_free_plan( $plans ) { 
  81. if ( ! is_array( $plans ) || 0 === count( $plans ) ) { 
  82. return true; 
  83.  
  84. /** 
  85. * @var FS_Plugin_Plan[] $plans 
  86. */ 
  87. for ( $i = 0, $len = count( $plans ); $i < $len; $i ++ ) { 
  88. if ( $plans[ $i ]->is_free() ) { 
  89. return true; 
  90.  
  91. return false; 
  92.  
  93. /** 
  94. * Find all plans that have trial. 
  95. * 
  96. * @author Vova Feldman (@svovaf) 
  97. * @since 1.0.9 
  98. * 
  99. * @param FS_Plugin_Plan[] $plans 
  100. * 
  101. * @return FS_Plugin_Plan[] 
  102. */ 
  103. function get_trial_plans( $plans ) { 
  104. $trial_plans = array(); 
  105.  
  106. if ( is_array( $plans ) && 0 < count( $plans ) ) { 
  107. /** 
  108. * @var FS_Plugin_Plan[] $plans 
  109. */ 
  110. for ( $i = 0, $len = count( $plans ); $i < $len; $i ++ ) { 
  111. if ( $plans[ $i ]->has_trial() ) { 
  112. $trial_plans[] = $plans[ $i ]; 
  113.  
  114. return $trial_plans; 
  115.  
  116. /** 
  117. * Check if plugin has any trial plan. 
  118. * 
  119. * @author Vova Feldman (@svovaf) 
  120. * @since 1.0.9 
  121. * 
  122. * @param FS_Plugin_Plan[] $plans 
  123. * 
  124. * @return bool 
  125. */ 
  126. function has_trial_plan( $plans ) { 
  127. if ( ! is_array( $plans ) || 0 === count( $plans ) ) { 
  128. return true; 
  129.  
  130. /** 
  131. * @var FS_Plugin_Plan[] $plans 
  132. */ 
  133. for ( $i = 0, $len = count( $plans ); $i < $len; $i ++ ) { 
  134. if ( $plans[ $i ]->has_trial() ) { 
  135. return true; 
  136.  
  137. return false; 
.