-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuninstall.php
88 lines (66 loc) · 2.89 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
<?php
defined( 'WP_UNINSTALL_PLUGIN' ) || exit;
$uninstall = get_option( 'sunshine_uninstall_delete_data' );
if ( $uninstall ) {
global $wpdb, $current_user;
//$galleries = $wpdb->query( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'sunshine-gallery';" );
//sunshine_log( $galleries, 'GALLERIES DURING DELETE' );
// Remove settings
$wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'sunshine_%'" );
// Remove user meta data
$wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key LIKE 'sunshine_%'" );
// Remove pages
$pages = array(
get_option( 'sunshine_page' ),
get_option( 'sunshine_page_cart' ),
get_option( 'sunshine_page_checkout' ),
get_option( 'sunshine_page_account' ),
get_option( 'sunshine_page_favorites' )
);
foreach ( $pages as $page_id ) {
if ( !empty( $page_id ) ) {
wp_delete_post( $page_id, true );
}
}
// Get all galleries for use in deleting attachments
$galleries = $wpdb->query( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'sunshine-gallery';" );
// Remove user meta
$wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key LIKE 'sunshine_%';" );
// Remove post type data
$wpdb->query( "DELETE FROM {$wpdb->posts} WHERE post_type IN ( 'sunshine-product', 'sunshine-gallery', 'sunshine-order' );" );
// Delete all meta data that is not assigned anymore
$wpdb->query( "DELETE meta FROM {$wpdb->postmeta} meta LEFT JOIN {$wpdb->posts} posts ON posts.ID = meta.post_id WHERE posts.ID IS NULL;" );
// Remove taxonomy data
foreach ( array( 'sunshine-product-category', 'sunshine-product-price-level', 'sunshine-order-status' ) as $taxonomy ) {
$wpdb->delete(
$wpdb->term_taxonomy,
array(
'taxonomy' => $taxonomy,
)
);
}
// Remove session table
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}sunshine_sessions" );
do_action( 'sunshine_uninstall' );
}
/* Not ready yet
// Remove attachments
if ( $options['uninstall_delete_attachments'] ) {
if ( !empty( $galleries ) ) {
$gallery_ids = array();
foreach ( $galleries as $gallery_id ) {
$gallery_ids[] = $gallery_id;
}
// Build single query to delete all attachment posts
$wpdb->query( "DELETE FROM {$wpdb->posts} WHERE post_type='attachment' AND post_parent IN ( " . join( ',', $gallery_ids ) . " );" );
// Clear all unattached meta data query
$wpdb->query( "DELETE meta FROM {$wpdb->postmeta} meta LEFT JOIN {$wpdb->posts} posts ON posts.ID = meta.post_id WHERE posts.ID IS NULL;" );
// Delete files from server
$upload_dir = wp_upload_dir();
$folder = $upload_dir['basedir'] . '/sunshine/*';
array_map( 'unlink', array_filter( (array) glob( $folder ) ) );
}
}
*/
wp_cache_flush();
?>