Blocks
3 months ago
Contracts
1 year ago
Database
1 month ago
Integrations
3 months ago
Libraries
3 months ago
Models
1 month ago
Seeds
1 year ago
Services
1 month ago
Support
1 month ago
config
1 month ago
lib
1 month ago
Activator.php
1 month ago
Attachment.php
4 months ago
Controller.php
1 year ago
Core.php
1 year ago
Deactivator.php
2 months ago
Factory.php
3 months ago
Files.php
1 year ago
Playlist.php
1 year ago
Plugin.php
1 month ago
Requirements.php
1 year ago
support.php
1 year ago
Plugin.php
151 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Plugin main class file. |
| 4 | * |
| 5 | * @package PrestoPlayer |
| 6 | */ |
| 7 | |
| 8 | namespace PrestoPlayer; |
| 9 | |
| 10 | /** |
| 11 | * Main Plugin class. |
| 12 | */ |
| 13 | class Plugin { |
| 14 | /** |
| 15 | * Required versions for features. |
| 16 | * |
| 17 | * @var array |
| 18 | */ |
| 19 | protected const REQUIRED_VERSIONS = array( |
| 20 | 'popups' => '3.0.0', |
| 21 | ); |
| 22 | |
| 23 | /** |
| 24 | * Check if pro version is enabled AND licensed. |
| 25 | * |
| 26 | * In wp-env tests, defining `PRESTO_TESTSUITE` short-circuits the license |
| 27 | * check so unrelated Pro feature tests don't have to seed license state. |
| 28 | * To exercise the actual license-validity path inside a test, opt in via: |
| 29 | * |
| 30 | * add_filter( 'presto_player_force_license_check', '__return_true' ); |
| 31 | * |
| 32 | * @return bool |
| 33 | */ |
| 34 | protected function isPro() { |
| 35 | if ( ! defined( 'PRESTO_PLAYER_PRO_ENABLED' ) ) { |
| 36 | return false; |
| 37 | } |
| 38 | |
| 39 | // Test-suite bypass; opt back in via `presto_player_force_license_check`. |
| 40 | if ( |
| 41 | defined( 'PRESTO_TESTSUITE' ) && PRESTO_TESTSUITE |
| 42 | && ! apply_filters( 'presto_player_force_license_check', false ) |
| 43 | ) { |
| 44 | return true; |
| 45 | } |
| 46 | |
| 47 | return Services\License\License::isActive(); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Get the required pro version. |
| 52 | * |
| 53 | * @return string |
| 54 | */ |
| 55 | protected function requiredProVersion() { |
| 56 | return '0.0.3'; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Get the required pro version for a feature. |
| 61 | * |
| 62 | * @param string $feature Feature name to check. |
| 63 | * @return string |
| 64 | */ |
| 65 | protected function requiredProVersionForFeature( $feature ) { |
| 66 | return self::REQUIRED_VERSIONS[ $feature ]; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Get the version from plugin data |
| 71 | * |
| 72 | * @return string |
| 73 | */ |
| 74 | protected function version() { |
| 75 | // Load version from plugin data. |
| 76 | if ( ! \function_exists( 'get_plugin_data' ) ) { |
| 77 | require_once \ABSPATH . 'wp-admin/includes/plugin.php'; |
| 78 | } |
| 79 | |
| 80 | return \get_plugin_data( PRESTO_PLAYER_PLUGIN_FILE, false, false )['Version']; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Get the current pro version. |
| 85 | * |
| 86 | * @return string|false |
| 87 | */ |
| 88 | protected function proVersion() { |
| 89 | if ( ! $this->isPro() ) { |
| 90 | return false; |
| 91 | } |
| 92 | if ( class_exists( '\PrestoPlayer\Pro\Plugin' ) ) { |
| 93 | return \PrestoPlayer\Pro\Plugin::version(); |
| 94 | } |
| 95 | return false; |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Check if pro version meets minimum required version for a feature. |
| 100 | * |
| 101 | * @param string $feature Feature name to check. |
| 102 | * @return bool |
| 103 | */ |
| 104 | protected function hasRequiredProVersion( $feature ) { |
| 105 | // get the required version for the feature. |
| 106 | $required_versions = $this->requiredProVersionForFeature( $feature ); |
| 107 | |
| 108 | // The feature does not exist. |
| 109 | if ( empty( $required_versions ) ) { |
| 110 | return false; |
| 111 | } |
| 112 | |
| 113 | // get the pro version. |
| 114 | $pro_version = $this->proVersion(); |
| 115 | |
| 116 | // Pro version is not set (not installed). |
| 117 | if ( ! $pro_version ) { |
| 118 | return false; |
| 119 | } |
| 120 | |
| 121 | // Compare the pro version with the required version. |
| 122 | return version_compare( $pro_version, $required_versions, '>=' ); |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Get the license status. |
| 127 | * |
| 128 | * @return string 'licensed' or 'unlicensed' |
| 129 | */ |
| 130 | protected function licenseStatus() { |
| 131 | if ( ! $this->isPro() || ! class_exists( '\PrestoPlayer\Pro\Plugin' ) ) { |
| 132 | return 'unlicensed'; |
| 133 | } |
| 134 | |
| 135 | $pro_plugin = new \PrestoPlayer\Pro\Plugin(); |
| 136 | return $pro_plugin->hasLicense() ? 'licensed' : 'unlicensed'; |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * Static Facade Accessor |
| 141 | * |
| 142 | * @param string $method Method to call. |
| 143 | * @param mixed $params Method params. |
| 144 | * |
| 145 | * @return mixed |
| 146 | */ |
| 147 | public static function __callStatic( $method, $params ) { |
| 148 | return call_user_func_array( array( new static(), $method ), $params ); |
| 149 | } |
| 150 | } |
| 151 |