This repository has been archived by the owner on Sep 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
uninstall.php
84 lines (69 loc) · 1.82 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
<?php
/**
* Fired when the plugin is uninstalled.
*
* @link https://devonostendorf.com/projects/#post-notif
* @since 1.0.0
*
* @package Post_Notif
*/
// If uninstall not called from WordPress, then exit.
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}
// Define set of plugin-specific options
$option_arr = array(
'post_notif_settings'
,'post_notif_widget_defaults'
,'post_notif_db_version'
,'widget_post-notif'
,'post_notif_count_to_send'
,'post_notif_count_sent'
);
// Define set of plugin-specific custom tables
global $wpdb;
$custom_table_arr = array(
'post_notif_subscriber'
,'post_notif_sub_cat'
,'post_notif_post'
,'post_notif_subscriber_stage'
,'post_notif_sub_cat_stage'
);
if ( !is_multisite() ) {
// NOT multisite
// Delete options
foreach ( $option_arr as $option_name)
{
delete_option( $option_name );
}
// Delete language detector
delete_option( 'post_notif_language_detector_' . get_locale() );
// Delete custom tables
foreach ( $custom_table_arr as $custom_table_name)
{
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}" . $custom_table_name );
}
}
else {
// IS multisite
$site_id_arr = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
$root_blog_id = get_current_blog_id();
// Iterate through sites in network
foreach ( $site_id_arr as $site_id )
{
switch_to_blog( $site_id );
// Delete options
foreach ( $option_arr as $option_name)
{
delete_option( $option_name );
}
// Delete language detector
delete_option( 'post_notif_language_detector_' . get_locale() );
// Delete custom tables
foreach ( $custom_table_arr as $custom_table_name)
{
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}" . $custom_table_name );
}
}
switch_to_blog( $root_blog_id );
}