<?php
/**
 * Fired when the plugin is uninstalled.
 *
 * @since      1.0.0
 * @package    Subscription_System
 */

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

// Delete options
delete_option('ss_settings');
delete_option('ss_subscription_plans');

// Drop custom tables
global $wpdb;
$wpdb->query("DROP TABLE IF EXISTS {$wpdb->prefix}subscriptions");

// Clear any cached data that has been removed
wp_cache_flush();

// Delete custom post types and their data
$posts = get_posts( array(
    'post_type'   => 'my_custom_post_type',
    'numberposts' => -1,
) );

foreach ( $posts as $post ) {
    wp_delete_post( $post->ID, true );
}

// Drop custom database tables
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}my_plugin_table" ); 