<?php
/**
 * Remove LocalGuard Scanner data.
 *
 * @package LocalGuardScanner
 */

defined( 'WP_UNINSTALL_PLUGIN' ) || exit;

global $wpdb;

$localguard_scanner_tables = array(
	$wpdb->base_prefix . 'lgs_scans',
	$wpdb->base_prefix . 'lgs_inventory',
	$wpdb->base_prefix . 'lgs_findings',
	$wpdb->base_prefix . 'lgs_suppressions',
);

foreach ( $localguard_scanner_tables as $localguard_scanner_table ) {
	// Table names are constructed exclusively from WordPress's trusted base prefix and fixed suffixes.
	$wpdb->query( "DROP TABLE IF EXISTS `{$localguard_scanner_table}`" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.DirectDatabaseQuery.SchemaChange,WordPress.DB.PreparedSQL.InterpolatedNotPrepared
}

delete_site_option( 'lgs_schema_version' );
delete_site_option( 'lgs_network_activated' );
delete_site_option( 'localguard_scanner_settings' );
delete_site_option( 'localguard_scanner_lock' );
delete_site_option( 'lgs_last_cron_error' );

foreach ( array( 'lgs_daily_scan', 'lgs_continue_scan', 'lgs_cleanup' ) as $localguard_scanner_hook ) {
	wp_clear_scheduled_hook( $localguard_scanner_hook );
}

$localguard_scanner_role = get_role( 'administrator' );
if ( $localguard_scanner_role ) {
	$localguard_scanner_role->remove_cap( 'manage_localguard_scanner' );
}
