fix
This commit is contained in:
@@ -77,6 +77,13 @@ class Igny8RestAPI {
|
||||
'callback' => array($this, 'get_site_metadata'),
|
||||
'permission_callback' => '__return_true',
|
||||
));
|
||||
|
||||
// Status endpoint for health checks (public)
|
||||
register_rest_route('igny8/v1', '/status', array(
|
||||
'methods' => 'GET',
|
||||
'callback' => array($this, 'get_plugin_status'),
|
||||
'permission_callback' => '__return_true', // Public endpoint for health checks
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -419,6 +426,60 @@ class Igny8RestAPI {
|
||||
|
||||
return $this->build_unified_response(true, $data, 'Site metadata retrieved', null, null, 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get plugin status for health checks
|
||||
*
|
||||
* @param WP_REST_Request $request Request object
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
public function get_plugin_status($request) {
|
||||
// Get plugin configuration status
|
||||
$api_key = function_exists('igny8_get_secure_option') ? igny8_get_secure_option('igny8_api_key') : get_option('igny8_api_key');
|
||||
$access_token = function_exists('igny8_get_secure_option') ? igny8_get_secure_option('igny8_access_token') : get_option('igny8_access_token');
|
||||
$email = get_option('igny8_email', '');
|
||||
$site_id = get_option('igny8_site_id', '');
|
||||
$connection_enabled = igny8_is_connection_enabled();
|
||||
$two_way_sync = (int) get_option('igny8_enable_two_way_sync', 1);
|
||||
|
||||
// Check if plugin is configured
|
||||
$has_api_key = !empty($api_key);
|
||||
$has_access_token = !empty($access_token);
|
||||
$has_site_id = !empty($site_id);
|
||||
$is_configured = $has_api_key && $has_access_token && $has_site_id && $connection_enabled;
|
||||
|
||||
// Get last sync times
|
||||
$last_site_sync = intval(get_option('igny8_last_site_sync', 0));
|
||||
$last_structure_sync = intval(get_option('igny8_last_structure_sync', 0));
|
||||
|
||||
// Determine plugin status
|
||||
$status = 'not_configured';
|
||||
if ($is_configured && ($last_site_sync > 0 || $last_structure_sync > 0)) {
|
||||
$status = 'active';
|
||||
} elseif ($is_configured) {
|
||||
$status = 'configured';
|
||||
} elseif ($has_api_key || $has_access_token) {
|
||||
$status = 'partial';
|
||||
}
|
||||
|
||||
// Build response
|
||||
return rest_ensure_response(array(
|
||||
'plugin' => 'IGNY8 WordPress Bridge',
|
||||
'version' => defined('IGNY8_BRIDGE_VERSION') ? IGNY8_BRIDGE_VERSION : 'unknown',
|
||||
'status' => $status,
|
||||
'connected' => $is_configured,
|
||||
'has_api_key' => $has_api_key,
|
||||
'has_site_id' => $has_site_id,
|
||||
'connection_enabled' => $connection_enabled,
|
||||
'two_way_sync_enabled' => (bool) $two_way_sync,
|
||||
'last_site_sync' => $last_site_sync > 0 ? gmdate('Y-m-d\TH:i:s\Z', $last_site_sync) : null,
|
||||
'last_structure_sync' => $last_structure_sync > 0 ? gmdate('Y-m-d\TH:i:s\Z', $last_structure_sync) : null,
|
||||
'can_reach_igny8' => $last_site_sync > 0 || $last_structure_sync > 0, // If we've synced, we can reach IGNY8
|
||||
'timestamp' => current_time('mysql'),
|
||||
'site_url' => get_site_url(),
|
||||
'site_name' => get_bloginfo('name'),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize REST API
|
||||
|
||||
Reference in New Issue
Block a user