Completed
Push — dev/2.1.0 ( 0893b9...39cfde )
by Sudar
01:42
created

uninstall.php ➔ email_log_delete_table()   B

Complexity

Conditions 6
Paths 3

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
cc 6
eloc 12
nc 3
nop 0
dl 0
loc 22
ccs 0
cts 14
cp 0
crap 42
rs 8.6737
c 0
b 0
f 0
1
<?php
2
/**
3
 * Uninstall page for Email Log Plugin to clean up db.
4
 *
5
 * This file is named uninstall.php since WordPress requires that name.
6
 */
7
8
// exit if WordPress is not uninstalling the plugin.
9
if ( ! defined( 'ABSPATH' ) && ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
10
	exit();
11
}
12
13
if ( is_multisite() ) {
14
	// Note: if there are more than 10,000 blogs or
15
	// if `wp_is_large_network` filter is set, then this may fail.
16
	$sites = wp_get_sites();
17
18
	foreach ( $sites as $site ) {
19
		switch_to_blog( $site['blog_id'] );
20
		email_log_delete_table();
21
		restore_current_blog();
22
	}
23
} else {
24
	email_log_delete_table();
25
}
26
27
/**
28
 * Delete email log table and db option
29
 *
30
 * @since 1.7
31
 *
32
 * @global object $wpdb
33
 */
34
function email_log_delete_table() {
35
	global $wpdb;
36
37
	$retain_email_log = get_option( 'el_email_log_core' );
38
39
	// This is hardcoded on purpose, since the entire plugin is not loaded during uninstall.
40
	$table_name = $wpdb->prefix . 'email_log';
41
42
	if ( $wpdb->get_var( "SHOW TABLES LIKE '{$table_name}'" ) == $table_name ) {
43
		if ( ! empty( $retain_email_log ) &&
44
			 is_array( $retain_email_log ) &&
45
			 array_key_exists( 'remove_on_uninstall', $retain_email_log ) &&
46
			 'true' === strtolower( $retain_email_log['remove_on_uninstall'] ) ) {
47
			// If table is present, drop it
48
			$wpdb->query( "DROP TABLE $table_name" );
49
		}
50
	}
51
52
	// Delete the options.
53
	delete_option( 'email-log-db' );
54
	delete_option( 'el_email_log_core' );
55
}
56