| 1 |
<?php |
| 2 |
/** |
| 3 |
* Ability: report NotificationX status — versions, edition, key toggles and |
| 4 |
* notification counts — so a client can orient itself in one call. |
| 5 |
* |
| 6 |
* @package NotificationX\Abilities\Read |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace NotificationX\Abilities\Read; |
| 10 |
|
| 11 |
use NotificationX\Abilities\AbilityBase; |
| 12 |
use NotificationX\NotificationX; |
| 13 |
use NotificationX\Admin\Settings; |
| 14 |
use NotificationX\Core\PostType; |
| 15 |
|
| 16 |
if ( ! defined( 'ABSPATH' ) ) { |
| 17 |
exit; |
| 18 |
} |
| 19 |
|
| 20 |
/** |
| 21 |
* A one-call overview: Free/Pro versions, whether Pro is active, whether the MCP |
| 22 |
* connector / REST API / analytics are on, and how many notifications exist vs |
| 23 |
* how many are active. Call this first to tell a Free site from a Pro one and to |
| 24 |
* know which features are available before acting. |
| 25 |
*/ |
| 26 |
class GetStatus extends AbilityBase { |
| 27 |
|
| 28 |
protected $id = 'notificationx/get-status'; |
| 29 |
protected $label = 'Get status'; |
| 30 |
protected $description = 'Get a one-call overview of this NotificationX install: Free and Pro versions, whether Pro is active, whether the MCP connector, REST API and analytics are enabled, and the total vs active notification counts. Use it to tell a Free site from a Pro one and to know what is available before creating or editing.'; |
| 31 |
|
| 32 |
public function input_schema() { |
| 33 |
return array( |
| 34 |
'type' => 'object', |
| 35 |
'properties' => (object) array(), |
| 36 |
); |
| 37 |
} |
| 38 |
|
| 39 |
public function output_schema() { |
| 40 |
return array( |
| 41 |
'type' => 'object', |
| 42 |
'properties' => array( |
| 43 |
'version' => array( 'type' => 'string' ), |
| 44 |
'pro_version' => array( 'type' => 'string' ), |
| 45 |
'is_pro' => array( 'type' => 'boolean' ), |
| 46 |
'mcp_enabled' => array( 'type' => 'boolean' ), |
| 47 |
'rest_api_enabled' => array( 'type' => 'boolean' ), |
| 48 |
'analytics_enabled' => array( 'type' => 'boolean' ), |
| 49 |
'notifications' => array( 'type' => 'object' ), |
| 50 |
), |
| 51 |
); |
| 52 |
} |
| 53 |
|
| 54 |
public function execute( $input ) { |
| 55 |
$settings = Settings::get_instance(); |
| 56 |
$post_type = PostType::get_instance(); |
| 57 |
|
| 58 |
$all = $post_type->get_posts( array(), 'nx_id' ); |
| 59 |
$active = $post_type->get_posts( array( 'enabled' => true ), 'nx_id' ); |
| 60 |
|
| 61 |
return array( |
| 62 |
'version' => defined( 'NOTIFICATIONX_VERSION' ) ? NOTIFICATIONX_VERSION : '', |
| 63 |
'pro_version' => defined( 'NOTIFICATIONX_PRO_VERSION' ) ? NOTIFICATIONX_PRO_VERSION : '', |
| 64 |
'is_pro' => (bool) NotificationX::is_pro(), |
| 65 |
'mcp_enabled' => (bool) $settings->get( 'settings.enable_mcp' ), |
| 66 |
'rest_api_enabled' => (bool) $settings->get( 'settings.enable_rest_api', false ), |
| 67 |
'analytics_enabled' => (bool) $settings->get( 'settings.enable_analytics', true ), |
| 68 |
'notifications' => array( |
| 69 |
'total' => is_array( $all ) ? count( $all ) : 0, |
| 70 |
'active' => is_array( $active ) ? count( $active ) : 0, |
| 71 |
), |
| 72 |
); |
| 73 |
} |
| 74 |
} |
| 75 |
|