| 1 |
<?php |
| 2 |
defined('ABSPATH') || exit; |
| 3 |
|
| 4 |
if(!class_exists('Vision_Deactivator')) : |
| 5 |
|
| 6 |
class Vision_Deactivator { |
| 7 |
public function deactivate() { |
| 8 |
global $wpdb; |
| 9 |
$table = $wpdb->prefix . VISION_PLUGIN_NAME; |
| 10 |
|
| 11 |
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching |
| 12 |
$count = $wpdb->get_var( "SELECT COUNT(*) FROM {$table}" ); |
| 13 |
// phpcs:enable |
| 14 |
|
| 15 |
if($count > 0) { |
| 16 |
return; |
| 17 |
} |
| 18 |
|
| 19 |
// delete all if our tables are empty |
| 20 |
$table = $wpdb->prefix . VISION_PLUGIN_NAME; |
| 21 |
|
| 22 |
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange |
| 23 |
$wpdb->query( "DROP TABLE IF EXISTS {$table}" ); |
| 24 |
// phpcs:enable |
| 25 |
|
| 26 |
delete_option('vision_db_version'); |
| 27 |
delete_option('vision_activated'); |
| 28 |
delete_option('vision_settings'); |
| 29 |
|
| 30 |
$this->delete_files(VISION_PLUGIN_UPLOAD_DIR . '/'); |
| 31 |
} |
| 32 |
|
| 33 |
private function delete_files($target) { |
| 34 |
if(is_dir($target)) { |
| 35 |
$files = glob($target . '*', GLOB_MARK); //GLOB_MARK adds a slash to directories returned |
| 36 |
foreach($files as $file) { |
| 37 |
$this->delete_files($file); |
| 38 |
} |
| 39 |
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_rmdir |
| 40 |
rmdir($target); |
| 41 |
} else if(is_file($target)) { |
| 42 |
wp_delete_file($target); |
| 43 |
} |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
endif; |