<?php
/**
 * Remove plugin-owned data after an administrator uninstalls the plugin.
 *
 * @package SwairishXHeaderBarNotificationOffer
 */

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

global $wpdb;
$swairishx_campaign_ids = get_posts(array('post_type' => 'swairishx_campaign', 'post_status' => 'any', 'numberposts' => -1, 'fields' => 'ids'));
foreach ($swairishx_campaign_ids as $swairishx_campaign_id) {
    wp_delete_post($swairishx_campaign_id, true);
}
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.DirectDatabaseQuery.SchemaChange -- Uninstall removes plugin-owned tables.
$wpdb->query($wpdb->prepare('DROP TABLE IF EXISTS %i', $wpdb->prefix . 'swairishx_events'));
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.DirectDatabaseQuery.SchemaChange -- Uninstall removes plugin-owned tables.
$wpdb->query($wpdb->prepare('DROP TABLE IF EXISTS %i', $wpdb->prefix . 'swairishx_stats'));
delete_option('swairishx_brand_name');
wp_clear_scheduled_hook('swairishx_cleanup');
wp_clear_scheduled_hook('swairishx_sync_wordpress_org');
