Repository navigation
Expand file tree
/
Copy pathuninstall.php
More file actions
83 lines (73 loc) · 2.27 KB
/
Copy pathuninstall.php
File metadata and controls
83 lines (73 loc) · 2.27 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
/**
* {{name}} Uninstall
*
* Fired when the plugin is uninstalled to remove the plugin's own settings.
*
* Content is deliberately kept: posts, terms and their meta belong to the
* site, not the plugin, and remain in place if the plugin is reinstalled.
*
* @package {{namespace}}
*/
// If uninstall not called from WordPress, exit.
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}
global $wpdb;
// Prefix shared by every option, transient and cron hook the plugin creates.
$option_prefix = '{{namespace}}_';
// Never run unscoped: an empty prefix would match unrelated site data.
// Always false once rendered correctly; kept to catch a broken render.
/** @phpstan-ignore-next-line */
if ( '_' === $option_prefix ) {
return;
}
/**
* Delete plugin options, including SCF options page values
* (options_{prefix}* and their _options_{prefix}* field references).
*/
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.NoCaching
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->options} WHERE option_name LIKE %s OR option_name LIKE %s OR option_name LIKE %s",
$wpdb->esc_like( $option_prefix ) . '%',
$wpdb->esc_like( 'options_' . $option_prefix ) . '%',
$wpdb->esc_like( '_options_' . $option_prefix ) . '%'
)
);
/**
* Delete transients.
*/
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.NoCaching
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->options} WHERE option_name LIKE %s OR option_name LIKE %s OR option_name LIKE %s OR option_name LIKE %s",
$wpdb->esc_like( '_transient_' . $option_prefix ) . '%',
$wpdb->esc_like( '_transient_timeout_' . $option_prefix ) . '%',
$wpdb->esc_like( '_site_transient_' . $option_prefix ) . '%',
$wpdb->esc_like( '_site_transient_timeout_' . $option_prefix ) . '%'
)
);
/**
* Clear scheduled cron hooks.
*/
$hooks = array(
$option_prefix . 'cron',
$option_prefix . 'daily',
$option_prefix . 'hourly',
$option_prefix . 'cleanup',
);
foreach ( $hooks as $hook ) {
wp_clear_scheduled_hook( $hook );
}
/**
* Flush rewrite rules so the plugin's post type and taxonomy permalinks
* are removed.
*/
flush_rewrite_rules();
/**
* Clear cached copies of the options deleted above.
*/
wp_cache_flush();