-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuninstall.php
More file actions
47 lines (40 loc) · 1019 Bytes
/
uninstall.php
File metadata and controls
47 lines (40 loc) · 1019 Bytes
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
<?php
/**
* Insert Codes Uninstall.
*
* @since 1.0.0
* @package InsertCodes
*/
defined( 'WP_UNINSTALL_PLUGIN' ) || exit;
/**
* Delete options by prefix.
*
* @param string $prefix Prefix of the option name.
*
* @since 1.0.0
* @return void
*/
function insertcodes_delete_options( $prefix ) {
// Retrieve all options.
$all_options = wp_load_alloptions();
// Loop through options and delete those with the specified prefix.
foreach ( $all_options as $option_name => $option_value ) {
if ( strpos( $option_name, $prefix ) === 0 ) {
delete_option( $option_name );
}
}
}
if ( 'yes' === get_option( 'insertcodes_delete_data' ) ) {
$option_prefix = 'insertcodes_';
// Delete options for the main site.
insertcodes_delete_options( $option_prefix );
// Delete options in a multisite network.
if ( is_multisite() ) {
$sites = get_sites();
foreach ( $sites as $site ) {
switch_to_blog( $site->blog_id );
insertcodes_delete_options( $option_prefix );
restore_current_blog();
}
}
}