<?php
/**
 * Uninstall script 
 */

if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
    exit;
}

// Delete plugin options 
delete_option('ccspllms_version');
delete_option('ccspllms_enabled');
delete_option('ccspllms_post_types');
delete_option('ccspllms_excerpt_priority');
delete_option('ccspllms_word_limit');
delete_option('ccspllms_use_canonical');

// Clear scheduled cron job
$timestamp = wp_next_scheduled('ccspllms_generate_file');
if ($timestamp) {
    wp_unschedule_event($timestamp, 'ccspllms_generate_file');
}
wp_clear_scheduled_hook('ccspllms_generate_file');

// Drop tables 
global $wpdb;
$table_prefix = $wpdb->prefix;


$tables = array(
    $table_prefix . 'ccspllms_settings',
    $table_prefix . 'ccspllms_analytics',
    $table_prefix . 'ccspllms_generation_log',
    $table_prefix . 'ccspllms_bots'
);

foreach ($tables as $table) {
    $wpdb->query("DROP TABLE IF EXISTS {$table}");
}
