<?php

/**
 * Fired when the plugin is uninstalled.
 *
 * @link       https://list2play.net
 * @since      1.1.0
 *
 * @package    List2Play_Servers
 */

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

// Delete all plugin options
$list2play_options = [
    'list2play_api_base_url',
    'list2play_api_token',
    'list2play_cache_duration',
    'list2play_default_per_page',
    'list2play_default_style_preset',
    'list2play_selected_server_ids',
    'list2play_server_order',
    'list2play_show_hostname',
    'list2play_show_status',
    'list2play_show_address',
    'list2play_show_game',
    'list2play_show_region',
    'list2play_show_players',
    'list2play_show_map',
    'list2play_show_votes',
    'list2play_show_chart',
    'list2play_show_stats',
    'list2play_show_vote_button',
    'list2play_send_metadata',
];

foreach ($list2play_options as $list2play_option) {
    delete_option($list2play_option);
}

// Delete all transients
// Direct DB query is acceptable in uninstall.php for cleanup purposes
global $wpdb;
$wpdb->query( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
    $wpdb->prepare(
        "DELETE FROM {$wpdb->options} WHERE option_name LIKE %s OR option_name LIKE %s",
        $wpdb->esc_like('_transient_list2play_') . '%',
        $wpdb->esc_like('_transient_timeout_list2play_') . '%'
    )
);

