| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Plugin Name: Logtivity Site Registration |
| 5 |
*/ |
| 6 |
|
| 7 |
abstract class Logtivity_Register |
| 8 |
{ |
| 9 |
/** |
| 10 |
* Enter your Team API Key here |
| 11 |
* |
| 12 |
* @var string |
| 13 |
*/ |
| 14 |
protected static string $teamApi = 'YOUR-TEAM-APIKEY-HERE'; |
| 15 |
|
| 16 |
/** |
| 17 |
* @var WP_Error|Logtivity_Response|null |
| 18 |
*/ |
| 19 |
protected static $response = null; |
| 20 |
|
| 21 |
public static function register() |
| 22 |
{ |
| 23 |
$apiKey = get_option('logtivity_site_api_key'); |
| 24 |
if (empty($apiKey) && is_callable([Logtivity::class, 'registerSite'])) { |
| 25 |
static::$response = Logtivity::registerSite(static::$teamApi); |
| 26 |
} |
| 27 |
|
| 28 |
add_action('admin_notices', [static::class, 'adminMessage']); |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* @return void |
| 33 |
*/ |
| 34 |
public static function adminMessage() |
| 35 |
{ |
| 36 |
if (static::$response instanceof WP_Error) { |
| 37 |
$message = static::$response->get_error_message(); |
| 38 |
$status = 'error'; |
| 39 |
|
| 40 |
} elseif (static::$response instanceof Logtivity_Response) { |
| 41 |
$message = static::$response->message; |
| 42 |
$status = 'success'; |
| 43 |
} |
| 44 |
|
| 45 |
if (empty($message) === false) { |
| 46 |
echo sprintf( |
| 47 |
'<div class="notice notice-%s"><p>%s</p></div>', |
| 48 |
$status, |
| 49 |
$message |
| 50 |
); |
| 51 |
} |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
add_action('init', [Logtivity_Register::class, 'register']); |
| 56 |
|