backup-backup
Last commit date
admin
5 months ago
analyst
5 months ago
includes
5 months ago
modules
5 months ago
backup-backup.php
5 months ago
composer.json
5 months ago
phpunit.xml
5 months ago
readme.txt
5 months ago
uninstall.php
5 months ago
uninstall.php
62 lines
| 1 | <?php |
| 2 | |
| 3 | // Namespace |
| 4 | namespace BMI\Plugin\Uninstaller; |
| 5 | |
| 6 | // Exit on direct access |
| 7 | if (!defined('ABSPATH')) exit; |
| 8 | |
| 9 | // Get config file |
| 10 | $configFile = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'backup-migration-config.php'; |
| 11 | |
| 12 | if (!file_exists($configFile)) { |
| 13 | return; |
| 14 | } |
| 15 | |
| 16 | $config = file_get_contents($configFile); |
| 17 | $config = json_decode(substr($config, 8), true); |
| 18 | |
| 19 | |
| 20 | $deleteBackups = $config['OTHER:UNINSTALL:BACKUPS']; |
| 21 | $deleteConfigs = $config['OTHER:UNINSTALL:CONFIGS']; |
| 22 | |
| 23 | |
| 24 | if ($deleteBackups === 'true' || $deleteBackups === true) { |
| 25 | $backupsPath = $config['STORAGE::LOCAL::PATH']; |
| 26 | $backupsPath = $backupsPath . DIRECTORY_SEPARATOR . 'backups'; |
| 27 | |
| 28 | if (file_exists($backupsPath) && is_dir($backupsPath)) { |
| 29 | |
| 30 | $files = scandir($backupsPath); |
| 31 | for ($i = 0; $i < sizeof($files); ++$i) { |
| 32 | |
| 33 | $file = $backupsPath . DIRECTORY_SEPARATOR . $files[$i]; |
| 34 | if (is_file($file) && !in_array($files[$i], ['.', '..'])) { |
| 35 | @unlink($file); |
| 36 | } |
| 37 | |
| 38 | } |
| 39 | |
| 40 | $files = scandir($backupsPath); |
| 41 | if (sizeof($files) <= 2) rmdir($backupsPath); |
| 42 | |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | if ($deleteConfigs === 'true' || $deleteConfigs === true) { |
| 47 | $configFile = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'backup-migration-config.php'; |
| 48 | |
| 49 | if (file_exists($configFile)) { |
| 50 | @unlink($configFile); |
| 51 | } |
| 52 | |
| 53 | global $wpdb; |
| 54 | |
| 55 | |
| 56 | $free_options = $wpdb->get_results( "SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%bmi_%' OR option_name LIKE '%bmip_%' OR option_name LIKE '%bmi_pro_%'" ); |
| 57 | |
| 58 | foreach( $free_options as $option ) { |
| 59 | delete_option( $option->option_name ); |
| 60 | } |
| 61 | |
| 62 | } |