class-edd-provider.php
15 hours ago
class-freemius-provider.php
15 hours ago
class-licensing-factory.php
15 hours ago
index.php
15 hours ago
interface-licensing-provider.php
15 hours ago
interface-licensing-provider.php
180 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Licensing Provider Interface for WP2FA plugin. |
| 4 | * |
| 5 | * Defines the common interface that all licensing providers must implement. |
| 6 | * This allows the plugin to support multiple licensing systems (Freemius, EDD, etc.) |
| 7 | * through a unified API. |
| 8 | * |
| 9 | * @since 3.2.0 |
| 10 | * @package wp2fa |
| 11 | * @subpackage Licensing |
| 12 | * @copyright 2026 Melapress |
| 13 | * @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0 |
| 14 | * @link https://wordpress.org/plugins/wp-2fa/ |
| 15 | */ |
| 16 | |
| 17 | declare(strict_types=1); |
| 18 | |
| 19 | namespace WP2FA\Licensing; |
| 20 | |
| 21 | /** |
| 22 | * Interface for licensing providers. |
| 23 | * |
| 24 | * @since 3.2.0 |
| 25 | */ |
| 26 | interface Licensing_Provider { |
| 27 | |
| 28 | /** |
| 29 | * Initialize the licensing provider. |
| 30 | * |
| 31 | * Sets up hooks, filters, and any necessary configurations. |
| 32 | * |
| 33 | * @return void |
| 34 | * @since 3.2.0 |
| 35 | */ |
| 36 | public static function init(); |
| 37 | |
| 38 | /** |
| 39 | * Check if the license is active and valid. |
| 40 | * |
| 41 | * @return bool True if license is active and valid, false otherwise. |
| 42 | * @since 3.2.0 |
| 43 | */ |
| 44 | public static function has_active_valid_license(): bool; |
| 45 | |
| 46 | /** |
| 47 | * Check if the premium version is active. |
| 48 | * |
| 49 | * Resource cautious function intended for quick check during initial stages |
| 50 | * of plugin bootstrap, especially on front-end. |
| 51 | * |
| 52 | * @return bool True if premium is active, false otherwise. |
| 53 | * @since 3.2.0 |
| 54 | */ |
| 55 | public static function is_premium(): bool; |
| 56 | |
| 57 | /** |
| 58 | * Check if the plugin is registered with the licensing provider. |
| 59 | * |
| 60 | * @return bool True if registered, false otherwise. |
| 61 | * @since 3.2.0 |
| 62 | */ |
| 63 | public static function is_registered(): bool; |
| 64 | |
| 65 | /** |
| 66 | * Get the license object/data. |
| 67 | * |
| 68 | * @return mixed License object or data structure, null if not available. |
| 69 | * @since 3.2.0 |
| 70 | */ |
| 71 | public static function get_license(); |
| 72 | |
| 73 | /** |
| 74 | * Get the license quota (number of allowed users/sites). |
| 75 | * |
| 76 | * @return int Number of allowed users/sites, -1 if unlimited or unavailable. |
| 77 | * @since 3.2.0 |
| 78 | */ |
| 79 | public static function get_license_quota(): int; |
| 80 | |
| 81 | /** |
| 82 | * Check if license quota has been exceeded. |
| 83 | * |
| 84 | * @return bool True if quota exceeded, false otherwise. |
| 85 | * @since 3.2.0 |
| 86 | */ |
| 87 | public static function is_quota_exceeded(): bool; |
| 88 | |
| 89 | /** |
| 90 | * Get the pricing page URL. |
| 91 | * |
| 92 | * @return string Pricing page URL. |
| 93 | * @since 3.2.0 |
| 94 | */ |
| 95 | public static function get_pricing_url(): string; |
| 96 | |
| 97 | /** |
| 98 | * Get the account/dashboard URL. |
| 99 | * |
| 100 | * @return string Account/dashboard URL. |
| 101 | * @since 3.2.0 |
| 102 | */ |
| 103 | public static function get_account_url(): string; |
| 104 | |
| 105 | /** |
| 106 | * Sync/refresh the license status. |
| 107 | * |
| 108 | * Forces a check with the licensing server to update local license status. |
| 109 | * |
| 110 | * @return bool True on success, false on failure. |
| 111 | * @since 3.2.0 |
| 112 | */ |
| 113 | public static function sync_license(): bool; |
| 114 | |
| 115 | /** |
| 116 | * Activate a license key. |
| 117 | * |
| 118 | * @param string $license_key The license key to activate. |
| 119 | * @return bool|array True on success, array with error info on failure. |
| 120 | * @since 3.2.0 |
| 121 | */ |
| 122 | public static function activate_license( string $license_key ); |
| 123 | |
| 124 | /** |
| 125 | * Deactivate the current license. |
| 126 | * |
| 127 | * @return bool True on success, false on failure. |
| 128 | * @since 3.2.0 |
| 129 | */ |
| 130 | public static function deactivate_license(): bool; |
| 131 | |
| 132 | /** |
| 133 | * Get the provider name. |
| 134 | * |
| 135 | * @return string Provider name (e.g., 'freemius', 'edd'). |
| 136 | * @since 3.2.0 |
| 137 | */ |
| 138 | public static function get_provider_name(): string; |
| 139 | |
| 140 | /** |
| 141 | * Check if this provider is available/configured. |
| 142 | * |
| 143 | * @return bool True if provider is available, false otherwise. |
| 144 | * @since 3.2.0 |
| 145 | */ |
| 146 | public static function is_available(): bool; |
| 147 | |
| 148 | /** |
| 149 | * Get the plugin basename. |
| 150 | * |
| 151 | * @return string Plugin basename (e.g., 'wp-2fa/wp-2fa.php'). |
| 152 | * @since 3.2.0 |
| 153 | */ |
| 154 | public static function get_plugin_basename(): string; |
| 155 | |
| 156 | /** |
| 157 | * Add an action hook specific to this provider. |
| 158 | * |
| 159 | * @param string $tag The action hook name. |
| 160 | * @param callable $callback The callback function. |
| 161 | * @param int $priority Priority (default 10). |
| 162 | * @param int $args Number of arguments (default 1). |
| 163 | * @return void |
| 164 | * @since 3.2.0 |
| 165 | */ |
| 166 | public static function add_action( string $tag, callable $callback, int $priority = 10, int $args = 1 ); |
| 167 | |
| 168 | /** |
| 169 | * Add a filter hook specific to this provider. |
| 170 | * |
| 171 | * @param string $tag The filter hook name. |
| 172 | * @param callable $callback The callback function. |
| 173 | * @param int $priority Priority (default 10). |
| 174 | * @param int $args Number of arguments (default 1). |
| 175 | * @return void |
| 176 | * @since 3.2.0 |
| 177 | */ |
| 178 | public static function add_filter( string $tag, callable $callback, int $priority = 10, int $args = 1 ); |
| 179 | } |
| 180 |