Completed
Push — feature/45-drop-php-52 ( d61672...167909 )
by Sudar
11:21
created

uninstall.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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