| 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 |
* @version 1.0.0 |
| 10 |
* @author Eric Daams |
| 11 |
* @copyright Copyright (c) 2019, Studio 164a |
| 12 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 13 |
*/ |
| 14 |
// Exit if accessed directly. |
| 15 |
if ( ! defined( 'ABSPATH' ) ) { exit; } |
| 16 |
|
| 17 |
if ( ! class_exists( 'Charitable_Uninstall' ) ) : |
| 18 |
|
| 19 |
/** |
| 20 |
* Charitable_Uninstall |
| 21 |
* |
| 22 |
* @since 1.0.0 |
| 23 |
*/ |
| 24 |
class Charitable_Uninstall { |
| 25 |
|
| 26 |
/** |
| 27 |
* Uninstall the plugin. |
| 28 |
* |
| 29 |
* @since 1.0.0 |
| 30 |
*/ |
| 31 |
public function __construct() { |
| 32 |
if ( charitable()->is_deactivation() && charitable_get_option( 'delete_data_on_uninstall' ) ) { |
| 33 |
|
| 34 |
$this->remove_caps(); |
| 35 |
$this->remove_post_data(); |
| 36 |
$this->remove_tables(); |
| 37 |
|
| 38 |
do_action( 'charitable_uninstall' ); |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Remove plugin-specific roles. |
| 44 |
* |
| 45 |
* @since 1.0.0 |
| 46 |
* |
| 47 |
* @return void |
| 48 |
*/ |
| 49 |
private function remove_caps() { |
| 50 |
$roles = new Charitable_Roles(); |
| 51 |
$roles->remove_caps(); |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Remove post objects created by Charitable. |
| 56 |
* |
| 57 |
* @since 1.0.0 |
| 58 |
* |
| 59 |
* @return void |
| 60 |
*/ |
| 61 |
private function remove_post_data() { |
| 62 |
foreach ( array( 'campaign', 'donation' ) as $post_type ) { |
| 63 |
$posts = get_posts( array( |
| 64 |
'posts_per_page' => -1, |
| 65 |
'post_type' => $post_type |
| 66 |
) ); |
| 67 |
|
| 68 |
foreach ( $posts as $post ) { |
| 69 |
wp_delete_post( $post->ID, true ); |
| 70 |
} |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
/** |
| 75 |
* Remove the custom tables added by Charitable. |
| 76 |
* |
| 77 |
* @since 1.0.0 |
| 78 |
* |
| 79 |
* @return void |
| 80 |
*/ |
| 81 |
private function remove_tables() { |
| 82 |
global $wpdb; |
| 83 |
|
| 84 |
$wpdb->query( "DROP TABLE IF EXISTS " . $wpdb->prefix . "charitable_campaign_donations" ); |
| 85 |
$wpdb->query( "DROP TABLE IF EXISTS " . $wpdb->prefix . "charitable_donors" ); |
| 86 |
$wpdb->query( "DROP TABLE IF EXISTS " . $wpdb->prefix . "charitable_benefactors" ); |
| 87 |
|
| 88 |
delete_option( $wpdb->prefix . 'charitable_campaign_donations_db_version' ); |
| 89 |
delete_option( $wpdb->prefix . 'charitable_donors_db_version' ); |
| 90 |
delete_option( $wpdb->prefix . 'charitable_benefactors_db_version' ); |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
endif; |