-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathuninstall.php
106 lines (95 loc) · 2.4 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
99
100
101
102
103
104
105
106
<?php
/**
* Scripts to Footer Uninstall File
*
* @package Scripts_To_Footer
* @subpackage Uninstall
* @author Joshua David Nelson <[email protected]>
* @copyright Copyright (c) 2023, Joshua David Nelson
* @license http://www.opensource.org/licenses/gpl-license.php GPL-2.0+
* @link https://github.com/joshuadavidnelson/scripts-to-footer
* @since 0.2.0
**/
/**
* Prevent direct access to this file.
*
* @since 0.2
*/
if ( ! defined( 'ABSPATH' ) ) {
exit( 'You are not allowed to access this file directly.' );
}
/**
* If uninstall not called from WordPress, exit.
*
* @since 0.2
*
* @uses WP_UNINSTALL_PLUGIN
*/
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
header( 'Status: 403 Forbidden' );
header( 'HTTP/1.1 403 Forbidden' );
exit();
}
/**
* Various user checks.
*
* @since 0.2
*
* @uses is_user_logged_in()
* @uses current_user_can()
* @uses wp_die()
*/
// @codingStandardsIgnoreStart
if ( ! is_user_logged_in() ) {
wp_die(
__( 'You must be logged in to run this script.', 'stf' ),
__( 'Scripts To Footer', 'stf' ),
array( 'back_link' => true )
);
}
if ( ! current_user_can( 'install_plugins' ) ) {
wp_die(
__( 'You do not have permission to run this script.', 'stf' ),
__( 'Scripts To Footer', 'stf' ),
array( 'back_link' => true )
);
}
// @codingStandardsIgnoreEnd
/**
* Delete options array (settings field) from the database.
* Note: Respects Multisite setups and single installs.
*
* @since 0.2
*
* @uses switch_to_blog()
* @uses restore_current_blog()
*
* @param array $blogs
* @param int $blog
*
* @global $wpdb
*/
// First, check for Multisite, if yes, delete options on a per site basis.
if ( is_multisite() ) {
global $wpdb;
// Get array of Site/Blog IDs from the database.
$blogs = $wpdb->get_results( "SELECT blog_id FROM {$wpdb->blogs}", ARRAY_A ); // phpcs:ignore
if ( $blogs ) {
foreach ( $blogs as $blog ) {
// Repeat for every Site ID.
switch_to_blog( $blog['blog_id'] );
// Delete plugin options.
delete_option( 'scripts-to-footer' );
delete_option( 'stf_version' );
// Delete all post meta.
delete_post_meta_by_key( 'stf_exclude' );
}
restore_current_blog();
}
} else { // Otherwise, delete options from main options table.
// Delete plugin options.
delete_option( 'scripts-to-footer' );
delete_option( 'stf_version' );
// Delete all post meta.
delete_post_meta_by_key( 'stf_exclude' );
}