| 1 |
<?php |
| 2 |
/** |
| 3 |
* Handles plugin uninstall. |
| 4 |
* |
| 5 |
* @package Custom_404_Pro |
| 6 |
*/ |
| 7 |
|
| 8 |
/** |
| 9 |
* Uninstall class. |
| 10 |
*/ |
| 11 |
class UninstallClass { |
| 12 |
|
| 13 |
/** |
| 14 |
* Removes all plugin data on uninstall. |
| 15 |
* |
| 16 |
* On Multisite, data is removed from every site in the network. On single-site |
| 17 |
* installs the cleanup runs once for the current site. |
| 18 |
*/ |
| 19 |
public static function uninstall() { |
| 20 |
if ( is_multisite() ) { |
| 21 |
$sites = get_sites( array( 'fields' => 'ids' ) ); |
| 22 |
foreach ( $sites as $blog_id ) { |
| 23 |
switch_to_blog( $blog_id ); |
| 24 |
self::cleanup_site(); |
| 25 |
restore_current_blog(); |
| 26 |
} |
| 27 |
} else { |
| 28 |
self::cleanup_site(); |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* Removes all plugin data for the current site. |
| 34 |
* |
| 35 |
* Drops the logs table, deletes the settings and db-version entries from |
| 36 |
* wp_options, and drops the legacy options table if the migration had not |
| 37 |
* run before uninstall. |
| 38 |
*/ |
| 39 |
private static function cleanup_site() { |
| 40 |
global $wpdb; |
| 41 |
|
| 42 |
// Remove plugin settings, migration marker, and transients from wp_options. |
| 43 |
delete_option( Helpers::OPTION_KEY ); |
| 44 |
delete_option( 'custom_404_pro_db_version' ); |
| 45 |
delete_transient( 'custom_404_pro_email_cooldown' ); |
| 46 |
wp_unschedule_hook( 'custom_404_pro_prune_logs' ); |
| 47 |
|
| 48 |
// Drop the logs table. |
| 49 |
$table_logs = $wpdb->prefix . 'custom_404_pro_logs'; |
| 50 |
$wpdb->query( 'DROP TABLE IF EXISTS ' . $table_logs ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching |
| 51 |
|
| 52 |
// Drop the legacy options table if the migration had not run yet. |
| 53 |
$table_options = $wpdb->prefix . 'custom_404_pro_options'; |
| 54 |
$wpdb->query( 'DROP TABLE IF EXISTS ' . $table_options ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching |
| 55 |
} |
| 56 |
} |
| 57 |
|