-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuninstall.php
More file actions
39 lines (35 loc) · 1.26 KB
/
Copy pathuninstall.php
File metadata and controls
39 lines (35 loc) · 1.26 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
<?php
/**
* Uninstall handler: removes all plugin options and transients.
*
* WordPress calls this file directly (not through the normal plugin
* bootstrap) when the plugin is deleted from the Plugins screen.
*
* @package IPDataInfo
*/
// If uninstall is not called from WordPress, bail.
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}
/**
* Delete the plugin's settings option.
*/
delete_option( 'ipdatainfo_settings' );
delete_site_option( 'ipdatainfo_settings' );
/**
* Delete every cached per-IP lookup transient created by the plugin.
*
* Transients are stored with keys like `ipdatainfo_<md5>` (and their
* paired `_transient_timeout_` rows), so a direct `$wpdb` query is the
* only practical way to clean them all up without knowing every IP hash.
*/
global $wpdb;
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- required for a full bulk cleanup on uninstall.
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->options} WHERE option_name LIKE %s OR option_name LIKE %s",
$wpdb->esc_like( '_transient_ipdatainfo_' ) . '%',
$wpdb->esc_like( '_transient_timeout_ipdatainfo_' ) . '%'
)
);
// phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching