Files
2026-03-18 14:21:32 -07:00

61 lines
1.4 KiB
PHP

<?php
/**
* Uninstall WP to HTML
*
* This file runs when the plugin is deleted from WordPress.
* It removes all plugin data including cached files and database options.
*/
// If uninstall not called from WordPress, exit
if (!defined('WP_UNINSTALL_PLUGIN')) {
exit;
}
// Define cache directory path
$cache_dir = WP_CONTENT_DIR . '/cache/wp-to-html/';
/**
* Recursively delete a directory and its contents
*
* @param string $dir Directory path
*/
function wp_to_html_recursive_delete($dir) {
if (!is_dir($dir)) {
return;
}
$files = array_diff(scandir($dir), array('.', '..'));
foreach ($files as $file) {
$path = $dir . '/' . $file;
if (is_dir($path)) {
wp_to_html_recursive_delete($path);
} else {
unlink($path);
}
}
rmdir($dir);
}
// Delete cache directory and all contents
if (file_exists($cache_dir)) {
wp_to_html_recursive_delete($cache_dir);
}
// Delete plugin options
delete_option('wp_to_html_settings');
delete_option('wp_to_html_last_cron_run');
// Clear any scheduled cron events
$cron_hook = 'wp_to_html_scheduled_regeneration';
$timestamp = wp_next_scheduled($cron_hook);
if ($timestamp) {
wp_unschedule_event($timestamp, $cron_hook);
}
wp_clear_scheduled_hook($cron_hook);
// Clear the single regeneration events
wp_clear_scheduled_hook('wp_to_html_regenerate_post');