<?php
/**
 * Uninstall Tryly.ai Plugin
 *
 * @package TrylyAI
 * @since 1.0.8
 */

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

// Remove plugin options
delete_option( 'tryly_connected' );
delete_option( 'tryly_version' );
delete_option( 'tryly_merchant_key' );
delete_option( 'tryly_user_email' );
delete_option( 'tryly_disconnect_token' );
delete_option( 'tryly_activation_redirect' );

// Remove transients
global $wpdb;
$wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_tryly_settings_%'" );
$wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_timeout_tryly_settings_%'" );
$wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_tryly_oauth_state_%'" );
$wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_timeout_tryly_oauth_state_%'" );

// Drop custom events table
$table_name = $wpdb->prefix . 'tryly_events';
$wpdb->query( "DROP TABLE IF EXISTS {$table_name}" );