<?php
/**
 * Plugin deactivator.
 *
 * Runs when the plugin is deactivated. Clears transient cache so
 * stale metadata does not persist, but leaves user settings and
 * station presets intact in case the user reactivates.
 *
 * @package VMPlayer
 */

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

/**
 * Class VMPlayer_Deactivator
 */
class VMPlayer_Deactivator {

    /**
     * Main deactivation routine.
     *
     * @return void
     */
    public static function deactivate() {
        self::clear_transients();
        flush_rewrite_rules();
    }

    /**
     * Delete all VMPlayer transients from the options table.
     *
     * @return void
     */
    private static function clear_transients() {
        global $wpdb;

        $wpdb->query(
            $wpdb->prepare(
                "DELETE FROM {$wpdb->options} WHERE option_name LIKE %s OR option_name LIKE %s",
                $wpdb->esc_like( '_transient_vmplayer_' ) . '%',
                $wpdb->esc_like( '_transient_timeout_vmplayer_' ) . '%'
            )
        );
    }
}
