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