<?php
/**
 * Uninstall handler — runs when the plugin is deleted via the WordPress admin.
 *
 * Removes the custom database table and plugin options.
 *
 * @package Smart_Product_Sort
 */

// Exit if not called by WordPress.
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
	exit;
}

global $wpdb;

// Remove the custom sort rules table.
$table = $wpdb->prefix . 'spsort_sort_rules';

// Uninstall-only query — no caching applicable; table is being removed.
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange
$wpdb->query( $wpdb->prepare( 'DROP TABLE IF EXISTS %i', $table ) );

// Remove plugin options.
delete_option( 'spsort_version' );
