is_features_enabled() ) { return 0; } if ( $this->is_unlimited() ) { return 999; } return ( $this->quota - $this->activated - ( $this->is_free_localhost ? 0 : $this->activated_local ) ); } /** * Check if single site license. * * @author Vova Feldman (@svovaf) * @since 1.1.8.1 * * @return bool */ function is_single_site() { return ( is_numeric( $this->quota ) && 1 == $this->quota ); } /** * @author Vova Feldman (@svovaf) * @since 1.0.5 * * @return bool */ function is_expired() { return ! $this->is_lifetime() && ( strtotime( $this->expiration ) < WP_FS__SCRIPT_START_TIME ); } /** * Check if license is not expired. * * @author Vova Feldman (@svovaf) * @since 1.2.1 * * @return bool */ function is_valid() { return ! $this->is_expired(); } /** * @author Vova Feldman (@svovaf) * @since 1.0.6 * * @return bool */ function is_lifetime() { return is_null( $this->expiration ); } /** * @author Vova Feldman (@svovaf) * @since 1.2.0 * * @return bool */ function is_unlimited() { return is_null( $this->quota ); } /** * Check if license is fully utilized. * * @author Vova Feldman (@svovaf) * @since 1.0.6 * * @param bool|null $is_localhost * * @return bool */ function is_utilized( $is_localhost = null ) { if ( is_null( $is_localhost ) ) { $is_localhost = WP_FS__IS_LOCALHOST_FOR_SERVER; } if ( $this->is_unlimited() ) { return false; } 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) * @since 2.0.0 * * @param bool|null $is_localhost * * @return bool */ 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) * @since 2.0.0 * * @param int $production_count * @param int $localhost_count * * @return bool */ function can_activate_bulk( $production_count, $localhost_count ) { if ( $this->is_unlimited() ) { return true; } /** * 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) * @since 1.2.1 * * @return bool */ function is_active() { 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) * @since 1.0.6 * * @return bool */ 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) * @since 1.0.9 * * @return bool */ function is_first_payment_pending() { return ( WP_FS__TIME_24_HOURS_IN_SEC >= strtotime( $this->expiration ) - strtotime( $this->created ) ); } /** * @return int */ function total_activations() { return ( $this->activated + $this->activated_local ); } /** * @author Vova Feldman (@svovaf) * @since 2.3.1 * * @return string */ function get_html_escaped_masked_secret_key() { return self::mask_secret_key_for_html( $this->secret_key ); } /** * @author Vova Feldman (@svovaf) * @since 2.3.1 * * @param string $secret_key * * @return string */ static function mask_secret_key_for_html( $secret_key ) { return ( // Initial 6 chars - sk_ABC htmlspecialchars( substr( $secret_key, 0, 6 ) ) . // Masking str_pad( '', ( strlen( $secret_key ) - 9 ) * 6, '•' ) . // Last 3 chars. htmlspecialchars( substr( $secret_key, - 3 ) ) ); } }