<?php
/**
 * Uninstall script for PDF Smart Viewer for Elementor
 *
 * This file is executed when the plugin is deleted from WordPress admin.
 * It removes all plugin data including options and settings.
 *
 * @package PDFSmartViewerElementor
 * @version 1.0.0
 */

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

// Remove plugin options
delete_option('pdfsmvif_default_zoom');
delete_option('pdfsmvif_enable_download');
delete_option('pdfsmvif_enable_fullscreen');
delete_option('pdfsmvif_enable_print');
delete_option('pdfsmvif_enable_zoom_controls');
delete_option('pdfsmvif_enable_page_info');
delete_option('pdfsmvif_default_height');

// Remove any transients
delete_transient('pdfsmvif_version_check');

// Clear any cached data
wp_cache_flush();

// Remove any custom database tables if they exist
global $wpdb;

// Example: Remove custom table if it exists
// $table_name = $wpdb->prefix . 'epsv_logs';
// $wpdb->query("DROP TABLE IF EXISTS $table_name");

// Clear any scheduled events
wp_clear_scheduled_hook('epsv_cleanup_task');

// Remove any custom post types if they exist
// $post_types = array('epsv_document');
// foreach ($post_types as $post_type) {
//     $items = get_posts(array(
//         'post_type' => $post_type,
//         'post_status' => 'any',
//         'numberposts' => -1,
//         'fields' => 'ids'
//     ));
//     foreach ($items as $item) {
//         wp_delete_post($item, true);
//     }
// }

// Remove any custom taxonomies if they exist
// $terms = get_terms(array(
//     'taxonomy' => 'epsv_category',
//     'hide_empty' => false,
// ));
// foreach ($terms as $term) {
//     wp_delete_term($term->term_id, 'epsv_category');
// }

// Log the uninstall for debugging purposes
// if (defined('WP_DEBUG') && WP_DEBUG) {
//     error_log('PDF Smart Viewer for Elementor plugin uninstalled successfully');
// } 