#!/bin/bash

# Debug shortcode registration issue

echo "=== Debugging Shortcode Registration ==="

ssh roodev@146.190.76.204 << 'EOF'
cd /home/974670.cloudwaysapps.com/uberrxmprk/public_html

echo "1. Checking if Login_Handler file exists:"
ls -la wp-content/plugins/hvac-community-events/includes/community/class-login-handler.php

echo -e "\n2. Checking HVAC_Community_Events initialization:"
wp eval 'if (class_exists("HVAC_Community_Events")) { echo "✅ HVAC_Community_Events class exists\n"; } else { echo "❌ HVAC_Community_Events class NOT found\n"; }'

echo -e "\n3. Checking Login_Handler namespace:"
wp eval 'if (class_exists("\HVAC_Community_Events\Community\Login_Handler")) { echo "✅ Login_Handler class exists with namespace\n"; } else { echo "❌ Login_Handler class NOT found\n"; }'

echo -e "\n4. Manually testing shortcode registration:"
wp eval 'if (file_exists(HVAC_CE_PLUGIN_DIR . "includes/community/class-login-handler.php")) { require_once HVAC_CE_PLUGIN_DIR . "includes/community/class-login-handler.php"; $handler = new \HVAC_Community_Events\Community\Login_Handler(); echo "Login handler instantiated\n"; } else { echo "Login handler file not found\n"; }'

echo -e "\n5. Checking all registered shortcodes:"
wp eval 'global $shortcode_tags; echo "Total shortcodes: " . count($shortcode_tags) . "\n"; foreach($shortcode_tags as $tag => $callback) { if (strpos($tag, "hvac") !== false) { echo "- " . $tag . "\n"; } }'

echo -e "\n6. Check plugin constants:"
wp eval 'if (defined("HVAC_CE_PLUGIN_DIR")) { echo "HVAC_CE_PLUGIN_DIR: " . HVAC_CE_PLUGIN_DIR . "\n"; } else { echo "HVAC_CE_PLUGIN_DIR not defined\n"; }'

echo -e "\n7. Debug shortcode registration with error handling:"
wp eval '
try {
    $file = HVAC_CE_PLUGIN_DIR . "includes/community/class-login-handler.php";
    echo "Looking for file: " . $file . "\n";
    if (file_exists($file)) {
        echo "File exists, including...\n";
        require_once $file;
        echo "File included, creating instance...\n";
        $handler = new \HVAC_Community_Events\Community\Login_Handler();
        echo "Instance created\n";
        global $shortcode_tags;
        if (isset($shortcode_tags["hvac_community_login"])) {
            echo "✅ Shortcode registered successfully!\n";
        } else {
            echo "❌ Shortcode NOT registered after instantiation\n";
        }
    } else {
        echo "File does not exist at: " . $file . "\n";
    }
} catch (Exception $e) {
    echo "Exception: " . $e->getMessage() . "\n";
} catch (Error $e) {
    echo "Error: " . $e->getMessage() . "\n";
}
'
EOF