API ISsues fixes pluigna dn app, plugin v udapte 1.4.0
This commit is contained in:
@@ -79,10 +79,11 @@ class Igny8RestAPI {
|
||||
));
|
||||
|
||||
// Plugin status endpoint - returns connection status and API key info
|
||||
// SECURITY: Requires API key authentication
|
||||
register_rest_route('igny8/v1', '/status', array(
|
||||
'methods' => 'GET',
|
||||
'callback' => array($this, 'get_status'),
|
||||
'permission_callback' => '__return_true', // Public endpoint for health checks
|
||||
'permission_callback' => array($this, 'check_permission'), // Requires API key
|
||||
));
|
||||
|
||||
// API key verification endpoint - requires valid API key in header
|
||||
@@ -397,6 +398,10 @@ class Igny8RestAPI {
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
public function get_status($request) {
|
||||
// If we reach here, API key was validated by check_permission
|
||||
// Update last health check timestamp
|
||||
update_option('igny8_last_api_health_check', time());
|
||||
|
||||
$api = new Igny8API();
|
||||
$api_key = function_exists('igny8_get_secure_option') ? igny8_get_secure_option('igny8_api_key') : get_option('igny8_api_key');
|
||||
$connection_enabled = igny8_is_connection_enabled();
|
||||
@@ -404,10 +409,11 @@ class Igny8RestAPI {
|
||||
$data = array(
|
||||
'connected' => !empty($api_key) && $api->is_authenticated(),
|
||||
'has_api_key' => !empty($api_key),
|
||||
'api_key_validated' => true, // Since check_permission passed
|
||||
'communication_enabled' => $connection_enabled,
|
||||
'plugin_version' => defined('IGNY8_BRIDGE_VERSION') ? IGNY8_BRIDGE_VERSION : '1.0.0',
|
||||
'wordpress_version' => get_bloginfo('version'),
|
||||
'last_health_check' => get_option('igny8_last_api_health_check', 0),
|
||||
'last_health_check' => time(),
|
||||
'health' => (!empty($api_key) && $connection_enabled) ? 'healthy' : 'not_configured'
|
||||
);
|
||||
|
||||
|
||||
@@ -58,6 +58,9 @@ class Igny8_Updater {
|
||||
add_filter('pre_set_site_transient_update_plugins', array($this, 'check_for_updates'));
|
||||
add_filter('plugins_api', array($this, 'plugin_info'), 10, 3);
|
||||
|
||||
// Clear update cache after plugin is updated
|
||||
add_action('upgrader_process_complete', array($this, 'clear_update_cache'), 10, 2);
|
||||
|
||||
// Add custom styling for plugin details popup
|
||||
add_action('admin_enqueue_scripts', array($this, 'enqueue_plugin_details_styles'));
|
||||
}
|
||||
@@ -94,8 +97,24 @@ class Igny8_Updater {
|
||||
'requires_php' => $update_info['requires_php'] ?? '',
|
||||
);
|
||||
} else {
|
||||
// Remove from response if version is current or newer
|
||||
unset($transient->response[$plugin_basename]);
|
||||
// CRITICAL FIX: Explicitly mark as no update by removing from response
|
||||
// and adding to no_update to prevent false update notifications
|
||||
if (isset($transient->response[$plugin_basename])) {
|
||||
unset($transient->response[$plugin_basename]);
|
||||
}
|
||||
|
||||
// Mark plugin as checked with no update available
|
||||
if (!isset($transient->no_update)) {
|
||||
$transient->no_update = array();
|
||||
}
|
||||
|
||||
$transient->no_update[$plugin_basename] = (object) array(
|
||||
'slug' => $this->plugin_slug,
|
||||
'plugin' => $plugin_basename,
|
||||
'new_version' => $this->version,
|
||||
'url' => $update_info['info_url'] ?? '',
|
||||
'package' => '',
|
||||
);
|
||||
}
|
||||
|
||||
return $transient;
|
||||
@@ -142,6 +161,44 @@ class Igny8_Updater {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear update cache after plugin update completes
|
||||
*
|
||||
* Fixes the double-update notification bug by forcing WordPress
|
||||
* to re-check for updates with the new version number
|
||||
*
|
||||
* @param WP_Upgrader $upgrader WP_Upgrader instance
|
||||
* @param array $hook_extra Extra arguments passed to hooked filters
|
||||
*/
|
||||
public function clear_update_cache($upgrader, $hook_extra) {
|
||||
// Check if this is a plugin update
|
||||
if (!isset($hook_extra['type']) || $hook_extra['type'] !== 'plugin') {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if our plugin was updated
|
||||
$plugin_basename = plugin_basename($this->plugin_file);
|
||||
$updated_plugins = array();
|
||||
|
||||
if (isset($hook_extra['plugin'])) {
|
||||
$updated_plugins[] = $hook_extra['plugin'];
|
||||
} elseif (isset($hook_extra['plugins'])) {
|
||||
$updated_plugins = $hook_extra['plugins'];
|
||||
}
|
||||
|
||||
// If our plugin was updated, force WordPress to recheck updates
|
||||
if (in_array($plugin_basename, $updated_plugins, true)) {
|
||||
// Delete the update_plugins transient to force a fresh check
|
||||
delete_site_transient('update_plugins');
|
||||
|
||||
// Also clear any cached update info
|
||||
wp_cache_delete('igny8_update_check', 'igny8');
|
||||
|
||||
// Log the cache clear for debugging
|
||||
error_log('IGNY8: Cleared update cache after plugin update to version ' . $this->version);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue custom styles for plugin details popup
|
||||
*/
|
||||
|
||||
@@ -363,17 +363,24 @@ function igny8_get_connection_state() {
|
||||
$integration_id = get_option('igny8_integration_id');
|
||||
$last_structure_sync = get_option('igny8_last_structure_sync');
|
||||
|
||||
// SECURITY: Must have API key to show ANY connection state
|
||||
if (empty($api_key)) {
|
||||
igny8_log_connection_state('not_connected', 'No API key found');
|
||||
return 'not_connected';
|
||||
}
|
||||
|
||||
if (!empty($api_key) && !empty($integration_id) && !empty($last_structure_sync)) {
|
||||
igny8_log_connection_state('connected', 'Fully connected and synced');
|
||||
// SECURITY: Only show 'connected' if API key is validated
|
||||
// Check if we have a recent successful API health check (within last hour)
|
||||
$last_health_check = get_option('igny8_last_api_health_check', 0);
|
||||
$one_hour_ago = time() - 3600;
|
||||
|
||||
if (!empty($api_key) && !empty($integration_id) && !empty($last_structure_sync) && $last_health_check > $one_hour_ago) {
|
||||
igny8_log_connection_state('connected', 'Fully connected and synced with validated API key');
|
||||
return 'connected';
|
||||
}
|
||||
|
||||
igny8_log_connection_state('configured', 'API key set, pending structure sync');
|
||||
// If we have API key but no recent validation, show as 'configured' not 'connected'
|
||||
igny8_log_connection_state('configured', 'API key set, validation pending');
|
||||
return 'configured';
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user