<?php

/**
 * LolaCore � Deactivation
 *
 * @package LolaCore
 * @license GPL-2.0-or-later
 */

declare(strict_types=1);

namespace LolaCore;

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

class Deactivation
{
    /**
     * Run deactivation procedures (non-destructive).
     */
    public static function run(): void
    {
        // Clear scheduled WP-Cron events
        wp_clear_scheduled_hook('lolacore_daily_decay');
        wp_clear_scheduled_hook('lolacore_log_cleanup');

        // Clear plugin transients
        global $wpdb;
        // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter -- Deactivation cleanup.
        $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE '\_transient\_lolacore\_%'");
        // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter -- Deactivation cleanup.
        $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE '\_transient\_timeout\_lolacore\_%'");

        // Flush rewrite rules
        flush_rewrite_rules();
    }
}
