<?php
/**
 * Uninstall WP Shieldon plugin
 *
 * @author Terry Lin
 * @link https://terryl.in
 *
 * @package Shieldon
 * @since 1.0.0
 * @version 1.6.1
 */

// if uninstall.php is not called by WordPress, die.
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
	die;
}

/**
 * Remove settings generated by Shieldon.
 */
$options_names = array(
	'shieldon_daemon',
	'shieldon_component',
	'shieldon_filter',
	'shieldon_captcha',
	'shieldon_wp_tweak',
	'shieldon_ip_global',
	'shieldon_ip_login',
	'shieldon_ip_signup',
	'shieldon_ip_xmlrpc',
	'shieldon_authetication',
	'shieldon_xss_protected_type',
	'shieldon_xss_protected_list',
	'wpso_channel_id',
	'wpso_driver_hash',
	'wpso_lang_code',
	'wpso_driver_reset',
	'wpso_update_notice',
);

foreach ( $options_names as $option_name ) {
	delete_option( $option_name );
	delete_site_option( $option_name );
}

/**
 * Remove logs files generated by Shieldon.
 *
 * [data driver: file, sqlite]
 */
$shieldon_dir = WP_CONTENT_DIR . '/uploads/wp-shieldon';

if ( file_exists( $shieldon_dir ) ) {
	$it    = new RecursiveDirectoryIterator( $shieldon_dir, RecursiveDirectoryIterator::SKIP_DOTS );
	$files = new RecursiveIteratorIterator( $it, RecursiveIteratorIterator::CHILD_FIRST );

	foreach ( $files as $file ) {
		if ( $file->isDir() ) {
			rmdir( $file->getRealPath() );
		} else {
			unlink( $file->getRealPath() );
		}
	}
	unset( $it, $files );

	if ( is_dir( $shieldon_dir ) ) {
		rmdir( $shieldon_dir );
	}
}
