Completed
Push — feature/45-drop-php-52 ( f96425 )
by Sudar
11:51
created

uninstall.php ➔ email_log_delete_table()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
cc 2
eloc 6
c 2
b 0
f 2
nc 2
nop 0
dl 0
loc 12
rs 9.4285
1
<?php
2
/**
3
 * Uninstall page for Email Log Plugin to clean up db.
4
 */
5
6
// exit if WordPress is not uninstalling the plugin.
7
if ( ! defined( 'ABSPATH' ) && ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
8
	exit();
9
}
10
11
if ( is_multisite() ) {
12
	global $wpdb;
13
14
	$original_blog_id = get_current_blog_id();
15
16
	$blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
1 ignored issue
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $wpdb 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...
17
18
	foreach ( $blog_ids as $blog_id ) {
19
		switch_to_blog( $blog_id );
20
		email_log_delete_table();
21
	}
22
23
	switch_to_blog( $original_blog_id );
24
25
} else {
26
	email_log_delete_table();
27
}
28
29
/**
30
 * Delete email log table and db option
31
 *
32
 * @since 1.7
33
 *
34
 * @global object $wpdb
35
 */
36
function email_log_delete_table() {
37
	global $wpdb;
38
	$table_name = $wpdb->prefix . 'email_log'; // This is hardcoded on purpose
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