<?php
/**
 * Debug helper for WP Registration Plugin
 * Add this to wp-config.php to enable: define('WPR_DEBUG_INSTALL', true);
 */

if (defined('WPR_DEBUG_INSTALL') && WPR_DEBUG_INSTALL) {
    
    add_action('admin_notices', 'wpr_debug_installation_status');
    
    function wpr_debug_installation_status() {
        if (!current_user_can('manage_options')) return;
        
        $default_form_id = get_option('wpr_default_signup_form');
        $is_installed = get_option('wpr_is_installed');
        $cpt_exists = post_type_exists('wpr');
        
        echo '<div class="notice notice-info">';
        echo '<h3>WP Registration Debug Info</h3>';
        echo '<p><strong>Default Form ID:</strong> ' . ($default_form_id ? $default_form_id : 'Not set') . '</p>';
        echo '<p><strong>Installation Status:</strong> ' . ($is_installed ? 'Installed' : 'Not installed') . '</p>';
        echo '<p><strong>CPT Registered:</strong> ' . ($cpt_exists ? 'Yes' : 'No') . '</p>';
        
        if ($default_form_id) {
            $form_exists = get_post($default_form_id);
            echo '<p><strong>Form Exists:</strong> ' . ($form_exists ? 'Yes' : 'No') . '</p>';
            if ($form_exists) {
                echo '<p><strong>Form Title:</strong> ' . $form_exists->post_title . '</p>';
                echo '<p><strong>Form Status:</strong> ' . $form_exists->post_status . '</p>';
            }
        }
        
        // Show all WPR forms
        $forms = get_posts(array('post_type' => 'wpr', 'numberposts' => -1));
        echo '<p><strong>Total WPR Forms:</strong> ' . count($forms) . '</p>';
        
        if ($forms) {
            echo '<ul>';
            foreach ($forms as $form) {
                echo '<li>ID: ' . $form->ID . ' - ' . $form->post_title . ' (' . $form->post_status . ')</li>';
            }
            echo '</ul>';
        }
        
        echo '<p><a href="' . admin_url('edit.php?post_type=wpr') . '">View All Forms</a></p>';
        echo '</div>';
    }
}
?>
