| 1 |
<?php |
| 2 |
/** |
| 3 |
* Premium Feature Gate |
| 4 |
* |
| 5 |
* Central function to check if a feature requires premium. |
| 6 |
* Uses Freemius license OR built-in 7-day trial from activation. |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace Upress\EzCache; |
| 10 |
|
| 11 |
class PremiumFeatures { |
| 12 |
|
| 13 |
const TRIAL_DAYS = 7; |
| 14 |
const TRIAL_OPTION = 'ezcache_trial_started'; |
| 15 |
|
| 16 |
/** |
| 17 |
* Features that require premium license |
| 18 |
*/ |
| 19 |
private static $premium_features = [ |
| 20 |
// CSS/JS optimization |
| 21 |
'minify_css', |
| 22 |
'combine_css', |
| 23 |
'combine_css_footer', |
| 24 |
'minify_js', |
| 25 |
'combine_head_js', |
| 26 |
'combine_body_js', |
| 27 |
'combine_head_inline_js', |
| 28 |
'combine_body_inline_js', |
| 29 |
'minify_inline_js', |
| 30 |
'minify_inline_css', |
| 31 |
'critical_css', |
| 32 |
'optimize_google_fonts', |
| 33 |
'defer_js', |
| 34 |
'remove_query_strings', |
| 35 |
|
| 36 |
// WebP |
| 37 |
'enable_webp_support', |
| 38 |
|
| 39 |
// Preload |
| 40 |
'enable_preload', |
| 41 |
'preload_on_cache_clear', |
| 42 |
|
| 43 |
// CDN |
| 44 |
'cdn_enabled', |
| 45 |
|
| 46 |
// Heartbeat & DNS |
| 47 |
'heartbeat_control', |
| 48 |
'dns_prefetch', |
| 49 |
'preconnect', |
| 50 |
|
| 51 |
// Database cleanup |
| 52 |
'db_cleanup_revisions', |
| 53 |
'db_cleanup_auto_drafts', |
| 54 |
'db_cleanup_trashed_posts', |
| 55 |
'db_cleanup_spam_comments', |
| 56 |
'db_cleanup_trashed_comments', |
| 57 |
'db_cleanup_expired_transients', |
| 58 |
'db_cleanup_orphan_postmeta', |
| 59 |
'db_optimize_tables', |
| 60 |
'db_cleanup_schedule', |
| 61 |
|
| 62 |
// Redis (2.2.0+) |
| 63 |
'enable_redis_object_cache', |
| 64 |
'enable_redis_fullpage', |
| 65 |
|
| 66 |
// Critical CSS (2.2.0+) |
| 67 |
'enable_critical_css', |
| 68 |
]; |
| 69 |
|
| 70 |
/** |
| 71 |
* No-op — trial system removed. Pro is unlocked for everyone. |
| 72 |
* Also cleans up legacy trial option from previous installs. |
| 73 |
*/ |
| 74 |
public static function maybe_start_trial() { |
| 75 |
if ( get_option( self::TRIAL_OPTION ) ) { |
| 76 |
delete_option( self::TRIAL_OPTION ); |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
/** |
| 81 |
* Legacy stub — trial system removed. Always returns false. |
| 82 |
* @return bool |
| 83 |
*/ |
| 84 |
public static function is_builtin_trial() { |
| 85 |
return false; |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* Legacy stub — trial system removed. Always returns 0. |
| 90 |
* @return int |
| 91 |
*/ |
| 92 |
public static function trial_days_remaining() { |
| 93 |
return 0; |
| 94 |
} |
| 95 |
|
| 96 |
/** |
| 97 |
* Check if user has premium access. |
| 98 |
* Licensing system removed — Pro is unlocked for everyone. |
| 99 |
* @return bool |
| 100 |
*/ |
| 101 |
public static function is_premium() { |
| 102 |
return true; |
| 103 |
} |
| 104 |
|
| 105 |
/** |
| 106 |
* Check if a specific feature requires premium |
| 107 |
* @param string $feature |
| 108 |
* @return bool |
| 109 |
*/ |
| 110 |
public static function is_premium_feature( $feature ) { |
| 111 |
return in_array( $feature, self::$premium_features, true ); |
| 112 |
} |
| 113 |
|
| 114 |
/** |
| 115 |
* Check if a feature is available (either free or user has premium) |
| 116 |
* @param string $feature |
| 117 |
* @return bool |
| 118 |
*/ |
| 119 |
public static function is_feature_available( $feature ) { |
| 120 |
if ( ! self::is_premium_feature( $feature ) ) { |
| 121 |
return true; // Free feature |
| 122 |
} |
| 123 |
return self::is_premium(); |
| 124 |
} |
| 125 |
|
| 126 |
/** |
| 127 |
* Get list of premium features |
| 128 |
* @return array |
| 129 |
*/ |
| 130 |
public static function get_premium_features() { |
| 131 |
return self::$premium_features; |
| 132 |
} |
| 133 |
|
| 134 |
/** |
| 135 |
* No-op — Pro is unlocked for everyone, so settings pass through unchanged. |
| 136 |
* @param object $settings |
| 137 |
* @return object |
| 138 |
*/ |
| 139 |
public static function enforce_settings( $settings ) { |
| 140 |
return $settings; |
| 141 |
} |
| 142 |
} |
| 143 |
|