<?php

/**
 * @package CsvImporterPlusforACF
 *
 * Triger this file to uninstall plugin
 *
 */

// make sure this file called by wordpress only
if (!defined('WP_UNINSTALL_PLUGIN')) {
    die;
}

// Remove custom capability from all roles
global $wp_roles;
if (!isset($wp_roles)) {
    $wp_roles = new WP_Roles();
}
foreach ($wp_roles->roles as $cipfa_role_name => $cipfa_role_info) {
    $role = get_role($cipfa_role_name);
    if ($role && $role->has_cap('cipfa_import_data')) {
        $role->remove_cap('cipfa_import_data');
    }
}

// Clean up options
$cipfa_options = [
    'cipfa_total_imported_so_far',
    'cipfa_import_completed',
    'cipfa_enable_log',
    'cipfa_flush_cache',
    'cipfa_replace_categories',
    'cipfa_replace_tags',
    'cipfa_replace_custom_taxonomies',
    'cipfa_duplicate_media_path',
    'cipfa_current_log_path',
    'cipfa_imported_categories',
    'cipfa_imported_tags',
    'cipfa_imported_custom_taxonomies',
    'cipfa_imported_user',
    'cipfa_csv_file_path',
];

foreach ($cipfa_options as $cipfa_option) {
    if (get_option($cipfa_option) !== false) {
        delete_option($cipfa_option);
    }
}
