| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Fired when the plugin is uninstalled. |
| 5 |
* |
| 6 |
* When populating this file, consider the following flow |
| 7 |
* of control: |
| 8 |
* |
| 9 |
* - This method should be static |
| 10 |
* - Check if the $_REQUEST content actually is the plugin name |
| 11 |
* - Run an admin referrer check to make sure it goes through authentication |
| 12 |
* - Verify the output of $_GET makes sense |
| 13 |
* - Repeat with other user roles. Best directly by using the links/query string parameters. |
| 14 |
* - Repeat things for multisite. Once for a single site in the network, once sitewide. |
| 15 |
* |
| 16 |
* This file may be updated more in future version of the Boilerplate; however, this is the |
| 17 |
* general skeleton and outline for how the file should work. |
| 18 |
* |
| 19 |
* For more information, see the following discussion: |
| 20 |
* https://github.com/tommcfarlin/WordPress-Plugin-Boilerplate/pull/123#issuecomment-28541913 |
| 21 |
* |
| 22 |
* @link https://if-so.com |
| 23 |
* @since 1.0.0 |
| 24 |
* |
| 25 |
* @package IfSo |
| 26 |
*/ |
| 27 |
|
| 28 |
require_once ('services/plugin-settings-service/plugin-settings-service.class.php'); |
| 29 |
|
| 30 |
use IfSo\Services; |
| 31 |
|
| 32 |
// If uninstall not called from WordPress, then exit. |
| 33 |
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { |
| 34 |
exit; |
| 35 |
} |
| 36 |
|
| 37 |
function ifso_delete_plugin() { |
| 38 |
require_once plugin_dir_path( __FILE__ ) . 'includes/ifso-constants.php'; |
| 39 |
require_once IFSO_PLUGIN_BASE_DIR . 'services/license-service/license-service.class.php'; |
| 40 |
require_once IFSO_PLUGIN_BASE_DIR . 'services/license-service/geo-license-service.class.php'; |
| 41 |
require_once(IFSO_PLUGIN_BASE_DIR. 'public/services/analytics-service/analytics-service.class.php'); |
| 42 |
|
| 43 |
global $wpdb; |
| 44 |
|
| 45 |
$posts = get_posts( array( |
| 46 |
'numberposts' => -1, |
| 47 |
'post_type' => 'ifso_triggers', |
| 48 |
'post_status' => 'any' ) ); |
| 49 |
|
| 50 |
foreach ( $posts as $post ) { |
| 51 |
wp_delete_post( $post->ID, true ); |
| 52 |
delete_post_meta($post->ID, 'ifso_trigger_default'); |
| 53 |
delete_post_meta($post->ID, 'ifso_trigger_rules'); |
| 54 |
delete_post_meta($post->ID, 'ifso_trigger_version'); |
| 55 |
} |
| 56 |
|
| 57 |
delete_option('ifso_groups_data'); //Remove "groups" data |
| 58 |
|
| 59 |
Services\LicenseService\LicenseService::get_instance()->clear_license(); |
| 60 |
Services\GeoLicenseService\GeoLicenseService::get_instance()->clear_license(); |
| 61 |
$an_db = \IfSo\PublicFace\Services\AnalyticsService\AnalyticsService::get_instance()->records; |
| 62 |
|
| 63 |
$tables_created_by_ifso = [$an_db->conversions_table_name,$an_db->conversions_events_table_name, |
| 64 |
$an_db->conversion_urls_table_name,"{$wpdb->prefix}ifso_local_user","{$wpdb->prefix}ifso_daily_sessions"]; |
| 65 |
foreach($tables_created_by_ifso as $table){ |
| 66 |
$wpdb->query("DROP TABLE IF EXISTS {$table}"); |
| 67 |
} |
| 68 |
|
| 69 |
} |
| 70 |
|
| 71 |
function ifso_is_remove_checked() { |
| 72 |
$settings_service = Services\PluginSettingsService\PluginSettingsService::get_instance(); |
| 73 |
$to_remove = $settings_service->removePluginDataOption->get(); |
| 74 |
|
| 75 |
return $to_remove; |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
if ( ifso_is_remove_checked() ) { |
| 80 |
ifso_delete_plugin(); |
| 81 |
} |