TEC Community Events Debug Report\n";
echo "\n";
// Check 1: TEC Plugin Status
echo "
1. The Events Calendar Plugin Status
\n";
$tec_active = is_plugin_active('the-events-calendar/the-events-calendar.php');
$tec_ce_active = is_plugin_active('the-events-calendar-community-events/tribe-community-events.php');
echo "The Events Calendar: " . ($tec_active ? '✓ Active' : '✗ Not Active') . "
\n";
echo "TEC Community Events: " . ($tec_ce_active ? '✓ Active' : '✗ Not Active') . "
\n";
// Check if TEC classes/functions exist
$tec_functions = [
    'tribe_community_events_init' => function_exists('tribe_community_events_init'),
    'tribe_is_community_edit_event_page' => function_exists('tribe_is_community_edit_event_page'),
    'tribe_community_events_list' => function_exists('tribe_community_events_list'),
];
echo "TEC Functions Available:
\n";
foreach ($tec_functions as $func => $exists) {
    echo "$func(): " . ($exists ? '✓ Available' : '✗ Not Available') . "
\n";
}
// Check 2: Shortcode Registration
echo "2. Shortcode Registration Status
\n";
global $shortcode_tags;
$hvac_shortcodes = [
    'hvac_create_event',
    'hvac_edit_event',
    'tribe_community_events'
];
foreach ($hvac_shortcodes as $shortcode) {
    $registered = shortcode_exists($shortcode);
    echo "[$shortcode]: " . ($registered ? '✓ Registered' : '✗ Not Registered') . "
\n";
    
    if ($registered) {
        $callback = $shortcode_tags[$shortcode];
        if (is_array($callback)) {
            echo "Callback: " . get_class($callback[0]) . "::" . $callback[1] . "()
\n";
        } else {
            echo "Callback: $callback
\n";
        }
    }
}
// Check 3: HVAC Plugin Classes
echo "3. HVAC Plugin Classes
\n";
$hvac_classes = [
    'HVAC_Shortcodes',
    'HVAC_Edit_Event_Shortcode',
    'HVAC_Community_Events',
    'HVAC_Menu_System',
    'HVAC_Breadcrumbs'
];
foreach ($hvac_classes as $class) {
    $exists = class_exists($class);
    echo "$class: " . ($exists ? '✓ Available' : '✗ Not Available') . "
\n";
}
// Check 4: Current User Capabilities
echo "4. Current User Status
\n";
if (is_user_logged_in()) {
    $user = wp_get_current_user();
    echo "Logged in as: {$user->user_login} (ID: {$user->ID})
\n";
    echo "Roles: " . implode(', ', $user->roles) . "
\n";
    
    $capabilities = [
        'hvac_trainer',
        'hvac_master_trainer',
        'edit_tribe_events',
        'manage_options'
    ];
    
    echo "Capabilities:
\n";
    foreach ($capabilities as $cap) {
        $has_cap = current_user_can($cap);
        echo "$cap: " . ($has_cap ? '✓ Has Permission' : '✗ No Permission') . "
\n";
    }
} else {
    echo "⚠ Not logged in
\n";
}
// Check 5: Test Direct Shortcode Execution
echo "5. Direct Shortcode Testing
\n";
if (shortcode_exists('tribe_community_events')) {
    echo "Testing [tribe_community_events] directly:
\n";
    
    // Test basic shortcode
    ob_start();
    $basic_output = do_shortcode('[tribe_community_events]');
    $basic_errors = ob_get_clean();
    
    echo "Basic shortcode output:
\n";
    if (!empty($basic_errors)) {
        echo "PHP Errors/Warnings:" . esc_html($basic_errors) . "
 \n";
    }
    echo "" . substr(esc_html($basic_output), 0, 1000) . (strlen($basic_output) > 1000 ? '...' : '') . "
\n";
    
    // Test with submission_form view
    echo "Testing with view='submission_form':
\n";
    ob_start();
    $form_output = do_shortcode('[tribe_community_events view="submission_form"]');
    $form_errors = ob_get_clean();
    
    if (!empty($form_errors)) {
        echo "PHP Errors/Warnings:" . esc_html($form_errors) . "
 \n";
    }
    echo "" . substr(esc_html($form_output), 0, 1000) . (strlen($form_output) > 1000 ? '...' : '') . "
\n";
    
} else {
    echo "✗ [tribe_community_events] shortcode not available for testing
\n";
}
// Check 6: Test HVAC Shortcodes
echo "6. Testing HVAC Shortcodes
\n";
if (shortcode_exists('hvac_create_event')) {
    echo "Testing [hvac_create_event]:
\n";
    ob_start();
    $hvac_create_output = do_shortcode('[hvac_create_event]');
    $hvac_create_errors = ob_get_clean();
    
    if (!empty($hvac_create_errors)) {
        echo "PHP Errors/Warnings:" . esc_html($hvac_create_errors) . "
 \n";
    }
    echo "" . substr(esc_html($hvac_create_output), 0, 1000) . (strlen($hvac_create_output) > 1000 ? '...' : '') . "
\n";
} else {
    echo "✗ [hvac_create_event] shortcode not registered
\n";
}
if (shortcode_exists('hvac_edit_event')) {
    echo "Testing [hvac_edit_event]:
\n";
    ob_start();
    $hvac_edit_output = do_shortcode('[hvac_edit_event]');
    $hvac_edit_errors = ob_get_clean();
    
    if (!empty($hvac_edit_errors)) {
        echo "PHP Errors/Warnings:" . esc_html($hvac_edit_errors) . "
 \n";
    }
    echo "" . substr(esc_html($hvac_edit_output), 0, 1000) . (strlen($hvac_edit_output) > 1000 ? '...' : '') . "
\n";
} else {
    echo "✗ [hvac_edit_event] shortcode not registered
\n";
}
// Check 7: WordPress Error Log
echo "7. Recent WordPress Errors
\n";
$error_log_path = ini_get('error_log');
if (!$error_log_path) {
    $error_log_path = WP_CONTENT_DIR . '/debug.log';
}
if (file_exists($error_log_path)) {
    $recent_errors = shell_exec("tail -20 " . escapeshellarg($error_log_path));
    if ($recent_errors) {
        echo "Last 20 lines from error log:
\n";
        echo "" . esc_html($recent_errors) . "
\n";
    } else {
        echo "✓ No recent errors in log
\n";
    }
} else {
    echo "⚠ Error log not found at: $error_log_path
\n";
}
// Check 8: Plugin Activation Order
echo "8. Plugin Load Order Analysis
\n";
$active_plugins = get_option('active_plugins');
$hvac_plugin_found = false;
$tec_plugin_found = false;
echo "Active Plugins (in load order):
\n";
echo "\n";
foreach ($active_plugins as $plugin) {
    echo "- $plugin";
    if (strpos($plugin, 'hvac-community-events') !== false) {
        echo " (HVAC Plugin)";
        $hvac_plugin_found = true;
    } elseif (strpos($plugin, 'the-events-calendar') !== false) {
        echo " (TEC Plugin)";
        $tec_plugin_found = true;
    }
    echo "
\n";
}
echo "
\n";
if ($hvac_plugin_found && $tec_plugin_found) {
    echo "✓ Both HVAC and TEC plugins are active
\n";
} else {
    echo "✗ Missing required plugins
\n";
}
echo "Debugging Complete
\n";
echo "If issues persist, check the WordPress admin > Plugins page to ensure both 'The Events Calendar' and 'The Events Calendar Community Events' are properly activated.
\n";