#!/bin/bash

echo "=== Fixing Escaped HTML Comments in Page Content ==="

# Function to fix escaped HTML comments in database
fix_escaped_comments() {
    echo "Connecting to staging server..."
    
    # Update the manage event page content
    ssh roodev@146.190.76.204 << 'EOF'
    cd /home/974670.cloudwaysapps.com/uberrxmprk/public_html
    
    echo "Updating Manage Event page content..."
    wp post update 5344 --post_content='<div class="hvac-event-manage-header">
    <h2>Create and Manage Your HVAC Training Events</h2>
    <p>Use this form to create new training events or edit existing ones. Please fill out all required fields to ensure your event is properly listed and attendees receive accurate information.</p>
    <div class="hvac-event-manage-tips">
        <h3>Event Creation Tips:</h3>
        <ul>
            <li><strong>Event Title:</strong> Use a clear, descriptive title that indicates the training topic</li>
            <li><strong>Date & Time:</strong> Ensure you select the correct timezone for your location</li>
            <li><strong>Description:</strong> Provide detailed information about what attendees will learn</li>
            <li><strong>Capacity:</strong> Set an appropriate maximum number of attendees</li>
        </ul>
    </div>
    <hr style="margin: 20px 0;">
</div>
[tribe_community_events view="submission_form"]'
    
    # Check for other pages with escaped HTML comments
    echo "Checking for other pages with escaped HTML comments..."
    wp db query "SELECT ID, post_title FROM wp_posts WHERE post_type='page' AND post_content LIKE '%<\\\\!--%' AND post_status='publish'" --skip-column-names
    
    # Clear caches
    echo "Clearing caches..."
    wp cache flush
    wp breeze purge --cache=all
EOF
}

# Run the fix
fix_escaped_comments

echo ""
echo "=== Fix Complete ==="
echo "The escaped HTML comments have been removed from the page content."
echo "This script can be run again if the issue reoccurs."