check-email
Last commit date
assets
2 months ago
include
2 months ago
languages
2 months ago
vendor
2 months ago
changelog.txt
2 months ago
check-email.php
2 months ago
readme.txt
2 months ago
uninstall.php
2 months ago
uninstall.php
68 lines
| 1 | <?php |
| 2 | |
| 3 | // exit if WordPress is not uninstalling the plugin. |
| 4 | if ( ! defined( 'ABSPATH' ) && ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { |
| 5 | exit(); |
| 6 | } |
| 7 | |
| 8 | if ( is_multisite() ) { |
| 9 | // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound |
| 10 | $check_email_sites = get_sites(); |
| 11 | // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound |
| 12 | foreach ( $check_email_sites as $check_email_site ) { |
| 13 | switch_to_blog( $check_email_site->blog_id ); |
| 14 | check_email_delete_db_data(); |
| 15 | restore_current_blog(); |
| 16 | } |
| 17 | } else { |
| 18 | check_email_delete_db_data(); |
| 19 | } |
| 20 | // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound |
| 21 | function check_email_delete_db_data() { |
| 22 | global $wpdb; |
| 23 | |
| 24 | $remove_data_on_uninstall = false; |
| 25 | |
| 26 | $option = get_option( 'check-email-log-core' ); |
| 27 | if ( is_array( $option ) && array_key_exists( 'remove_on_uninstall', $option ) && |
| 28 | 'true' === strtolower( $option['remove_on_uninstall'] ) ) { |
| 29 | |
| 30 | $remove_data_on_uninstall = true; |
| 31 | } |
| 32 | |
| 33 | // This is hardcoded on purpose, since the entire plugin is not loaded during uninstall. |
| 34 | $table_name = $wpdb->prefix . 'check_email_log'; |
| 35 | |
| 36 | if ( $remove_data_on_uninstall ) { |
| 37 | //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- just to check if table exists |
| 38 | if ( $wpdb->get_var( $wpdb->prepare( "SHOW TABLES LIKE %s",$wpdb->esc_like( $table_name )) ) == $table_name ) { |
| 39 | |
| 40 | $wpdb->query( |
| 41 | //phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.SchemaChange,PluginCheck.Security.DirectDB.UnescapedDBParameter -- Reason Custom table drop on uninstall |
| 42 | "DROP TABLE $table_name" ); |
| 43 | } |
| 44 | $table_name_email_tracker = $wpdb->prefix . 'check_email_error_logs'; |
| 45 | //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- just to check if table exists |
| 46 | if ( $wpdb->get_var( $wpdb->prepare( "SHOW TABLES LIKE %s",$wpdb->esc_like( $table_name_email_tracker )) ) == $table_name_email_tracker ) { |
| 47 | // phpcs:ignore PluginCheck.Security.DirectDB.UnescapedDBParameter |
| 48 | $wpdb->query( |
| 49 | //phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.SchemaChange -- Reason Custom table drop on uninstall |
| 50 | "DROP TABLE $table_name_email_tracker" ); |
| 51 | } |
| 52 | |
| 53 | delete_option( 'check-email-log-db' ); |
| 54 | delete_option( 'check-email-log-core' ); |
| 55 | delete_option( 'check-email-smtp-options' ); |
| 56 | delete_option( 'check_email_smtp_status' ); |
| 57 | |
| 58 | $roles = get_editable_roles(); |
| 59 | foreach ( $roles as $role_name => $role_obj ) { |
| 60 | $role = get_role( $role_name ); |
| 61 | |
| 62 | if ( ! is_null( $role ) ) { |
| 63 | $role->remove_cap( 'manage_check_email' ); |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 |