← All changes
|
freemius/includes/managers/class-fs-plan-manager.php
+41
-10
1.3
→
3.6.0
View file →
| @@ -1,9 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * @package Freemius |
| 4 | 4 | * @copyright Copyright (c) 2015, Freemius, Inc. |
| 5 | - * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License | |
| 5 | + * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3 | |
| 6 | 6 | * @since 1.0.6 |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | if ( ! defined( 'ABSPATH' ) ) { |
| @@ -107,8 +107,9 @@ | ||
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /** |
| 110 | 110 | * Find all plans that have trial. |
| 111 | + * Since 2.6.2 call get_filtered_plan | |
| 111 | 112 | * |
| 112 | 113 | * @author Vova Feldman (@svovaf) |
| 113 | 114 | * @since 1.0.9 |
| 114 | 115 | * |
| @@ -116,22 +117,52 @@ | ||
| 116 | 117 | * |
| 117 | 118 | * @return FS_Plugin_Plan[] |
| 118 | 119 | */ |
| 119 | 120 | function get_trial_plans( $plans ) { |
| 120 | - $trial_plans = array(); | |
| 121 | + return $this->get_filtered_plans( $plans, true ); | |
| 122 | + } | |
| 121 | 123 | |
| 122 | - if ( is_array( $plans ) && 0 < count( $plans ) ) { | |
| 123 | - /** | |
| 124 | - * @var FS_Plugin_Plan[] $plans | |
| 125 | - */ | |
| 126 | - for ( $i = 0, $len = count( $plans ); $i < $len; $i ++ ) { | |
| 127 | - if ( $plans[ $i ]->has_trial() ) { | |
| 128 | - $trial_plans[] = $plans[ $i ]; | |
| 124 | + /** | |
| 125 | + * Find all plans that are not hidden and have trial. | |
| 126 | + * | |
| 127 | + * @author Daniele Alessandra (@danielealessandra) | |
| 128 | + * | |
| 129 | + * @param FS_Plugin_Plan[] $plans | |
| 130 | + * | |
| 131 | + * @return FS_Plugin_Plan[] | |
| 132 | + * @since 2.6.3 | |
| 133 | + * | |
| 134 | + */ | |
| 135 | + function get_visible_trial_plans( $plans ) { | |
| 136 | + return $this->get_filtered_plans( $plans, true, true ); | |
| 137 | + } | |
| 138 | + | |
| 139 | + /** | |
| 140 | + * Find all plans filtered by trial or visibility. | |
| 141 | + * | |
| 142 | + * @author Daniele Alessandra (@danielealessandra) | |
| 143 | + * | |
| 144 | + * @param FS_Plugin_Plan[] $plans | |
| 145 | + * @param boolean $should_have_trials | |
| 146 | + * @param boolean $should_be_visible | |
| 147 | + * | |
| 148 | + * @return FS_Plugin_Plan[] | |
| 149 | + * @since 2.6.3 | |
| 150 | + * | |
| 151 | + */ | |
| 152 | + function get_filtered_plans( $plans, $should_have_trials = false, $should_be_visible = false ) { | |
| 153 | + $filtered_plans = array(); | |
| 154 | + | |
| 155 | + if ( is_array( $plans ) && count( $plans ) > 0 ) { | |
| 156 | + foreach ( $plans as $plan ) { | |
| 157 | + if ( ( $should_have_trials && ! $plan->has_trial() ) || ( $should_be_visible && $plan->is_hidden ) ) { | |
| 158 | + continue; | |
| 129 | 159 | } |
| 160 | + $filtered_plans[] = $plan; | |
| 130 | 161 | } |
| 131 | 162 | } |
| 132 | 163 | |
| 133 | - return $trial_plans; | |
| 164 | + return $filtered_plans; | |
| 134 | 165 | } |
| 135 | 166 | |
| 136 | 167 | /** |
| 137 | 168 | * Check if plugin has any trial plan. |