<?php
/**
 * MindWebConcierge Plugin Uninstall Handler
 *
 * Runs only when the plugin is deleted from WordPress admin.
 *
 * @package MindWebConcierge
 */

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

global $wpdb;

$tables = array(
	$wpdb->prefix . 'mindweco_indexed_items',
	$wpdb->prefix . 'mindweco_conversations',
	$wpdb->prefix . 'mindweco_questions',
	$wpdb->prefix . 'mindweco_responses',
	$wpdb->prefix . 'mindweco_indexed_products',
	$wpdb->prefix . 'mindweco_indexed_media_files',
);

foreach ( $tables as $table ) {
	$wpdb->query( 'DROP TABLE IF EXISTS `' . esc_sql( $table ) . '`' ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
}

// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching
$wpdb->query(
	$wpdb->prepare(
		"DELETE FROM {$wpdb->options} WHERE option_name LIKE %s",
		'%mindweco%'
	)
);

wp_clear_scheduled_hook( 'mindweco_cleanup_transients' );