This repository was archived by the owner on Mar 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathuninstall.php
More file actions
61 lines (60 loc) · 2.52 KB
/
uninstall.php
File metadata and controls
61 lines (60 loc) · 2.52 KB
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
<?php
if (is_multisite()) {
mdocs_multi_site_remove();
} else {
mdocs_single_site_remove();
}
function mdocs_multi_site_remove() {
global $wpdb;
$blogs = $wpdb->get_results("SELECT blog_id FROM {$wpdb->blogs}", ARRAY_A);
if ($blogs) {
$init_blog = true;
foreach($blogs as $blog) {
switch_to_blog($blog['blog_id']);
$upload_dir = wp_upload_dir();
$mdocs_list = get_option('mdocs-list');
if(is_array($mdocs_list)) {
foreach($mdocs_list as $the_doc) {
wp_delete_attachment( intval($the_doc['id']), true );
wp_delete_post( intval($the_doc['parent']), true );
}
}
if($init_blog) $results = $wpdb->get_results( 'SELECT * FROM wp_options WHERE option_name LIKE "mdocs%" ', ARRAY_A );
else $results = $wpdb->get_results( 'SELECT * FROM wp_'.$blog['blog_id'].'_options WHERE option_name LIKE "mdocs%" ', ARRAY_A );
foreach($results as $result) delete_option($result['option_name']);
$files = glob($upload_dir['basedir'].'/mdocs/*');
foreach($files as $file) if(is_file($file)) unlink($file);
$files = glob($upload_dir['basedir'].'/mdocs/.*');
foreach($files as $file) if(is_file($file)) unlink($file);
if(is_dir($upload_dir['basedir'].'/mdocs/')) rmdir($upload_dir['basedir'].'/mdocs/');
$query = new WP_Query('pagename=mdocuments-library');
wp_delete_post( $query->post->ID, true );
$mdocs_cat_id = get_cat_ID( 'mdocs-media' );
wp_delete_category(get_cat_ID( 'mdocs-media' ));
$init_blog = false;
}
restore_current_blog();
}
}
function mdocs_single_site_remove($blog_id=null) {
global $wpdb;
$mdocs_list = get_option('mdocs-list');
if(is_array($mdocs_list)) {
foreach($mdocs_list as $the_doc) {
wp_delete_attachment( intval($the_doc['id']), true );
wp_delete_post( intval($the_doc['parent']), true );
}
}
if($blog_id == null) $results = $wpdb->get_results( 'SELECT * FROM wp_options WHERE option_name LIKE "mdocs%" ', ARRAY_A );
else $results = $wpdb->get_results( 'SELECT * FROM wp_'.$blog_id.'_options WHERE option_name LIKE "mdocs%" ', ARRAY_A );
foreach($results as $result) delete_option($result['option_name']);
$files = glob($upload_dir['basedir'].'/mdocs/*');
foreach($files as $file) if(is_file($file)) unlink($file);
$files = glob($upload_dir['basedir'].'/mdocs/.*');
foreach($files as $file) if(is_file($file)) unlink($file);
if(is_dir($upload_dir['basedir'].'/mdocs/')) rmdir($upload_dir['basedir'].'/mdocs/');
$query = new WP_Query('pagename=mdocuments-library');
wp_delete_post( $query->post->ID, true );
wp_delete_category(get_cat_ID( 'mdocs-media' ));
}
?>