| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- /**
- * Fired when the plugin is uninstalled.
- *
- * @package QDR_Temporary_Shared_Storage
- * @since 1.0.0
- */
- // If uninstall not called from WordPress, then exit.
- if (!defined('WP_UNINSTALL_PLUGIN')) {
- exit;
- }
- // Define constants if not already defined
- if (!defined('QDR_TSS_PLUGIN_TABLE')) {
- define('QDR_TSS_PLUGIN_TABLE', 'qdr_temporary_shared_storage');
- }
- if (!defined('QDR_TSS_UPLOADS_DIR')) {
- $uploads_dir = wp_upload_dir();
- define('QDR_TSS_UPLOADS_DIR', $uploads_dir['basedir'] . '/qdr-shared-storage/');
- }
- // Delete plugin settings
- delete_option('qdr_tss_settings');
- delete_option('qdr_tss_version');
- // Drop custom database table
- global $wpdb;
- $table_name = $wpdb->prefix . QDR_TSS_PLUGIN_TABLE;
- $wpdb->query("DROP TABLE IF EXISTS $table_name");
- // Delete all files in upload directory
- function qdr_tss_delete_directory($dir) {
- if (!file_exists($dir)) {
- return true;
- }
-
- if (!is_dir($dir)) {
- return unlink($dir);
- }
-
- foreach (scandir($dir) as $item) {
- if ($item == '.' || $item == '..') {
- continue;
- }
-
- if (!qdr_tss_delete_directory($dir . DIRECTORY_SEPARATOR . $item)) {
- return false;
- }
- }
-
- return rmdir($dir);
- }
- // Delete upload directory
- qdr_tss_delete_directory(QDR_TSS_UPLOADS_DIR);
- // Delete download page
- $download_page = get_page_by_path('shared-file-download');
- if ($download_page) {
- wp_delete_post($download_page->ID, true);
- }
- // Clear scheduled tasks
- $timestamp = wp_next_scheduled('qdr_tss_purge_expired_files');
- if ($timestamp) {
- wp_unschedule_event($timestamp, 'qdr_tss_purge_expired_files');
- }
- // Clear any transients
- $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_qdr_tss_%'");
- $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_timeout_qdr_tss_%'");
|