-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuninstall.php
More file actions
34 lines (30 loc) · 1.1 KB
/
Copy pathuninstall.php
File metadata and controls
34 lines (30 loc) · 1.1 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
<?php
/**
* Uninstall — leave no trace.
*
* Runs when the user deletes the plugin from wp-admin. Removes every option,
* transient, scheduled event, and table the plugin creates. Users who
* uninstall expect to be forgotten.
*
* @package PLExample
*/
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}
// Options.
delete_option( 'pl_example_options' );
delete_site_option( 'pl_example_options' );
// Transients seeded by the Utils helper. A direct query is intentional here:
// uninstall runs once, object caching is irrelevant, and core offers no API to
// bulk-delete transients by prefix.
global $wpdb;
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- one-shot uninstall cleanup, see note above.
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->options} WHERE option_name LIKE %s OR option_name LIKE %s",
$wpdb->esc_like( '_transient_pl_example_' ) . '%',
$wpdb->esc_like( '_transient_timeout_pl_example_' ) . '%'
)
);
// Scheduled cron events would be cleared here, e.g. via
// wp_clear_scheduled_hook() under the plugin's hook prefix.