This repository has been archived by the owner on Mar 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
/
uninstall.php
105 lines (92 loc) · 3.46 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
<?php
// If uninstall not called from WordPress exit
if( !defined( 'WP_UNINSTALL_PLUGIN' ) )
exit ();
// Delete option from options table
if (is_multisite()) {
global $wpdb;
$blogs = $wpdb->get_results("SELECT blog_id FROM {$wpdb->blogs}", ARRAY_A);
if ($blogs) {
foreach($blogs as $blog) {
switch_to_blog($blog['blog_id']);
$post_options_uninstall = get_option('rss_post_options');
if ($post_options_uninstall['plugindelete']==1){
rssmi_uninstall_delete_posts_admin();
delete_post_meta_by_key('rssmi_feed');
}
delete_option('rss_import_items');
delete_option('rss_import_options');
delete_option('rss_import_categories');
delete_option('rss_template_item');
delete_option('rss_admin_options');
delete_option('rss_feed_options');
delete_option('rss_post_options');
delete_option('rssmi_dismiss_rating');
delete_option('rss_import_categories_images');
delete_option('rssmi_global_options');
$allposts = get_posts('numberposts=-1&post_type=post&post_status=any');
foreach( $allposts as $postinfo) {
delete_post_meta($postinfo->ID, 'rssmi_source_link');
delete_post_meta($postinfo->ID, 'rssmi_source_protect');
}
rssmi_uninstall_restore_all();
}
restore_current_blog();
}
} else {
$post_options_uninstall = get_option('rss_post_options');
if ($post_options_uninstall['plugindelete']==1){
rssmi_uninstall_delete_posts_admin();
delete_post_meta_by_key('rssmi_feed');
}
delete_option('rss_import_items');
delete_option('rss_import_categories');
delete_option('rss_template_item');
delete_option('rss_import_options');
delete_option('rss_admin_options');
delete_option('rss_feed_options');
delete_option('rss_post_options');
delete_option('rssmi_dismiss_rating');
delete_option('rss_import_categories_images');
delete_option('rssmi_global_options');
$allposts = get_posts('numberposts=-1&post_type=post&post_status=any');
foreach( $allposts as $postinfo) {
delete_post_meta($postinfo->ID, 'rssmi_source_link');
delete_post_meta($postinfo->ID, 'rssmi_source_protect');
}
rssmi_uninstall_restore_all();
}
//
function rssmi_uninstall_delete_attachment($id_ID){ // DELETE ATTACHMENTS CREATED BY THIS PLUGIN
$args = array( 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' =>'any', 'post_parent' => $id_ID );
$attachments = get_posts($args);
if ($attachments) {
foreach ( $attachments as $attachment ) {
wp_delete_attachment($attachment->ID,true);
}
}
}
function rssmi_uninstall_delete_posts_admin(){ // DELETE BLOG POSTS CREATED BY PLUGIN
global $wpdb;
$expiration=-1;
$query = "SELECT ID FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' AND DATEDIFF(NOW(), `post_date`) > ".$expiration;
$ids = $wpdb->get_results($query);
foreach ($ids as $id){
$mypostids = $wpdb->get_results("SELECT * FROM $wpdb->postmeta WHERE meta_key = 'rssmi_source_link' AND post_id = ".$id->ID);
if (!empty($mypostids)){
rssmi_uninstall_delete_attachment($id->ID);
wp_delete_post($id->ID, true);
}
}
}
function rssmi_uninstall_restore_all(){ // DELETES EVERYTHING CAUSED BY THIS PLUGIN IN THE POST AND POST META TABLES
global $wpdb;
$query = "SELECT ID FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'rssmi_feed_item' OR post_type = 'rssmi_feed'";
$ids = $wpdb->get_results($query);
if (!empty($ids)){
foreach ($ids as $id){
wp_delete_post($id->ID, true);
}
}
}
?>