Skip to content

Conversation

imantsk
Copy link
Member

@imantsk imantsk commented Aug 22, 2025

🔄 Version Switching Functionality Implementation

This PR introduces comprehensive version switching functionality in the Code Snippets plugin settings, enabling users to safely switch between different plugin versions directly from the WordPress admin interface.

✨ Features Implemented

🎛️ New Settings Section

  • New "Version" Tab: Added to plugin settings (Settings > Snippets Settings > Version)
  • Current Version Display: Shows active version with distinctive styling
  • Available Versions: Fetches and displays all versions from WordPress.org repository

🔄 Version Switching Interface

  • Smart Dropdown: Lists available versions with current version highlighted
  • One-Click Switching: Secure version change execution with validation
  • Real-time Feedback: Loading states, progress indicators, success/error messages
  • Safety Features:
    • ⚠️ Compatibility warnings with backup recommendations
    • 🔒 Progress tracking prevents concurrent operations
    • 🔄 Automatic page refresh after successful switches

🚀 Performance & Caching

  • Intelligent Caching: 1-hour cache for version data (reduces API calls)
  • Manual Refresh: Force cache updates with dedicated button
  • Auto-cleanup: Cache cleared after successful version switches

🔐 Security & Safety

  • WordPress Standards: Nonce verification, capability checks (update_plugins)
  • Progress Locking: Transient-based system prevents concurrent switches
  • Error Handling: Comprehensive logging with user-friendly messages
  • Core Integration: Uses WordPress upgrader for maximum reliability

🎨 User Experience

  • Responsive Design: Mobile and desktop optimized
  • Visual Feedback: Clear states (loading, success, error, warning)
  • Intuitive Flow: Dropdown → Warning → Confirmation → Progress → Success
  • Accessibility: Proper ARIA labels and keyboard navigation

🧪 Testing Steps

📋 Prerequisites

  • WordPress admin access with plugin update permissions
  • Active Code Snippets plugin installation
  • Hosting environment that allows plugin updates

1️⃣ Settings Access

  • Passed
# Test Steps:
1. Navigate to "Snippets > Settings"
2. Click "Version" tab
3. Verify current version display
4. Confirm dropdown population

Expected: Clean interface with current version highlighted, dropdown populated with available versions.

2️⃣ Version Selection Flow

  • Passed
# Test Steps:
1. Select different version from dropdown
2. Observe button state changes
3. Check warning message appearance
4. Verify current version remains disabled

Expected: Switch button enables, warning appears, current version shows "(Current)" label.

3️⃣ Cache Refresh Mechanism

  • Passed
# Test Steps:
1. Click "Refresh Available Versions"
2. Monitor button text changes
3. Wait for completion
4. Verify page reload

Expected: Button shows "Refreshing...""Refreshed!" → page reloads with fresh data.

4️⃣ Successful Version Switch

  • Passed
# Test Steps:
1. Select stable previous version
2. Click "Switch Version"  
3. Monitor progress messages
4. Wait for completion
5. Verify version change

Expected:
- Button → "Switching..." (disabled)
- Progress message appears
- Success confirmation
- Auto-refresh after 3 seconds
- New version displayed

5️⃣ Error Handling

  • Passed
# Test Network Issues:
1. Disable internet connection
2. Attempt version switch
3. Verify error handling

# Test Permission Issues:  
1. Test with non-admin user
2. Attempt access
3. Verify permission messages

Expected: Graceful error handling, no fatal errors, clear user guidance.

6️⃣ Concurrent Operation Prevention

  • Passed
# Test Steps:
1. Open two browser tabs
2. Start switch in tab 1
3. Immediately try switch in tab 2

Expected: Second attempt blocked with "switch in progress" message.

7️⃣ Input Validation

  • Passed
# Test Steps:
1. Use dev tools to modify dropdown values
2. Submit invalid version
3. Verify rejection

Expected: Server-side validation rejects invalid versions with error message.

8️⃣ CSRF Protection

  • Passed
# Test Steps:  
1. Submit AJAX request without nonce
2. Verify security rejection

Expected: Request blocked with "Security check failed" message.

📊 Expected Results

✅ Success Indicators

  • Immediate Feedback: Visual confirmation of all user actions
  • Progress Transparency: Users always know current operation status
  • State Persistence: Interface reflects actual plugin state
  • Error Recovery: Failed operations don't leave system in bad state

⚠️ Error Handling

  • Graceful Degradation: Errors don't break interface
  • Actionable Messages: Users get clear next steps
  • Safe Fallbacks: No partial installs or corrupted states
  • Debug Information: Errors logged for troubleshooting

🔍 Code Review Focus Areas

📁 File Changes

  • src/php/settings/version-switch.php: Complete version switching logic
  • src/css/settings.scss: UI styling and responsive design
  • Settings integration: Proper WordPress settings API usage

⚠️ Known Limitations

  • Requires internet connectivity for version fetching
  • Depends on WordPress.org API availability
  • File system write permissions needed for upgrades
  • Some hosting providers may block plugin modifications

@imantsk imantsk added the build Adding this label will trigger the zip build action label Aug 22, 2025
@codesnippetspro codesnippetspro deleted a comment from github-actions bot Aug 22, 2025
@code-snippets-bot code-snippets-bot added build Adding this label will trigger the zip build action and removed build Adding this label will trigger the zip build action labels Aug 22, 2025
Copy link

github-actions bot commented Aug 22, 2025

Download and install

📦 code-snippets.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Adding this label will trigger the zip build action
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants