-
Notifications
You must be signed in to change notification settings - Fork 0
/
uninstall.php
51 lines (41 loc) · 1020 Bytes
/
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
<?php
namespace epiphyt\Form_Block;
// if uninstall.php is not called by WordPress, die
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}
$GLOBALS['options'] = [
'form_block_form_ids',
'form_block_maximum_upload_size',
'form_block_preserve_data_on_uninstall',
];
if ( is_multisite() ) {
$sites = get_sites( [ 'number' => 99999 ] );
foreach ( $sites as $site ) {
switch_to_blog( $site->blog_id );
// do nothing if option says so
if ( get_option( 'form_block_preserve_data_on_uninstall' ) ) {
continue;
}
delete_data();
restore_current_blog();
}
}
else if ( ! get_option( 'form_block_preserve_data_on_uninstall' ) ) {
delete_data();
}
/**
* Delete all data.
*/
function delete_data() {
global $options;
foreach ( $options as $option ) {
if ( $option === 'form_block_form_ids' ) {
$form_ids = get_option( $option, [] );
foreach ( $form_ids as $form_id => $object_ids ) {
delete_option( 'form_block_data_' . $form_id );
}
}
delete_option( $option );
}
}