media-cleaner
Last commit date
app
1 month ago
classes
1 month ago
common
1 month ago
languages
1 year ago
logs
6 years ago
media-cleaner.php
1 month ago
readme.txt
1 month ago
uninstall.php
1 month ago
uninstall.php
60 lines
| 1 | <?php |
| 2 | if ( !defined( 'WP_UNINSTALL_PLUGIN' ) ) { |
| 3 | die; |
| 4 | } |
| 5 | |
| 6 | // Get option to check if clean uninstall is enabled |
| 7 | $options = get_option( 'wpmc_options', [] ); |
| 8 | $clean_uninstall = isset( $options['clean_uninstall'] ) ? $options['clean_uninstall'] : false; |
| 9 | |
| 10 | if ( $clean_uninstall ) { |
| 11 | global $wpdb; |
| 12 | $table_scan = $wpdb->prefix . 'mclean_scan'; |
| 13 | $table_exists = $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $table_scan ) ) ) === $table_scan; |
| 14 | $quarantined = 0; |
| 15 | if ( $table_exists ) { |
| 16 | $has_run_id = $wpdb->get_var( "SHOW COLUMNS FROM $table_scan LIKE 'run_id'" ) === 'run_id'; |
| 17 | if ( $has_run_id ) { |
| 18 | $tracked_run_id = max( 0, (int) get_option( 'wpmc_active_run_id', 0 ) ); |
| 19 | if ( $tracked_run_id < 1 ) { |
| 20 | $tracked_run_id = max( 0, (int) $wpdb->get_var( "SELECT MAX(run_id) FROM $table_scan" ) ); |
| 21 | } |
| 22 | $quarantined = (int) $wpdb->get_var( $wpdb->prepare( |
| 23 | "SELECT COUNT(*) FROM $table_scan WHERE run_id = %d AND deleted = 1", |
| 24 | $tracked_run_id |
| 25 | ) ); |
| 26 | } |
| 27 | else { |
| 28 | $quarantined = (int) $wpdb->get_var( "SELECT COUNT(*) FROM $table_scan WHERE deleted = 1" ); |
| 29 | } |
| 30 | } |
| 31 | if ( $quarantined > 0 ) { |
| 32 | wp_die( |
| 33 | sprintf( |
| 34 | __( 'Media Cleaner still has %d item(s) in its trash. Restore them or empty the trash before uninstalling so no files are stranded.', 'media-cleaner' ), |
| 35 | $quarantined |
| 36 | ), |
| 37 | __( 'Media Cleaner uninstall blocked', 'media-cleaner' ), |
| 38 | array( 'response' => 409, 'back_link' => true ) |
| 39 | ); |
| 40 | } |
| 41 | |
| 42 | delete_transient( 'wpmc_progress' ); |
| 43 | |
| 44 | // Remove all wpmc options |
| 45 | $option_pattern = $wpdb->esc_like( 'wpmc_' ) . '%'; |
| 46 | $db_options = $wpdb->get_results( $wpdb->prepare( "SELECT option_name FROM $wpdb->options WHERE option_name LIKE %s", $option_pattern ) ); |
| 47 | foreach ( $db_options as $option ) { |
| 48 | delete_option( $option->option_name ); |
| 49 | } |
| 50 | |
| 51 | // Remove database tables |
| 52 | $table_refs = $wpdb->prefix . "mclean_refs"; |
| 53 | $table_legacy = $wpdb->prefix . "wpmcleaner"; |
| 54 | $table_runs = $wpdb->prefix . 'mclean_runs'; |
| 55 | $table_work = $wpdb->prefix . 'mclean_work'; |
| 56 | $table_operations = $wpdb->prefix . 'mclean_operations'; |
| 57 | $table_duplicates = $wpdb->prefix . 'mclean_duplicates'; |
| 58 | $wpdb->query( "DROP TABLE IF EXISTS $table_scan, $table_refs, $table_legacy, $table_runs, $table_work, $table_operations, $table_duplicates" ); |
| 59 | } |
| 60 |