<?php
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- direct DB calls required for Instinctor standalone database driver

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

// Remove custom roles
remove_role('instinctor_chat_agent');
remove_role('instinctor_store_manager');

// Remove capabilities from administrator
$instinctor_admin = get_role('administrator');
if ($instinctor_admin) {
    foreach (['instinctor_access', 'instinctor_chat', 'instinctor_chat_settings', 'instinctor_store', 'instinctor_impulse', 'instinctor_settings'] as $instinctor_cap) {
        $instinctor_admin->remove_cap($instinctor_cap);
    }
}

global $wpdb;
$wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'instinctor_%'" );