Skip to content

Commit

Permalink
Merge pull request #8953 from awesomemotive/issue/8952
Browse files Browse the repository at this point in the history
Add more helper methods to Pass_Manager class #8952
  • Loading branch information
ashleyfae authored Oct 29, 2021
2 parents 6535647 + ae978ba commit d3a9c4e
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions includes/admin/class-pass-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ class Pass_Manager {
*/
public $has_pass_data = false;

/**
* Number of license keys entered on this site.
*
* @var int
*/
public $number_license_keys;

/**
* Hierarchy of passes. This helps us determine if one pass
* is "higher" than another.
Expand Down Expand Up @@ -77,6 +84,10 @@ public function __construct() {
}

$this->highest_pass_id = $this->get_highest_pass_id();

global $edd_licensed_products;

$this->number_license_keys = is_array( $edd_licensed_products ) ? count( $edd_licensed_products ) : 0;
}

/**
Expand Down Expand Up @@ -136,6 +147,73 @@ public function has_pass() {
return ! empty( $this->highest_pass_id );
}

/**
* If this is a "free install". That means there are no à la carte or pass licenses activated.
*
* @since 2.11.4
*
* @return bool
*/
public function isFree() {
return 0 === $this->number_license_keys;
}

/**
* If this site has an individual product license active (à la carte), but no pass active.
*
* @since 2.11.4
*
* @return bool
*/
public function hasIndividualLicense() {
return ! $this->isFree() && ! $this->has_pass();
}

/**
* If this site has a Personal Pass active.
*
* @since 2.11.4
*
* @return bool
*/
public function hasPersonalPass() {
return self::pass_compare( $this->highest_pass_id, self::PERSONAL_PASS_ID, '=' );
}

/**
* If this site has an Extended Pass active.
*
* @since 2.11.4
*
* @return bool
*/
public function hasExtendedPass() {
return self::pass_compare( $this->highest_pass_id, self::EXTENDED_PASS_ID, '=' );
}

/**
* If this site has a Professional Pass active.
*
* @since 2.11.4
*
* @return bool
*/
public function hasProfessionalPass() {
return self::pass_compare( $this->highest_pass_id, self::PROFESSIONAL_PASS_ID, '=' );
}

/**
* If this site has an All Access Pass active.
* Note: This uses >= to account for both All Access and lifetime All Access.
*
* @since 2.11.4
*
* @return bool
*/
public function hasAllAccessPass() {
return self::pass_compare( $this->highest_pass_id, self::ALL_ACCESS_PASS_ID, '>=' );
}

/**
* Compares two passes with each other according to the supplied operator.
*
Expand Down

0 comments on commit d3a9c4e

Please sign in to comment.