| 1 |
<?php |
| 2 |
/** |
| 3 |
* Charitable Uninstall class. |
| 4 |
* |
| 5 |
* The responsibility of this class is to manage the events that need to happen |
| 6 |
* when the plugin is deactivated. |
| 7 |
* |
| 8 |
* @package Charitable/Charitable_Uninstall |
| 9 |
* @author David Bisset |
| 10 |
* @copyright Copyright (c) 2023, WP Charitable LLC |
| 11 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 12 |
* @since 1.0.0 |
| 13 |
* @version 1.6.42 |
| 14 |
*/ |
| 15 |
|
| 16 |
// Exit if accessed directly. |
| 17 |
if ( ! defined( 'ABSPATH' ) ) { |
| 18 |
exit; |
| 19 |
} |
| 20 |
|
| 21 |
if ( ! class_exists( 'Charitable_Uninstall' ) ) : |
| 22 |
|
| 23 |
/** |
| 24 |
* Charitable_Uninstall |
| 25 |
* |
| 26 |
* @since 1.0.0 |
| 27 |
*/ |
| 28 |
class Charitable_Uninstall { |
| 29 |
|
| 30 |
/** |
| 31 |
* Uninstall the plugin. |
| 32 |
* |
| 33 |
* @since 1.0.0 |
| 34 |
*/ |
| 35 |
public function __construct() { |
| 36 |
if ( charitable()->is_deactivation() && charitable_get_option( 'delete_data_on_uninstall' ) ) { |
| 37 |
|
| 38 |
$this->remove_caps(); |
| 39 |
$this->remove_post_data(); |
| 40 |
$this->remove_tables(); |
| 41 |
$this->remove_settings(); |
| 42 |
|
| 43 |
do_action( 'charitable_uninstall' ); |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Remove plugin-specific roles. |
| 49 |
* |
| 50 |
* @since 1.0.0 |
| 51 |
* |
| 52 |
* @return void |
| 53 |
*/ |
| 54 |
private function remove_caps() { |
| 55 |
$roles = new Charitable_Roles(); |
| 56 |
$roles->remove_caps(); |
| 57 |
} |
| 58 |
|
| 59 |
/** |
| 60 |
* Remove post objects created by Charitable. |
| 61 |
* |
| 62 |
* @since 1.0.0 |
| 63 |
* |
| 64 |
* @global WPDB $wpdb The WordPress database object. |
| 65 |
* @return void |
| 66 |
*/ |
| 67 |
private function remove_post_data() { |
| 68 |
global $wpdb; |
| 69 |
|
| 70 |
$posts = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_type IN ( 'donation', 'campaign' );" ); |
| 71 |
|
| 72 |
foreach ( $posts as $post_id ) { |
| 73 |
wp_delete_post( $post_id, true ); |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* Remove the custom tables added by Charitable. |
| 79 |
* |
| 80 |
* @since 1.0.0 |
| 81 |
* @version 1.8.1 |
| 82 |
* |
| 83 |
* @global WPDB $wpdb The WordPress database object. |
| 84 |
* @return void |
| 85 |
*/ |
| 86 |
private function remove_tables() { |
| 87 |
global $wpdb; |
| 88 |
|
| 89 |
$wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'charitable_campaign_donations' ); |
| 90 |
$wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'charitable_donors' ); |
| 91 |
$wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'charitable_donormeta' ); |
| 92 |
$wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'charitable_benefactors' ); |
| 93 |
$wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'charitable_donation_activities' ); |
| 94 |
$wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'charitable_campaign_activities' ); |
| 95 |
|
| 96 |
delete_option( $wpdb->prefix . 'charitable_campaign_donations_db_version' ); |
| 97 |
delete_option( $wpdb->prefix . 'charitable_donors_db_version' ); |
| 98 |
delete_option( $wpdb->prefix . 'charitable_donormeta_db_version' ); |
| 99 |
delete_option( $wpdb->prefix . 'charitable_benefactors_db_version' ); |
| 100 |
delete_option( $wpdb->prefix . 'charitable_donation_activities_db_version' ); |
| 101 |
delete_option( $wpdb->prefix . 'charitable_campaign_activities_db_version' ); |
| 102 |
} |
| 103 |
|
| 104 |
/** |
| 105 |
* Remove any other options added by Charitable. |
| 106 |
* |
| 107 |
* @since 1.6.42 |
| 108 |
* |
| 109 |
* @return void |
| 110 |
*/ |
| 111 |
private function remove_settings() { |
| 112 |
delete_option( 'charitable_settings' ); |
| 113 |
delete_option( 'charitable_version' ); |
| 114 |
delete_option( 'charitable_upgrade_log' ); |
| 115 |
delete_option( 'charitable_skipped_donations_with_empty_donor_id' ); |
| 116 |
|
| 117 |
delete_transient( 'charitable_notices' ); |
| 118 |
delete_transient( 'charitable_user_dashboard_objects' ); |
| 119 |
delete_transient( 'charitable_custom_styles' ); |
| 120 |
|
| 121 |
/* Stop Charitable from re-adding the notices transient. */ |
| 122 |
if ( function_exists( 'charitable_get_admin_notices' ) ) { |
| 123 |
remove_action( 'shutdown', array( charitable_get_admin_notices(), 'shutdown' ) ); |
| 124 |
} |
| 125 |
} |
| 126 |
} |
| 127 |
|
| 128 |
endif; |
| 129 |
|