-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathuninstall.php
executable file
·98 lines (86 loc) · 2.74 KB
/
uninstall.php
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
/**
* Fired when the plugin is uninstalled.
*
* When populating this file, consider the following flow
* of control:
*
* - This method should be static
* - Check if the $_REQUEST content actually is the plugin name
* - Run an admin referrer check to make sure it goes through authentication
* - Verify the output of $_GET makes sense
* - Repeat with other user roles. Best directly by using the links/query string parameters.
* - Repeat things for multisite. Once for a single site in the network, once sitewide.
*
* This file may be updated more in future version of the Boilerplate; however, this is the
* general skeleton and outline for how the file should work.
*
* For more information, see the following discussion:
* https://github.com/tommcfarlin/WordPress-Plugin-Boilerplate/pull/123#issuecomment-28541913
*
* @link https://profiles.wordpress.org/mociofiletto/
* @since 1.0.0
*
* @package No_Unsafe_Inline
*/
// If uninstall not called from WordPress, then exit.
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}
global $wpdb;
// If we are in multisite we delete for all blogs (deletion = network level).
if ( is_multisite() ) {
// Get all blogs in the network and delete tables on each one.
$no_unsafe_inline_blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
foreach ( $no_unsafe_inline_blog_ids as $no_unsafe_inline_site_id ) {
switch_to_blog( $no_unsafe_inline_site_id );
no_unsafe_inline_uninstall_plugin();
restore_current_blog();
}
no_unsafe_inline_mu_plugin_delete();
} else {
no_unsafe_inline_uninstall_plugin();
no_unsafe_inline_mu_plugin_delete();
}
/**
* Remove all options and tables on uninstall
*
* @since 1.0.0
* @return void
*/
function no_unsafe_inline_uninstall_plugin() {
global $wpdb;
// Let's remove all options.
foreach ( wp_load_alloptions() as $option => $value ) {
if ( strpos( $option, 'no-unsafe-inline_' ) === 0 ) {
// for site options in Multisite.
delete_option( $option );
}
}
// let's drop the tables.
$tables_name = array(
'inline_scripts',
'external_scripts',
'event_handlers',
'occurences',
'nunil_logs',
);
foreach ( $tables_name as $table ) {
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}nunil_$table" );
}
}
/**
* Remove the mu-plugin on uninstall
*
* @since 1.0.0
* @return void
*/
function no_unsafe_inline_mu_plugin_delete() {
$mu_dir = ( defined( 'WPMU_PLUGIN_DIR' ) && defined( 'WPMU_PLUGIN_URL' ) ) ? WPMU_PLUGIN_DIR : trailingslashit( WP_CONTENT_DIR ) . 'mu-plugins';
$mu_dir = untrailingslashit( $mu_dir );
$mu_plugin = $mu_dir . '/no-unsafe-inline-output-buffering.php';
if ( file_exists( $mu_plugin ) ) {
unlink( $mu_plugin );
}
}