<?php
/**
 * FAQ Magic Uninstall
 *
 * This file runs when the plugin is deleted from the WordPress dashboard.
 *
 * @package FAQ_Magic
 */

// If uninstall not called from WordPress, exit.
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
    exit;
}

// Only proceed if the user enabled "Clean data on uninstall"
if ( get_option( 'qcld_faq_cleanup_on_uninstall' ) === '1' ) {
    
    global $wpdb;

    // 1. Remove all FAQ metadata from every post and page
    // Using a direct query for high performance across large sites
    $wpdb->query( "DELETE FROM {$wpdb->postmeta} WHERE meta_key LIKE '_qcld_faq_data_%'" );

    // 2. Remove all global settings options
    $options = array(
        'qcld_faq_primary_color',
        'qcld_faq_header_text_color',
        'qcld_faq_content_text_color',
        'qcld_faq_default_style',
        'qcld_faq_open_first',
        'qcld_faq_ai_meta_enabled',
        'qcld_faq_ai_author',
        'qcld_faq_ai_org',
        'qcld_faq_ignore_webpage_schema',
        'qcld_faq_auto_webpage_schema',
        'qcld_faq_use_excerpt_as_desc',
        'qcld_faq_disable_schema_globally',
        'qcld_faq_cleanup_on_uninstall'
    );

    foreach ( $options as $option ) {
        delete_option( $option );
    }

}
