Skip to content

Commit

Permalink
[fix] [hidden-plans] [notices] Added is_hidden property to `FS_Plug…
Browse files Browse the repository at this point in the history
…in_Plan`. Added `get_filtered_plans`and `get_visible_trial_plans` to `FS_Plan_Manager`. Modified `_add_trial_notice` in `Freemius` to use only visible plan with trials.
  • Loading branch information
DanieleAlessandra committed Mar 27, 2024
1 parent 9acc3ad commit c5d6acb
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 10 deletions.
2 changes: 1 addition & 1 deletion includes/class-freemius.php
Original file line number Diff line number Diff line change
Expand Up @@ -24110,7 +24110,7 @@ function _add_trial_notice() {

if ( $this->is_registered() ) {
// If opted-in, override trial with up to date data from API.
$trial_plans = FS_Plan_Manager::instance()->get_trial_plans( $this->_plans );
$trial_plans = FS_Plan_Manager::instance()->get_visible_trial_plans( $this->_plans );
$trial_plans_count = count( $trial_plans );

if ( 0 === $trial_plans_count ) {
Expand Down
4 changes: 4 additions & 0 deletions includes/entities/class-fs-plugin-plan.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ class FS_Plugin_Plan extends FS_Entity {
* @var bool Is featured plan.
*/
public $is_featured;
/**
* @var bool Is hidden plan.
*/
public $is_hidden;

#endregion Properties

Expand Down
49 changes: 40 additions & 9 deletions includes/managers/class-fs-plan-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ function has_free_plan( $plans ) {

/**
* Find all plans that have trial.
* Since 2.6.2 call get_filtered_plan
*
* @author Vova Feldman (@svovaf)
* @since 1.0.9
Expand All @@ -117,20 +118,50 @@ function has_free_plan( $plans ) {
* @return FS_Plugin_Plan[]
*/
function get_trial_plans( $plans ) {
$trial_plans = array();
return $this->get_filtered_plans( $plans, true );
}

if ( is_array( $plans ) && 0 < count( $plans ) ) {
/**
* @var FS_Plugin_Plan[] $plans
*/
for ( $i = 0, $len = count( $plans ); $i < $len; $i ++ ) {
if ( $plans[ $i ]->has_trial() ) {
$trial_plans[] = $plans[ $i ];
/**
* Find all plans that are not hidden and have trial.
*
* @author Daniele Alessandra (@danielealessandra)
*
* @param FS_Plugin_Plan[] $plans
*
* @return FS_Plugin_Plan[]
* @since 2.6.3
*
*/
function get_visible_trial_plans( $plans ) {
return $this->get_filtered_plans( $plans, true, true );
}

/**
* Find all plans filtered by trial or visibility.
*
* @author Daniele Alessandra (@danielealessandra)
*
* @param FS_Plugin_Plan[] $plans
* @param boolean $should_have_trials
* @param boolean $should_be_visible
*
* @return FS_Plugin_Plan[]
* @since 2.6.3
*
*/
function get_filtered_plans( $plans, $should_have_trials = false, $should_be_visible = false ) {
$filtered_plans = array();

if ( is_array( $plans ) && count( $plans ) > 0 ) {
foreach ( $plans as $plan ) {
if ( ( $should_have_trials && ! $plan->has_trial() ) || ( $should_be_visible && $plan->is_hidden ) ) {
continue;
}
$filtered_plans[] = $plan;
}
}

return $trial_plans;
return $filtered_plans;
}

/**
Expand Down

0 comments on commit c5d6acb

Please sign in to comment.