loadPremiumModule(); } /** * Loads the Premium module and starts its hooks (only available in the premium version) */ private function loadPremiumModule() { $premium_file = AIPT_PLUGIN_DIR . 'src/Premium/PremiumFeatureManager.php'; if ( file_exists( $premium_file ) && ! self::$premium_loaded ) { require_once $premium_file; self::$premium_loaded = class_exists( 'AIPT\Premium\PremiumFeatureManager' ); if ( self::$premium_loaded ) { \AIPT\Premium\PremiumFeatureManager::initHooks(); } } } /** * Has the Premium class been loaded? */ private function isPremiumLoaded(): bool { return self::$premium_loaded; } /** * Can Premium features be used? */ public function canUsePremiumFeatures(): bool { if ($this->isPremiumLoaded()) { return \AIPT\Premium\PremiumFeatureManager::canUsePremiumFeatures(); } return false; } /** * Can Pro features be used? */ public function canUseProFeatures(): bool { if ($this->isPremiumLoaded()) { return \AIPT\Premium\PremiumFeatureManager::canUseProFeatures(); } return false; } /** * Check Pro feature access using display-safe cached entitlement data only. */ public function canUseProFeaturesCacheOnly(): bool { if ($this->isPremiumLoaded()) { return \AIPT\Premium\PremiumFeatureManager::canUseProFeaturesCacheOnly(); } return false; } /** * Can Business features be used? */ public function canUseBusinessFeatures(): bool { if ($this->isPremiumLoaded()) { return \AIPT\Premium\PremiumFeatureManager::canUseBusinessFeatures(); } return false; } /** * Returns the current plan */ public function getCurrentPlan(): string { if ($this->isPremiumLoaded()) { return \AIPT\Premium\PremiumFeatureManager::getCurrentPlan(); } return 'free'; } /** * Prepares data for JavaScript */ public function prepareDataForJS(): array { if ($this->isPremiumLoaded()) { return \AIPT\Premium\PremiumFeatureManager::preparePremiumDataForJS(); } return [ 'is_premium' => false, 'plan' => 'free', 'pluginId' => null, 'upgradeUrl' => $this->getUpgradeUrl(), 'features' => \AIPT\Core\Licensing\FeatureKeys::allLocked(), ]; } /** * Upgrade URL'ini getirir */ private function getUpgradeUrl(): string { if (function_exists('aipt_fs')) { $resolved = self::resolveUpgradeUrlFromSdk(aipt_fs()); if ('' !== $resolved) { return $resolved; } } return \AIPT\Core\FsManager::PUBLIC_PRICING_URL; } /** * Resolve the upgrade URL from a live Freemius SDK object, routing an * unregistered install (e.g. "Activate Free Version") to the public * pricing page instead of the Pricing page, which 403s in that state, or * the reconnect screen, which sends a user who skipped the opt-in back * to it. * * Single source of truth for this decision: Premium\PremiumFeatureManager * ::resolveUpgradeUrl() delegates here instead of keeping its own copy, * since this always-shipped class is safe for both builds to depend on. * * @param mixed $fs Live aipt_fs() SDK object, or anything falsy/foreign. * @return string Resolved URL, or '' when $fs is not a usable SDK object. */ public static function resolveUpgradeUrlFromSdk($fs): string { if (!is_object($fs) || !method_exists($fs, 'get_upgrade_url')) { return ''; } if (method_exists($fs, 'is_registered') && !$fs->is_registered()) { return \AIPT\Core\FsManager::PUBLIC_PRICING_URL; } return (string) $fs->get_upgrade_url(); } /** * Extends aiptData with the premium information */ public function extendAiptData(array $data): array { if (isset($data['fs'])) { if (!isset($data['fs']['features'])) { $premiumData = $this->prepareDataForJS(); $data['fs']['features'] = $premiumData['features']; } } else { $data['fs'] = $this->prepareDataForJS(); } return $data; } /** * Checks the state of a Premium feature */ public function checkFeatureAccess(string $feature): bool { if ($this->isPremiumLoaded()) { return \AIPT\Premium\PremiumFeatureManager::checkFeatureAccess($feature); } return false; } /** * Singleton instance getirir */ public static function getInstance(): self { if ( null !== self::$test_instance ) { return self::$test_instance; } static $instance = null; if ($instance === null) { $instance = new self(); } return $instance; } /** * Override the singleton for test environments only. * * @internal PHPUnit use only — never call in production code. * @param self|null $instance Replacement instance, or null to reset. */ public static function setInstanceForTesting( ?self $instance ): void { if ( ! self::isTestEnvironment() ) { return; } self::$test_instance = $instance; } /** * Test-only override slot. Always null in production. * * @internal * @var self|null */ private static $test_instance = null; }