<?php

/**
 * Fired during plugin deactivation
 *
 * @link       https://wedima.de
 * @since      1.0.0
 *
 * @package    Wedima_Site
 * @subpackage Wedima_Site/includes
 */

/**
 * Fired during plugin deactivation.
 *
 * This class defines all code necessary to run during the plugin's deactivation.
 *
 * @since      1.0.0
 * @package    Wedima_Site
 * @subpackage Wedima_Site/includes
 * @author     Jitendra Bodmann <jitendra.bodmann@wedima.de>
 */
class Wedima_Site_Deactivator
{

	/**
	 * Short Description. (use period)
	 *
	 * Long Description.
	 *
	 * @since    1.0.0
	 */
	public static function deactivate()
	{
		if (get_option('wedima_site_purge_on_uninstall', 0) == 1) {
			self::delete_all_options();
		}
	}

	/**
	 * Deletes and removes all options and unregister the settings
	 * Copy the code block from admin/class-wedima-site-admin.php and rename add and remove to delete and unregister
	 *
	 * @return void
	 */
	static function delete_all_options()
	{
		// general plugin related settings
		delete_option('wedima_site_purge_on_uninstall', 0); // this setting is used in the includes/class-plugin-name-deactivator.php
		unregister_setting('wedima_site_options_group', 'wedima_site_purge_on_uninstall');

		// site options
		$site_options = array(
			['wedima_site_client_name', 'Wedima'],
			['wedima_site_enable_login_language_switcher', 0],
			['wedima_site_disable_mail_templates', 0],
		);
		foreach ($site_options as $option) {
			delete_option($option[0], $option[1]);
			unregister_setting('wedima_site_site_options_options_group', $option[0]);
		}

		// maintenance settings
		delete_option('wedima_site_maintenance_mode', 0);
		unregister_setting('wedima_site_maintenance_options_group', 'wedima_site_maintenance_mode');
	}
}
