| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Whether connections work on this site at all. |
| 5 |
*/ |
| 6 |
|
| 7 |
namespace Extendify\Mcp; |
| 8 |
|
| 9 |
defined('ABSPATH') || die('No direct access.'); |
| 10 |
|
| 11 |
use Extendify\PartnerData; |
| 12 |
|
| 13 |
/** |
| 14 |
* An administrator can undo their own switch, never the partner's. |
| 15 |
*/ |
| 16 |
class Availability |
| 17 |
{ |
| 18 |
// phpcs:ignore PSR12.Properties.ConstantVisibility.NotFound |
| 19 |
const OPTION = 'extendify_mcp_turned_off'; |
| 20 |
|
| 21 |
/** |
| 22 |
* @return boolean |
| 23 |
*/ |
| 24 |
public static function offered() |
| 25 |
{ |
| 26 |
// A blocked partner's last mcpConfig would otherwise keep every token working. |
| 27 |
return PartnerData::setting('license') === 'active' && Allowed::reads() !== Allowed::NONE; |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* @return boolean |
| 32 |
*/ |
| 33 |
public static function live() |
| 34 |
{ |
| 35 |
return self::offered() && !self::turnedOff(); |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* @return array|null |
| 40 |
*/ |
| 41 |
public static function turnedOff() |
| 42 |
{ |
| 43 |
$off = \get_option(self::OPTION); |
| 44 |
|
| 45 |
return is_array($off) ? $off : null; |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* @param integer $userId - The administrator turning connections off. |
| 50 |
* @return void |
| 51 |
*/ |
| 52 |
public static function turnOff($userId) |
| 53 |
{ |
| 54 |
\update_option(self::OPTION, ['by' => (int) $userId, 'at' => time()], false); |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* @return void |
| 59 |
*/ |
| 60 |
public static function turnOn() |
| 61 |
{ |
| 62 |
\delete_option(self::OPTION); |
| 63 |
} |
| 64 |
} |
| 65 |
|