| 1 |
<?php |
| 2 |
|
| 3 |
namespace Extendify\Shared\Services\PluginsActivation; |
| 4 |
|
| 5 |
defined('ABSPATH') || die('No direct access.'); |
| 6 |
|
| 7 |
class Imagify extends PluginActivation |
| 8 |
{ |
| 9 |
// phpcs:ignore PSR12.Properties.ConstantVisibility.NotFound |
| 10 |
const API_URL = 'https://app.imagify.io/api/partners/users/'; |
| 11 |
|
| 12 |
public static function slug(): string |
| 13 |
{ |
| 14 |
return 'imagify'; |
| 15 |
} |
| 16 |
|
| 17 |
public static function isEligible(): bool |
| 18 |
{ |
| 19 |
// A key from IMAGIFY_API_KEY or the network option reaches only their accessor. |
| 20 |
if (function_exists('get_imagify_option')) { |
| 21 |
return empty(\get_imagify_option('api_key')); |
| 22 |
} |
| 23 |
|
| 24 |
$settings = (array) \get_option('imagify_settings', []); |
| 25 |
|
| 26 |
return empty($settings['api_key']); |
| 27 |
} |
| 28 |
|
| 29 |
protected static function saveKey(array $data) |
| 30 |
{ |
| 31 |
$key = $data['api_key'] ?? null; |
| 32 |
|
| 33 |
if (!$key) { |
| 34 |
return; |
| 35 |
} |
| 36 |
|
| 37 |
$settings = (array) \get_option('imagify_settings', []); |
| 38 |
$settings['api_key'] = \sanitize_text_field($key); |
| 39 |
\update_option('imagify_settings', $settings); |
| 40 |
|
| 41 |
// clear the stale validation cache. |
| 42 |
\delete_transient('imagify_user_cache'); |
| 43 |
} |
| 44 |
} |
| 45 |
|