<?php
/**
 * Plugin deactivation handler.
 *
 * @package MasterQuiz
 * @since   1.0.0
 */

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

/**
 * Class MasterQuiz_Deactivator
 *
 * Handles tasks that run on plugin deactivation.
 *
 * @since 1.0.0
 */
class MasterQuiz_Deactivator {

	/**
	 * Run deactivation tasks.
	 *
	 * Unschedules all cron events. Does NOT delete data — that's done in uninstall.php.
	 *
	 * @since 1.0.0
	 */
	public static function deactivate() {
		// Unschedule all plugin cron events.
		$cron_hooks = array(
			'masterquiz_process_job',
			'masterquiz_cleanup_uploads',
		);

		foreach ( $cron_hooks as $hook ) {
			$timestamp = wp_next_scheduled( $hook );
			if ( $timestamp ) {
				wp_unschedule_event( $timestamp, $hook );
			}
			wp_clear_scheduled_hook( $hook );
		}
	}
}
