| 1 |
<?php |
| 2 |
/** |
| 3 |
* Sellkit Uninstall |
| 4 |
* |
| 5 |
* Uninstalling Sellkit deletes tables, and options. |
| 6 |
* |
| 7 |
* @package Sellkit\Uninstaller |
| 8 |
* @version NEXT |
| 9 |
*/ |
| 10 |
|
| 11 |
defined( 'WP_UNINSTALL_PLUGIN' ) || exit; |
| 12 |
|
| 13 |
// Include file of Database Class. |
| 14 |
require_once dirname( __FILE__ ) . '/includes/db.php'; |
| 15 |
|
| 16 |
$options = get_option( 'sellkit', [] ); |
| 17 |
|
| 18 |
if ( '1' === $options['delete_data'] ) { |
| 19 |
// Drop Sellkit admin tables. |
| 20 |
Sellkit\Database::drop_all_tables(); |
| 21 |
|
| 22 |
// Delete sellkit option from wp_options. |
| 23 |
delete_option( 'sellkit' ); |
| 24 |
|
| 25 |
// Delete alls sellkit posts with their related meta fields. |
| 26 |
global $wpdb; |
| 27 |
|
| 28 |
$posts_id = $wpdb->prefix . 'posts.id'; |
| 29 |
$meta_id = $wpdb->prefix . 'postmeta.post_id'; |
| 30 |
$posts = $wpdb->prefix . 'posts'; // phpcs:ignore |
| 31 |
$meta = $wpdb->prefix . 'postmeta'; |
| 32 |
$post_type = $wpdb->prefix . 'posts.post_type'; //phpcs:ignore |
| 33 |
|
| 34 |
// phpcs:disable |
| 35 |
$wpdb->query( |
| 36 |
"DELETE $posts, $meta |
| 37 |
FROM $posts |
| 38 |
INNER JOIN $meta ON $meta_id = $posts_id |
| 39 |
WHERE $post_type IN ( 'sellkit-funnels', 'sellkit_step' )" |
| 40 |
); |
| 41 |
// phpcs:enable |
| 42 |
|
| 43 |
// Unset sellkit cookie. |
| 44 |
setcookie( 'sellkit_contact_segmentation', null, -1, '/' ); |
| 45 |
|
| 46 |
// Clear any cached data that has been removed. |
| 47 |
wp_cache_flush(); |
| 48 |
|
| 49 |
// Temporary option. |
| 50 |
update_option( 'sellkit_pro_delete_data', '1' ); |
| 51 |
} |
| 52 |
|