-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathuninstall.php
More file actions
53 lines (44 loc) · 1.92 KB
/
Copy pathuninstall.php
File metadata and controls
53 lines (44 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
/**
* Plugin uninstall handler.
*
* Runs when the user clicks "Delete" on the plugin in
* `wp-admin/plugins.php`. Removes every database trace the plugin
* leaves behind:
* - the v4 settings option,
* - the v4 custom tables (logs + redirects),
* - the legacy v3 `404_to_301` table and its options (in case the
* user uninstalls before migrating),
* - dismissed-notice user meta.
*
* Intentionally side-effect-free aside from those `DELETE`s and
* `DROP TABLE`s — the file stays readable so audits can confirm
* "deleting the plugin actually deletes the plugin's data".
*
* @package DuckDev\FourNotFour
*/
declare( strict_types = 1 );
// Exit unless the file was loaded by WordPress's uninstall handler.
defined( 'WP_UNINSTALL_PLUGIN' ) || exit;
// v4 settings option.
delete_option( '404_to_301_settings' );
delete_option( '404_to_301_has_active' );
// BerlinDB schema-version markers.
delete_option( 'wpdb_404_to_301_logs_version' );
delete_option( 'wpdb_404_to_301_redirects_version' );
// Legacy v3 options.
delete_option( 'i4t3_gnrl_options' );
delete_option( 'i4t3_activated_time' );
delete_option( 'i4t3_db_version' );
delete_option( 'i4t3_version_no' );
delete_option( 'i4t3_review_notice' );
global $wpdb;
// v4 tables.
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}404_to_301_logs" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}404_to_301_redirects" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery
// Legacy v3 table (kept around in case the user uninstalls before migrating).
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}404_to_301" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery
// Per-user dismissed-notice flags.
delete_metadata( 'user', 0, 'i4t3_review_notice_dismissed', '', true );
delete_metadata( 'user', 0, '404_to_301_review_dismissed', '', true );
delete_metadata( 'user', 0, '404_to_301_migration_dismissed', '', true );