opticore/uninstall.php

58 lines
1.3 KiB
PHP

<?php
/**
* OptiCore Uninstall
*
* This file runs when the plugin is uninstalled (deleted).
*/
// If uninstall not called from WordPress, exit
if (!defined('WP_UNINSTALL_PLUGIN')) {
exit;
}
// Delete plugin options
delete_option('opticore_settings');
delete_option('opticore_last_optimization');
// Clear scheduled events
wp_clear_scheduled_hook('opticore_database_optimization');
// Delete cache directory and its contents
$cache_dir = WP_CONTENT_DIR . '/cache/opticore';
if (file_exists($cache_dir)) {
opticore_delete_directory($cache_dir);
}
/**
* Recursively delete a directory
*/
function opticore_delete_directory($dir) {
if (!file_exists($dir)) {
return;
}
$files = array_diff(scandir($dir), array('.', '..'));
foreach ($files as $file) {
$path = $dir . '/' . $file;
if (is_dir($path)) {
opticore_delete_directory($path);
} else {
unlink($path);
}
}
return rmdir($dir);
}
// Optional: Delete transients
global $wpdb;
$wpdb->query(
"DELETE FROM {$wpdb->options}
WHERE option_name LIKE '_transient_opticore_%'
OR option_name LIKE '_transient_timeout_opticore_%'"
);
// Optional: Clean up any custom database tables if you add them in the future
// $wpdb->query("DROP TABLE IF EXISTS {$wpdb->prefix}opticore_stats");