-
Notifications
You must be signed in to change notification settings - Fork 0
/
uninstall.php
59 lines (50 loc) · 1.25 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
<?php
/**
* This file is responsible for clearing the Database of all plugin entries.
*
* @package translations for pressbooks
* @since 1.2.6
* 1.2.8 modifications
*/
if (!defined('WP_UNINSTALL_PLUGIN')) {
die;
}
/**
* If 'tfp_uninstall_save' option is not checked clears all plugin DB data on uninstall.
*
* @since 1.2.6
* 1.2.8 modifications
*/
if (1 != get_option( 'tfp_uninstall_save' )){
global $wpdb;
$post_types = ['metadata','front-matter','chapter','part', 'back-matter'];
$args = array(
'fields' => 'ids',
'posts_per_page' => -1,
'post_type' => $post_types,
'number' => 1000
);
$sites = get_sites($args);
// go through all the sites(books) and delete entries which were created by the plugin.
foreach ( $sites as $site ) {
switch_to_blog( $site );
$wpdb->query(
$wpdb->prepare(
"
DELETE FROM $wpdb->postmeta
WHERE meta_key = %s",
'tfp_post_translation_disable'
)
);
$wpdb->query(
$wpdb->prepare(
"
DELETE FROM $wpdb->options
WHERE option_name = %s",
'tfp_book_translation_enable'
)
);
restore_current_blog();
}
delete_option( 'tfp_uninstall_save' );
}