forked from git-connected/masvideos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuninstall.php
52 lines (41 loc) · 2.06 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
<?php
/**
* MasVideos Uninstall
*
* Uninstalling MasVideos deletes user roles, pages, tables, and options.
*
* @package MasVideos\Uninstaller
* @version 1.0.0
*/
defined( 'WP_UNINSTALL_PLUGIN' ) || exit;
global $wpdb;
/*
* Only remove ALL movie, video, tv show and page data if MASVIDEOS_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( 'MASVIDEOS_REMOVE_ALL_DATA' ) && true === MASVIDEOS_REMOVE_ALL_DATA ) {
include_once dirname( __FILE__ ) . '/includes/class-masvideos-install.php';
// Roles + caps.
MasVideos_Install::remove_roles();
// Pages.
wp_trash_post( get_option( 'masvideos_myaccount_page_id' ) );
wp_trash_post( get_option( 'masvideos_upload_video_page_id' ) );
wp_trash_post( get_option( 'masvideos_movies_page_id' ) );
wp_trash_post( get_option( 'masvideos_tv_shows_page_id' ) );
wp_trash_post( get_option( 'masvideos_videos_page_id' ) );
wp_trash_post( get_option( 'masvideos_persons_page_id' ) );
// Tables.
MasVideos_Install::drop_tables();
// Delete options.
$wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE 'masvideos\_%';" );
$wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE 'widget\_masvideos\_%';" );
// Delete usermeta.
$wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key LIKE 'masvideos\_%';" );
// Delete posts + data.
$wpdb->query( "DELETE FROM {$wpdb->posts} WHERE post_type IN ( 'movie', 'movie_playlist', 'video', 'video_playlist', 'tv_show', 'tv_show_playlist', 'episode' );" );
$wpdb->query( "DELETE meta FROM {$wpdb->postmeta} meta LEFT JOIN {$wpdb->posts} posts ON posts.ID = meta.post_id WHERE posts.ID IS NULL;" );
$wpdb->query( "DELETE meta FROM {$wpdb->commentmeta} meta LEFT JOIN {$wpdb->comments} comments ON comments.comment_ID = meta.comment_id WHERE comments.comment_ID IS NULL;" );
// Clear any cached data that has been removed.
wp_cache_flush();
}