Passed
Push — 194-hotfix/wp-ses-incompatibil... ( a813c4...881597 )
by Maria Daniel Deepak
04:37
created

uninstall.php (1 issue)

1
<?php
2
/**
3
 * Uninstall page for Email Log Plugin to clean up all plugin data.
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();
0 ignored issues
show
Deprecated Code introduced by
The function wp_get_sites() has been deprecated: 4.6.0 Use get_sites() ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

16
	$sites = /** @scrutinizer ignore-deprecated */ wp_get_sites();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
17
18
	foreach ( $sites as $site ) {
19
		switch_to_blog( $site['blog_id'] );
20
		email_log_delete_db_data();
21
		restore_current_blog();
22
	}
23
} else {
24
	email_log_delete_db_data();
25
}
26
27
/**
28
 * Delete all email log data from db.
29
 *
30
 * The data include email log table, options, capability and add-on license data.
31
 *
32
 * @since 1.7
33
 *
34
 * @global object $wpdb
35
 */
36
function email_log_delete_db_data() {
37
	global $wpdb;
38
39
	$remove_data_on_uninstall = false;
40
41
	$option = get_option( 'email-log-core' );
42
	if ( is_array( $option ) && array_key_exists( 'remove_on_uninstall', $option ) &&
43
	     'true' === strtolower( $option['remove_on_uninstall'] ) ) {
44
45
		$remove_data_on_uninstall = true;
46
	}
47
48
	// This is hardcoded on purpose, since the entire plugin is not loaded during uninstall.
49
	$table_name = $wpdb->prefix . 'email_log';
50
51
	if ( $remove_data_on_uninstall ) {
52
		if ( $wpdb->get_var( "SHOW TABLES LIKE '{$table_name}'" ) == $table_name ) {
53
			$wpdb->query( "DROP TABLE $table_name" );
54
		}
55
56
		delete_option( 'email-log-db' );
57
		delete_option( 'email-log-core' );
58
59
		$roles = get_editable_roles();
60
		foreach ( $roles as $role_name => $role_obj ) {
61
			$role = get_role( $role_name );
62
63
			if ( ! is_null( $role ) ) {
64
				$role->remove_cap( 'manage_email_logs' );
65
			}
66
		}
67
68
		delete_option( 'el_bundle_license' );
69
		$wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'el_license_%'" );
70
	}
71
}
72