: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* @copyright Copyright (c) 2015, Freemius, Inc.
* @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
if ( ! defined( 'ABSPATH' ) ) {
* Class FS_Plugin_License
class FS_Plugin_License extends FS_Entity {
* @author Leo Fajardo (@leorw)
public $parent_plan_name;
* @author Leo Fajardo (@leorw)
public $parent_plan_title;
* @author Leo Fajardo (@leorw)
public $parent_license_id;
* @author Leo Fajardo (@leorw)
* @var bool $is_free_localhost Defaults to true. If true, allow unlimited localhost installs with the same
public $is_free_localhost;
* @var bool $is_block_features Defaults to true. If false, don't block features after license expiry - only
* block updates and support.
public $is_block_features;
* @param stdClass|bool $license
function __construct( $license = false ) {
parent::__construct( $license );
static function get_type() {
* Check how many site activations left.
* @author Vova Feldman (@svovaf)
if ( ! $this->is_features_enabled() ) {
if ( $this->is_unlimited() ) {
return ( $this->quota - $this->activated - ( $this->is_free_localhost ? 0 : $this->activated_local ) );
* Check if single site license.
* @author Vova Feldman (@svovaf)
function is_single_site() {
return ( is_numeric( $this->quota ) && 1 == $this->quota );
* @author Vova Feldman (@svovaf)
return ! $this->is_lifetime() && ( strtotime( $this->expiration ) < WP_FS__SCRIPT_START_TIME );
* Check if license is not expired.
* @author Vova Feldman (@svovaf)
return ! $this->is_expired();
* @author Vova Feldman (@svovaf)
return is_null( $this->expiration );
* @author Vova Feldman (@svovaf)
function is_unlimited() {
return is_null( $this->quota );
* Check if license is fully utilized.
* @author Vova Feldman (@svovaf)
* @param bool|null $is_localhost
function is_utilized( $is_localhost = null ) {
if ( is_null( $is_localhost ) ) {
$is_localhost = WP_FS__IS_LOCALHOST_FOR_SERVER;
if ( $this->is_unlimited() ) {
return ! ( $this->is_free_localhost && $is_localhost ) &&
( $this->quota <= $this->activated + ( $this->is_free_localhost ? 0 : $this->activated_local ) );
* Check if license can be activated.
* @author Vova Feldman (@svovaf)
* @param bool|null $is_localhost
function can_activate( $is_localhost = null ) {
return ! $this->is_utilized( $is_localhost ) && $this->is_features_enabled();
* Check if license can be activated on a given number of production and localhost sites.
* @author Vova Feldman (@svovaf)
* @param int $production_count
* @param int $localhost_count
function can_activate_bulk( $production_count, $localhost_count ) {
if ( $this->is_unlimited() ) {
* For simplicity, the logic will work as following: when given X sites to activate the license on, if it's
* possible to activate on ALL of them, do the activation. If it's not possible to activate on ALL of them,
* do NOT activate on any of them.
return ( $this->quota >= $this->activated + $production_count + ( $this->is_free_localhost ? 0 : $this->activated_local + $localhost_count ) );
* @author Vova Feldman (@svovaf)
return ( ! $this->is_cancelled );
* Check if license's plan features are enabled.
* - Either if plan not expired
* - If expired, based on the configuration to block features or not.
* @author Vova Feldman (@svovaf)
function is_features_enabled() {
return $this->is_active() && ( ! $this->is_block_features || ! $this->is_expired() );
* Subscription considered to be new without any payments
* if the license expires in less than 24 hours
* from the license creation.
* @author Vova Feldman (@svovaf)
function is_first_payment_pending() {
return ( WP_FS__TIME_24_HOURS_IN_SEC >= strtotime( $this->expiration ) - strtotime( $this->created ) );
function total_activations() {
return ( $this->activated + $this->activated_local );
* @author Vova Feldman (@svovaf)
function get_html_escaped_masked_secret_key() {
return self::mask_secret_key_for_html( $this->secret_key );
* @author Vova Feldman (@svovaf)
* @param string $secret_key
static function mask_secret_key_for_html( $secret_key ) {
// Initial 6 chars - sk_ABC
htmlspecialchars( substr( $secret_key, 0, 6 ) ) .
str_pad( '', ( strlen( $secret_key ) - 9 ) * 6, '•' ) .
htmlspecialchars( substr( $secret_key, - 3 ) )