#!/bin/bash

echo "=== Clearing cache for manage event page ==="

# Try to clear Breeze cache if available
if command -v wp &> /dev/null; then
    echo "Clearing WordPress cache..."
    wp cache flush 2>/dev/null || echo "  - WordPress cache flush not available"
    
    echo "Clearing Breeze cache..."
    wp breeze purge --cache=all 2>/dev/null || echo "  - Breeze cache purge not available"
    
    echo "Clearing transients..."
    wp transient delete --all 2>/dev/null || echo "  - Transient deletion not available"
else
    echo "WP-CLI not found. Manual cache clearing may be needed."
fi

# Clear object cache files if they exist
if [ -d "/tmp/breeze" ]; then
    echo "Clearing Breeze file cache..."
    rm -rf /tmp/breeze/*
fi

# Clear any server-side caches
if command -v redis-cli &> /dev/null; then
    echo "Flushing Redis cache..."
    redis-cli FLUSHALL 2>/dev/null || echo "  - Redis flush failed or not configured"
fi

if command -v service &> /dev/null; then
    echo "Restarting PHP-FPM (if available)..."
    sudo service php*-fpm restart 2>/dev/null || echo "  - PHP-FPM restart not available"
fi

echo "Cache clearing complete!"
echo ""
echo "Next steps:"
echo "1. Visit the manage event page in an incognito/private browser window"
echo "2. Check if the HTML comment is still appearing"
echo "3. If it still appears, the issue is likely in The Events Calendar plugin itself"