<?php
/**
 * Fired when the plugin is uninstalled.
 *
 * @package AdminLoginGuardBranding
 */

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

$admilogu_options = [
    'admilogu_login_slug',
    'admilogu_enable_custom_login',
    'admilogu_logo_url',
    'admilogu_hide_logo',
    'admilogu_logo_width',
    'admilogu_logo_height',
    'admilogu_logo_title',
    'admilogu_logo_link',
    'admilogu_logo_target_blank',
    'admilogu_logo_bg_color',
    'admilogu_bg_type',
    'admilogu_bg_image',
    'admilogu_bg_video',
    'admilogu_bg_video_mute',
    'admilogu_bg_color',
    'admilogu_center_form',
    'admilogu_loginform_bg_color',
    'admilogu_loginform_border_color',
    'admilogu_loginform_label_color',
    'admilogu_lostpwd_color',
    'admilogu_lostpwd_hover_color',
    'admilogu_backtoblog_color',
    'admilogu_backtoblog_hover_color',
    'admilogu_btn_bg_color',
    'admilogu_btn_text_color',
    'admilogu_btn_bg_hover_color',
    'admilogu_btn_text_hover_color',
    'admilogu_enable_2fa',
    'admilogu_custom_css',
    'admilogu_custom_js',
    'admilogu_custom_font',
    'admilogu_custom_footer',
    'admilogu_max_attempts',
    'admilogu_lockout_duration',
    'admilogu_ip_whitelist',
    'admilogu_ip_blacklist',
    'admilogu_notify_admin_lockout',
    'admilogu_notify_user_new_ip',
    'admilogu_block_shortcuts',
    'admilogu_hide_backtoblog',
    'admilogu_fail_redirect_page',
    'admilogu_tracking_optin',
    'admilogu_plugin_version',
];

// Delete options.
foreach ($admilogu_options as $admilogu_option) {
    delete_option($admilogu_option);
}

// For multisite, delete options from all sites.
if (is_multisite()) {
    $admilogu_sites = get_sites();
    foreach ($admilogu_sites as $admilogu_site) {
        switch_to_blog($admilogu_site->blog_id);
        foreach ($admilogu_options as $admilogu_option) {
            delete_option($admilogu_option);
        }

        // Drop the table.
        global $wpdb;
        $admilogu_table_name = $wpdb->prefix . 'admilogu_login_history';
        // phpcs:ignore WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, PluginCheck.Security.DirectDB.UnescapedDBParameter
        $wpdb->query("DROP TABLE IF EXISTS $admilogu_table_name");

        restore_current_blog();
    }
} else {
    // Drop the table.
    global $wpdb;
    $admilogu_table_name = $wpdb->prefix . 'admilogu_login_history';
    // phpcs:ignore WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, PluginCheck.Security.DirectDB.UnescapedDBParameter
    $wpdb->query("DROP TABLE IF EXISTS $admilogu_table_name");
}
