-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathuninstall.php
More file actions
64 lines (51 loc) · 2.06 KB
/
uninstall.php
File metadata and controls
64 lines (51 loc) · 2.06 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
62
63
64
<?php
/**
* RestaurantPress Uninstall
*
* Uninstalls the plugin deletes user roles, tables, and options.
*
* @package RestaurantPress\Uninstaller
* @version 1.0.0
*/
defined( 'WP_UNINSTALL_PLUGIN' ) || exit;
global $wpdb, $wp_version;
wp_clear_scheduled_hook( 'restaurantpress_cleanup_sessions' );
/*
* Only remove ALL plugin data if RP_REMOVE_ALL_DATA constant is set to true in user's
* wp-config.php. This is to prevent data loss when deleting the plugin from the backend
* and to ensure only the site owner can perform this action.
*/
if ( defined( 'RP_REMOVE_ALL_DATA' ) && true === RP_REMOVE_ALL_DATA ) {
include_once dirname( __FILE__ ) . '/includes/class-rp-install.php';
// Roles + caps.
RP_Install::remove_roles();
// Tables.
RP_Install::drop_tables();
// Delete options.
$wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE 'restaurantpress\_%';" );
// Delete posts + data.
$wpdb->query( "DELETE FROM {$wpdb->posts} WHERE post_type IN ( 'food_menu', 'food_group' );" );
$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 terms if > WP 4.2 (term splitting was added in 4.2).
if ( version_compare( $wp_version, '4.2', '>=' ) ) {
// Delete term taxonomies.
foreach ( array( 'food_menu_cat' ) as $taxonomy ) {
$wpdb->delete(
$wpdb->term_taxonomy,
array(
'taxonomy' => $taxonomy,
)
);
}
// Delete orphan relationships.
$wpdb->query( "DELETE tr FROM {$wpdb->term_relationships} tr LEFT JOIN {$wpdb->posts} posts ON posts.ID = tr.object_id WHERE posts.ID IS NULL;" );
// Delete orphan terms.
$wpdb->query( "DELETE t FROM {$wpdb->terms} t LEFT JOIN {$wpdb->term_taxonomy} tt ON t.term_id = tt.term_id WHERE tt.term_id IS NULL;" );
// Delete orphan term meta.
if ( ! empty( $wpdb->termmeta ) ) {
$wpdb->query( "DELETE tm FROM {$wpdb->termmeta} tm LEFT JOIN {$wpdb->term_taxonomy} tt ON tm.term_id = tt.term_id WHERE tt.term_id IS NULL;" );
}
}
// Clear any cached data that has been removed.
wp_cache_flush();
}