2018-07-11 15:37:04 -04:00
|
|
|
<?php
|
|
|
|
/**
|
2024-10-28 21:54:52 -04:00
|
|
|
* Runs on Uninstall of SLM Plus
|
2018-07-11 15:37:04 -04:00
|
|
|
*
|
2024-10-28 21:54:52 -04:00
|
|
|
* @package SLM Plus
|
2018-07-11 15:37:04 -04:00
|
|
|
* @author Michel Velis
|
|
|
|
* @license GPL-2.0+
|
|
|
|
* @link http://epikly.com
|
|
|
|
*/
|
|
|
|
|
2024-11-08 15:06:21 -05:00
|
|
|
// Exit if accessed directly
|
2020-03-17 09:56:06 -04:00
|
|
|
if (!defined('WP_UNINSTALL_PLUGIN')) {
|
2024-11-08 15:06:21 -05:00
|
|
|
exit();
|
2018-07-11 15:37:04 -04:00
|
|
|
}
|
|
|
|
|
2024-11-08 15:06:21 -05:00
|
|
|
// Check user permissions
|
2020-03-17 09:56:06 -04:00
|
|
|
if (!current_user_can('activate_plugins')) {
|
2018-07-11 15:37:04 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
global $wpdb;
|
|
|
|
|
2024-11-08 15:06:21 -05:00
|
|
|
// Delete all related options
|
2018-07-11 15:37:04 -04:00
|
|
|
$slm_options = array(
|
2019-05-13 15:14:11 -04:00
|
|
|
'slm_db_version',
|
2018-07-13 10:00:10 -04:00
|
|
|
'slm_plugin_options',
|
2024-11-08 15:06:21 -05:00
|
|
|
'slm_lic_creation_secret',
|
|
|
|
'slm_backup_dir_hash',
|
|
|
|
'slm_woo_affect_downloads',
|
|
|
|
'slm_woo_enable_my_licenses_page',
|
2018-07-11 15:37:04 -04:00
|
|
|
);
|
|
|
|
|
2020-03-17 09:56:06 -04:00
|
|
|
foreach ($slm_options as $option) {
|
2024-11-08 15:06:21 -05:00
|
|
|
delete_option($option);
|
2018-07-11 15:37:04 -04:00
|
|
|
}
|
|
|
|
|
2024-11-19 10:01:55 -05:00
|
|
|
// List all tables related to the plugin
|
2024-11-08 15:06:21 -05:00
|
|
|
$tables_to_drop = array(
|
|
|
|
$wpdb->prefix . 'lic_key_tbl',
|
|
|
|
$wpdb->prefix . 'lic_reg_domain_tbl',
|
|
|
|
$wpdb->prefix . 'lic_reg_devices_tbl',
|
|
|
|
$wpdb->prefix . 'lic_log_tbl',
|
|
|
|
$wpdb->prefix . 'slm_license_status',
|
|
|
|
$wpdb->prefix . 'slm_subscribers_tbl',
|
|
|
|
$wpdb->prefix . 'slm_activations_tbl',
|
|
|
|
);
|
|
|
|
|
2024-11-19 10:01:55 -05:00
|
|
|
// Drop custom database tables using the `prepare` method
|
2024-11-08 15:06:21 -05:00
|
|
|
foreach ($tables_to_drop as $table) {
|
2024-11-19 10:01:55 -05:00
|
|
|
// Check if the table exists before attempting to drop it
|
|
|
|
if ($wpdb->get_var($wpdb->prepare("SHOW TABLES LIKE %s", $table)) !== null) {
|
|
|
|
// Drop the table if it exists
|
2025-01-05 11:49:59 -05:00
|
|
|
$wpdb->query("DROP TABLE IF EXISTS {$table}");
|
2024-11-19 10:01:55 -05:00
|
|
|
}
|
2024-11-08 15:06:21 -05:00
|
|
|
}
|
2018-07-11 15:37:04 -04:00
|
|
|
|
2024-11-19 10:01:55 -05:00
|
|
|
// Delete Custom Post Type posts and related metadata using the `delete` method
|
2024-11-08 15:06:21 -05:00
|
|
|
$post_types = array('slm_manage_license', 'slm_license_product'); // Add any other custom post types if needed
|
|
|
|
foreach ($post_types as $post_type) {
|
2024-11-19 10:01:55 -05:00
|
|
|
// Check if post type data is cached
|
|
|
|
$cached_posts = wp_cache_get($post_type, 'slm_posts');
|
|
|
|
if ($cached_posts) {
|
|
|
|
wp_cache_delete($post_type, 'slm_posts');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Safely delete posts and metadata for this post type
|
|
|
|
$wpdb->delete($wpdb->posts, array('post_type' => $post_type));
|
|
|
|
$wpdb->delete($wpdb->postmeta, array('post_id' => $post_type));
|
2024-11-08 15:06:21 -05:00
|
|
|
}
|
|
|
|
|
2024-11-19 10:01:55 -05:00
|
|
|
// Clean orphaned postmeta entries using `DELETE` queries
|
2024-11-08 15:06:21 -05:00
|
|
|
$wpdb->query(
|
2025-01-05 11:49:59 -05:00
|
|
|
"DELETE pm FROM {$wpdb->postmeta} pm
|
|
|
|
LEFT JOIN {$wpdb->posts} p ON pm.post_id = p.ID
|
|
|
|
WHERE p.ID IS NULL"
|
2024-11-08 15:06:21 -05:00
|
|
|
);
|
2018-07-11 15:37:04 -04:00
|
|
|
|
2024-11-08 15:06:21 -05:00
|
|
|
// Clean orphaned term relationships if there are custom taxonomies involved
|
|
|
|
$wpdb->query(
|
2025-01-05 11:49:59 -05:00
|
|
|
"DELETE tr FROM {$wpdb->term_relationships} tr
|
|
|
|
LEFT JOIN {$wpdb->posts} p ON tr.object_id = p.ID
|
|
|
|
WHERE p.ID IS NULL"
|
2024-11-08 15:06:21 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
// Delete custom user meta related to the plugin (if applicable)
|
|
|
|
$user_meta_keys = array(
|
|
|
|
'slm_user_license_data',
|
|
|
|
// Add any other related user meta keys here
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach ($user_meta_keys as $meta_key) {
|
2024-11-19 10:01:55 -05:00
|
|
|
// Check if user meta data is cached
|
|
|
|
$cached_meta = wp_cache_get($meta_key, 'slm_usermeta');
|
|
|
|
if ($cached_meta) {
|
|
|
|
wp_cache_delete($meta_key, 'slm_usermeta');
|
|
|
|
}
|
|
|
|
|
|
|
|
$wpdb->delete($wpdb->usermeta, array('meta_key' => $meta_key));
|
2024-11-08 15:06:21 -05:00
|
|
|
}
|
2024-11-19 10:01:55 -05:00
|
|
|
|
|
|
|
// Clear the relevant cache after heavy operations
|
|
|
|
wp_cache_flush();
|