Files
igny8/docs/90-REFERENCE/PLUGIN-UPDATE-BUG-FIX.md
2026-01-13 04:42:58 +00:00

8.9 KiB

Plugin Update Double-Notification Bug - Fixed

Issue Description

Bug: After updating the IGNY8 WordPress plugin, the update notification appears again even though the plugin is already on the latest version. Users had to click "Update" twice, and the notification persisted even when current version matched the update notification version.

Affected Areas:

  • Plugin update page (/wp-admin/update-core.php)
  • Plugins list page (/wp-admin/plugins.php)

Root Causes

1. Improper Transient State Management

The check_for_updates() method was using unset() to remove the plugin from the update response when no update was available. However, WordPress requires explicit indication that a plugin has been checked and no update is available.

Problem Code:

} else {
    // Remove from response if version is current or newer
    unset($transient->response[$plugin_basename]);
}

Issue: Simply unsetting from the response doesn't persist properly in WordPress transient cache.

2. Missing Post-Update Cache Clear

After a plugin update completes, WordPress continues to use cached update information. There was no hook to clear this cache, causing stale update notifications to persist.

Missing: No upgrader_process_complete hook handler to clear transients after update.

3. No Manual Cache Clear Option

Administrators had no way to manually clear the update cache when it got stuck, requiring manual database manipulation or complex workarounds.

Solutions Implemented

Fix 1: Proper Transient State Management

File: includes/class-igny8-updater.php

Changes:

  1. When no update is available, explicitly add plugin to $transient->no_update array
  2. Remove from $transient->response if present
  3. Mark plugin as "checked with no update available"

New Code:

} else {
    // 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' => '',
    );
}

Impact: WordPress now correctly recognizes when plugin is up-to-date and doesn't show false update notifications.


Fix 2: Automatic Cache Clear After Update

File: includes/class-igny8-updater.php

Changes:

  1. Added upgrader_process_complete action hook
  2. Detects when IGNY8 plugin is updated
  3. Automatically clears WordPress update transients
  4. Forces fresh update check on next page load

New Code:

// In constructor:
add_action('upgrader_process_complete', array($this, 'clear_update_cache'), 10, 2);

// New method:
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);
    }
}

Impact: After plugin update, WordPress immediately recognizes new version and removes update notification.


Fix 3: Manual Cache Clear Button

File: admin/pages/settings.php

Changes:

  1. Added "Clear Update Cache" button in Settings page
  2. AJAX handler for instant cache clearing
  3. Visual feedback (loading, success, error states)

UI Addition:

<button type="button" id="igny8-clear-update-cache" class="igny8-btn">
    <svg>...</svg>
    Clear Update Cache
</button>

JavaScript Handler:

  • Shows loading state while processing
  • Success: Green background, checkmark icon, "Cache Cleared!"
  • Error: Red background, X icon, "Failed" or "Error"
  • Returns to normal state after 2 seconds

File: admin/class-admin.php

AJAX Handler:

public static function clear_update_cache_ajax() {
    // Verify nonce
    if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'igny8_clear_cache')) {
        wp_send_json_error(array('message' => 'Invalid security token'));
        return;
    }
    
    // Check user permissions
    if (!current_user_can('manage_options')) {
        wp_send_json_error(array('message' => 'Insufficient permissions'));
        return;
    }
    
    // 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');
    
    // Clear WordPress object cache
    wp_cache_flush();
    
    error_log('IGNY8: Update cache cleared manually by admin');
    
    wp_send_json_success(array(
        'message' => 'Update cache cleared successfully.'
    ));
}

Registered AJAX Action:

add_action('wp_ajax_igny8_clear_update_cache', array('Igny8Admin', 'clear_update_cache_ajax'));

Impact: Administrators can instantly clear stuck update notifications without technical knowledge.


Technical Details

WordPress Update Check Flow (Before Fix)

1. WordPress checks for updates
2. Plugin returns new_version if available
3. Plugin does unset() if no update
4. Transient caches partial state ❌
5. Next check sees partial cache
6. Shows update notification again ❌

WordPress Update Check Flow (After Fix)

1. WordPress checks for updates
2. Plugin returns new_version if available
3. Plugin adds to no_update if current ✅
4. Transient properly caches state ✅
5. After update: clear_update_cache() runs ✅
6. Next check sees fresh state ✅
7. No false update notification ✅

Files Modified

  1. includes/class-igny8-updater.php

    • Added clear_update_cache() method
    • Fixed check_for_updates() transient logic
    • Added upgrader_process_complete hook
  2. admin/pages/settings.php

    • Added "Clear Update Cache" button
    • Added JavaScript AJAX handler
    • Added loading/success/error states
  3. admin/class-admin.php

    • Added clear_update_cache_ajax() static method
    • Registered AJAX action igny8_clear_update_cache

Testing Checklist

Automatic Clearing (Fix 1 & 2)

  • Update plugin to new version
  • Verify update notification disappears immediately
  • Verify no second "Update" prompt
  • Check plugins list page shows correct version
  • Check update-core page shows no IGNY8 update

Manual Clearing (Fix 3)

  • Navigate to IGNY8 → Settings
  • Click "Clear Update Cache" button
  • Verify button shows loading state
  • Verify button shows success (green, checkmark)
  • Refresh plugins page
  • Verify update notifications are current

Edge Cases

  • Clear cache with no updates available
  • Clear cache with update available (should still show update)
  • Update plugin while on settings page
  • Update multiple plugins simultaneously

Deployment

Backend Changes

No backend changes required (WordPress plugin only)

Plugin Changes

Ready for deployment:

  • includes/class-igny8-updater.php - Core fix
  • admin/pages/settings.php - UI enhancement
  • admin/class-admin.php - AJAX handler

Version Bump

Recommended: Bump plugin version to test the fix itself

  • Current version: (check igny8-bridge.php)
  • New version: Current + 0.0.1
  • Update IGNY8_BRIDGE_VERSION constant
  • Update changelog

Rollout Plan

  1. Test in Development

    • Deploy updated plugin to test WordPress site
    • Trigger update process
    • Verify no double-notification
  2. Deploy to Production

    • Update plugin files on IGNY8 update server
    • WordPress sites will auto-update
    • Monitor for any issues
  3. User Communication

    • Fixed: Double-update notification bug
    • Added: Manual cache clear button in Settings
    • Improved: Update check reliability

Date: January 13, 2026
Status: Implemented, Ready for Testing
Priority: MEDIUM - Bug Fix, User Experience Improvement
Related: AUTHENTICATION-SECURITY-FIXES.md