Completed
Push — feature/addons-page ( 59ba10...83b77b )
by Maria Daniel Deepak
03:58
created

uninstall.php ➔ email_log_delete_table()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 3
Bugs 0 Features 2
Metric Value
cc 2
eloc 6
c 3
b 0
f 2
nc 2
nop 0
dl 0
loc 14
ccs 0
cts 7
cp 0
crap 6
rs 9.4285
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
	// This is hardcoded on purpose, since the entire plugin is not loaded during uninstall.
38
	$table_name = $wpdb->prefix . 'email_log';
39
40
	if ( $wpdb->get_var( "SHOW TABLES LIKE '{$table_name}'" ) == $table_name ) {
1 ignored issue
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $table_name instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
41
		// If table is present, drop it
42
		$wpdb->query( "DROP TABLE $table_name" );
1 ignored issue
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $table_name instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
43
	}
44
45
	// Delete the option
46
	delete_option( 'email-log-db' );
47
}
48